#include <windows.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <assert.h>#include "basetype.h"#include "ram.h"#include "vfile.h"#include "vfile._h"#include "fsmemory.h"Go to the source code of this file.
Compounds | |
| struct | MemoryFile |
Defines | |
| #define | WIN32_LEAN_AND_MEAN |
| #define | MEMORYFILE_SIGNATURE 0x3130464D |
| #define | MEMORYFINDER_SIGNATURE 0x3230464D |
| #define | CHECK_HANDLE(H) assert(H);assert(H->Signature == MEMORYFILE_SIGNATURE); |
| #define | CHECK_FINDER(F) assert(F);assert(F->Signature == MEMORYFINDER_SIGNATURE); |
| #define | MEMORY_FILE_GROW 0x2000 |
Typedefs | |
| typedef MemoryFile | MemoryFile |
Functions | |
| void *GENESISCC | FSMemory_FinderCreate (geVFile *FS, void *Handle, const char *FileSpec) |
| geBoolean GENESISCC | FSMemory_FinderGetNextFile (void *Handle) |
| geBoolean GENESISCC | FSMemory_FinderGetProperties (void *Handle, geVFile_Properties *Props) |
| void GENESISCC | FSMemory_FinderDestroy (void *Handle) |
| void *GENESISCC | FSMemory_Open (geVFile *FS, void *Handle, const char *Name, void *Context, unsigned int OpenModeFlags) |
| void *GENESISCC | FSMemory_OpenNewSystem (geVFile *FS, const char *Name, void *Context, unsigned int OpenModeFlags) |
| geBoolean GENESISCC | FSMemory_UpdateContext (geVFile *FS, void *Handle, void *Context, int ContextSize) |
| void GENESISCC | FSMemory_Close (void *Handle) |
| int GENESISCC | ClampOperationSize (const MemoryFile *File, int Size) |
| char *GENESISCC | DataPtr (const MemoryFile *File) |
| geBoolean GENESISCC | FSMemory_GetS (void *Handle, void *Buff, int MaxLen) |
| geBoolean GENESISCC | FSMemory_Read (void *Handle, void *Buff, int Count) |
| geBoolean GENESISCC | TestForExpansion (MemoryFile *File, int Size) |
| geBoolean GENESISCC | FSMemory_Write (void *Handle, const void *Buff, int Count) |
| geBoolean GENESISCC | FSMemory_Seek (void *Handle, int Where, geVFile_Whence Whence) |
| geBoolean GENESISCC | FSMemory_EOF (const void *Handle) |
| geBoolean GENESISCC | FSMemory_Tell (const void *Handle, long *Position) |
| geBoolean GENESISCC | FSMemory_Size (const void *Handle, long *Size) |
| geBoolean GENESISCC | FSMemory_GetProperties (const void *Handle, geVFile_Properties *Properties) |
| geBoolean GENESISCC | FSMemory_SetSize (void *Handle, long Size) |
| geBoolean GENESISCC | FSMemory_SetAttributes (void *Handle, geVFile_Attributes Attributes) |
| geBoolean GENESISCC | FSMemory_SetTime (void *Handle, const geVFile_Time *Time) |
| geBoolean GENESISCC | FSMemory_SetHints (void *Handle, const geVFile_Hints *Hints) |
| geBoolean GENESISCC | FSMemory_FileExists (geVFile *FS, void *Handle, const char *Name) |
| geBoolean GENESISCC | FSMemory_Disperse (geVFile *FS, void *Handle, const char *Directory, geBoolean Recursive) |
| geBoolean GENESISCC | FSMemory_DeleteFile (geVFile *FS, void *Handle, const char *Name) |
| geBoolean GENESISCC | FSMemory_RenameFile (geVFile *FS, void *Handle, const char *Name, const char *NewName) |
| const geVFile_SystemAPIs *GENESISCC | FSMemory_GetAPIs (void) |
Variables | |
| geVFile_SystemAPIs | FSMemory_APIs |
|
|
Definition at line 46 of file FSMEMORY.C. |
|
|
Definition at line 45 of file FSMEMORY.C. |
|
|
Definition at line 48 of file FSMEMORY.C. Referenced by TestForExpansion(). |
|
|
Definition at line 40 of file FSMEMORY.C. Referenced by FSMemory_OpenNewSystem(). |
|
|
Definition at line 43 of file FSMEMORY.C. |
|
|
Definition at line 23 of file FSMEMORY.C. |
|
|
|
|
||||||||||||
|
Definition at line 185 of file FSMEMORY.C. References GENESISCC, min, MemoryFile::Position, and MemoryFile::Size.
|
|
|
Definition at line 190 of file FSMEMORY.C. References GENESISCC, MemoryFile::Memory, and MemoryFile::Position. Referenced by FSMemory_GetS(), FSMemory_Read(), and FSMemory_Write().
|
|
|
Definition at line 172 of file FSMEMORY.C. References CHECK_HANDLE, GE_TRUE, GENESISCC, geRam_Free, MemoryFile::Memory, and MemoryFile::WeOwnMemory.
00173 {
00174 MemoryFile * File;
00175
00176 File = Handle;
00177
00178 CHECK_HANDLE(File);
00179
00180 if (File->WeOwnMemory == GE_TRUE && File->Memory)
00181 geRam_Free(File->Memory);
00182 geRam_Free(File);
00183 }
|
|
||||||||||||||||
|
Definition at line 459 of file FSMEMORY.C. References GE_FALSE, geBoolean, and GENESISCC.
00460 {
00461 return GE_FALSE;
00462 }
|
|
||||||||||||||||||||
|
Definition at line 450 of file FSMEMORY.C. References GE_FALSE, geBoolean, and GENESISCC.
00455 {
00456 return GE_FALSE;
00457 }
|
|
|
Definition at line 375 of file FSMEMORY.C. References CHECK_HANDLE, GE_FALSE, GE_TRUE, geBoolean, GENESISCC, MemoryFile::Position, and MemoryFile::Size.
00376 {
00377 const MemoryFile * File;
00378
00379 File = Handle;
00380
00381 CHECK_HANDLE(File);
00382
00383 if (File->Position == File->Size)
00384 return GE_TRUE;
00385
00386 return GE_FALSE;
00387 }
|
|
||||||||||||||||
|
Definition at line 445 of file FSMEMORY.C. References GE_FALSE, geBoolean, and GENESISCC.
00446 {
00447 return GE_FALSE;
00448 }
|
|
||||||||||||||||
|
Definition at line 61 of file FSMEMORY.C. References GENESISCC, and NULL.
00065 {
00066 return NULL;
00067 }
|
|
|
Definition at line 81 of file FSMEMORY.C. References GENESISCC.
00082 {
00083 assert(!Handle);
00084 }
|
|
|
Definition at line 69 of file FSMEMORY.C. References GE_FALSE, geBoolean, and GENESISCC.
00070 {
00071 assert(!Handle);
00072 return GE_FALSE;
00073 }
|
|
||||||||||||
|
Definition at line 75 of file FSMEMORY.C. References GE_FALSE, geBoolean, and GENESISCC.
00076 {
00077 assert(!Handle);
00078 return GE_FALSE;
00079 }
|
|
|
Definition at line 501 of file FSMEMORY.C. References FSMemory_APIs, and GENESISCC. Referenced by RegisterBuiltInAPIs().
00502 {
00503 return &FSMemory_APIs;
00504 }
|
|
||||||||||||
|
Definition at line 415 of file FSMEMORY.C. References GE_FALSE, geBoolean, and GENESISCC.
00416 {
00417 assert(!"Not implemented");
00418 return GE_FALSE;
00419 }
|
|
||||||||||||||||
|
Definition at line 195 of file FSMEMORY.C. References MemoryFile::AllocatedSize, CHECK_HANDLE, ClampOperationSize(), DataPtr(), GE_FALSE, GE_TRUE, geBoolean, GENESISCC, MemoryFile::Position, and MemoryFile::Size.
00196 {
00197 MemoryFile * File;
00198 char * p;
00199 char * Start;
00200 char * pBuff;
00201
00202 assert(Buff);
00203 assert(MaxLen != 0);
00204
00205 File = Handle;
00206
00207 CHECK_HANDLE(File);
00208
00209 MaxLen = ClampOperationSize(File, MaxLen);
00210 if (MaxLen == 0)
00211 return GE_FALSE;
00212
00213 p = DataPtr(File);
00214 pBuff = Buff;
00215 Start = p;
00216
00217 //---------
00218 // Bug fix thanks to Tim Brengle
00219 //---------
00220
00221 //while (*p != '\n' && MaxLen > 0)
00222 while (*p != '\n' && MaxLen > 1)
00223 {
00224 *pBuff++ = *p++;
00225 MaxLen--;
00226 }
00227
00228 File->Position += p - Start + 1;
00229 assert(File->Position <= File->Size);
00230 assert(File->Size <= File->AllocatedSize);
00231
00232 #if 0
00233 if (MaxLen != 0)
00234 {
00235 *pBuff = *p;
00236 return GE_TRUE;
00237 }
00238 return GE_FALSE;
00239 #endif
00240
00241 *(pBuff + 1) = 0;
00242 return GE_TRUE;
00243
00244 }
|
|
||||||||||||||||||||||||
|
Definition at line 86 of file FSMEMORY.C. References GENESISCC, and NULL.
00092 {
00093 return NULL;
00094 }
|
|
||||||||||||||||||||
|
Definition at line 96 of file FSMEMORY.C. References MemoryFile::AllocatedSize, geVFile_MemoryContext::Data, geVFile_MemoryContext::DataLength, GE_FALSE, GE_TRUE, GE_VFILE_OPEN_CREATE, GE_VFILE_OPEN_DIRECTORY, GE_VFILE_OPEN_UPDATE, GENESISCC, geRam_Allocate, MemoryFile::Memory, MEMORYFILE_SIGNATURE, NULL, MemoryFile::ReadOnly, MemoryFile::Signature, MemoryFile::Size, and MemoryFile::WeOwnMemory.
00101 {
00102 MemoryFile * NewFS;
00103 geVFile_MemoryContext * MemContext;
00104
00105 if (FS || Name || !Context)
00106 return NULL;
00107
00108 MemContext = Context;
00109
00110 // Don't allow the user to pass in memory pointer if we're updating or creating, because
00111 // we don't know what allocation functions we should use to resize their block if
00112 // necessary. If you want to create a new file, you have to pass in NULL and let
00113 // us manage the allocations.
00114 if (MemContext->Data && (OpenModeFlags & (GE_VFILE_OPEN_UPDATE | GE_VFILE_OPEN_CREATE)))
00115 return NULL;
00116
00117 if (OpenModeFlags & GE_VFILE_OPEN_DIRECTORY)
00118 return NULL;
00119
00120 NewFS = geRam_Allocate(sizeof(*NewFS));
00121 if (!NewFS)
00122 return NewFS;
00123 memset(NewFS, 0, sizeof(*NewFS));
00124
00125 NewFS->Memory = MemContext->Data;
00126 NewFS->Size = MemContext->DataLength;
00127 NewFS->AllocatedSize = NewFS->Size;
00128
00129 if (NewFS->Memory)
00130 {
00131 NewFS->ReadOnly = GE_TRUE;
00132 NewFS->WeOwnMemory = GE_FALSE;
00133 }
00134 else
00135 {
00136 NewFS->ReadOnly = GE_FALSE;
00137 NewFS->WeOwnMemory = GE_TRUE;
00138 }
00139
00140 NewFS->Signature = MEMORYFILE_SIGNATURE;
00141
00142 return NewFS;
00143 }
|
|
||||||||||||||||
|
Definition at line 246 of file FSMEMORY.C. References MemoryFile::AllocatedSize, CHECK_HANDLE, ClampOperationSize(), DataPtr(), GE_FALSE, GE_TRUE, geBoolean, GENESISCC, MemoryFile::Position, and MemoryFile::Size.
00247 {
00248 MemoryFile * File;
00249
00250 assert(Buff);
00251 assert(Count != 0);
00252
00253 File = Handle;
00254
00255 CHECK_HANDLE(File);
00256
00257 if (ClampOperationSize(File, Count) != Count)
00258 return GE_FALSE;
00259
00260 memcpy(Buff, DataPtr(File), Count);
00261
00262 File->Position += Count;
00263 assert(File->Position <= File->Size);
00264 assert(File->Size <= File->AllocatedSize);
00265
00266 return GE_TRUE;
00267 }
|
|
||||||||||||||||||||
|
Definition at line 464 of file FSMEMORY.C. References GE_FALSE, geBoolean, and GENESISCC.
00465 {
00466 return GE_FALSE;
00467 }
|
|
||||||||||||||||
|
Definition at line 321 of file FSMEMORY.C. References MemoryFile::AllocatedSize, CHECK_HANDLE, GE_FALSE, GE_TRUE, GE_VFILE_SEEKCUR, GE_VFILE_SEEKEND, GE_VFILE_SEEKSET, geBoolean, GENESISCC, MemoryFile::Position, MemoryFile::ReadOnly, MemoryFile::Size, and TestForExpansion().
00322 {
00323 MemoryFile * File;
00324
00325 File = Handle;
00326
00327 CHECK_HANDLE(File);
00328
00329 switch (Whence)
00330 {
00331 int NewPos;
00332
00333 case GE_VFILE_SEEKCUR:
00334 NewPos = File->Position + Where;
00335 if (NewPos > File->AllocatedSize)
00336 {
00337 if (File->ReadOnly == GE_TRUE)
00338 return GE_FALSE;
00339 if (TestForExpansion(File, Where) == GE_FALSE)
00340 return GE_FALSE;
00341 }
00342 File->Position = NewPos;
00343 break;
00344
00345 case GE_VFILE_SEEKEND:
00346 if (File->Size < Where)
00347 return GE_FALSE;
00348 File->Position = File->Size - Where;
00349 break;
00350
00351 case GE_VFILE_SEEKSET:
00352 if (Where > File->AllocatedSize)
00353 {
00354 if (File->ReadOnly == GE_TRUE)
00355 return GE_FALSE;
00356 if (TestForExpansion(File, Where - File->Position) == GE_FALSE)
00357 return GE_FALSE;
00358 }
00359 File->Position = Where;
00360 break;
00361
00362 default:
00363 assert(!"Unknown seek kind");
00364 }
00365
00366 if (File->Position > File->Size)
00367 File->Size = File->Position;
00368
00369 assert(File->Size <= File->AllocatedSize);
00370 assert(File->Position <= File->AllocatedSize);
00371
00372 return GE_TRUE;
00373 }
|
|
||||||||||||
|
Definition at line 427 of file FSMEMORY.C. References GE_FALSE, geBoolean, and GENESISCC.
00428 {
00429 assert(!"Not implemented");
00430 return GE_FALSE;
00431 }
|
|
||||||||||||
|
Definition at line 439 of file FSMEMORY.C. References GE_FALSE, geBoolean, and GENESISCC.
00440 {
00441 assert(!"Not implemented");
00442 return GE_FALSE;
00443 }
|
|
||||||||||||
|
Definition at line 421 of file FSMEMORY.C. References GE_FALSE, geBoolean, and GENESISCC.
00422 {
00423 assert(!"Not implemented");
00424 return GE_FALSE;
00425 }
|
|
||||||||||||
|
Definition at line 433 of file FSMEMORY.C. References GE_FALSE, geBoolean, and GENESISCC.
00434 {
00435 assert(!"Not implemented");
00436 return GE_FALSE;
00437 }
|
|
||||||||||||
|
Definition at line 402 of file FSMEMORY.C. References CHECK_HANDLE, GE_TRUE, geBoolean, GENESISCC, and MemoryFile::Size.
00403 {
00404 const MemoryFile * File;
00405
00406 File = Handle;
00407
00408 CHECK_HANDLE(File);
00409
00410 *Size = File->Size;
00411
00412 return GE_TRUE;
00413 }
|
|
||||||||||||
|
Definition at line 389 of file FSMEMORY.C. References CHECK_HANDLE, GE_TRUE, geBoolean, GENESISCC, and MemoryFile::Position.
00390 {
00391 const MemoryFile * File;
00392
00393 File = Handle;
00394
00395 CHECK_HANDLE(File);
00396
00397 *Position = File->Position;
00398
00399 return GE_TRUE;
00400 }
|
|
||||||||||||||||||||
|
Definition at line 145 of file FSMEMORY.C. References CHECK_HANDLE, geVFile_MemoryContext::Data, geVFile_MemoryContext::DataLength, GE_FALSE, GE_TRUE, geBoolean, GENESISCC, MemoryFile::Memory, and MemoryFile::Size.
00150 {
00151 MemoryFile * File;
00152 geVFile_MemoryContext * MemoryContext;
00153
00154 assert(FS);
00155 assert(Context);
00156
00157 File = Handle;
00158
00159 CHECK_HANDLE(File);
00160
00161 if (ContextSize != sizeof(geVFile_MemoryContext))
00162 return GE_FALSE;
00163
00164 MemoryContext = Context;
00165
00166 MemoryContext->Data = File->Memory;
00167 MemoryContext->DataLength = File->Size;
00168
00169 return GE_TRUE;
00170 }
|
|
||||||||||||||||
|
Definition at line 295 of file FSMEMORY.C. References CHECK_HANDLE, DataPtr(), GE_FALSE, GE_TRUE, geBoolean, GENESISCC, MemoryFile::Position, MemoryFile::ReadOnly, MemoryFile::Size, and TestForExpansion().
00296 {
00297 MemoryFile * File;
00298
00299 assert(Buff);
00300 assert(Count != 0);
00301
00302 File = Handle;
00303
00304 CHECK_HANDLE(File);
00305
00306 if (File->ReadOnly == GE_TRUE)
00307 return GE_FALSE;
00308
00309 if (TestForExpansion(File, Count) == GE_FALSE)
00310 return GE_FALSE;
00311
00312 memcpy(DataPtr(File), Buff, Count);
00313
00314 File->Position += Count;
00315 if (File->Size < File->Position)
00316 File->Size = File->Position;
00317
00318 return GE_TRUE;
00319 }
|
|
||||||||||||
|
Definition at line 269 of file FSMEMORY.C. References MemoryFile::AllocatedSize, GE_FALSE, GE_TRUE, geBoolean, GENESISCC, geRam_Realloc, MemoryFile::Memory, MEMORY_FILE_GROW, MemoryFile::Position, MemoryFile::ReadOnly, MemoryFile::Size, and MemoryFile::WeOwnMemory. Referenced by FSMemory_Seek(), and FSMemory_Write().
00270 {
00271 assert(File);
00272 assert(File->ReadOnly == GE_FALSE);
00273 assert(File->WeOwnMemory == GE_TRUE);
00274
00275 assert(File->AllocatedSize >= File->Size);
00276 assert(File->AllocatedSize >= File->Position);
00277
00278 if (File->AllocatedSize - File->Position < Size)
00279 {
00280 int NewSize;
00281 char * NewBlock;
00282
00283 NewSize = ((File->AllocatedSize + Size + (MEMORY_FILE_GROW - 1)) / MEMORY_FILE_GROW) * MEMORY_FILE_GROW;
00284 NewBlock = geRam_Realloc(File->Memory, NewSize);
00285 if (!NewBlock)
00286 return GE_FALSE;
00287 File->Memory = NewBlock;
00288 File->AllocatedSize = NewSize;
00289 //printf("FSMemory: Expanded file to %d bytes\n", NewSize);
00290 }
00291
00292 return GE_TRUE;
00293 }
|
|
|
Definition at line 469 of file FSMEMORY.C. Referenced by FSMemory_GetAPIs(). |
1.3.2