Commit 6b755d82 authored by Damien George's avatar Damien George
Browse files

lib/fatfs: Support our volume names; make some funcs static.

parent c546b66b
...@@ -119,6 +119,8 @@ ...@@ -119,6 +119,8 @@
/ Fixed null pointer dereference on attempting to delete the root direcotry. / Fixed null pointer dereference on attempting to delete the root direcotry.
/---------------------------------------------------------------------------*/ /---------------------------------------------------------------------------*/
#include <string.h>
#include "ff.h" /* Declarations of FatFs API */ #include "ff.h" /* Declarations of FatFs API */
#include "diskio.h" /* Declarations of disk I/O functions */ #include "diskio.h" /* Declarations of disk I/O functions */
...@@ -506,7 +508,8 @@ static FATFS *FatFs[_VOLUMES]; /* Pointer to the file system objects (logical dr ...@@ -506,7 +508,8 @@ static FATFS *FatFs[_VOLUMES]; /* Pointer to the file system objects (logical dr
static WORD Fsid; /* File system mount ID */ static WORD Fsid; /* File system mount ID */
#if _FS_RPATH && _VOLUMES >= 2 #if _FS_RPATH && _VOLUMES >= 2
static BYTE CurrVol; /* Current drive */ // dpgeorge: changed name and made non-static
BYTE ff_CurrVol; /* Current drive */
#endif #endif
#if _FS_LOCK #if _FS_LOCK
...@@ -559,6 +562,12 @@ static const BYTE ExCvt[] = _EXCVT; /* Upper conversion table for extended chara ...@@ -559,6 +562,12 @@ static const BYTE ExCvt[] = _EXCVT; /* Upper conversion table for extended chara
/* String functions */ /* String functions */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
// dpgeorge:
// We use stdlib version of memset and memcmp to reduce code size.
// We use the original custom version of mem_cpy so that gcc doesn't
// recognise the builtin function and then inline it. Allowing gcc
// to use the builtin memcpy increases code size by 72 bytes.
/* Copy memory to memory */ /* Copy memory to memory */
static static
void mem_cpy (void* dst, const void* src, UINT cnt) { void mem_cpy (void* dst, const void* src, UINT cnt) {
...@@ -577,6 +586,7 @@ void mem_cpy (void* dst, const void* src, UINT cnt) { ...@@ -577,6 +586,7 @@ void mem_cpy (void* dst, const void* src, UINT cnt) {
} }
/* Fill memory */ /* Fill memory */
#if 0
static static
void mem_set (void* dst, int val, UINT cnt) { void mem_set (void* dst, int val, UINT cnt) {
BYTE *d = (BYTE*)dst; BYTE *d = (BYTE*)dst;
...@@ -584,8 +594,13 @@ void mem_set (void* dst, int val, UINT cnt) { ...@@ -584,8 +594,13 @@ void mem_set (void* dst, int val, UINT cnt) {
while (cnt--) while (cnt--)
*d++ = (BYTE)val; *d++ = (BYTE)val;
} }
#else
// use stdlib
#define mem_set memset
#endif
/* Compare memory to memory */ /* Compare memory to memory */
#if 0
static static
int mem_cmp (const void* dst, const void* src, UINT cnt) { int mem_cmp (const void* dst, const void* src, UINT cnt) {
const BYTE *d = (const BYTE *)dst, *s = (const BYTE *)src; const BYTE *d = (const BYTE *)dst, *s = (const BYTE *)src;
...@@ -594,6 +609,10 @@ int mem_cmp (const void* dst, const void* src, UINT cnt) { ...@@ -594,6 +609,10 @@ int mem_cmp (const void* dst, const void* src, UINT cnt) {
while (cnt-- && (r = *d++ - *s++) == 0) ; while (cnt-- && (r = *d++ - *s++) == 0) ;
return r; return r;
} }
#else
// use stdlib
#define mem_cmp memcmp
#endif
/* Check if chr is contained in the string */ /* Check if chr is contained in the string */
static static
...@@ -854,6 +873,8 @@ FRESULT sync_fs ( /* FR_OK: successful, FR_DISK_ERR: failed */ ...@@ -854,6 +873,8 @@ FRESULT sync_fs ( /* FR_OK: successful, FR_DISK_ERR: failed */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* Hidden API for hacks and disk tools */ /* Hidden API for hacks and disk tools */
// dpgeorge: made static
static
DWORD clust2sect ( /* !=0: Sector number, 0: Failed - invalid cluster# */ DWORD clust2sect ( /* !=0: Sector number, 0: Failed - invalid cluster# */
FATFS* fs, /* File system object */ FATFS* fs, /* File system object */
DWORD clst /* Cluster# to be converted */ DWORD clst /* Cluster# to be converted */
...@@ -872,6 +893,8 @@ DWORD clust2sect ( /* !=0: Sector number, 0: Failed - invalid cluster# */ ...@@ -872,6 +893,8 @@ DWORD clust2sect ( /* !=0: Sector number, 0: Failed - invalid cluster# */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* Hidden API for hacks and disk tools */ /* Hidden API for hacks and disk tools */
// dpgeorge: made static
static
DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x0FFFFFFF:Cluster status */ DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x0FFFFFFF:Cluster status */
FATFS* fs, /* File system object */ FATFS* fs, /* File system object */
DWORD clst /* FAT item index (cluster#) to get the value */ DWORD clst /* FAT item index (cluster#) to get the value */
...@@ -927,6 +950,8 @@ DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x0FFFFFFF:Cluste ...@@ -927,6 +950,8 @@ DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x0FFFFFFF:Cluste
/* Hidden API for hacks and disk tools */ /* Hidden API for hacks and disk tools */
#if !_FS_READONLY #if !_FS_READONLY
// dpgeorge: made static
static
FRESULT put_fat ( FRESULT put_fat (
FATFS* fs, /* File system object */ FATFS* fs, /* File system object */
DWORD clst, /* FAT item index (cluster#) to be set */ DWORD clst, /* FAT item index (cluster#) to be set */
...@@ -2093,6 +2118,8 @@ FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ ...@@ -2093,6 +2118,8 @@ FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */
/* Get logical drive number from path name */ /* Get logical drive number from path name */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
// dpgeorge: replaced with custom ff_get_ldnumber
#if 0
static static
int get_ldnumber ( /* Returns logical drive number (-1:invalid drive) */ int get_ldnumber ( /* Returns logical drive number (-1:invalid drive) */
const TCHAR** path /* Pointer to pointer to the path name */ const TCHAR** path /* Pointer to pointer to the path name */
...@@ -2144,6 +2171,7 @@ int get_ldnumber ( /* Returns logical drive number (-1:invalid drive) */ ...@@ -2144,6 +2171,7 @@ int get_ldnumber ( /* Returns logical drive number (-1:invalid drive) */
} }
return vol; return vol;
} }
#endif
...@@ -2197,7 +2225,7 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */ ...@@ -2197,7 +2225,7 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
/* Get logical drive number from the path name */ /* Get logical drive number from the path name */
*rfs = 0; *rfs = 0;
vol = get_ldnumber(path); vol = ff_get_ldnumber(path);
if (vol < 0) return FR_INVALID_DRIVE; if (vol < 0) return FR_INVALID_DRIVE;
/* Check if the file system object is valid or not */ /* Check if the file system object is valid or not */
...@@ -2397,7 +2425,7 @@ FRESULT f_mount ( ...@@ -2397,7 +2425,7 @@ FRESULT f_mount (
const TCHAR *rp = path; const TCHAR *rp = path;
vol = get_ldnumber(&rp); vol = ff_get_ldnumber(&rp);
if (vol < 0) return FR_INVALID_DRIVE; if (vol < 0) return FR_INVALID_DRIVE;
cfs = FatFs[vol]; /* Pointer to fs object */ cfs = FatFs[vol]; /* Pointer to fs object */
...@@ -2885,10 +2913,10 @@ FRESULT f_chdrive ( ...@@ -2885,10 +2913,10 @@ FRESULT f_chdrive (
int vol; int vol;
vol = get_ldnumber(&path); vol = ff_get_ldnumber(&path);
if (vol < 0) return FR_INVALID_DRIVE; if (vol < 0) return FR_INVALID_DRIVE;
CurrVol = (BYTE)vol; ff_CurrVol = (BYTE)vol;
return FR_OK; return FR_OK;
} }
...@@ -2984,11 +3012,19 @@ FRESULT f_getcwd ( ...@@ -2984,11 +3012,19 @@ FRESULT f_getcwd (
tp = buff; tp = buff;
if (res == FR_OK) { if (res == FR_OK) {
#if _VOLUMES >= 2 #if _VOLUMES >= 2
// dpgeorge: change to use our volume names
#if 0
*tp++ = '0' + CurrVol; /* Put drive number */ *tp++ = '0' + CurrVol; /* Put drive number */
*tp++ = ':'; *tp++ = ':';
#else
ff_get_volname(ff_CurrVol, &tp);
#endif
#endif #endif
if (i == len) { /* Root-directory */ if (i == len) { /* Root-directory */
// dpgeorge: not needed with volume names
#if 0
*tp++ = '/'; *tp++ = '/';
#endif
} else { /* Sub-directroy */ } else { /* Sub-directroy */
do /* Add stacked path str */ do /* Add stacked path str */
*tp++ = buff[i++]; *tp++ = buff[i++];
...@@ -3671,7 +3707,7 @@ FRESULT f_rename ( ...@@ -3671,7 +3707,7 @@ FRESULT f_rename (
} else { } else {
mem_cpy(buf, djo.dir+DIR_Attr, 21); /* Save the object information except name */ mem_cpy(buf, djo.dir+DIR_Attr, 21); /* Save the object information except name */
mem_cpy(&djn, &djo, sizeof (DIR)); /* Duplicate the directory object */ mem_cpy(&djn, &djo, sizeof (DIR)); /* Duplicate the directory object */
if (get_ldnumber(&path_new) >= 0) /* Snip drive number off and ignore it */ if (ff_get_ldnumber(&path_new) >= 0) /* Snip drive number off and ignore it */
res = follow_path(&djn, path_new); /* and make sure if new object name is not conflicting */ res = follow_path(&djn, path_new); /* and make sure if new object name is not conflicting */
else else
res = FR_INVALID_DRIVE; res = FR_INVALID_DRIVE;
...@@ -3850,6 +3886,7 @@ FRESULT f_setlabel ( ...@@ -3850,6 +3886,7 @@ FRESULT f_setlabel (
/* Create a volume label in directory form */ /* Create a volume label in directory form */
vn[0] = 0; vn[0] = 0;
if (label[0] == '/') label++; // dpgeorge: skip '/' to handle our volume names
for (sl = 0; label[sl]; sl++) ; /* Get name length */ for (sl = 0; label[sl]; sl++) ; /* Get name length */
for ( ; sl && label[sl-1] == ' '; sl--) ; /* Remove trailing spaces */ for ( ; sl && label[sl-1] == ' '; sl--) ; /* Remove trailing spaces */
if (sl) { /* Create volume label in directory form */ if (sl) { /* Create volume label in directory form */
...@@ -4010,7 +4047,7 @@ FRESULT f_mkfs ( ...@@ -4010,7 +4047,7 @@ FRESULT f_mkfs (
/* Check mounted drive and clear work area */ /* Check mounted drive and clear work area */
if (sfd > 1) return FR_INVALID_PARAMETER; if (sfd > 1) return FR_INVALID_PARAMETER;
vol = get_ldnumber(&path); vol = ff_get_ldnumber(&path);
if (vol < 0) return FR_INVALID_DRIVE; if (vol < 0) return FR_INVALID_DRIVE;
fs = FatFs[vol]; fs = FatFs[vol];
if (!fs) return FR_NOT_ENABLED; if (!fs) return FR_NOT_ENABLED;
......
...@@ -36,7 +36,7 @@ typedef struct { ...@@ -36,7 +36,7 @@ typedef struct {
BYTE pd; /* Physical drive number */ BYTE pd; /* Physical drive number */
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */ BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
} PARTITION; } PARTITION;
extern PARTITION VolToPart[]; /* Volume - Partition resolution table */ extern const PARTITION VolToPart[]; /* Volume - Partition resolution table */
#define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive number */ #define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive number */
#define LD2PT(vol) (VolToPart[vol].pt) /* Get partition index */ #define LD2PT(vol) (VolToPart[vol].pt) /* Get partition index */
...@@ -273,8 +273,16 @@ void ff_rel_grant (_SYNC_t sobj); /* Unlock sync object */ ...@@ -273,8 +273,16 @@ void ff_rel_grant (_SYNC_t sobj); /* Unlock sync object */
int ff_del_syncobj (_SYNC_t sobj); /* Delete a sync object */ int ff_del_syncobj (_SYNC_t sobj); /* Delete a sync object */
#endif #endif
// dpgeorge: added the following 3 declarations to support our volume names
// Current drive
extern BYTE ff_CurrVol;
// Returns logical drive number (-1:invalid drive)
int ff_get_ldnumber(const TCHAR** path);
// Store the volume name into dest, and advance the pointer
void ff_get_volname(BYTE vol, TCHAR **dest);
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
/* Flags and offset address */ /* Flags and offset address */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment