39 #define _________________________________________PROTOTYPES_SECTION_________________________________________________________________________ 43 #undef _________________________________________PROTOTYPES_SECTION_________________________________________________________________________ 50 #define _________________________________________TYPES______________________________________________________________________________________ 67 #undef _________________________________________TYPES______________________________________________________________________________________ 74 #define _________________________________________VARIABLES__________________________________________________________________________________ 80 .init = oC_FlashFs_init ,
81 .deinit = oC_FlashFs_deinit ,
82 .fopen = oC_FlashFs_fopen ,
83 .fclose = oC_FlashFs_fclose ,
84 .fread = oC_FlashFs_fread ,
85 .fwrite = oC_FlashFs_fwrite ,
86 .lseek = oC_FlashFs_lseek ,
87 .ioctl = oC_FlashFs_ioctl ,
88 .sync = oC_FlashFs_sync ,
89 .Getc = oC_FlashFs_getc ,
90 .Putc = oC_FlashFs_putc ,
91 .tell = oC_FlashFs_tell ,
92 .eof = oC_FlashFs_eof ,
93 .size = oC_FlashFs_size ,
95 .opendir = oC_FlashFs_opendir ,
96 .closedir = oC_FlashFs_closedir ,
97 .readdir = oC_FlashFs_readdir ,
99 .stat = oC_FlashFs_stat ,
100 .unlink = oC_FlashFs_unlink ,
101 .rename = oC_FlashFs_rename ,
102 .chmod = oC_FlashFs_chmod ,
103 .utime = oC_FlashFs_utime ,
104 .mkdir = oC_FlashFs_mkdir ,
105 .DirExists= oC_FlashFs_DirExists,
109 #undef _________________________________________VARIABLES__________________________________________________________________________________ 117 #define _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________ 119 static bool IsFileCorrect (
oC_File_t File );
120 static bool IsDirCorrect (
oC_Dir_t Dir );
123 #undef _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________ 131 #define _________________________________________INTERFACE_FUNCTIONS________________________________________________________________________ 138 return oC_ErrorCode_None;
145 return oC_ErrorCode_None;
152 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
155 ErrorCondition( isram(outFile) , oC_ErrorCode_OutputAddressNotInRAM )
156 && ErrorCondition( isaddresscorrect(Path) , oC_ErrorCode_WrongAddress )
157 && ErrorCondition( Path[0] ==
'/' , oC_ErrorCode_PathNotCorrect )
158 && ErrorCondition(
oC_Bits_AreBitsClearU32(Mode , oC_FileSystem_ModeFlags__Create) , oC_ErrorCode_FileIsReadOnly )
163 if(ErrorCondition(isrom(fileDefinition) , oC_ErrorCode_PathNotCorrect))
165 oC_File_t file = smartalloc(
sizeof(
struct File_t),AllocationFlags_CanWait1Second);
171 file->FileDefinition = fileDefinition;
173 errorCode = oC_ErrorCode_None;
177 errorCode = oC_ErrorCode_AllocationError;
189 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
192 ErrorCondition(IsFileCorrect(File),oC_ErrorCode_ObjectNotCorrect)
195 File->ObjectControl = 0;
197 if(smartfree(File,
sizeof(
struct File_t),AllocationFlags_CanWaitForever))
199 errorCode = oC_ErrorCode_None;
203 errorCode = oC_ErrorCode_ReleaseError;
213 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
216 ErrorCondition( IsFileCorrect(File) , oC_ErrorCode_FileNotCorrect )
217 && ErrorCondition( isram(outBuffer) , oC_ErrorCode_OutputAddressNotInRAM )
218 && ErrorCondition( isram(Size) , oC_ErrorCode_OutputAddressNotInRAM )
221 uint32_t bytesRead = 0;
222 uint8_t* buffer = outBuffer;
224 for(;File->Offset < File->FileDefinition->Size && bytesRead < (*Size); File->Offset++, bytesRead++)
226 buffer[bytesRead] = File->FileDefinition->Data[File->Offset];
230 errorCode = oC_ErrorCode_None;
240 return oC_ErrorCode_FileIsReadOnly;
247 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
250 ErrorCondition( IsFileCorrect(File) , oC_ErrorCode_FileNotCorrect )
251 && ErrorCondition( Offset < File->FileDefinition->Size , oC_ErrorCode_OffsetTooBig )
254 File->Offset = Offset;
255 errorCode = oC_ErrorCode_None;
265 return oC_ErrorCode_NotHandledByFileSystem;
272 return oC_ErrorCode_NotHandledByFileSystem;
279 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
282 ErrorCondition( IsFileCorrect(File) , oC_ErrorCode_FileNotCorrect )
283 && ErrorCondition( isram(outCharacter) , oC_ErrorCode_OutputAddressNotInRAM )
284 && ErrorCondition( File->Offset < File->FileDefinition->Size , oC_ErrorCode_EndOfFile )
287 *outCharacter = File->FileDefinition->Data[File->Offset++];
288 errorCode = oC_ErrorCode_None;
298 return oC_ErrorCode_FileIsReadOnly;
314 if(IsFileCorrect(File))
316 eof = File->Offset >= File->FileDefinition->Size;
320 oC_SaveError(
"FlashFs: EOF error - " , oC_ErrorCode_FileNotCorrect);
332 if(IsFileCorrect(File))
334 size = File->FileDefinition->Size;
344 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
347 ErrorCondition( isram(outDir) , oC_ErrorCode_OutputAddressNotInRAM )
348 && ErrorCondition( isaddresscorrect(Path) , oC_ErrorCode_WrongAddress )
349 && ErrorCondition( strcmp(Path,
"/") == 0 , oC_ErrorCode_NoSuchFile )
352 oC_Dir_t dir = smartalloc(
sizeof(
struct Dir_t),AllocationFlags_CanWaitForever);
359 errorCode = oC_ErrorCode_None;
363 errorCode = oC_ErrorCode_AllocationError;
374 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
376 if(oC_AssignErrorCodeIfFalse(&errorCode , IsDirCorrect(Dir) , oC_ErrorCode_ObjectNotCorrect ))
378 Dir->ObjectControl = 0;
380 if(smartfree(Dir,
sizeof(
struct Dir_t),AllocationFlags_CanWaitForever))
382 errorCode = oC_ErrorCode_None;
386 errorCode = oC_ErrorCode_ReleaseError;
397 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
400 ErrorCondition( IsDirCorrect(Dir) , oC_ErrorCode_ObjectNotCorrect )
401 && ErrorCondition( isram(outFileInfo) , oC_ErrorCode_OutputAddressNotInRAM )
402 && ErrorCondition( Dir->FileIndex < oC_FlashFs_NumberOfFiles , oC_ErrorCode_NoSuchFile )
405 outFileInfo->Name = oC_FlashFs_FileDefinitions[Dir->FileIndex].Name;
406 outFileInfo->Size = oC_FlashFs_FileDefinitions[Dir->FileIndex].Size;
407 outFileInfo->FileType = oC_FileSystem_FileType_File;
408 outFileInfo->Timestamp = 0;
411 errorCode = oC_ErrorCode_None;
421 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
424 ErrorCondition( isaddresscorrect(Path) , oC_ErrorCode_WrongAddress )
425 && ErrorCondition( isram(outFileInfo) , oC_ErrorCode_OutputAddressNotInRAM )
426 && ErrorCondition( Path[0] ==
'/' , oC_ErrorCode_PathNotCorrect )
431 if(ErrorCondition(isrom(fileDefinition) , oC_ErrorCode_NoSuchFile))
433 outFileInfo->Name = fileDefinition->Name;
434 outFileInfo->Size = fileDefinition->Size;
435 outFileInfo->FileType = oC_FileSystem_FileType_File;
436 outFileInfo->Timestamp = 0;
437 errorCode = oC_ErrorCode_None;
448 return oC_ErrorCode_NotHandledByFileSystem;
453 oC_ErrorCode_t oC_FlashFs_rename(
oC_FlashFs_Context_t Context ,
const char * OldName ,
const char * NewName)
455 return oC_ErrorCode_NotHandledByFileSystem;
460 oC_ErrorCode_t oC_FlashFs_chmod(
oC_FlashFs_Context_t Context ,
const char * Path, oC_FileSystem_FileAttributes_t Attributes , oC_FileSystem_FileAttributes_t Mask)
462 return oC_ErrorCode_NotHandledByFileSystem;
467 oC_ErrorCode_t oC_FlashFs_utime(
oC_FlashFs_Context_t Context ,
const char * Path , oC_Timestamp_t Timestamp )
469 return oC_ErrorCode_NotHandledByFileSystem;
476 return oC_ErrorCode_NotHandledByFileSystem;
483 return strcmp(Path,
"/") == 0;
486 #undef _________________________________________INTERFACE_FUNCTIONS________________________________________________________________________ 494 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ 496 static bool IsFileCorrect(
oC_File_t File )
501 static bool IsDirCorrect(
oC_Dir_t Dir )
510 oC_ARRAY_FOREACH_IN_ARRAY_WITH_SIZE(oC_FlashFs_FileDefinitions,oC_FlashFs_NumberOfFiles,file)
512 if(strcmp(&Path[1],file->Name) == 0)
514 fileDefinition = file;
519 return fileDefinition;
522 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
The file with helper macros for managing objects.
uint32_t oC_ObjectControl_t
stores object control value
Interface for the Flash File System.
oC_FileSystem_ModeFlags_t
The file with interface for file systems.
static bool oC_Bits_AreBitsClearU32(uint32_t BitMask, uint32_t BitsToCheck)
checks if all bits in field are clear
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
The file with functions for the bits operation.
Static array definitions.
The file with interface for string library.
moves offset pointer to the end of the file
#define NULL
pointer to a zero