first working FatFS implementation. Modes ToDo
This commit is contained in:
parent
1785f32976
commit
11e3d1fa22
2 changed files with 27 additions and 13 deletions
|
@ -33,7 +33,7 @@
|
||||||
/ 3: f_lseek() function is removed in addition to 2. */
|
/ 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. */
|
/* To enable string functions, set _USE_STRFUNC to 1 or 2. */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,12 +15,11 @@
|
||||||
/*
|
/*
|
||||||
* ToDo:
|
* ToDo:
|
||||||
*
|
*
|
||||||
* - fatfsExists()
|
|
||||||
* - f_mount has to be called before the disk can be accessed
|
* - f_mount has to be called before the disk can be accessed
|
||||||
* - complete _flags2mode()
|
* - complete _flags2mode()
|
||||||
* - restructure provided diskio.c files
|
* - restructure provided diskio.c files
|
||||||
* - do full testing
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/********************************************************
|
/********************************************************
|
||||||
* The FAT file-system VMT
|
* The FAT file-system VMT
|
||||||
********************************************************/
|
********************************************************/
|
||||||
|
@ -39,7 +38,7 @@ static bool_t fatfsEOF(GFILE* f);
|
||||||
|
|
||||||
static const GFILEVMT FsFatFSVMT = {
|
static const GFILEVMT FsFatFSVMT = {
|
||||||
GFILE_CHAINHEAD,
|
GFILE_CHAINHEAD,
|
||||||
GFSFLG_SEEKABLE,
|
GFSFLG_WRITEABLE | GFSFLG_SEEKABLE,
|
||||||
'F',
|
'F',
|
||||||
fatfsDel,
|
fatfsDel,
|
||||||
fatfsExists,
|
fatfsExists,
|
||||||
|
@ -61,12 +60,14 @@ static void _flags2mode(GFILE* f, BYTE* mode)
|
||||||
{
|
{
|
||||||
*mode = 0;
|
*mode = 0;
|
||||||
|
|
||||||
if (f->flags & GFILEFLG_MUSTEXIST)
|
if (f->flags & GFILEFLG_READ)
|
||||||
*mode |= FA_READ;
|
*mode |= FA_READ;
|
||||||
else if (f->flags & GFILEFLG_APPEND)
|
if (f->flags & GFILEFLG_WRITE)
|
||||||
*mode |= 0; /* ToDO */
|
|
||||||
else
|
|
||||||
*mode |= FA_WRITE;
|
*mode |= FA_WRITE;
|
||||||
|
if (f->flags & GFILEFLG_APPEND)
|
||||||
|
*mode |= 0; // ToDo
|
||||||
|
if (f->flags & GFILEFLG_TRUNC)
|
||||||
|
*mode |= FA_CREATE_ALWAYS;
|
||||||
|
|
||||||
/* ToDo - Complete */
|
/* ToDo - Complete */
|
||||||
}
|
}
|
||||||
|
@ -84,9 +85,12 @@ static bool_t fatfsDel(const char* fname)
|
||||||
|
|
||||||
static bool_t fatfsExists(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;
|
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)
|
static bool_t fatfsOpen(GFILE* f, const char* fname)
|
||||||
{
|
{
|
||||||
FIL* fd = 0;
|
FIL* fd;
|
||||||
BYTE mode;
|
BYTE mode;
|
||||||
FRESULT ferr;
|
FRESULT ferr;
|
||||||
|
|
||||||
|
if (!(fd = gfxAlloc(sizeof(FIL))))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
_flags2mode(f, &mode);
|
_flags2mode(f, &mode);
|
||||||
|
|
||||||
ferr = f_open(fd, fname, mode);
|
ferr = f_open(fd, fname, mode);
|
||||||
if (ferr != FR_OK)
|
if (ferr != FR_OK) {
|
||||||
|
gfxFree( (FIL*)f->obj );
|
||||||
|
f->obj = 0;
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
f->obj = (void*)fd;
|
f->obj = (void*)fd;
|
||||||
|
|
||||||
|
@ -133,6 +144,9 @@ static bool_t fatfsOpen(GFILE* f, const char* fname)
|
||||||
|
|
||||||
static void fatfsClose(GFILE* f)
|
static void fatfsClose(GFILE* f)
|
||||||
{
|
{
|
||||||
|
if ((FIL*)f->obj != 0)
|
||||||
|
gfxFree( (FIL*)f->obj );
|
||||||
|
|
||||||
f_close( (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)
|
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)
|
static bool_t fatfsEOF(GFILE* f)
|
||||||
|
|
Loading…
Add table
Reference in a new issue