39 #define _________________________________________DEFINITIONS_SECTION________________________________________________________________________ 41 #define MAX_PATH_LENGTH 30 43 #undef _________________________________________DEFINITIONS_SECTION________________________________________________________________________ 51 #define _________________________________________TYPES_SECTION______________________________________________________________________________ 63 uint32_t CurrentDriver;
66 #undef _________________________________________TYPES_SECTION______________________________________________________________________________ 73 #define _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________ 75 static bool IsFileCorrect(
oC_File_t File );
76 static bool IsDirCorrect(
oC_Dir_t Dir );
78 #undef _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________ 86 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________ 92 .init = oC_DevFs_init ,
93 .deinit = oC_DevFs_deinit ,
94 .fopen = oC_DevFs_fopen ,
95 .fclose = oC_DevFs_fclose ,
96 .fread = oC_DevFs_fread ,
97 .fwrite = oC_DevFs_fwrite ,
98 .lseek = oC_DevFs_lseek ,
99 .ioctl = oC_DevFs_ioctl ,
100 .sync = oC_DevFs_sync ,
101 .Getc = oC_DevFs_getc ,
102 .Putc = oC_DevFs_putc ,
103 .tell = oC_DevFs_tell ,
104 .eof = oC_DevFs_eof ,
105 .size = oC_DevFs_size ,
107 .opendir = oC_DevFs_opendir ,
108 .closedir = oC_DevFs_closedir ,
109 .readdir = oC_DevFs_readdir ,
111 .stat = oC_DevFs_stat ,
112 .unlink = oC_DevFs_unlink ,
113 .rename = oC_DevFs_rename ,
114 .chmod = oC_DevFs_chmod ,
115 .utime = oC_DevFs_utime ,
116 .mkdir = oC_DevFs_mkdir ,
117 .DirExists= oC_DevFs_DirExists,
120 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________ 128 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 134 return oC_ErrorCode_None;
141 return oC_ErrorCode_None;
148 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
150 if(ErrorCondition(isaddresscorrect(Path) , oC_ErrorCode_PathNotCorrect))
152 oC_Driver_t driver = oC_DriverMan_GetDriver(&Path[1]);
155 oC_AssignErrorCodeIfFalse(&errorCode , isram(outFile) , oC_ErrorCode_OutputAddressNotInRAM) &&
156 oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(driver) , oC_ErrorCode_NoSuchFile)
159 oC_File_t file = smartalloc(
sizeof(
struct File_t),AllocationFlags_CanWait1Second);
164 file->Driver = driver;
165 file->DriverContext =
NULL;
167 errorCode = oC_ErrorCode_None;
171 errorCode = oC_ErrorCode_AllocationError;
183 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
186 oC_AssignErrorCodeIfFalse(&errorCode,IsFileCorrect(File),oC_ErrorCode_ObjectNotCorrect)
189 File->ObjectControl = 0;
191 if(smartfree(File,
sizeof(
struct File_t),AllocationFlags_CanWaitForever))
193 errorCode = oC_ErrorCode_None;
197 errorCode = oC_ErrorCode_ReleaseError;
208 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
211 oC_AssignErrorCodeIfFalse(&errorCode,IsFileCorrect(File), oC_ErrorCode_ObjectNotCorrect) &&
212 oC_AssignErrorCodeIfFalse(&errorCode,isram(outBuffer), oC_ErrorCode_OutputAddressNotInRAM) &&
213 oC_AssignErrorCodeIfFalse(&errorCode,isram(Size), oC_ErrorCode_OutputAddressNotInRAM) &&
214 oC_AssignErrorCodeIfFalse(&errorCode,*Size > 0, oC_ErrorCode_SizeNotCorrect) &&
215 oC_AssignErrorCodeIfFalse(&errorCode,isarrayinram(outBuffer,*Size), oC_ErrorCode_ArraySizeTooBig)
218 errorCode = oC_Driver_Read(File->Driver,File->DriverContext,outBuffer,Size,oC_hour(1));
228 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
231 oC_AssignErrorCodeIfFalse(&errorCode,IsFileCorrect(File), oC_ErrorCode_ObjectNotCorrect) &&
232 oC_AssignErrorCodeIfFalse(&errorCode,isaddresscorrect(Buffer), oC_ErrorCode_WrongAddress) &&
233 oC_AssignErrorCodeIfFalse(&errorCode,isram(Size), oC_ErrorCode_OutputAddressNotInRAM) &&
234 oC_AssignErrorCodeIfFalse(&errorCode,*Size > 0, oC_ErrorCode_SizeNotCorrect) &&
235 oC_AssignErrorCodeIfFalse(&errorCode,isarraycorrect(Buffer,*Size), oC_ErrorCode_ArraySizeTooBig)
238 errorCode = oC_Driver_Write(File->Driver,File->DriverContext,Buffer,Size,oC_hour(1));
248 return oC_ErrorCode_NotHandledByDriver;
255 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
258 oC_AssignErrorCodeIfFalse(&errorCode,IsFileCorrect(File), oC_ErrorCode_ObjectNotCorrect) &&
259 oC_AssignErrorCodeIfFalse(&errorCode,oC_Ioctl_IsCorrectCommand(Command), oC_ErrorCode_CommandNotCorrect)
262 if(Command == oC_IoCtl_SpecialCommand_SetDriverContext)
264 File->DriverContext = Pointer;
265 errorCode = oC_ErrorCode_None;
269 errorCode = oC_Driver_HandleIoctl(File->Driver,File->DriverContext,Command,Pointer);
280 return oC_ErrorCode_NotHandledByFileSystem;
287 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
290 oC_AssignErrorCodeIfFalse(&errorCode,IsFileCorrect(File), oC_ErrorCode_ObjectNotCorrect) &&
291 oC_AssignErrorCodeIfFalse(&errorCode,isram(outCharacter), oC_ErrorCode_OutputAddressNotInRAM)
294 uint32_t bytesToRead = 1;
295 errorCode = oC_Driver_Read(File->Driver,File->DriverContext,outCharacter,&bytesToRead,oC_hour(1));
305 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
308 oC_AssignErrorCodeIfFalse(&errorCode,IsFileCorrect(File), oC_ErrorCode_ObjectNotCorrect)
311 uint32_t bytesToWrite = 1;
312 errorCode = oC_Driver_Write(File->Driver,File->DriverContext,&Character,&bytesToWrite,oC_hour(1));
336 return sizeof(oC_Driver_Registration_t);
343 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
346 oC_AssignErrorCodeIfFalse(&errorCode , isram(outDir) , oC_ErrorCode_OutputAddressNotInRAM) &&
347 oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Path) , oC_ErrorCode_WrongAddress) &&
348 oC_AssignErrorCodeIfFalse(&errorCode , strcmp(Path,
"/") == 0 , oC_ErrorCode_NoSuchFile)
351 oC_Dir_t dir = smartalloc(
sizeof(
struct Dir_t),AllocationFlags_CanWaitForever);
356 dir->CurrentDriver = 0;
358 errorCode = oC_ErrorCode_None;
362 errorCode = oC_ErrorCode_AllocationError;
373 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
375 if(oC_AssignErrorCodeIfFalse(&errorCode , IsDirCorrect(Dir) , oC_ErrorCode_ObjectNotCorrect ))
377 Dir->ObjectControl = 0;
379 if(smartfree(Dir,
sizeof(
struct Dir_t),AllocationFlags_CanWaitForever))
381 errorCode = oC_ErrorCode_None;
385 errorCode = oC_ErrorCode_ReleaseError;
396 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
399 oC_AssignErrorCodeIfFalse(&errorCode , IsDirCorrect(Dir) , oC_ErrorCode_ObjectNotCorrect ) &&
400 oC_AssignErrorCodeIfFalse(&errorCode , isram(outFileInfo), oC_ErrorCode_OutputAddressNotInRAM )
403 oC_List(oC_Driver_t) drivers = oC_DriverMan_GetList();
405 if(oC_List_IsCorrect(drivers))
407 oC_Driver_t driver =
NULL;
409 oC_List_At(drivers,Dir->CurrentDriver,driver);
413 outFileInfo->Name = driver->FileName;
414 outFileInfo->Size =
sizeof(oC_Driver_Registration_t);
415 outFileInfo->Timestamp = 0;
416 outFileInfo->FileType = oC_FileSystem_FileType_File;
418 Dir->CurrentDriver++;
420 errorCode = oC_ErrorCode_None;
424 errorCode = oC_ErrorCode_NoSuchFile;
429 errorCode = oC_ErrorCode_ListNotCorrect;
440 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
443 oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Path) , oC_ErrorCode_WrongAddress ) &&
444 oC_AssignErrorCodeIfFalse(&errorCode , isram(outFileInfo) , oC_ErrorCode_OutputAddressNotInRAM ) &&
445 oC_AssignErrorCodeIfFalse(&errorCode , strlen(Path) >= 2 , oC_ErrorCode_NoSuchFile ) &&
446 oC_AssignErrorCodeIfFalse(&errorCode , Path[0] ==
'/' , oC_ErrorCode_NoSuchFile )
449 oC_List(oC_Driver_t) drivers = oC_DriverMan_GetList();
451 errorCode = oC_ErrorCode_NoSuchFile;
453 oC_List_Foreach(drivers,driver)
455 if(strcmp(&Path[1],driver->FileName)==0)
457 outFileInfo->Name = driver->FileName;
458 outFileInfo->Size =
sizeof(oC_Driver_Registration_t);
459 outFileInfo->Timestamp = 0;
461 errorCode = oC_ErrorCode_None;
475 return oC_ErrorCode_NotHandledByFileSystem;
480 oC_ErrorCode_t oC_DevFs_rename(
oC_DevFs_Context_t Context ,
const char * OldName ,
const char * NewName)
482 return oC_ErrorCode_NotHandledByFileSystem;
487 oC_ErrorCode_t oC_DevFs_chmod(
oC_DevFs_Context_t Context ,
const char * Path, oC_FileSystem_FileAttributes_t Attributes , oC_FileSystem_FileAttributes_t Mask)
489 return oC_ErrorCode_NotHandledByFileSystem;
494 oC_ErrorCode_t oC_DevFs_utime(
oC_DevFs_Context_t Context ,
const char * Path , oC_Timestamp_t Timestamp )
496 return oC_ErrorCode_NotHandledByFileSystem;
503 return oC_ErrorCode_NotHandledByFileSystem;
510 return strcmp(Path,
"/") == 0;
513 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 520 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ 522 static bool IsFileCorrect(
oC_File_t File )
527 static bool IsDirCorrect(
oC_Dir_t Dir )
532 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
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
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 drivers manager interface.
The file with interface for device drivers file system.
The file with standard input/output operations.
#define NULL
pointer to a zero