12 #include "../../gfx.h"
14 #if GFX_USE_GFILE && GFILE_NEED_PETITFS
19 static gBool petitfsExists(
const char* fname);
20 static gBool petitfsOpen(
GFILE* f,
const char* fname);
21 static int petitfsRead(
GFILE* f,
void* buf,
int size);
22 static gBool petitfsSetPos(
GFILE* f, gFileSize pos);
23 #if GFILE_NEED_FILELISTS && _FS_MINIMIZE <= 1
24 static gfileList *petitfsFlOpen(
const char *path, gBool dirs);
25 static const char *petitfsFlRead(gfileList *pfl);
26 static void petitfsFlClose(gfileList *pfl);
29 const GFILEVMT FsPetitFSVMT = {
30 GFSFLG_WRITEABLE | GFSFLG_SEEKABLE,
44 #if GFILE_NEED_FILELISTS
46 petitfsFlOpen, petitfsFlRead, petitfsFlClose
54 typedef struct petitfsList {
61 static gBool petitfs_mounted = gFalse;
62 static FATFS petitfs_fs;
64 static gBool petitfsExists(
const char* fname)
67 if (!petitfs_mounted && pf_mount(&petitfs_fs) != FR_OK)
71 if (pf_open(fname) != FR_OK)
77 static gBool petitfsOpen(
GFILE* f,
const char* fname)
80 if ((f->flags & GFILEFLG_WRITE))
84 if (!petitfs_mounted && pf_mount(&petitfs_fs) != FR_OK)
88 if (pf_open(fname) != FR_OK)
95 static int petitfsRead(
GFILE* f,
void* buf,
int size)
100 if (pf_read(buf, size, (UINT*)&br) != FR_OK)
106 static gBool petitfsSetPos(
GFILE* f, gFileSize pos)
109 return pf_lseek((DWORD)pos) == FR_OK;
112 #if GFILE_NEED_FILELISTS
113 static gfileList *petitfsFlOpen(
const char *path, gBool dirs) {
117 if (!(p =
gfxAlloc(
sizeof(petitfsList))))
120 if (pf_opendir(&p->dir, path) != FR_OK) {
127 static const char *petitfsFlRead(gfileList *pfl) {
128 #define ffl ((petitfsList *)pfl)
132 if (pf_readdir(&ffl->dir, &ffl->fno) != FR_OK || !ffl->fno.fname[0])
136 if (ffl->fno.fname[0] ==
'.')
continue;
140 if ((ffl->fno.fattrib & AM_DIR))
143 if (!(ffl->fno.fattrib & (AM_DIR|AM_HID|AM_SYS)))
148 return ffl->fno.fname;
151 static void petitfsFlClose(gfileList *pfl) {
GFILE file system header.
struct GFILE GFILE
A file pointer.
void * gfxAlloc(gMemSize sz)
Allocate memory.
void gfxFree(void *ptr)
Free memory.