aboutsummaryrefslogtreecommitdiffstats
path: root/src/gfile/inc_fatfs.c
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2014-08-12 16:43:45 +1000
committerinmarket <andrewh@inmarket.com.au>2014-08-12 16:43:45 +1000
commit10902154aec652a3fcdf028b2c6ff16743464973 (patch)
tree2941d4f7ed14450ee5731da2e106f824e3435ee8 /src/gfile/inc_fatfs.c
parent6ff7d90500bf5939252eb39272558706da1b8f44 (diff)
downloaduGFX-10902154aec652a3fcdf028b2c6ff16743464973.tar.gz
uGFX-10902154aec652a3fcdf028b2c6ff16743464973.tar.bz2
uGFX-10902154aec652a3fcdf028b2c6ff16743464973.zip
GFILE: restructure files, add File Listing, add C String files
Fix compile error for ChibiOS BaseStreamFile based GFILES'.
Diffstat (limited to 'src/gfile/inc_fatfs.c')
-rw-r--r--src/gfile/inc_fatfs.c81
1 files changed, 78 insertions, 3 deletions
diff --git a/src/gfile/inc_fatfs.c b/src/gfile/inc_fatfs.c
index 8d7233e7..c8db0e64 100644
--- a/src/gfile/inc_fatfs.c
+++ b/src/gfile/inc_fatfs.c
@@ -30,6 +30,11 @@ 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);
+#if _FS_MINIMIZE <= 1 && GFILE_NEED_FILELISTS
+ static gfileList *fatfsFlOpen(const char *path, bool_t dirs);
+ static const char *fatfsFlRead(gfileList *pfl);
+ static void fatfsFlClose(gfileList *pfl);
+#endif
static const GFILEVMT FsFatFSVMT = {
GFILE_CHAINHEAD,
@@ -46,14 +51,29 @@ static const GFILEVMT FsFatFSVMT = {
fatfsSetPos,
fatfsGetSize,
fatfsEOF,
- fatfsMount,
- fatfsUnmount,
- fatfsSync
+ fatfsMount, fatfsUnmount, fatfsSync,
+ #if GFILE_NEED_FILELISTS
+ #if _FS_MINIMIZE <= 1
+ fatfsFlOpen, fatfsFlRead, fatfsFlClose
+ #else
+ 0, 0, 0
+ #endif
+ #endif
};
#undef GFILE_CHAINHEAD
#define GFILE_CHAINHEAD &FsFatFSVMT
+// Our directory list structure
+typedef struct fatfsList {
+ gfileList fl; // This must be the first element.
+ DIR dir;
+ FILINFO fno;
+ #if _USE_LFN
+ char lfn[_MAX_LFN + 1]; /* Buffer to store the LFN */
+ #endif
+} fatfsList;
+
// optimize these later on. Use an array to have multiple FatFS
static bool_t fatfs_mounted = FALSE;
static FATFS fatfs_fs;
@@ -245,3 +265,58 @@ static bool_t fatfsSync(GFILE *f)
return TRUE;
}
+#if _FS_MINIMIZE <= 1 && GFILE_NEED_FILELISTS
+ static gfileList *fatfsFlOpen(const char *path, bool_t dirs) {
+ fatfsList *p;
+ (void) dirs;
+
+ if (!(p = gfxAlloc(sizeof(fatfsList))))
+ return 0;
+
+ if (f_opendir(&p->dir, path) != FR_OK) {
+ gfxFree(p);
+ return 0;
+ }
+ return &p->fl;
+ }
+
+ static const char *fatfsFlRead(gfileList *pfl) {
+ #define ffl ((fatfsList *)pfl)
+
+ while(1) {
+ #if _USE_LFN
+ ffl->fno.lfname = ffl->lfn;
+ ffl->fno.lfsize = sizeof(ffl->lfn);
+ #endif
+
+ // Read the next entry
+ if (f_readdir(&ffl->dir, &ffl->fno) != FR_OK || !ffl->fno.fname[0])
+ return 0;
+
+ /* Ignore dot entries */
+ if (ffl->fno.fname[0] == '.') continue;
+
+ /* Is it a directory */
+ if (ffl->fl.dirs) {
+ if ((ffl->fno.fattrib & AM_DIR))
+ break;
+ } else {
+ if (!(ffl->fno.fattrib & AM_DIR))
+ break;
+ }
+ }
+
+ #if _USE_LFN
+ return ffl->fno.lfname[0] ? ffl->fno.lfname : ffl->fno.fname;
+ #else
+ return ffl->fno.fname;
+ #endif
+ #undef ffl
+ }
+
+ static void fatfsFlClose(gfileList *pfl) {
+ f_closedir(&((fatfsList *)pfl)->dir);
+ gfxFree(pfl);
+ }
+
+#endif