aboutsummaryrefslogtreecommitdiffstats
path: root/src/gfile
diff options
context:
space:
mode:
authorJoel Bodenmann <joel@unormal.org>2014-06-29 16:15:46 +0200
committerJoel Bodenmann <joel@unormal.org>2014-06-29 16:15:46 +0200
commit5c13e08e76ae1d75240e1e8e46d1e9c3a8ba50cd (patch)
treef5c30d5e5c9342d308ff1a20786ea6a86bb04c1f /src/gfile
parente318ec02d6c3cb96a84679befd0ac447eb597158 (diff)
downloaduGFX-5c13e08e76ae1d75240e1e8e46d1e9c3a8ba50cd.tar.gz
uGFX-5c13e08e76ae1d75240e1e8e46d1e9c3a8ba50cd.tar.bz2
uGFX-5c13e08e76ae1d75240e1e8e46d1e9c3a8ba50cd.zip
added gfileSync() and autosync feature
Diffstat (limited to 'src/gfile')
-rw-r--r--src/gfile/gfile.c7
-rw-r--r--src/gfile/inc_chibiosfs.c3
-rw-r--r--src/gfile/inc_fatfs.c24
-rw-r--r--src/gfile/inc_memfs.c3
-rw-r--r--src/gfile/inc_nativefs.c3
-rw-r--r--src/gfile/inc_romfs.c3
-rw-r--r--src/gfile/sys_defs.h13
-rw-r--r--src/gfile/sys_options.h13
8 files changed, 64 insertions, 5 deletions
diff --git a/src/gfile/gfile.c b/src/gfile/gfile.c
index ba1b2dba..6aadda09 100644
--- a/src/gfile/gfile.c
+++ b/src/gfile/gfile.c
@@ -58,6 +58,7 @@ typedef struct GFILEVMT {
bool_t (*eof) (GFILE *f);
bool_t (*mount) (const char *drive);
bool_t (*unmount) (const char *drive);
+ bool_t (*sync) (GFILE *f);
} GFILEVMT;
// The chain of FileSystems
@@ -505,6 +506,12 @@ bool_t gfileUnmount(char fs, const char* drive) {
return FALSE;
}
+bool_t gfileSync(GFILE *f) {
+ if (!f->vmt->sync)
+ return FALSE;
+ return f->vmt->sync(f);
+}
+
/********************************************************
* String VMT routines
********************************************************/
diff --git a/src/gfile/inc_chibiosfs.c b/src/gfile/inc_chibiosfs.c
index 92664288..8d321b33 100644
--- a/src/gfile/inc_chibiosfs.c
+++ b/src/gfile/inc_chibiosfs.c
@@ -27,7 +27,8 @@ static const GFILEVMT FsCHIBIOSVMT = {
0, 0, 0, 0,
0, ChibiOSBFSClose, ChibiOSBFSRead, ChibiOSBFSWrite,
ChibiOSBFSSetpos, ChibiOSBFSGetsize, ChibiOSBFSEof,
- 0, 0
+ 0, 0,
+ 0
};
static void ChibiOSBFSClose(GFILE *f) {
diff --git a/src/gfile/inc_fatfs.c b/src/gfile/inc_fatfs.c
index a9066bf9..447b8a71 100644
--- a/src/gfile/inc_fatfs.c
+++ b/src/gfile/inc_fatfs.c
@@ -29,6 +29,7 @@ static long int fatfsGetSize(GFILE* f);
static bool_t fatfsEOF(GFILE* f);
static bool_t fatfsMount(const char* drive);
static bool_t fatfsUnmount(const char* drive);
+static bool_t fatfsSync(GFILE* f);
static const GFILEVMT FsFatFSVMT = {
GFILE_CHAINHEAD,
@@ -46,7 +47,8 @@ static const GFILEVMT FsFatFSVMT = {
fatfsGetSize,
fatfsEOF,
fatfsMount,
- fatfsUnmount
+ fatfsUnmount,
+ fatfsSync
};
#undef GFILE_CHAINHEAD
@@ -140,6 +142,13 @@ static bool_t fatfsOpen(GFILE* f, const char* fname)
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;
}
@@ -165,6 +174,7 @@ static int fatfsWrite(GFILE* f, const void* buf, int size)
int wr;
f_write( (FIL*)f->obj, buf, size, (UINT*)&wr);
+ f_sync( (FIL*)f->obj );
return wr;
}
@@ -221,3 +231,15 @@ static bool_t fatfsUnmount(const char* drive)
return FALSE;
}
+static bool_t fatfsSync(GFILE *f)
+{
+ FRESULT ferr;
+
+ ferr = f_sync( (FIL*)f->obj );
+ if (ferr != FR_OK) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
diff --git a/src/gfile/inc_memfs.c b/src/gfile/inc_memfs.c
index c7322686..baeb0e97 100644
--- a/src/gfile/inc_memfs.c
+++ b/src/gfile/inc_memfs.c
@@ -26,7 +26,8 @@ static const GFILEVMT FsMemVMT = {
0, 0, 0, 0,
0, 0, MEMRead, MEMWrite,
MEMSetpos, 0, 0,
- 0, 0
+ 0, 0,
+ 0
};
static int MEMRead(GFILE *f, void *buf, int size) {
diff --git a/src/gfile/inc_nativefs.c b/src/gfile/inc_nativefs.c
index 98e0ab10..6845cb71 100644
--- a/src/gfile/inc_nativefs.c
+++ b/src/gfile/inc_nativefs.c
@@ -46,7 +46,8 @@ static const GFILEVMT FsNativeVMT = {
NativeDel, NativeExists, NativeFilesize, NativeRen,
NativeOpen, NativeClose, NativeRead, NativeWrite,
NativeSetpos, NativeGetsize, NativeEof,
- 0, 0
+ 0, 0,
+ 0
};
#undef GFILE_CHAINHEAD
#define GFILE_CHAINHEAD &FsNativeVMT
diff --git a/src/gfile/inc_romfs.c b/src/gfile/inc_romfs.c
index 9f7faf7c..167430ce 100644
--- a/src/gfile/inc_romfs.c
+++ b/src/gfile/inc_romfs.c
@@ -52,7 +52,8 @@ static const GFILEVMT FsROMVMT = {
0, ROMExists, ROMFilesize, 0,
ROMOpen, ROMClose, ROMRead, 0,
ROMSetpos, ROMGetsize, ROMEof,
- 0, 0
+ 0, 0,
+ 0
};
#undef GFILE_CHAINHEAD
#define GFILE_CHAINHEAD &FsROMVMT
diff --git a/src/gfile/sys_defs.h b/src/gfile/sys_defs.h
index 6b1d27ff..4280f7fe 100644
--- a/src/gfile/sys_defs.h
+++ b/src/gfile/sys_defs.h
@@ -226,6 +226,19 @@ extern "C" {
*/
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
GFILE * gfileOpenBaseFileStream(void *BaseFileStreamPtr, const char *mode);
#endif
diff --git a/src/gfile/sys_options.h b/src/gfile/sys_options.h
index 41cf6a63..ee52298c 100644
--- a/src/gfile/sys_options.h
+++ b/src/gfile/sys_options.h
@@ -31,6 +31,19 @@
#define GFILE_NEED_NOAUTOMOUNT FALSE
#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
* @details Defaults to FALSE
*/