Integration of FatFS with ChocoOS

Issue #234 new
Patryk Kubiak created an issue

General Description

To use SD/MMC cards (or other storages) it is required to port FatFS with the system to allow for using FAT. Description of FatFS library can be found here: http://elm-chan.org/fsw/ff/00index_e.html

Here is the link to FatFS from dnx-rtos: FatFS

The library has to be ported to the ChocoOS file system interface

Trello link: https://trello.com/c/sCm2zIfQ

File System Definition

  • Name - "fatfs"

Architecture

FatFS1.png

Interface

Here is an interface required to be implemented:

struct Context_t
{
    oC_ObjectControl_t     ObjectControl;
    FATFS                          FatFsContext;
};

struct File_t
{
    oC_ObjectControl_t     ObjectControl;
    FIL                                FatFsFile;
};

struct Dir_t
{
    oC_ObjectControl_t ObjectControl;
    DIR   FatFsDir;
};

extern const oC_FileSystem_Registration_t FatFs;
// Initializes file system
extern oC_ErrorCode_t       oC_FatFs_init           ( oC_FatFs_Context_t * outContext , oC_Storage_t Storage );
// destroys file system
extern oC_ErrorCode_t       oC_FatFs_deinit         ( oC_FatFs_Context_t Context );
// opens file
extern oC_ErrorCode_t       oC_FatFs_fopen          ( oC_FatFs_Context_t Context , oC_File_t * outFile , const char * Path , oC_FileSystem_ModeFlags_t Mode , oC_FileSystem_FileAttributes_t Attributes );
// closes file
extern oC_ErrorCode_t       oC_FatFs_fclose         ( oC_FatFs_Context_t Context , oC_File_t File );
// reads bytes from the file
extern oC_ErrorCode_t       oC_FatFs_fread          ( oC_FatFs_Context_t Context , oC_File_t File , void * outBuffer , uint32_t * Size );
// writes byte to the file
extern oC_ErrorCode_t       oC_FatFs_fwrite         ( oC_FatFs_Context_t Context , oC_File_t File , const void * Buffer , uint32_t * Size );
// sets offset in the file
extern oC_ErrorCode_t       oC_FatFs_lseek          ( oC_FatFs_Context_t Context , oC_File_t File , uint32_t Offset );
// performs special request to the file
extern oC_ErrorCode_t       oC_FatFs_ioctl          ( oC_FatFs_Context_t Context , oC_File_t File , oC_Ioctl_Command_t Command , void * Pointer);
// see `sync` from posix
extern oC_ErrorCode_t       oC_FatFs_sync           ( oC_FatFs_Context_t Context , oC_File_t File );
// reads 1 char from file
extern oC_ErrorCode_t       oC_FatFs_getc           ( oC_FatFs_Context_t Context , char * outCharacter , oC_File_t File );
// puts 1 char to file
extern oC_ErrorCode_t       oC_FatFs_putc           ( oC_FatFs_Context_t Context , char Character , oC_File_t File );
// reads offset in file
extern int32_t              oC_FatFs_tell           ( oC_FatFs_Context_t Context , oC_File_t File );
// returns true if this is end of file
extern bool                 oC_FatFs_eof            ( oC_FatFs_Context_t Context , oC_File_t File );
// returns file size
extern uint32_t             oC_FatFs_size           ( oC_FatFs_Context_t Context , oC_File_t File );

// opens directory
extern oC_ErrorCode_t       oC_FatFs_opendir        ( oC_DevFs_Context_t Context , oC_Dir_t * outDir , const char * Path );
// closes directory
extern oC_ErrorCode_t       oC_FatFs_closedir       ( oC_DevFs_Context_t Context , oC_Dir_t Dir );
// reads next file information from the directory (each execution returns info about next file)
extern oC_ErrorCode_t       oC_FatFs_readdir        ( oC_DevFs_Context_t Context , oC_Dir_t Dir , oC_FileInfo_t * outFileInfo );
// Returns info about the given file
extern oC_ErrorCode_t       oC_FatFs_stat           ( oC_DevFs_Context_t Context , const char * Path , oC_FileInfo_t * outFileInfo);
// deletes a file
extern oC_ErrorCode_t       oC_FatFs_unlink         ( oC_DevFs_Context_t Context , const char * Path);
// changes name of a file
extern oC_ErrorCode_t       oC_FatFs_rename         ( oC_DevFs_Context_t Context , const char * OldName , const char * NewName);
// changes attributes of the file
extern oC_ErrorCode_t       oC_FatFs_chmod          ( oC_DevFs_Context_t Context , const char * Path, oC_FileSystem_FileAttributes_t Attributes , oC_FileSystem_FileAttributes_t Mask);
// sets timestamp of file
extern oC_ErrorCode_t       oC_FatFs_utime          ( oC_DevFs_Context_t Context , const char * Path , oC_Timestamp_t Timestamp );
// creates new directory
extern oC_ErrorCode_t       oC_FatFs_mkdir          ( oC_DevFs_Context_t Context , const char * Path);
// returns true if directory exists
extern bool                 oC_FatFs_DirExists      ( oC_DevFs_Context_t Context , const char * Path);

Comments (9)

  1. Log in to comment