Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

fsdos.c

Go to the documentation of this file.
00001 /****************************************************************************************/
00002 /*  FSDOS.C                                                                             */
00003 /*                                                                                      */
00004 /*  Author: Eli Boling                                                                  */
00005 /*  Description: DOS file system implementation                                         */
00006 /*                                                                                      */
00007 /*  The contents of this file are subject to the Genesis3D Public License               */
00008 /*  Version 1.01 (the "License"); you may not use this file except in                   */
00009 /*  compliance with the License. You may obtain a copy of the License at                */
00010 /*  http://www.genesis3d.com                                                            */
00011 /*                                                                                      */
00012 /*  Software distributed under the License is distributed on an "AS IS"                 */
00013 /*  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See                */
00014 /*  the License for the specific language governing rights and limitations              */
00015 /*  under the License.                                                                  */
00016 /*                                                                                      */
00017 /*  The Original Code is Genesis3D, released March 25, 1999.                            */
00018 /*Genesis3D Version 1.1 released November 15, 1999                            */
00019 /*  Copyright (C) 1999 WildTangent, Inc. All Rights Reserved           */
00020 /*                                                                                      */
00021 /****************************************************************************************/
00022 #define WIN32_LEAN_AND_MEAN
00023 #include        <windows.h>
00024 
00025 #include        <stdio.h>
00026 #include        <stdlib.h>
00027 #include        <string.h>
00028 #include        <assert.h>
00029 
00030 #include        "basetype.h"
00031 #include        "ram.h"
00032 
00033 #include        "vfile.h"
00034 #include        "vfile._h"
00035 
00036 #include        "fsdos.h"
00037 
00038 //      "DF01"
00039 #define DOSFILE_SIGNATURE       0x31304644
00040 
00041 //      "DF02"
00042 #define DOSFINDER_SIGNATURE     0x32304644
00043 
00044 #define CHECK_HANDLE(H) assert(H);assert(H->Signature == DOSFILE_SIGNATURE);
00045 #define CHECK_FINDER(F) assert(F);assert(F->Signature == DOSFINDER_SIGNATURE);
00046 
00047 typedef struct  DosFile
00048 {
00049         unsigned int    Signature;
00050         HANDLE                  FileHandle;
00051         char *                  FullPath;
00052         const char *    Name;
00053         geBoolean               IsDirectory;
00054 }       DosFile;
00055 
00056 typedef struct  DosFinder
00057 {
00058         unsigned int    Signature;
00059         HANDLE                  FindHandle;
00060         WIN32_FIND_DATA FindData;
00061         geBoolean               FirstStillCached;
00062         int                             OffsetToName;
00063 }       DosFinder;
00064 
00065 static  geBoolean       BuildFileName(
00066         const DosFile * File,
00067         const char *    Name,
00068         char *                  Buff,
00069         char **                 NamePtr,
00070         int                     MaxLen)
00071 {
00072         int             DirLength;
00073         int             NameLength;
00074 
00075         if ( ! Name )
00076                 return GE_FALSE;
00077 
00078         if      (File)
00079         {
00080                 if      (File->IsDirectory == GE_FALSE)
00081                         return GE_FALSE;
00082 
00083                 assert(File->FullPath);
00084                 DirLength = strlen(File->FullPath);
00085 
00086                 if      (DirLength > MaxLen)
00087                         return GE_FALSE;
00088 
00089                 memcpy(Buff, File->FullPath, DirLength);
00090         }
00091         else
00092         {
00093                 DirLength = 0;
00094         }
00095 
00096         NameLength = strlen(Name);
00097         if      (DirLength + NameLength + 2 > MaxLen || ! Buff )
00098                 return GE_FALSE;
00099 
00100         if      (DirLength != 0)
00101         {
00102                 Buff[DirLength] = '\\';
00103                 memcpy(Buff + DirLength + 1, Name, NameLength + 1);
00104                 if      (NamePtr)
00105                         *NamePtr = Buff + DirLength + 1;
00106         }
00107         else
00108         {
00109                 memcpy(Buff, Name, NameLength + 1);
00110                 if      (NamePtr)
00111                         *NamePtr = Buff;
00112 
00113                 // Special case: no directory, no file name.  We meant something like ".\"
00114                 if      (!*Buff)
00115                 {
00116                         strcpy (Buff, ".\\");
00117                 }
00118         }
00119 
00120         return GE_TRUE;
00121 }
00122 
00123 static  void *  GENESISCC FSDos_FinderCreate(
00124         geVFile *                       FS,
00125         void *                  Handle,
00126         const char *    FileSpec)
00127 {
00128         DosFinder *             Finder;
00129         DosFile *               File;
00130         char *                  NamePtr;
00131         char                    Buff[_MAX_PATH];
00132 
00133         assert(FileSpec != NULL);
00134 
00135         File = Handle;
00136 
00137         CHECK_HANDLE(File);
00138 
00139         Finder = geRam_Allocate(sizeof(*Finder));
00140         if      (!Finder)
00141                 return NULL;
00142 
00143         memset(Finder, 0, sizeof(*Finder));
00144 
00145         if      (BuildFileName(File, FileSpec, Buff, &NamePtr, sizeof(Buff)) == GE_FALSE)
00146         {
00147                 geRam_Free(Finder);
00148                 return NULL;
00149         }
00150 
00151         Finder->OffsetToName = NamePtr - Buff;
00152 
00153         Finder->FindHandle = FindFirstFile(Buff, &Finder->FindData);
00154 
00155         Finder->FirstStillCached = GE_TRUE;
00156 
00157         Finder->Signature = DOSFINDER_SIGNATURE;
00158         return (void *)Finder;
00159 }
00160 
00161 static  geBoolean       GENESISCC FSDos_FinderGetNextFile(void *Handle)
00162 {
00163         DosFinder *     Finder;
00164 
00165         Finder = Handle;
00166 
00167         CHECK_FINDER(Finder);
00168 
00169         if      (Finder->FindHandle == INVALID_HANDLE_VALUE)
00170                 return GE_FALSE;
00171 
00172         if      (Finder->FirstStillCached == GE_TRUE)
00173         {
00174                 Finder->FirstStillCached = GE_FALSE;
00175 
00176                 if      (Finder->FindData.cFileName[0] != '.')
00177                         return GE_TRUE;
00178         }
00179         
00180         while   (FindNextFile(Finder->FindHandle, &Finder->FindData) == TRUE)
00181         {
00182                 if      (Finder->FindData.cFileName[0] != '.')
00183                         return GE_TRUE;
00184         }
00185 
00186         return GE_FALSE;
00187 }
00188 
00189 static  geBoolean       GENESISCC FSDos_FinderGetProperties(void *Handle, geVFile_Properties *Props)
00190 {
00191         DosFinder *                     Finder;
00192         geVFile_Attributes      Attribs;
00193         int                                     Length;
00194 
00195         assert(Props);
00196 
00197         Finder = Handle;
00198 
00199         CHECK_FINDER(Finder);
00200 
00201         if      (Finder->FindHandle == INVALID_HANDLE_VALUE)
00202                 return GE_FALSE;
00203 
00204         Attribs = 0;
00205         if      (Finder->FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
00206                 Attribs |= GE_VFILE_ATTRIB_DIRECTORY;
00207         if      (Finder->FindData.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
00208                 Attribs |= GE_VFILE_ATTRIB_READONLY;
00209 
00210         Props->Time.Time1 = Finder->FindData.ftLastWriteTime.dwLowDateTime;
00211         Props->Time.Time2 = Finder->FindData.ftLastWriteTime.dwHighDateTime;
00212 
00213         Props->AttributeFlags = Attribs;
00214         Props->Size = Finder->FindData.nFileSizeLow;
00215         Props->Hints.HintData = NULL;
00216         Props->Hints.HintDataLength = 0;
00217 
00218         Length = strlen(Finder->FindData.cFileName);
00219         if      (Length > sizeof(Props->Name) - 1)
00220                 return GE_FALSE;
00221         memcpy(Props->Name, Finder->FindData.cFileName, Length + 1);
00222 
00223         return GE_TRUE;
00224 }
00225 
00226 static  void GENESISCC FSDos_FinderDestroy(void *Handle)
00227 {
00228         DosFinder *     Finder;
00229 
00230         Finder = Handle;
00231 
00232         CHECK_FINDER(Finder);
00233 
00234         if      (Finder->FindHandle != INVALID_HANDLE_VALUE)
00235                 FindClose(Finder->FindHandle);
00236 
00237         Finder->Signature = 0;
00238         geRam_Free(Finder);
00239 }
00240 
00241 // Terrible function.  It mutated, and now it modifies its argument.
00242 static  geBoolean       IsRootDirectory(char *Path)
00243 {
00244         int             SlashCount;
00245 
00246         // Drive letter test
00247         if      (Path[1] == ':' && Path[2] == '\\' && Path[3] == '\0')
00248         {
00249                 Path[2] = '\0';
00250                 return GE_TRUE;
00251         }
00252 
00253         // Now UNC path test
00254         SlashCount = 0;
00255         if      (Path[0] == '\\' && Path[1] == '\\')
00256         {
00257                 Path += 2;
00258                 while   (*Path)
00259                 {
00260                         if      (*Path++ == '\\')
00261                                 SlashCount++;
00262                 }
00263         }
00264 
00265         if      (SlashCount == 1)
00266                 return GE_TRUE;
00267 
00268         return GE_FALSE;
00269 }
00270 
00271 static  void *  GENESISCC FSDos_Open(
00272         geVFile *               FS,
00273         void *                  Handle,
00274         const char *    Name,
00275         void *                  Context,
00276         unsigned int    OpenModeFlags)
00277 {
00278         DosFile *       DosFS;
00279         DosFile *       NewFile;
00280         char            Buff[_MAX_PATH];
00281         int                     Length;
00282         char *          NamePtr;
00283 
00284         DosFS = Handle;
00285 
00286         if      (DosFS && DosFS->IsDirectory != GE_TRUE)
00287                 return NULL;
00288 
00289         NewFile = geRam_Allocate(sizeof(*NewFile));
00290         if      (!NewFile)
00291                 return NewFile;
00292 
00293         memset(NewFile, 0, sizeof(*NewFile));
00294 
00295         if      (BuildFileName(DosFS, Name, Buff, &NamePtr, sizeof(Buff)) == GE_FALSE)
00296                 goto fail;
00297 
00298         Length = strlen(Buff);
00299         NewFile->FullPath = geRam_Allocate(Length + 1);
00300         if      (!NewFile->FullPath)
00301                 goto fail;
00302 
00303         NewFile->Name = NewFile->FullPath + (NamePtr - &Buff[0]);
00304 
00305         memcpy(NewFile->FullPath, Buff, Length + 1);
00306 
00307         if      (OpenModeFlags & GE_VFILE_OPEN_DIRECTORY)
00308         {
00309                 WIN32_FIND_DATA FileInfo;
00310                 HANDLE                  FindHandle;
00311                 geBoolean               IsDirectory;
00312 
00313                 assert(!DosFS || DosFS->IsDirectory == GE_TRUE);
00314 
00315                 memset(&FileInfo, 0, sizeof(FileInfo));
00316                 FindHandle = FindFirstFile(NewFile->FullPath, &FileInfo);
00317                 if      (FindHandle != INVALID_HANDLE_VALUE &&
00318                          FileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
00319                 {
00320                         IsDirectory = GE_TRUE;
00321                 }
00322                 else
00323                 {
00324                         IsDirectory = IsRootDirectory(NewFile->FullPath);
00325                 }
00326 
00327                 FindClose (FindHandle);
00328 
00329                 if      (OpenModeFlags & GE_VFILE_OPEN_CREATE)
00330                 {
00331                         if      (IsDirectory == GE_TRUE)
00332                                 goto fail;
00333 
00334                         if      (CreateDirectory(NewFile->FullPath, NULL) == FALSE)
00335                                 goto fail;
00336                 }
00337                 else
00338                 {
00339                         if      (IsDirectory != GE_TRUE)
00340                                 goto fail;
00341                 }
00342 
00343                 NewFile->IsDirectory = GE_TRUE;
00344                 NewFile->FileHandle = INVALID_HANDLE_VALUE;
00345         }
00346         else
00347         {
00348                 DWORD                   ShareMode=0;
00349                 DWORD                   CreationMode;
00350                 DWORD                   Access=0;
00351                 DWORD                   LastError;
00352 
00353                 CreationMode = OPEN_EXISTING;
00354 
00355                 switch  (OpenModeFlags & (GE_VFILE_OPEN_READONLY |
00356                                                                   GE_VFILE_OPEN_UPDATE   |
00357                                                                   GE_VFILE_OPEN_CREATE))
00358                 {
00359                 case    GE_VFILE_OPEN_READONLY:
00360                         Access = GENERIC_READ;
00361                         ShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
00362                         break;
00363 
00364                 case    GE_VFILE_OPEN_CREATE:
00365                         CreationMode = CREATE_ALWAYS;
00366                         // Fall through
00367 
00368                 case    GE_VFILE_OPEN_UPDATE:
00369                         Access = GENERIC_READ | GENERIC_WRITE;
00370                         ShareMode = FILE_SHARE_READ;
00371                         break;
00372 
00373                 default:
00374                         assert(!"Illegal open mode flags");
00375                         break;
00376                 }
00377 
00378                 NewFile->FileHandle = CreateFile(NewFile->FullPath,
00379                                                                                  Access,
00380                                                                                  ShareMode,
00381                                                                                  NULL,
00382                                                                                  CreationMode,
00383                                                                                  0,
00384                                                                                  NULL);
00385                 if      (NewFile->FileHandle == INVALID_HANDLE_VALUE)
00386                         {
00387                                 LastError = GetLastError();
00388                                 goto fail;
00389                         }
00390         }
00391 
00392         NewFile->Signature = DOSFILE_SIGNATURE;
00393 
00394         return (void *)NewFile;
00395 
00396 fail:
00397         if      (NewFile->FullPath)
00398                 geRam_Free(NewFile->FullPath);
00399         geRam_Free(NewFile);
00400         return NULL;
00401 }
00402 
00403 static  void *  GENESISCC FSDos_OpenNewSystem(
00404         geVFile *                       FS,
00405         const char *    Name,
00406         void *                  Context,
00407         unsigned int    OpenModeFlags)
00408 {
00409         return FSDos_Open(FS, NULL, Name, Context, OpenModeFlags);
00410 }
00411 
00412 static  geBoolean       GENESISCC FSDos_UpdateContext(
00413         geVFile *               FS,
00414         void *                  Handle,
00415         void *                  Context,
00416         int                     ContextSize)
00417 {
00418         return GE_FALSE;
00419 }
00420 
00421 static  void    GENESISCC FSDos_Close(void *Handle)
00422 {
00423         DosFile *       File;
00424         
00425         File = Handle;
00426         
00427         CHECK_HANDLE(File);
00428 
00429         if      (File->IsDirectory == GE_FALSE)
00430         {
00431                 assert(File->FileHandle != INVALID_HANDLE_VALUE);
00432 
00433                 CloseHandle(File->FileHandle);
00434         }
00435         
00436         assert(File->FullPath);
00437         File->Signature = 0;
00438         geRam_Free(File->FullPath);
00439         geRam_Free(File);
00440 }
00441 
00442 static  geBoolean       GENESISCC FSDos_GetS(void *Handle, void *Buff, int MaxLen)
00443 {
00444         DosFile *       File;
00445         DWORD           BytesRead;
00446         BOOL            Result;
00447         char *          p;
00448         char *          End;
00449 
00450         assert(Buff);
00451         assert(MaxLen != 0);
00452 
00453         File = Handle;
00454 
00455         CHECK_HANDLE(File);
00456 
00457         assert(File->FileHandle != INVALID_HANDLE_VALUE);
00458 
00459         if      (File->IsDirectory == GE_TRUE)
00460                 return GE_FALSE;
00461 
00462         Result = ReadFile(File->FileHandle, Buff, MaxLen - 1, &BytesRead, NULL);
00463         if      (BytesRead == 0)
00464         {
00465 #if 0
00466                 if      (Result == FALSE)
00467                         return GE_FALSE;
00468                 
00469                 // The Win32 API is vague about this, so we're being weird with the asserts
00470                 assert(Result != TRUE);
00471 #endif
00472                 return GE_FALSE;
00473         }
00474 
00475         End = (char *)Buff + BytesRead;
00476         p = Buff;
00477         while   (p < End)
00478         {
00479                 /*
00480                   This code will terminate a line on one of three conditions:
00481                         \r      Character changed to \n, next char set to 0
00482                         \n      Next char set to 0
00483                         \r\n    First \r changed to \n.  \n changed to 0.
00484                 */
00485                 if      (*p == '\r')
00486                 {
00487                         int Skip = 0;
00488                         
00489                         *p = '\n';              // set end of line
00490                         p++;                    // and skip to next char
00491                         // If the next char is a newline, then skip it too  (\r\n case)
00492                         if (*p == '\n')
00493                         {
00494                                 Skip = 1;
00495                         }
00496                         *p = '\0';
00497                         // Set the file pointer back a bit since we probably overran
00498                         SetFilePointer(File->FileHandle, -(int)(BytesRead - ((p + Skip) - (char *)Buff)), NULL, FILE_CURRENT); 
00499                         assert(p - (char *)Buff <= MaxLen);
00500                         return GE_TRUE;
00501                 }
00502                 else if (*p == '\n')
00503                 {
00504                         // Set the file pointer back a bit since we probably overran
00505                         p++;
00506                         SetFilePointer(File->FileHandle, -(int)(BytesRead - (p - (char *)Buff)), NULL, FILE_CURRENT); 
00507                         *p = '\0';
00508                         assert(p - (char *)Buff <= MaxLen);
00509                         return GE_TRUE;
00510                 }
00511                 p++;
00512         }
00513 
00514         return GE_FALSE;
00515 }
00516 
00517 
00518 static  geBoolean       GENESISCC FSDos_Read(void *Handle, void *Buff, int Count)
00519 {
00520         DosFile *       File;
00521         DWORD           BytesRead;
00522 
00523         assert(Buff);
00524         assert(Count != 0);
00525 
00526         File = Handle;
00527 
00528         CHECK_HANDLE(File);
00529 
00530         if      (File->IsDirectory == GE_TRUE)
00531                 return GE_FALSE;
00532 
00533 #ifdef  ELIDEBUG
00534 {
00535         FILE *  fp;
00536         long    Position;
00537 
00538         Position = SetFilePointer(File->FileHandle, 0, NULL, FILE_CURRENT);
00539         fp = fopen("c:\\vfs.eli", "ab+");
00540         fprintf(fp, "FSDos_Read: %-8d bytes @ %-8d\r\n", Count, Position);
00541         fclose(fp);
00542 }
00543 #endif
00544 
00545         if      (ReadFile(File->FileHandle, Buff, Count, &BytesRead, NULL) == FALSE)
00546                 return GE_FALSE;
00547 
00548         if      (BytesRead == 0)
00549                 return GE_FALSE;
00550 
00551         return GE_TRUE;
00552 }
00553 
00554 static  geBoolean       GENESISCC FSDos_Write(void *Handle, const void *Buff, int Count)
00555 {
00556         DosFile *       File;
00557         DWORD           BytesWritten;
00558 
00559         assert(Buff);
00560         assert(Count != 0);
00561 
00562         File = Handle;
00563 
00564         CHECK_HANDLE(File);
00565 
00566         if      (File->IsDirectory == GE_TRUE)
00567                 return GE_FALSE;
00568 
00569 #ifdef  ELIDEBUG
00570 {
00571         FILE *  fp;
00572         long    Position;
00573 
00574         Position = SetFilePointer(File->FileHandle, 0, NULL, FILE_CURRENT);
00575         fp = fopen("c:\\vfs.eli", "ab+");
00576         fprintf(fp, "FSDos_Write: %-8d bytes @ %-8d\r\n", Count, Position);
00577         fclose(fp);
00578 }
00579 #endif
00580 
00581         if      (WriteFile(File->FileHandle, Buff, Count, &BytesWritten, NULL) == FALSE)
00582                 return GE_FALSE;
00583 
00584         if      ((int)BytesWritten != Count)
00585                 return GE_FALSE;
00586 
00587         return GE_TRUE;
00588 }
00589 
00590 static  geBoolean       GENESISCC FSDos_Seek(void *Handle, int Where, geVFile_Whence Whence)
00591 {
00592         int                     RTLWhence=0;
00593         DosFile *       File;
00594 
00595         File = Handle;
00596 
00597         CHECK_HANDLE(File);
00598 
00599         if      (File->IsDirectory == GE_TRUE)
00600                 return GE_FALSE;
00601 
00602         switch  (Whence)
00603         {
00604         case    GE_VFILE_SEEKCUR:
00605                 RTLWhence = FILE_CURRENT;
00606                 break;
00607 
00608         case    GE_VFILE_SEEKEND:
00609                 RTLWhence = FILE_END;
00610                 break;
00611 
00612         case    GE_VFILE_SEEKSET:
00613                 RTLWhence = FILE_BEGIN;
00614                 break;
00615         default:
00616                 assert(!"Unknown seek kind");
00617         }
00618 
00619         if      (SetFilePointer(File->FileHandle, Where, NULL, RTLWhence) == 0xffffffff)
00620                 return GE_FALSE;
00621 
00622         return GE_TRUE;
00623 }
00624 
00625 static  geBoolean       GENESISCC FSDos_EOF(const void *Handle)
00626 {
00627         const DosFile * File;
00628         DWORD                   CurPos;
00629 
00630         File = Handle;
00631 
00632         CHECK_HANDLE(File);
00633 
00634         if      (File->IsDirectory == GE_TRUE)
00635                 return GE_FALSE;
00636 
00637         assert(File->FileHandle != INVALID_HANDLE_VALUE);
00638 
00639         CurPos = SetFilePointer(File->FileHandle, 0, NULL, FILE_CURRENT);
00640         assert(CurPos != 0xffffffff);
00641 
00642         if      (CurPos == GetFileSize(File->FileHandle, NULL))
00643                 return GE_TRUE;
00644 
00645         return GE_FALSE;
00646 }
00647 
00648 static  geBoolean       GENESISCC FSDos_Tell(const void *Handle, long *Position)
00649 {
00650         const DosFile * File;
00651 
00652         File = Handle;
00653 
00654         CHECK_HANDLE(File);
00655 
00656         if      (File->IsDirectory == GE_TRUE)
00657                 return GE_FALSE;
00658 
00659         assert(File->FileHandle != INVALID_HANDLE_VALUE);
00660 
00661         *Position = SetFilePointer(File->FileHandle, 0, NULL, FILE_CURRENT);
00662         if      (*Position == -1L)
00663                 return GE_FALSE;
00664 
00665         return GE_TRUE;
00666 }
00667 
00668 static  geBoolean       GENESISCC FSDos_Size(const void *Handle, long *Size)
00669 {
00670         const DosFile * File;
00671 
00672         File = Handle;
00673 
00674         CHECK_HANDLE(File);
00675 
00676         if      (File->IsDirectory == GE_TRUE)
00677                 return GE_FALSE;
00678 
00679         assert(File->FileHandle != INVALID_HANDLE_VALUE);
00680 
00681         *Size = GetFileSize(File->FileHandle, NULL);
00682         if      (*Size != (long)0xffffffff)
00683                 return GE_TRUE;
00684 
00685         return GE_FALSE;
00686 }
00687 
00688 static  geBoolean       GENESISCC FSDos_GetProperties(const void *Handle, geVFile_Properties *Properties)
00689 {
00690         const DosFile *                         File;
00691         geVFile_Attributes                      Attribs;
00692         BY_HANDLE_FILE_INFORMATION      Info;
00693         int                                                     Length;
00694 
00695         assert(Properties);
00696 
00697         File = Handle;
00698 
00699         CHECK_HANDLE(File);
00700 
00701         if      (File->IsDirectory == GE_TRUE)
00702         {
00703                 memset(Properties, 0, sizeof(*Properties));
00704                 Properties->AttributeFlags = FILE_ATTRIBUTE_DIRECTORY;
00705 #pragma message ("FSDos_GetProperties: Time support is not there for directories")
00706         }
00707         else
00708         {
00709                 assert(File->FileHandle != INVALID_HANDLE_VALUE);
00710         
00711                 if      (GetFileInformationByHandle(File->FileHandle, &Info) == FALSE)
00712                         return GE_FALSE;
00713         
00714                 Attribs = 0;
00715                 if      (Info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
00716                         Attribs |= GE_VFILE_ATTRIB_DIRECTORY;
00717                 if      (Info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
00718                         Attribs |= GE_VFILE_ATTRIB_READONLY;
00719         
00720                 Properties->Time.Time1 = Info.ftLastWriteTime.dwLowDateTime;
00721                 Properties->Time.Time2 = Info.ftLastWriteTime.dwHighDateTime;
00722         
00723                 Properties->AttributeFlags               = Attribs;
00724                 Properties->Size                                 = Info.nFileSizeLow;
00725                 Properties->Hints.HintData               = NULL;
00726                 Properties->Hints.HintDataLength = 0;
00727         }
00728 
00729         Length = strlen(File->Name) + 1;
00730         if      (Length > sizeof(Properties->Name))
00731                 return GE_FALSE;
00732         memcpy(Properties->Name, File->Name, Length);
00733 
00734         return GE_TRUE;
00735 }
00736 
00737 static  geBoolean       GENESISCC FSDos_SetSize(void *Handle, long size)
00738 {
00739         DosFile *       File;
00740 
00741         File = Handle;
00742 
00743         CHECK_HANDLE(File);
00744 
00745         if      (File->IsDirectory == GE_FALSE)
00746         {
00747                 assert(File->FileHandle != INVALID_HANDLE_VALUE);
00748         
00749                 if      (SetFilePointer(File->FileHandle, 0, NULL, FILE_END) == 0xffffffff)
00750                         return GE_FALSE;
00751         
00752                 if      (SetEndOfFile(File->FileHandle) == FALSE)
00753                         return GE_FALSE;
00754         }
00755 
00756         return GE_FALSE;
00757 }
00758 
00759 static  geBoolean       GENESISCC FSDos_SetAttributes(void *Handle, geVFile_Attributes Attributes)
00760 {
00761         DosFile *       File;
00762         DWORD           Win32Attributes;
00763 
00764         File = Handle;
00765 
00766         CHECK_HANDLE(File);
00767 
00768         assert(File->FileHandle != INVALID_HANDLE_VALUE);
00769 
00770         if      (File->IsDirectory == GE_TRUE)
00771                 return GE_FALSE;
00772 
00773         if      (Attributes & GE_VFILE_ATTRIB_READONLY)
00774                 Win32Attributes = FILE_ATTRIBUTE_READONLY;
00775         else
00776                 Win32Attributes = FILE_ATTRIBUTE_NORMAL;
00777 
00778         if      (SetFileAttributes(File->FullPath, Win32Attributes) == FALSE)
00779                 return GE_FALSE;
00780 
00781         return GE_TRUE;
00782 }
00783 
00784 static  geBoolean       GENESISCC FSDos_SetTime(void *Handle, const geVFile_Time *Time)
00785 {
00786         DosFile *       File;
00787         FILETIME        Win32Time;
00788 
00789         File = Handle;
00790 
00791         CHECK_HANDLE(File);
00792 
00793         assert(File->FileHandle != INVALID_HANDLE_VALUE);
00794 
00795         Win32Time.dwLowDateTime  = Time->Time1;
00796         Win32Time.dwHighDateTime = Time->Time2;
00797         if      (SetFileTime(File->FileHandle, &Win32Time, &Win32Time, &Win32Time) == FALSE)
00798                 return GE_FALSE;
00799 
00800         return GE_TRUE;
00801 }
00802 
00803 static  geBoolean       GENESISCC FSDos_SetHints(void *Handle, const geVFile_Hints *Hints)
00804 {
00805         DosFile *       File;
00806 
00807         File = Handle;
00808 
00809         CHECK_HANDLE(File);
00810 
00811         assert(File->FileHandle != INVALID_HANDLE_VALUE);
00812 
00813         return GE_FALSE;
00814 }
00815 
00816 static  geBoolean       GENESISCC FSDos_FileExists(geVFile *FS, void *Handle, const char *Name)
00817 {
00818         DosFile *       File;
00819         char            Buff[_MAX_PATH];
00820 
00821         File = Handle;
00822 
00823         if      (File && File->IsDirectory == GE_FALSE)
00824                 return GE_FALSE;
00825 
00826         if      (BuildFileName(File, Name, Buff, NULL, sizeof(Buff)) == GE_FALSE)
00827                 return GE_FALSE;
00828 
00829         if      (GetFileAttributes(Buff) == 0xffffffff)
00830                 return GE_FALSE;
00831 
00832         return GE_TRUE;
00833 }
00834 
00835 static  geBoolean       GENESISCC FSDos_Disperse(
00836         geVFile *               FS,
00837         void *          Handle,
00838         const char *Directory,
00839         geBoolean       Recursive)
00840 {
00841         return GE_FALSE;
00842 }
00843 
00844 static  geBoolean       GENESISCC FSDos_DeleteFile(geVFile *FS, void *Handle, const char *Name)
00845 {
00846         DosFile *       File;
00847         char            Buff[_MAX_PATH];
00848 
00849         File = Handle;
00850 
00851         if      (File && File->IsDirectory == GE_FALSE)
00852                 return GE_FALSE;
00853 
00854         if      (BuildFileName(File, Name, Buff, NULL, sizeof(Buff)) == GE_FALSE)
00855                 return GE_FALSE;
00856 
00857         if      (DeleteFile(Buff) == FALSE)
00858                 return GE_FALSE;
00859 
00860         return GE_TRUE;
00861 }
00862 
00863 static  geBoolean       GENESISCC FSDos_RenameFile(geVFile *FS, void *Handle, const char *Name, const char *NewName)
00864 {
00865         DosFile *       File;
00866         char            Old[_MAX_PATH];
00867         char            New[_MAX_PATH];
00868 
00869         File = Handle;
00870 
00871         if      (File && File->IsDirectory == GE_FALSE)
00872                 return GE_FALSE;
00873 
00874         if      (BuildFileName(File, Name, Old, NULL, sizeof(Old)) == GE_FALSE)
00875                 return GE_FALSE;
00876 
00877         if      (BuildFileName(File, NewName, New, NULL, sizeof(New)) == GE_FALSE)
00878                 return GE_FALSE;
00879 
00880         if      (MoveFile(Old, New) == FALSE)
00881                 return GE_FALSE;
00882 
00883         return GE_TRUE;
00884 }
00885 
00886 static  geVFile_SystemAPIs      FSDos_APIs =
00887 {
00888         FSDos_FinderCreate,
00889         FSDos_FinderGetNextFile,
00890         FSDos_FinderGetProperties,
00891         FSDos_FinderDestroy,
00892 
00893         FSDos_OpenNewSystem,
00894         FSDos_UpdateContext,
00895         FSDos_Open,
00896         FSDos_DeleteFile,
00897         FSDos_RenameFile,
00898         FSDos_FileExists,
00899         FSDos_Disperse,
00900         FSDos_Close,
00901 
00902         FSDos_GetS,
00903         FSDos_Read,
00904         FSDos_Write,
00905         FSDos_Seek,
00906         FSDos_EOF,
00907         FSDos_Tell,
00908         FSDos_Size,
00909 
00910         FSDos_GetProperties,
00911 
00912         FSDos_SetSize,
00913         FSDos_SetAttributes,
00914         FSDos_SetTime,
00915         FSDos_SetHints,
00916 };
00917 
00918 const geVFile_SystemAPIs *GENESISCC FSDos_GetAPIs(void)
00919 {
00920         return &FSDos_APIs;
00921 }
00922 

Generated on Tue Sep 30 12:35:44 2003 for GTestAndEngine by doxygen 1.3.2