aboutsummaryrefslogtreecommitdiffstats
path: root/src/gfile
diff options
context:
space:
mode:
authorJoel Bodenmann <joel@unormal.org>2014-06-27 00:38:46 +0200
committerJoel Bodenmann <joel@unormal.org>2014-06-27 00:38:46 +0200
commit11e3d1fa22ee8df088621dfefe5ebfa4b0697d9c (patch)
treef4b1b20e5a0395b0df090df3e9254d6a83a283d7 /src/gfile
parent1785f32976ece91f7b483222c0eb688ed61653e6 (diff)
downloaduGFX-11e3d1fa22ee8df088621dfefe5ebfa4b0697d9c.tar.gz
uGFX-11e3d1fa22ee8df088621dfefe5ebfa4b0697d9c.tar.bz2
uGFX-11e3d1fa22ee8df088621dfefe5ebfa4b0697d9c.zip
first working FatFS implementation. Modes ToDo
Diffstat (limited to 'src/gfile')
-rw-r--r--src/gfile/fatfs/src/ffconf.h2
-rw-r--r--src/gfile/inc_fatfs.c38
2 files changed, 27 insertions, 13 deletions
diff --git a/src/gfile/fatfs/src/ffconf.h b/src/gfile/fatfs/src/ffconf.h
index d883c14b..72fc6143 100644
--- a/src/gfile/fatfs/src/ffconf.h
+++ b/src/gfile/fatfs/src/ffconf.h
@@ -33,7 +33,7 @@
/ 3: f_lseek() function is removed in addition to 2. */
-#define _USE_STRFUNC 0 /* 0:Disable or 1-2:Enable */
+#define _USE_STRFUNC 1 /* 0:Disable or 1-2:Enable */
/* To enable string functions, set _USE_STRFUNC to 1 or 2. */
diff --git a/src/gfile/inc_fatfs.c b/src/gfile/inc_fatfs.c
index 911cf59c..a3976d24 100644
--- a/src/gfile/inc_fatfs.c
+++ b/src/gfile/inc_fatfs.c
@@ -15,12 +15,11 @@
/*
* ToDo:
*
- * - fatfsExists()
* - f_mount has to be called before the disk can be accessed
* - complete _flags2mode()
* - restructure provided diskio.c files
- * - do full testing
*/
+
/********************************************************
* The FAT file-system VMT
********************************************************/
@@ -39,7 +38,7 @@ static bool_t fatfsEOF(GFILE* f);
static const GFILEVMT FsFatFSVMT = {
GFILE_CHAINHEAD,
- GFSFLG_SEEKABLE,
+ GFSFLG_WRITEABLE | GFSFLG_SEEKABLE,
'F',
fatfsDel,
fatfsExists,
@@ -61,12 +60,14 @@ static void _flags2mode(GFILE* f, BYTE* mode)
{
*mode = 0;
- if (f->flags & GFILEFLG_MUSTEXIST)
+ if (f->flags & GFILEFLG_READ)
*mode |= FA_READ;
- else if (f->flags & GFILEFLG_APPEND)
- *mode |= 0; /* ToDO */
- else
+ if (f->flags & GFILEFLG_WRITE)
*mode |= FA_WRITE;
+ if (f->flags & GFILEFLG_APPEND)
+ *mode |= 0; // ToDo
+ if (f->flags & GFILEFLG_TRUNC)
+ *mode |= FA_CREATE_ALWAYS;
/* ToDo - Complete */
}
@@ -84,9 +85,12 @@ static bool_t fatfsDel(const char* fname)
static bool_t fatfsExists(const char* fname)
{
- (void)fname;
+ FRESULT ferr;
+ FILINFO fno;
- /* ToDo */
+ ferr = f_stat( (const TCHAR*)fname, &fno);
+ if (ferr != FR_OK)
+ return FALSE;
return TRUE;
}
@@ -116,15 +120,22 @@ static bool_t fatfsRename(const char* oldname, const char* newname)
static bool_t fatfsOpen(GFILE* f, const char* fname)
{
- FIL* fd = 0;
+ FIL* fd;
BYTE mode;
FRESULT ferr;
+ if (!(fd = gfxAlloc(sizeof(FIL))))
+ return FALSE;
+
_flags2mode(f, &mode);
ferr = f_open(fd, fname, mode);
- if (ferr != FR_OK)
+ if (ferr != FR_OK) {
+ gfxFree( (FIL*)f->obj );
+ f->obj = 0;
+
return FALSE;
+ }
f->obj = (void*)fd;
@@ -133,6 +144,9 @@ static bool_t fatfsOpen(GFILE* f, const char* fname)
static void fatfsClose(GFILE* f)
{
+ if ((FIL*)f->obj != 0)
+ gfxFree( (FIL*)f->obj );
+
f_close( (FIL*)f->obj );
}
@@ -167,7 +181,7 @@ static bool_t fatfsSetPos(GFILE* f, long int pos)
static long int fatfsGetSize(GFILE* f)
{
- return (long int)f_tell( (FIL*)f->obj );
+ return (long int)f_size( (FIL*)f->obj );
}
static bool_t fatfsEOF(GFILE* f)