added gfileSync() and autosync feature

ugfx_release_2.6
Joel Bodenmann 2014-06-29 16:15:46 +02:00
parent e318ec02d6
commit 5c13e08e76
10 changed files with 66 additions and 5 deletions

View File

@ -9,6 +9,7 @@ FEATURE: Added generic framebuffer driver
FEATURE: Added Linux-Framebuffer board definition FEATURE: Added Linux-Framebuffer board definition
FEATURE: Added FatFS support for GFILE FEATURE: Added FatFS support for GFILE
FEATURE: Added gfileMount() and gfileUnmount() FEATURE: Added gfileMount() and gfileUnmount()
FEATURE: Added gfileSync()
*** Release 2.1 *** *** Release 2.1 ***

View File

@ -220,6 +220,7 @@
// #define GFILE_ALLOW_DEVICESPECIFIC FALSE // #define GFILE_ALLOW_DEVICESPECIFIC FALSE
// #define GFILE_MAX_GFILES 3 // #define GFILE_MAX_GFILES 3
//#define GFILE_NEED_NOAUTOMOUNT FALSE //#define GFILE_NEED_NOAUTOMOUNT FALSE
//#define GFILE_NEED_NOAUTOSYNC FALSE
//#define GFILE_NEED_MEMFS FALSE //#define GFILE_NEED_MEMFS FALSE
//#define GFILE_NEED_ROMFS FALSE //#define GFILE_NEED_ROMFS FALSE

View File

@ -58,6 +58,7 @@ typedef struct GFILEVMT {
bool_t (*eof) (GFILE *f); bool_t (*eof) (GFILE *f);
bool_t (*mount) (const char *drive); bool_t (*mount) (const char *drive);
bool_t (*unmount) (const char *drive); bool_t (*unmount) (const char *drive);
bool_t (*sync) (GFILE *f);
} GFILEVMT; } GFILEVMT;
// The chain of FileSystems // The chain of FileSystems
@ -505,6 +506,12 @@ bool_t gfileUnmount(char fs, const char* drive) {
return FALSE; return FALSE;
} }
bool_t gfileSync(GFILE *f) {
if (!f->vmt->sync)
return FALSE;
return f->vmt->sync(f);
}
/******************************************************** /********************************************************
* String VMT routines * String VMT routines
********************************************************/ ********************************************************/

View File

@ -27,7 +27,8 @@ static const GFILEVMT FsCHIBIOSVMT = {
0, 0, 0, 0, 0, 0, 0, 0,
0, ChibiOSBFSClose, ChibiOSBFSRead, ChibiOSBFSWrite, 0, ChibiOSBFSClose, ChibiOSBFSRead, ChibiOSBFSWrite,
ChibiOSBFSSetpos, ChibiOSBFSGetsize, ChibiOSBFSEof, ChibiOSBFSSetpos, ChibiOSBFSGetsize, ChibiOSBFSEof,
0, 0 0, 0,
0
}; };
static void ChibiOSBFSClose(GFILE *f) { static void ChibiOSBFSClose(GFILE *f) {

View File

@ -29,6 +29,7 @@ static long int fatfsGetSize(GFILE* f);
static bool_t fatfsEOF(GFILE* f); static bool_t fatfsEOF(GFILE* f);
static bool_t fatfsMount(const char* drive); static bool_t fatfsMount(const char* drive);
static bool_t fatfsUnmount(const char* drive); static bool_t fatfsUnmount(const char* drive);
static bool_t fatfsSync(GFILE* f);
static const GFILEVMT FsFatFSVMT = { static const GFILEVMT FsFatFSVMT = {
GFILE_CHAINHEAD, GFILE_CHAINHEAD,
@ -46,7 +47,8 @@ static const GFILEVMT FsFatFSVMT = {
fatfsGetSize, fatfsGetSize,
fatfsEOF, fatfsEOF,
fatfsMount, fatfsMount,
fatfsUnmount fatfsUnmount,
fatfsSync
}; };
#undef GFILE_CHAINHEAD #undef GFILE_CHAINHEAD
@ -140,6 +142,13 @@ static bool_t fatfsOpen(GFILE* f, const char* fname)
f->obj = (void*)fd; f->obj = (void*)fd;
#if !GFILE_NEED_NOAUTOSYNC
// no need to sync when not opening for write
if (f->flags & GFILEFLG_WRITE) {
f_sync( (FIL*)f->obj );
}
#endif
return TRUE; return TRUE;
} }
@ -165,6 +174,7 @@ static int fatfsWrite(GFILE* f, const void* buf, int size)
int wr; int wr;
f_write( (FIL*)f->obj, buf, size, (UINT*)&wr); f_write( (FIL*)f->obj, buf, size, (UINT*)&wr);
f_sync( (FIL*)f->obj );
return wr; return wr;
} }
@ -221,3 +231,15 @@ static bool_t fatfsUnmount(const char* drive)
return FALSE; return FALSE;
} }
static bool_t fatfsSync(GFILE *f)
{
FRESULT ferr;
ferr = f_sync( (FIL*)f->obj );
if (ferr != FR_OK) {
return FALSE;
}
return TRUE;
}

View File

@ -26,7 +26,8 @@ static const GFILEVMT FsMemVMT = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, MEMRead, MEMWrite, 0, 0, MEMRead, MEMWrite,
MEMSetpos, 0, 0, MEMSetpos, 0, 0,
0, 0 0, 0,
0
}; };
static int MEMRead(GFILE *f, void *buf, int size) { static int MEMRead(GFILE *f, void *buf, int size) {

View File

@ -46,7 +46,8 @@ static const GFILEVMT FsNativeVMT = {
NativeDel, NativeExists, NativeFilesize, NativeRen, NativeDel, NativeExists, NativeFilesize, NativeRen,
NativeOpen, NativeClose, NativeRead, NativeWrite, NativeOpen, NativeClose, NativeRead, NativeWrite,
NativeSetpos, NativeGetsize, NativeEof, NativeSetpos, NativeGetsize, NativeEof,
0, 0 0, 0,
0
}; };
#undef GFILE_CHAINHEAD #undef GFILE_CHAINHEAD
#define GFILE_CHAINHEAD &FsNativeVMT #define GFILE_CHAINHEAD &FsNativeVMT

View File

@ -52,7 +52,8 @@ static const GFILEVMT FsROMVMT = {
0, ROMExists, ROMFilesize, 0, 0, ROMExists, ROMFilesize, 0,
ROMOpen, ROMClose, ROMRead, 0, ROMOpen, ROMClose, ROMRead, 0,
ROMSetpos, ROMGetsize, ROMEof, ROMSetpos, ROMGetsize, ROMEof,
0, 0 0, 0,
0
}; };
#undef GFILE_CHAINHEAD #undef GFILE_CHAINHEAD
#define GFILE_CHAINHEAD &FsROMVMT #define GFILE_CHAINHEAD &FsROMVMT

View File

@ -226,6 +226,19 @@ extern "C" {
*/ */
bool_t gfileUnmount(char fs, const char *drive); bool_t gfileUnmount(char fs, const char *drive);
/**
* @brief Syncs the file object (flushes the buffer)
*
* @details Not supported by every file system
*
* @param[in] f The file
*
* @return TRUE on success, FALSE otherwise
*
* @api
*/
bool_t gfileSync(GFILE *f);
#if GFILE_NEED_CHIBIOSFS && GFX_USE_OS_CHIBIOS #if GFILE_NEED_CHIBIOSFS && GFX_USE_OS_CHIBIOS
GFILE * gfileOpenBaseFileStream(void *BaseFileStreamPtr, const char *mode); GFILE * gfileOpenBaseFileStream(void *BaseFileStreamPtr, const char *mode);
#endif #endif

View File

@ -30,6 +30,19 @@
#ifndef GFILE_NEED_NOAUTOMOUNT #ifndef GFILE_NEED_NOAUTOMOUNT
#define GFILE_NEED_NOAUTOMOUNT FALSE #define GFILE_NEED_NOAUTOMOUNT FALSE
#endif #endif
/**
* @brief Should the filesystem be synced automatically
* @details The filesystem will automatically be synced after an open() or
* write() call unless this feature is disabled.
* @details If this feature is disabled, the user should sync the filesystem
* himself using @p gfileSync()
* @details Not all filesystems implement the syncing feature. This feature will
* have no effect in such a case.
* @details Defaults to FALSE
*/
#ifndef GFILE_NEED_NOAUTOSYNC
#define GFILE_NEED_NOAUTOSYNC FALSE
#endif
/** /**
* @brief Include printg, fprintg etc functions * @brief Include printg, fprintg etc functions
* @details Defaults to FALSE * @details Defaults to FALSE