EU1KY AA
ff.c File Reference
#include "ff.h"
#include "diskio.h"

Data Structures

struct  FILESEM
 

Macros

#define ENTER_FF(fs)
 
#define LEAVE_FF(fs, res)    return res
 
#define ABORT(fs, res)    { fp->err = (BYTE)(res); LEAVE_FF(fs, res); }
 
#define SS(fs)    ((UINT)_MAX_SS) /* Fixed sector size */
 
#define GET_FATTIME()    get_fattime()
 
#define _DF1S   0
 
#define _EXCVT
 
#define IsUpper(c)    (((c)>='A')&&((c)<='Z'))
 
#define IsLower(c)    (((c)>='a')&&((c)<='z'))
 
#define IsDigit(c)    (((c)>='0')&&((c)<='9'))
 
#define IsDBCS1(c)    0
 
#define IsDBCS2(c)    0
 
#define NSFLAG   11 /* Index of name status byte in fn[] */
 
#define NS_LOSS   0x01 /* Out of 8.3 format */
 
#define NS_LFN   0x02 /* Force to create LFN entry */
 
#define NS_LAST   0x04 /* Last segment */
 
#define NS_BODY   0x08 /* Lower case flag (body) */
 
#define NS_EXT   0x10 /* Lower case flag (ext) */
 
#define NS_DOT   0x20 /* Dot entry */
 
#define MIN_FAT16   4086U /* Minimum number of clusters as FAT16 */
 
#define MIN_FAT32   65526U /* Minimum number of clusters as FAT32 */
 
#define BS_jmpBoot   0 /* x86 jump instruction (3) */
 
#define BS_OEMName   3 /* OEM name (8) */
 
#define BPB_BytsPerSec   11 /* Sector size [byte] (2) */
 
#define BPB_SecPerClus   13 /* Cluster size [sector] (1) */
 
#define BPB_RsvdSecCnt   14 /* Size of reserved area [sector] (2) */
 
#define BPB_NumFATs   16 /* Number of FAT copies (1) */
 
#define BPB_RootEntCnt   17 /* Number of root directory entries for FAT12/16 (2) */
 
#define BPB_TotSec16   19 /* Volume size [sector] (2) */
 
#define BPB_Media   21 /* Media descriptor (1) */
 
#define BPB_FATSz16   22 /* FAT size [sector] (2) */
 
#define BPB_SecPerTrk   24 /* Track size [sector] (2) */
 
#define BPB_NumHeads   26 /* Number of heads (2) */
 
#define BPB_HiddSec   28 /* Number of special hidden sectors (4) */
 
#define BPB_TotSec32   32 /* Volume size [sector] (4) */
 
#define BS_DrvNum   36 /* Physical drive number (2) */
 
#define BS_BootSig   38 /* Extended boot signature (1) */
 
#define BS_VolID   39 /* Volume serial number (4) */
 
#define BS_VolLab   43 /* Volume label (8) */
 
#define BS_FilSysType   54 /* File system type (1) */
 
#define BPB_FATSz32   36 /* FAT size [sector] (4) */
 
#define BPB_ExtFlags   40 /* Extended flags (2) */
 
#define BPB_FSVer   42 /* File system version (2) */
 
#define BPB_RootClus   44 /* Root directory first cluster (4) */
 
#define BPB_FSInfo   48 /* Offset of FSINFO sector (2) */
 
#define BPB_BkBootSec   50 /* Offset of backup boot sector (2) */
 
#define BS_DrvNum32   64 /* Physical drive number (2) */
 
#define BS_BootSig32   66 /* Extended boot signature (1) */
 
#define BS_VolID32   67 /* Volume serial number (4) */
 
#define BS_VolLab32   71 /* Volume label (8) */
 
#define BS_FilSysType32   82 /* File system type (1) */
 
#define FSI_LeadSig   0 /* FSI: Leading signature (4) */
 
#define FSI_StrucSig   484 /* FSI: Structure signature (4) */
 
#define FSI_Free_Count   488 /* FSI: Number of free clusters (4) */
 
#define FSI_Nxt_Free   492 /* FSI: Last allocated cluster (4) */
 
#define MBR_Table   446 /* MBR: Partition table offset (2) */
 
#define SZ_PTE   16 /* MBR: Size of a partition table entry */
 
#define BS_55AA   510 /* Signature word (2) */
 
#define DIR_Name   0 /* Short file name (11) */
 
#define DIR_Attr   11 /* Attribute (1) */
 
#define DIR_NTres   12 /* Lower case flag (1) */
 
#define DIR_CrtTimeTenth   13 /* Created time sub-second (1) */
 
#define DIR_CrtTime   14 /* Created time (2) */
 
#define DIR_CrtDate   16 /* Created date (2) */
 
#define DIR_LstAccDate   18 /* Last accessed date (2) */
 
#define DIR_FstClusHI   20 /* Higher 16-bit of first cluster (2) */
 
#define DIR_WrtTime   22 /* Modified time (2) */
 
#define DIR_WrtDate   24 /* Modified date (2) */
 
#define DIR_FstClusLO   26 /* Lower 16-bit of first cluster (2) */
 
#define DIR_FileSize   28 /* File size (4) */
 
#define LDIR_Ord   0 /* LFN entry order and LLE flag (1) */
 
#define LDIR_Attr   11 /* LFN attribute (1) */
 
#define LDIR_Type   12 /* LFN type (1) */
 
#define LDIR_Chksum   13 /* Sum of corresponding SFN entry */
 
#define LDIR_FstClusLO   26 /* Must be zero (0) */
 
#define SZ_DIRE   32 /* Size of a directory entry */
 
#define LLEF   0x40 /* Last long entry flag in LDIR_Ord */
 
#define DDEM   0xE5 /* Deleted directory entry mark at DIR_Name[0] */
 
#define RDDEM   0x05 /* Replacement of the character collides with DDEM */
 
#define DEFINE_NAMEBUF   BYTE sfn[12]
 
#define INIT_BUF(dobj)    (dobj).fn = sfn
 
#define FREE_BUF()
 
#define N_ROOTDIR   512 /* Number of root directory entries for FAT12/16 */
 
#define N_FATS   1 /* Number of FATs (1 or 2) */
 

Functions

DWORD clust2sect (FATFS *fs, DWORD clst)
 
DWORD get_fat (FATFS *fs, DWORD clst)
 
FRESULT put_fat (FATFS *fs, DWORD clst, DWORD val)
 
static void mem_cpy (void *dst, const void *src, UINT cnt)
 
static void mem_set (void *dst, int val, UINT cnt)
 
static int mem_cmp (const void *dst, const void *src, UINT cnt)
 
static int chk_chr (const char *str, int chr)
 
static FRESULT chk_lock (DIR *dp, int acc)
 
static int enq_lock (void)
 
static UINT inc_lock (DIR *dp, int acc)
 
static FRESULT dec_lock (UINT i)
 
static void clear_lock (FATFS *fs)
 
static FRESULT sync_window (FATFS *fs)
 
static FRESULT move_window (FATFS *fs, DWORD sector)
 
static FRESULT sync_fs (FATFS *fs)
 
static FRESULT remove_chain (FATFS *fs, DWORD clst)
 
static DWORD create_chain (FATFS *fs, DWORD clst)
 
static DWORD clmt_clust (FIL *fp, DWORD ofs)
 
static FRESULT dir_sdi (DIR *dp, UINT idx)
 
static FRESULT dir_next (DIR *dp, int stretch)
 
static FRESULT dir_alloc (DIR *dp, UINT nent)
 
static DWORD ld_clust (FATFS *fs, BYTE *dir)
 
static void st_clust (BYTE *dir, DWORD cl)
 
static FRESULT dir_find (DIR *dp)
 
static FRESULT dir_read (DIR *dp, int vol)
 
static FRESULT dir_register (DIR *dp)
 
static FRESULT dir_remove (DIR *dp)
 
static void get_fileinfo (DIR *dp, FILINFO *fno)
 
static WCHAR get_achar (const TCHAR **ptr)
 
static int pattern_matching (const TCHAR *pat, const TCHAR *nam, int skip, int inf)
 
static FRESULT create_name (DIR *dp, const TCHAR **path)
 
static FRESULT follow_path (DIR *dp, const TCHAR *path)
 
static int get_ldnumber (const TCHAR **path)
 
static BYTE check_fs (FATFS *fs, DWORD sect)
 
static FRESULT find_volume (FATFS **rfs, const TCHAR **path, BYTE wmode)
 
static FRESULT validate (void *obj)
 
FRESULT f_mount (FATFS *fs, const TCHAR *path, BYTE opt)
 
FRESULT f_open (FIL *fp, const TCHAR *path, BYTE mode)
 
FRESULT f_read (FIL *fp, void *buff, UINT btr, UINT *br)
 
FRESULT f_write (FIL *fp, const void *buff, UINT btw, UINT *bw)
 
FRESULT f_sync (FIL *fp)
 
FRESULT f_close (FIL *fp)
 
FRESULT f_chdir (const TCHAR *path)
 
FRESULT f_lseek (FIL *fp, DWORD ofs)
 
FRESULT f_opendir (DIR *dp, const TCHAR *path)
 
FRESULT f_closedir (DIR *dp)
 
FRESULT f_readdir (DIR *dp, FILINFO *fno)
 
FRESULT f_findnext (DIR *dp, FILINFO *fno)
 
FRESULT f_findfirst (DIR *dp, FILINFO *fno, const TCHAR *path, const TCHAR *pattern)
 
FRESULT f_stat (const TCHAR *path, FILINFO *fno)
 
FRESULT f_getfree (const TCHAR *path, DWORD *nclst, FATFS **fatfs)
 
FRESULT f_truncate (FIL *fp)
 
FRESULT f_unlink (const TCHAR *path)
 
FRESULT f_mkdir (const TCHAR *path)
 
FRESULT f_chmod (const TCHAR *path, BYTE attr, BYTE mask)
 
FRESULT f_rename (const TCHAR *path_old, const TCHAR *path_new)
 
FRESULT f_utime (const TCHAR *path, const FILINFO *fno)
 
FRESULT f_mkfs (const TCHAR *path, BYTE sfd, UINT au)
 

Variables

static FATFSFatFs [_VOLUMES]
 
static WORD Fsid
 
static FILESEM Files [_FS_LOCK]
 
static const BYTE ExCvt [] = _EXCVT
 

Macro Definition Documentation

#define _DF1S   0
#define _EXCVT
Value:
{0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0xAd,0x9B,0x8C,0x9D,0xAE,0x9F, \
0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0x9F}
#define ABORT (   fs,
  res 
)    { fp->err = (BYTE)(res); LEAVE_FF(fs, res); }
#define BPB_BkBootSec   50 /* Offset of backup boot sector (2) */
#define BPB_BytsPerSec   11 /* Sector size [byte] (2) */
#define BPB_ExtFlags   40 /* Extended flags (2) */
#define BPB_FATSz16   22 /* FAT size [sector] (2) */
#define BPB_FATSz32   36 /* FAT size [sector] (4) */
#define BPB_FSInfo   48 /* Offset of FSINFO sector (2) */
#define BPB_FSVer   42 /* File system version (2) */
#define BPB_HiddSec   28 /* Number of special hidden sectors (4) */
#define BPB_Media   21 /* Media descriptor (1) */
#define BPB_NumFATs   16 /* Number of FAT copies (1) */
#define BPB_NumHeads   26 /* Number of heads (2) */
#define BPB_RootClus   44 /* Root directory first cluster (4) */
#define BPB_RootEntCnt   17 /* Number of root directory entries for FAT12/16 (2) */
#define BPB_RsvdSecCnt   14 /* Size of reserved area [sector] (2) */
#define BPB_SecPerClus   13 /* Cluster size [sector] (1) */
#define BPB_SecPerTrk   24 /* Track size [sector] (2) */
#define BPB_TotSec16   19 /* Volume size [sector] (2) */
#define BPB_TotSec32   32 /* Volume size [sector] (4) */
#define BS_55AA   510 /* Signature word (2) */
#define BS_BootSig   38 /* Extended boot signature (1) */
#define BS_BootSig32   66 /* Extended boot signature (1) */
#define BS_DrvNum   36 /* Physical drive number (2) */
#define BS_DrvNum32   64 /* Physical drive number (2) */
#define BS_FilSysType   54 /* File system type (1) */
#define BS_FilSysType32   82 /* File system type (1) */
#define BS_jmpBoot   0 /* x86 jump instruction (3) */
#define BS_OEMName   3 /* OEM name (8) */
#define BS_VolID   39 /* Volume serial number (4) */
#define BS_VolID32   67 /* Volume serial number (4) */
#define BS_VolLab   43 /* Volume label (8) */
#define BS_VolLab32   71 /* Volume label (8) */
#define DDEM   0xE5 /* Deleted directory entry mark at DIR_Name[0] */
#define DEFINE_NAMEBUF   BYTE sfn[12]
#define DIR_Attr   11 /* Attribute (1) */
#define DIR_CrtDate   16 /* Created date (2) */
#define DIR_CrtTime   14 /* Created time (2) */
#define DIR_CrtTimeTenth   13 /* Created time sub-second (1) */
#define DIR_FileSize   28 /* File size (4) */
#define DIR_FstClusHI   20 /* Higher 16-bit of first cluster (2) */
#define DIR_FstClusLO   26 /* Lower 16-bit of first cluster (2) */
#define DIR_LstAccDate   18 /* Last accessed date (2) */
#define DIR_Name   0 /* Short file name (11) */
#define DIR_NTres   12 /* Lower case flag (1) */
#define DIR_WrtDate   24 /* Modified date (2) */
#define DIR_WrtTime   22 /* Modified time (2) */
#define ENTER_FF (   fs)
#define FREE_BUF ( )
#define FSI_Free_Count   488 /* FSI: Number of free clusters (4) */
#define FSI_LeadSig   0 /* FSI: Leading signature (4) */
#define FSI_Nxt_Free   492 /* FSI: Last allocated cluster (4) */
#define FSI_StrucSig   484 /* FSI: Structure signature (4) */
#define GET_FATTIME ( )    get_fattime()
#define INIT_BUF (   dobj)    (dobj).fn = sfn
#define IsDBCS1 (   c)    0
#define IsDBCS2 (   c)    0
#define IsDigit (   c)    (((c)>='0')&&((c)<='9'))
#define IsLower (   c)    (((c)>='a')&&((c)<='z'))
#define IsUpper (   c)    (((c)>='A')&&((c)<='Z'))
#define LDIR_Attr   11 /* LFN attribute (1) */
#define LDIR_Chksum   13 /* Sum of corresponding SFN entry */
#define LDIR_FstClusLO   26 /* Must be zero (0) */
#define LDIR_Ord   0 /* LFN entry order and LLE flag (1) */
#define LDIR_Type   12 /* LFN type (1) */
#define LEAVE_FF (   fs,
  res 
)    return res
#define LLEF   0x40 /* Last long entry flag in LDIR_Ord */
#define MBR_Table   446 /* MBR: Partition table offset (2) */
#define MIN_FAT16   4086U /* Minimum number of clusters as FAT16 */
#define MIN_FAT32   65526U /* Minimum number of clusters as FAT32 */
#define N_FATS   1 /* Number of FATs (1 or 2) */
#define N_ROOTDIR   512 /* Number of root directory entries for FAT12/16 */
#define NS_BODY   0x08 /* Lower case flag (body) */
#define NS_DOT   0x20 /* Dot entry */
#define NS_EXT   0x10 /* Lower case flag (ext) */
#define NS_LAST   0x04 /* Last segment */
#define NS_LFN   0x02 /* Force to create LFN entry */
#define NS_LOSS   0x01 /* Out of 8.3 format */
#define NSFLAG   11 /* Index of name status byte in fn[] */
#define RDDEM   0x05 /* Replacement of the character collides with DDEM */
#define SS (   fs)    ((UINT)_MAX_SS) /* Fixed sector size */
#define SZ_DIRE   32 /* Size of a directory entry */
#define SZ_PTE   16 /* MBR: Size of a partition table entry */

Function Documentation

static BYTE check_fs ( FATFS fs,
DWORD  sect 
)
static
static int chk_chr ( const char *  str,
int  chr 
)
static
static FRESULT chk_lock ( DIR dp,
int  acc 
)
static
static void clear_lock ( FATFS fs)
static
static DWORD clmt_clust ( FIL fp,
DWORD  ofs 
)
static
DWORD clust2sect ( FATFS fs,
DWORD  clst 
)
static DWORD create_chain ( FATFS fs,
DWORD  clst 
)
static
static FRESULT create_name ( DIR dp,
const TCHAR **  path 
)
static
static FRESULT dec_lock ( UINT  i)
static
static FRESULT dir_alloc ( DIR dp,
UINT  nent 
)
static
static FRESULT dir_find ( DIR dp)
static
static FRESULT dir_next ( DIR dp,
int  stretch 
)
static
static FRESULT dir_read ( DIR dp,
int  vol 
)
static
static FRESULT dir_register ( DIR dp)
static
static FRESULT dir_remove ( DIR dp)
static
static FRESULT dir_sdi ( DIR dp,
UINT  idx 
)
static
static int enq_lock ( void  )
static
FRESULT f_chdir ( const TCHAR path)
FRESULT f_chmod ( const TCHAR path,
BYTE  attr,
BYTE  mask 
)
FRESULT f_close ( FIL fp)
FRESULT f_closedir ( DIR dp)
FRESULT f_findfirst ( DIR dp,
FILINFO fno,
const TCHAR path,
const TCHAR pattern 
)
FRESULT f_findnext ( DIR dp,
FILINFO fno 
)
FRESULT f_getfree ( const TCHAR path,
DWORD nclst,
FATFS **  fatfs 
)
FRESULT f_lseek ( FIL fp,
DWORD  ofs 
)
FRESULT f_mkdir ( const TCHAR path)
FRESULT f_mkfs ( const TCHAR path,
BYTE  sfd,
UINT  au 
)
FRESULT f_mount ( FATFS fs,
const TCHAR path,
BYTE  opt 
)
FRESULT f_open ( FIL fp,
const TCHAR path,
BYTE  mode 
)
FRESULT f_opendir ( DIR dp,
const TCHAR path 
)
FRESULT f_read ( FIL fp,
void buff,
UINT  btr,
UINT br 
)
FRESULT f_readdir ( DIR dp,
FILINFO fno 
)
FRESULT f_rename ( const TCHAR path_old,
const TCHAR path_new 
)
FRESULT f_stat ( const TCHAR path,
FILINFO fno 
)
FRESULT f_sync ( FIL fp)
FRESULT f_truncate ( FIL fp)
FRESULT f_unlink ( const TCHAR path)
FRESULT f_utime ( const TCHAR path,
const FILINFO fno 
)
FRESULT f_write ( FIL fp,
const void buff,
UINT  btw,
UINT bw 
)
static FRESULT find_volume ( FATFS **  rfs,
const TCHAR **  path,
BYTE  wmode 
)
static
static FRESULT follow_path ( DIR dp,
const TCHAR path 
)
static
static WCHAR get_achar ( const TCHAR **  ptr)
static
DWORD get_fat ( FATFS fs,
DWORD  clst 
)
static void get_fileinfo ( DIR dp,
FILINFO fno 
)
static
static int get_ldnumber ( const TCHAR **  path)
static
static UINT inc_lock ( DIR dp,
int  acc 
)
static
static DWORD ld_clust ( FATFS fs,
BYTE dir 
)
static
static int mem_cmp ( const void dst,
const void src,
UINT  cnt 
)
static
static void mem_cpy ( void dst,
const void src,
UINT  cnt 
)
static
static void mem_set ( void dst,
int  val,
UINT  cnt 
)
static
static FRESULT move_window ( FATFS fs,
DWORD  sector 
)
static
static int pattern_matching ( const TCHAR pat,
const TCHAR nam,
int  skip,
int  inf 
)
static
FRESULT put_fat ( FATFS fs,
DWORD  clst,
DWORD  val 
)
static FRESULT remove_chain ( FATFS fs,
DWORD  clst 
)
static
static void st_clust ( BYTE dir,
DWORD  cl 
)
static
static FRESULT sync_fs ( FATFS fs)
static
static FRESULT sync_window ( FATFS fs)
static
static FRESULT validate ( void obj)
static

Variable Documentation

const BYTE ExCvt[] = _EXCVT
static
FATFS* FatFs[_VOLUMES]
static
FILESEM Files[_FS_LOCK]
static
WORD Fsid
static