29 #include <oc_stdlib.h> 37 #include <oc_errors.h> 44 #define _________________________________________MACROS_SECTION_____________________________________________________________________________ 46 #define IsFileCorrect(File) (oC_CheckObjectControl((File),oC_ObjectId_RamFsFile,(File)->ObjectControl)) 47 #define IsDirCorrect(Dir) (oC_CheckObjectControl((Dir),oC_ObjectId_RamFsDir,(Dir)->ObjectControl)) 48 #define IsFileReadOnly(file) ((file)->Attributes & oC_FileSystem_FileAttributes_ReadOnly ) 49 #define IsFileLocked(File) ((file)->Lock) 51 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________ 59 #define _________________________________________TYPES_SECTION______________________________________________________________________________ 68 oC_FileSystem_FileType_t FileType;
69 oC_FileSystem_FileAttributes_t Attributes;
71 oC_Timestamp_t Timestamp;
87 #undef _________________________________________TYPES_SECTION______________________________________________________________________________ 94 #define _________________________________________PROTOTYPES_SECTION_________________________________________________________________________ 97 static const char * GetLastEntryNameFromPath(
const char * Path );
98 static char * GetParentDirOfPath(
const char * Path ,
char * outDir , oC_UInt_t Size );
99 static bool CheckIfParentDirectoryExists(
oC_RamFs_Context_t Context ,
const char * Path );
102 static oC_File_t CreateFile(
oC_RamFs_Context_t Context ,
const char * Path , oC_FileSystem_FileType_t FileType , oC_FileSystem_FileAttributes_t Attributes );
105 static void UnlockFile(
oC_File_t File );
107 #undef _________________________________________PROTOTYPES_SECTION_________________________________________________________________________ 115 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________ 121 .init = oC_RamFs_init ,
122 .deinit = oC_RamFs_deinit ,
123 .fopen = oC_RamFs_fopen ,
124 .fclose = oC_RamFs_fclose ,
125 .fread = oC_RamFs_fread ,
126 .fwrite = oC_RamFs_fwrite ,
127 .lseek = oC_RamFs_lseek ,
128 .ioctl = oC_RamFs_ioctl ,
129 .sync = oC_RamFs_sync ,
130 .Getc = oC_RamFs_getc ,
131 .Putc = oC_RamFs_putc ,
133 .eof = oC_RamFs_eof ,
134 .size = oC_RamFs_size ,
136 .opendir = oC_RamFs_opendir ,
137 .closedir = oC_RamFs_closedir ,
138 .readdir = oC_RamFs_readdir ,
140 .stat = oC_RamFs_stat ,
141 .unlink = oC_RamFs_unlink ,
142 .rename = oC_RamFs_rename ,
143 .chmod = oC_RamFs_chmod ,
144 .utime = oC_RamFs_utime ,
145 .mkdir = oC_RamFs_mkdir ,
146 .DirExists= oC_RamFs_DirExists ,
155 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________ 163 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 169 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
172 oC_AssignErrorCodeIfFalse(&errorCode , isram(outContext) , oC_ErrorCode_OutputAddressNotInRAM)
180 context->Files = oC_List_New(&Allocator,AllocationFlags_CanWait1Second);
182 if(oC_List_IsCorrect(context->Files))
184 *outContext = context;
185 errorCode = oC_ErrorCode_None;
189 errorCode = oC_ErrorCode_ListNotCorrect;
191 ifnot(kfree(context,AllocationFlags_CanWaitForever))
193 oC_SaveError(
"RamFs - init: Cannot release context memory" , oC_ErrorCode_ReleaseError);
199 errorCode = oC_ErrorCode_AllocationError;
210 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
213 oC_AssignErrorCodeIfFalse(&errorCode , IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect )
217 errorCode = oC_ErrorCode_None;
219 oC_List_Foreach(Context->Files,file)
223 ifnot(DeleteFile(Context,file->Path))
225 oC_SaveError(
"RamFs:deinit, cannot delete file" , oC_ErrorCode_ReleaseError);
229 oC_AssignErrorCodeIfFalse(&errorCode , oC_List_Delete(Context->Files,AllocationFlags_CanWaitForever) , oC_ErrorCode_ReleaseError );
230 oC_AssignErrorCodeIfFalse(&errorCode , kfree(Context,AllocationFlags_CanWaitForever) , oC_ErrorCode_ReleaseError );
240 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
243 oC_AssignErrorCodeIfFalse(&errorCode , IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect ) &&
244 oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Path) , oC_ErrorCode_WrongAddress ) &&
245 oC_AssignErrorCodeIfFalse(&errorCode , isram(outFile) , oC_ErrorCode_OutputAddressNotInRAM)
251 oC_AssignErrorCodeIfFalse(&errorCode , (file ==
NULL) && (Mode & oC_FileSystem_ModeFlags__FailIfNotExists), oC_ErrorCode_NoSuchFile ) &&
252 oC_AssignErrorCodeIfFalse(&errorCode , ((file !=
NULL) && (Mode & oC_FileSystem_ModeFlags__FailIfExists)) , oC_ErrorCode_FileAlreadyExists ) &&
253 oC_AssignErrorCodeIfFalse(&errorCode , !IsFileCorrect(file) || !IsFileLocked(file) , oC_ErrorCode_FileIsBusy )
258 if(!IsFileCorrect(file) && !(Mode & oC_FileSystem_ModeFlags__Create))
260 errorCode = oC_ErrorCode_ExistingFileNotCorrect;
264 errorCode = oC_ErrorCode_FileIsReadOnly;
266 else if(Mode & oC_FileSystem_ModeFlags__Open)
269 errorCode= oC_ErrorCode_None;
271 else if(Mode & oC_FileSystem_ModeFlags__Create)
273 if(IsFileReadOnly(file))
275 errorCode = oC_ErrorCode_FileIsReadOnly;
279 if(DeleteFile(Context,Path))
281 file = CreateFile(Context,Path,oC_FileSystem_FileType_File,Attributes);
286 errorCode = oC_ErrorCode_None;
290 errorCode = oC_ErrorCode_CannotCreateFile;
295 errorCode = oC_ErrorCode_CannotDeleteFile;
302 if(Mode & oC_FileSystem_ModeFlags__Create)
304 if(CheckIfParentDirectoryExists(Context,Path))
306 file = CreateFile(Context,Path,oC_FileSystem_FileType_File,Attributes);
311 errorCode = oC_ErrorCode_None;
315 errorCode = oC_ErrorCode_CannotCreateFile;
320 errorCode = oC_ErrorCode_DirectoryNotExists;
325 errorCode = oC_ErrorCode_ModeNotCorrect;
338 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
341 oC_AssignErrorCodeIfFalse(&errorCode , IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect ) &&
342 oC_AssignErrorCodeIfFalse(&errorCode , IsFileCorrect(Context) , oC_ErrorCode_FileNotCorrect )
346 errorCode = oC_ErrorCode_None;
356 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
359 oC_AssignErrorCodeIfFalse(&errorCode , IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect ) &&
360 oC_AssignErrorCodeIfFalse(&errorCode , IsFileCorrect(File) , oC_ErrorCode_FileNotCorrect ) &&
361 oC_AssignErrorCodeIfFalse(&errorCode , isram(outBuffer), oC_ErrorCode_OutputAddressNotInRAM) &&
362 oC_AssignErrorCodeIfFalse(&errorCode , isram(Size), oC_ErrorCode_OutputAddressNotInRAM) &&
363 oC_AssignErrorCodeIfFalse(&errorCode , *Size > 0, oC_ErrorCode_SizeNotCorrect) &&
364 oC_AssignErrorCodeIfFalse(&errorCode , isarrayinram(outBuffer,*Size), oC_ErrorCode_ArraySizeTooBig) &&
365 oC_AssignErrorCodeIfFalse(&errorCode , LockFile(File), oC_ErrorCode_FileIsBusy)
368 uint8_t * buffer = outBuffer;
369 uint32_t byteIndex = 0;
372 for(byteIndex = 0 ; isram(&File->Data[File->Offset]) && byteIndex < *Size && File->Offset < File->Size ; byteIndex++ )
374 buffer[byteIndex] = File->Data[File->Offset++];
377 if(byteIndex < *Size)
379 errorCode = oC_ErrorCode_NoAllBytesRead;
383 errorCode = oC_ErrorCode_None;
396 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
399 oC_AssignErrorCodeIfFalse(&errorCode , IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect ) &&
400 oC_AssignErrorCodeIfFalse(&errorCode , IsFileCorrect(File) , oC_ErrorCode_FileNotCorrect ) &&
401 oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Buffer), oC_ErrorCode_WrongAddress) &&
402 oC_AssignErrorCodeIfFalse(&errorCode , isram(Size), oC_ErrorCode_OutputAddressNotInRAM) &&
403 oC_AssignErrorCodeIfFalse(&errorCode , *Size > 0, oC_ErrorCode_SizeNotCorrect) &&
404 oC_AssignErrorCodeIfFalse(&errorCode , isarraycorrect(Buffer,*Size), oC_ErrorCode_ArraySizeTooBig) &&
405 oC_AssignErrorCodeIfFalse(&errorCode , LockFile(File), oC_ErrorCode_FileIsBusy)
408 uint32_t newSize = oC_MAX(*Size + File->Offset , File->Size);
409 uint8_t * newBuffer = kmalloc(newSize ,&Allocator,AllocationFlags_CanWait1Second);
410 const uint8_t * buffer = Buffer;
411 const uint8_t * bufferEnd = &buffer[*Size];
413 if(oC_AssignErrorCodeIfFalse(&errorCode , isram(newBuffer) , oC_ErrorCode_AllocationError))
415 for(uint32_t newBufferIndex = 0; newBufferIndex < newSize ; newBufferIndex++)
417 if(newBufferIndex < File->Offset || buffer >= bufferEnd)
419 newBuffer[newBufferIndex] = File->Data[newBufferIndex];
423 newBuffer[newBufferIndex] = *buffer;
428 if(oC_AssignErrorCodeIfFalse(&errorCode , File->Data ==
NULL || kfree(File->Data,AllocationFlags_CanWaitForever) , oC_ErrorCode_ReleaseError))
430 File->Size = newSize;
431 File->Data = newBuffer;
432 File->Offset += *Size;
433 File->Timestamp = oC_KTime_GetTimestamp();
435 errorCode = oC_ErrorCode_None;
439 ifnot(kfree(newBuffer,AllocationFlags_CanWaitForever))
441 oC_SaveError(
"RamFs: fwrite - relasing temp buffer error" , oC_ErrorCode_ReleaseError);
457 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
460 oC_AssignErrorCodeIfFalse(&errorCode , IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect ) &&
461 oC_AssignErrorCodeIfFalse(&errorCode , IsFileCorrect(File) , oC_ErrorCode_FileNotCorrect ) &&
462 oC_AssignErrorCodeIfFalse(&errorCode , Offset < File->Size , oC_ErrorCode_OffsetTooBig )
465 File->Offset = Offset;
475 return oC_ErrorCode_NotHandledByFileSystem;
482 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
485 oC_AssignErrorCodeIfFalse(&errorCode , IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect ) &&
486 oC_AssignErrorCodeIfFalse(&errorCode , IsFileCorrect(File) , oC_ErrorCode_FileNotCorrect )
489 errorCode = oC_ErrorCode_None;
499 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
502 oC_AssignErrorCodeIfFalse(&errorCode , IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect ) &&
503 oC_AssignErrorCodeIfFalse(&errorCode , IsFileCorrect(File) , oC_ErrorCode_FileNotCorrect ) &&
504 oC_AssignErrorCodeIfFalse(&errorCode , isram(outCharacter) , oC_ErrorCode_OutputAddressNotInRAM) &&
505 oC_AssignErrorCodeIfFalse(&errorCode , File->Data !=
NULL , oC_ErrorCode_FileIsEmpty) &&
506 oC_AssignErrorCodeIfFalse(&errorCode , File->Offset < File->Size , oC_ErrorCode_EndOfFile) &&
507 oC_AssignErrorCodeIfFalse(&errorCode , LockFile(File) , oC_ErrorCode_FileIsBusy)
510 *outCharacter = File->Data[File->Offset++];
511 errorCode = oC_ErrorCode_None;
524 return oC_RamFs_fwrite(Context,File,&Character,&size);
533 if(IsContextCorrect(Context) && IsFileCorrect(File))
535 eof = File->Offset >= File->Size;
547 if(IsContextCorrect(Context) && IsFileCorrect(File))
559 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
562 oC_AssignErrorCodeIfFalse(&errorCode , IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect) &&
563 oC_AssignErrorCodeIfFalse(&errorCode , isram(outDir) , oC_ErrorCode_OutputAddressNotInRAM) &&
564 oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Path) , oC_ErrorCode_WrongAddress) &&
565 oC_AssignErrorCodeIfFalse(&errorCode , CheckIfPathExists(Context,Path) , oC_ErrorCode_PathNotCorrect)
568 oC_Dir_t dir = smartalloc(
sizeof(
struct Dir_t),AllocationFlags_CanWaitForever);
573 dir->Path = smartalloc(strlen(Path)+1,AllocationFlags_CanWait1Second | AllocationFlags_ZeroFill);
575 if(dir->Path !=
NULL)
577 strcpy(dir->Path,Path);
578 dir->LastFile =
NULL;
580 errorCode = oC_ErrorCode_None;
584 if(smartfree(dir,
sizeof(
struct Dir_t),AllocationFlags_CanWaitForever)==
false)
586 oC_SaveError(
"RamFs-opendir: Cannot release memory previously allocated for DIR: " , oC_ErrorCode_ReleaseError);
588 errorCode = oC_ErrorCode_AllocationError;
594 errorCode = oC_ErrorCode_AllocationError;
605 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
608 oC_AssignErrorCodeIfFalse(&errorCode , IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect) &&
609 oC_AssignErrorCodeIfFalse(&errorCode , IsDirCorrect(Dir) , oC_ErrorCode_ObjectNotCorrect)
612 errorCode = oC_ErrorCode_None;
614 ifnot(smartfree(Dir->Path,strlen(Dir->Path)+1,AllocationFlags_CanWaitForever))
616 errorCode = oC_ErrorCode_ReleaseError;
619 ifnot(smartfree(Dir,
sizeof(
struct Dir_t),AllocationFlags_CanWaitForever))
621 errorCode = oC_ErrorCode_ReleaseError;
632 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
635 oC_AssignErrorCodeIfFalse(&errorCode , IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect) &&
636 oC_AssignErrorCodeIfFalse(&errorCode , IsDirCorrect(Dir) , oC_ErrorCode_ObjectNotCorrect) &&
637 oC_AssignErrorCodeIfFalse(&errorCode , isram(outFileInfo) , oC_ErrorCode_OutputAddressNotInRAM)
640 bool lastFileFound = Dir->LastFile ==
NULL;
641 bool nextFileFound =
false;
642 oC_UInt_t pathLength = strlen(Dir->Path);
643 char * tempDir = smartalloc(pathLength+1,AllocationFlags_ZeroFill);
646 oC_List_Foreach(Context->Files,file)
648 char * path = GetParentDirOfPath(file->Path,tempDir,pathLength+1);
651 if(strcmp(path,Dir->Path) == 0)
655 Dir->LastFile = file;
656 nextFileFound =
true;
661 lastFileFound = file == Dir->LastFile;
669 outFileInfo->FileType = Dir->LastFile->FileType;
670 outFileInfo->Size = Dir->LastFile->Size;
671 outFileInfo->Timestamp= Dir->LastFile->Timestamp;
672 outFileInfo->Name = GetLastEntryNameFromPath(Dir->LastFile->Path);
674 errorCode = oC_ErrorCode_None;
678 errorCode = oC_ErrorCode_NoSuchFile;
681 ifnot(smartfree(tempDir,pathLength+1,AllocationFlags_CanWaitForever))
683 oC_SaveError(
"RamFs-readdir: cannot release temp buffer",oC_ErrorCode_ReleaseError);
694 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
697 oC_AssignErrorCodeIfFalse(&errorCode , IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect) &&
698 oC_AssignErrorCodeIfFalse(&errorCode , isram(outFileInfo) , oC_ErrorCode_OutputAddressNotInRAM) &&
699 oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Path) , oC_ErrorCode_WrongAddress) &&
700 oC_AssignErrorCodeIfFalse(&errorCode , CheckIfPathExists(Context,Path) , oC_ErrorCode_PathNotCorrect)
707 outFileInfo->FileType = file->FileType;
708 outFileInfo->Name = GetLastEntryNameFromPath(file->Path);
709 outFileInfo->Size = file->Size;
710 outFileInfo->Timestamp= file->Timestamp;
711 errorCode = oC_ErrorCode_None;
715 errorCode = oC_ErrorCode_NoSuchFile;
726 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
729 oC_AssignErrorCodeIfFalse(&errorCode , IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect) &&
730 oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Path) , oC_ErrorCode_WrongAddress) &&
731 oC_AssignErrorCodeIfFalse(&errorCode , CheckIfPathExists(Context,Path) , oC_ErrorCode_PathNotCorrect)
738 if(DeleteFile(Context,Path))
740 errorCode = oC_ErrorCode_None;
742 if(file->FileType == oC_FileSystem_FileType_Directory)
744 oC_UInt_t pathLength = strlen(Path);
745 oC_List_Foreach(Context->Files,file)
747 if(strncmp(Path,file->Path,pathLength)==0)
749 ifnot(DeleteFile(Context,file->Path))
751 oC_SaveError(
"RamFs-unlink: Cannot delete one of subfiles",oC_ErrorCode_ReleaseError);
759 errorCode = oC_ErrorCode_CannotDeleteFile;
764 errorCode = oC_ErrorCode_NoSuchFile;
773 oC_ErrorCode_t oC_RamFs_rename(
oC_RamFs_Context_t Context ,
const char * OldName ,
const char * NewName)
775 return oC_ErrorCode_NotImplemented;
780 oC_ErrorCode_t oC_RamFs_chmod(
oC_RamFs_Context_t Context ,
const char * Path, oC_FileSystem_FileAttributes_t Attributes , oC_FileSystem_FileAttributes_t Mask)
782 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
785 oC_AssignErrorCodeIfFalse(&errorCode , IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect ) &&
786 oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Path) , oC_ErrorCode_WrongAddress ) &&
787 oC_AssignErrorCodeIfFalse(&errorCode , CheckIfPathExists(Context,Path) , oC_ErrorCode_PathNotCorrect)
794 file->Attributes &= ~Mask;
795 file->Attributes |= Attributes;
797 errorCode = oC_ErrorCode_None;
801 errorCode = oC_ErrorCode_NoSuchFile;
810 oC_ErrorCode_t oC_RamFs_utime(
oC_RamFs_Context_t Context ,
const char * Path , oC_Timestamp_t Timestamp )
812 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
815 oC_AssignErrorCodeIfFalse(&errorCode , IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect ) &&
816 oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Path) , oC_ErrorCode_WrongAddress ) &&
817 oC_AssignErrorCodeIfFalse(&errorCode , CheckIfPathExists(Context,Path) , oC_ErrorCode_PathNotCorrect)
824 file->Timestamp = Timestamp;
825 errorCode = oC_ErrorCode_None;
829 errorCode = oC_ErrorCode_NoSuchFile;
840 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
843 oC_AssignErrorCodeIfFalse(&errorCode , IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect ) &&
844 oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Path) , oC_ErrorCode_WrongAddress ) &&
845 oC_AssignErrorCodeIfFalse(&errorCode , !CheckIfPathExists(Context,Path) , oC_ErrorCode_PathAlreadyUsed) &&
846 oC_AssignErrorCodeIfFalse(&errorCode , CheckIfParentDirectoryExists(Context,Path) , oC_ErrorCode_PathNotCorrect)
849 if(CreateFile(Context,Path,oC_FileSystem_FileType_Directory,0)!=
NULL)
851 errorCode = oC_ErrorCode_None;
855 errorCode = oC_ErrorCode_CannotCreateFile;
866 return IsContextCorrect(Context) && CheckIfPathExists(Context,Path);
869 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 876 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ 887 static const char * GetLastEntryNameFromPath(
const char * Path )
889 oC_UInt_t pathLength = strlen(Path);
890 const char * entryName = (pathLength > 1)? &Path[pathLength-2] :&Path[pathLength-1];
892 while(entryName >= Path)
894 if(*entryName ==
'/')
908 static char * GetParentDirOfPath(
const char * Path ,
char * outDir , oC_UInt_t Size )
911 const char * entryName = GetLastEntryNameFromPath(Path);
912 oC_UInt_t dirLength = strlen(Path)-strlen(entryName);
914 if(dirLength <= (Size-1))
916 strncpy(dir,Path,dirLength);
929 static bool CheckIfParentDirectoryExists(
oC_RamFs_Context_t Context ,
const char * Path )
932 const char * lastEntry = GetLastEntryNameFromPath(Path);
933 oC_UInt_t parentPathLength = strlen(Path) - strlen(lastEntry);
935 exists = strncmp(
"/" , Path , parentPathLength) == 0;
937 oC_List_Foreach(Context->Files,file)
940 file->FileType == oC_FileSystem_FileType_Directory &&
941 strncmp(file->Path , Path , parentPathLength) == 0
957 bool exists = strcmp(Path,
"/") == 0;
959 oC_List_Foreach(Context->Files,file)
961 if(strcmp(file->Path,Path)==0)
977 oC_List_Foreach(Context->Files,file)
979 if(strcmp(file->Path,Path)==0)
991 static oC_File_t CreateFile(
oC_RamFs_Context_t Context ,
const char * Path , oC_FileSystem_FileType_t FileType , oC_FileSystem_FileAttributes_t Attributes )
993 oC_File_t file = kmalloc(
sizeof(
struct File_t),&Allocator,AllocationFlags_CanWait1Second);
997 file->Path = kmalloc(strlen(Path)+1,&Allocator,AllocationFlags_CanWait1Second | AllocationFlags_ZeroFill);
1001 strcpy(file->Path,Path);
1002 file->Attributes = Attributes;
1003 file->FileType = FileType;
1009 file->Timestamp = oC_KTime_GetTimestamp();
1011 bool pushed = oC_List_PushBack(Context->Files,file,&Allocator);
1015 file->ObjectControl = 0;
1017 ifnot(kfree(file->Path,AllocationFlags_CanWaitForever))
1019 oC_SaveError(
"RamFs: Create file error: " , oC_ErrorCode_ReleaseError);
1021 ifnot(kfree(file,AllocationFlags_CanWaitForever))
1023 oC_SaveError(
"RamFs: Create file error: " , oC_ErrorCode_ReleaseError);
1030 ifnot(kfree(file,AllocationFlags_CanWaitForever))
1032 oC_SaveError(
"RamFs: Create file error: " , oC_ErrorCode_ReleaseError);
1045 bool deleted =
false;
1048 if(file && LockFile(file))
1050 bool removedFromList = oC_List_RemoveAll(Context->Files,file);
1052 ifnot(removedFromList)
1054 oC_SaveError(
"RamFs:DeleteFile" , oC_ErrorCode_CannotRemoveObjectFromList);
1058 file->ObjectControl = 0;
1062 ifnot(file->Data ==
NULL || kfree(file->Data,AllocationFlags_CanWaitForever))
1064 oC_SaveError(
"RamFs: DeleteFile, cannot delete data buffer" , oC_ErrorCode_ReleaseError);
1068 ifnot(kfree(file->Path,AllocationFlags_CanWaitForever))
1070 oC_SaveError(
"RamFs: DeleteFile, cannot delete path buffer" , oC_ErrorCode_ReleaseError);
1074 ifnot(kfree(file,AllocationFlags_CanWaitForever))
1076 oC_SaveError(
"RamFs: DeleteFile, cannot release file memory" , oC_ErrorCode_ReleaseError);
1090 bool locked =
false;
1091 oC_IntMan_EnterCriticalSection();
1092 if(File->Lock==
false)
1097 oC_IntMan_ExitCriticalSection();
1104 static void UnlockFile(
oC_File_t File )
1106 oC_IntMan_EnterCriticalSection();
1108 oC_IntMan_ExitCriticalSection();
1112 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
identifier for allocations
The file with helper macros for managing objects.
uint32_t oC_ObjectControl_t
stores object control value
The file with list library.
oC_FileSystem_ModeFlags_t
The file with interface for interrupt manager.
static oC_ObjectControl_t oC_CountObjectControl(void *ObjectPointer, oC_ObjectId_t ObjectId)
counts object control for object
static bool oC_CheckObjectControl(void *ObjectPointer, oC_ObjectId_t ObjectId, oC_ObjectControl_t ObjectControl)
checks if object control is correct
specifies write access to the file
oC_ObjectControl_t ObjectControl
Static array definitions.
The file with source for the RAM file system.
The file with interface of kernel time module.
#define NULL
pointer to a zero