ECE 2036 Project

Dependencies:   mbed wave_player 4DGL-uLCD-SE

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers <title>ff.h Source File</title>

ff.h

00001 /*---------------------------------------------------------------------------/
00002 /  FatFs - FAT file system module include file  R0.09a    (C)ChaN, 2012
00003 /----------------------------------------------------------------------------/
00004 / FatFs module is a generic FAT file system module for small embedded systems.
00005 / This is a free software that opened for education, research and commercial
00006 / developments under license policy of following terms.
00007 /
00008 /  Copyright (C) 2012, ChaN, all right reserved.
00009 /
00010 / * The FatFs module is a free software and there is NO WARRANTY.
00011 / * No restriction on use. You can use, modify and redistribute it for
00012 /   personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
00013 / * Redistributions of source code must retain the above copyright notice.
00014 /
00015 /----------------------------------------------------------------------------*/
00016 
00017 #ifndef _FATFS
00018 #define _FATFS  4004    /* Revision ID */
00019 
00020 #ifdef __cplusplus
00021 extern "C" {
00022 #endif
00023 
00024 #include "integer.h"    /* Basic integer types */
00025 #include "ffconf.h"     /* FatFs configuration options */
00026 
00027 #if _FATFS != _FFCONF
00028 #error Wrong configuration file (ffconf.h).
00029 #endif
00030 
00031 
00032 
00033 /* Definitions of volume management */
00034 
00035 #if _MULTI_PARTITION        /* Multiple partition configuration */
00036 typedef struct {
00037     BYTE pd;    /* Physical drive number */
00038     BYTE pt;    /* Partition: 0:Auto detect, 1-4:Forced partition) */
00039 } PARTITION;
00040 extern PARTITION VolToPart[];   /* Volume - Partition resolution table */
00041 #define LD2PD(vol) (VolToPart[vol].pd)  /* Get physical drive number */
00042 #define LD2PT(vol) (VolToPart[vol].pt)  /* Get partition index */
00043 
00044 #else                           /* Single partition configuration */
00045 #define LD2PD(vol) (BYTE)(vol)  /* Each logical drive is bound to the same physical drive number */
00046 #define LD2PT(vol) 0            /* Always mounts the 1st partition or in SFD */
00047 
00048 #endif
00049 
00050 
00051 
00052 /* Type of path name strings on FatFs API */
00053 
00054 #if _LFN_UNICODE            /* Unicode string */
00055 #if !_USE_LFN
00056 #error _LFN_UNICODE must be 0 in non-LFN cfg.
00057 #endif
00058 #ifndef _INC_TCHAR
00059 typedef WCHAR TCHAR;
00060 #define _T(x) L ## x
00061 #define _TEXT(x) L ## x
00062 #endif
00063 
00064 #else                       /* ANSI/OEM string */
00065 #ifndef _INC_TCHAR
00066 typedef char TCHAR;
00067 #define _T(x) x
00068 #define _TEXT(x) x
00069 #endif
00070 
00071 #endif
00072 
00073 
00074 
00075 /* File system object structure (FATFS) */
00076 
00077 typedef struct {
00078     BYTE    fs_type;        /* FAT sub-type (0:Not mounted) */
00079     BYTE    drv;            /* Physical drive number */
00080     BYTE    csize;          /* Sectors per cluster (1,2,4...128) */
00081     BYTE    n_fats;         /* Number of FAT copies (1,2) */
00082     BYTE    wflag;          /* win[] dirty flag (1:must be written back) */
00083     BYTE    fsi_flag;       /* fsinfo dirty flag (1:must be written back) */
00084     WORD    id;             /* File system mount ID */
00085     WORD    n_rootdir;      /* Number of root directory entries (FAT12/16) */
00086 #if _MAX_SS != 512
00087     WORD    ssize;          /* Bytes per sector (512, 1024, 2048 or 4096) */
00088 #endif
00089 #if _FS_REENTRANT
00090     _SYNC_t sobj;           /* Identifier of sync object */
00091 #endif
00092 #if !_FS_READONLY
00093     DWORD   last_clust;     /* Last allocated cluster */
00094     DWORD   free_clust;     /* Number of free clusters */
00095     DWORD   fsi_sector;     /* fsinfo sector (FAT32) */
00096 #endif
00097 #if _FS_RPATH
00098     DWORD   cdir;           /* Current directory start cluster (0:root) */
00099 #endif
00100     DWORD   n_fatent;       /* Number of FAT entries (= number of clusters + 2) */
00101     DWORD   fsize;          /* Sectors per FAT */
00102     DWORD   fatbase;        /* FAT start sector */
00103     DWORD   dirbase;        /* Root directory start sector (FAT32:Cluster#) */
00104     DWORD   database;       /* Data start sector */
00105     DWORD   winsect;        /* Current sector appearing in the win[] */
00106     BYTE    win[_MAX_SS];   /* Disk access window for Directory, FAT (and Data on tiny cfg) */
00107 } FATFS;
00108 
00109 
00110 
00111 /* File object structure (FIL) */
00112 
00113 typedef struct {
00114     FATFS*  fs;             /* Pointer to the related file system object */
00115     WORD    id;             /* File system mount ID of the related file system object */
00116     BYTE    flag;           /* File status flags */
00117     BYTE    pad1;
00118     DWORD   fptr;           /* File read/write pointer (0ed on file open) */
00119     DWORD   fsize;          /* File size */
00120     DWORD   sclust;         /* File data start cluster (0:no data cluster, always 0 when fsize is 0) */
00121     DWORD   clust;          /* Current cluster of fpter */
00122     DWORD   dsect;          /* Current data sector of fpter */
00123 #if !_FS_READONLY
00124     DWORD   dir_sect;       /* Sector containing the directory entry */
00125     BYTE*   dir_ptr;        /* Pointer to the directory entry in the window */
00126 #endif
00127 #if _USE_FASTSEEK
00128     DWORD*  cltbl;          /* Pointer to the cluster link map table (null on file open) */
00129 #endif
00130 #if _FS_LOCK
00131     UINT    lockid;         /* File lock ID (index of file semaphore table Files[]) */
00132 #endif
00133 #if !_FS_TINY
00134     BYTE    buf[_MAX_SS];   /* File data read/write buffer */
00135 #endif
00136 } FIL;
00137 
00138 
00139 
00140 /* Directory object structure (DIR) */
00141 
00142 typedef struct {
00143     FATFS*  fs;             /* Pointer to the owner file system object */
00144     WORD    id;             /* Owner file system mount ID */
00145     WORD    index;          /* Current read/write index number */
00146     DWORD   sclust;         /* Table start cluster (0:Root dir) */
00147     DWORD   clust;          /* Current cluster */
00148     DWORD   sect;           /* Current sector */
00149     BYTE*   dir;            /* Pointer to the current SFN entry in the win[] */
00150     BYTE*   fn;             /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
00151 #if _USE_LFN
00152     WCHAR*  lfn;            /* Pointer to the LFN working buffer */
00153     WORD    lfn_idx;        /* Last matched LFN index number (0xFFFF:No LFN) */
00154 #endif
00155 } FATFS_DIR;
00156 
00157 
00158 
00159 /* File status structure (FILINFO) */
00160 
00161 typedef struct {
00162     DWORD   fsize;          /* File size */
00163     WORD    fdate;          /* Last modified date */
00164     WORD    ftime;          /* Last modified time */
00165     BYTE    fattrib;        /* Attribute */
00166     TCHAR   fname[13];      /* Short file name (8.3 format) */
00167 #if _USE_LFN
00168     TCHAR*  lfname;         /* Pointer to the LFN buffer */
00169     UINT    lfsize;         /* Size of LFN buffer in TCHAR */
00170 #endif
00171 } FILINFO;
00172 
00173 
00174 
00175 /* File function return code (FRESULT) */
00176 
00177 typedef enum {
00178     FR_OK = 0,              /* (0) Succeeded */
00179     FR_DISK_ERR,            /* (1) A hard error occurred in the low level disk I/O layer */
00180     FR_INT_ERR,             /* (2) Assertion failed */
00181     FR_NOT_READY,           /* (3) The physical drive cannot work */
00182     FR_NO_FILE,             /* (4) Could not find the file */
00183     FR_NO_PATH,             /* (5) Could not find the path */
00184     FR_INVALID_NAME,        /* (6) The path name format is invalid */
00185     FR_DENIED,              /* (7) Access denied due to prohibited access or directory full */
00186     FR_EXIST,               /* (8) Access denied due to prohibited access */
00187     FR_INVALID_OBJECT,      /* (9) The file/directory object is invalid */
00188     FR_WRITE_PROTECTED,     /* (10) The physical drive is write protected */
00189     FR_INVALID_DRIVE,       /* (11) The logical drive number is invalid */
00190     FR_NOT_ENABLED,         /* (12) The volume has no work area */
00191     FR_NO_FILESYSTEM,       /* (13) There is no valid FAT volume */
00192     FR_MKFS_ABORTED,        /* (14) The f_mkfs() aborted due to any parameter error */
00193     FR_TIMEOUT,             /* (15) Could not get a grant to access the volume within defined period */
00194     FR_LOCKED,              /* (16) The operation is rejected according to the file sharing policy */
00195     FR_NOT_ENOUGH_CORE,     /* (17) LFN working buffer could not be allocated */
00196     FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_SHARE */
00197     FR_INVALID_PARAMETER    /* (19) Given parameter is invalid */
00198 } FRESULT;
00199 
00200 
00201 
00202 /*--------------------------------------------------------------*/
00203 /* FatFs module application interface                           */
00204 
00205 FRESULT f_mount (BYTE, FATFS*);                     /* Mount/Unmount a logical drive */
00206 FRESULT f_open (FIL*, const TCHAR*, BYTE);          /* Open or create a file */
00207 FRESULT f_read (FIL*, void*, UINT, UINT*);          /* Read data from a file */
00208 FRESULT f_lseek (FIL*, DWORD);                      /* Move file pointer of a file object */
00209 FRESULT f_close (FIL*);                             /* Close an open file object */
00210 FRESULT f_opendir (FATFS_DIR*, const TCHAR*);             /* Open an existing directory */
00211 FRESULT f_readdir (FATFS_DIR*, FILINFO*);                 /* Read a directory item */
00212 FRESULT f_stat (const TCHAR*, FILINFO*);            /* Get file status */
00213 FRESULT f_write (FIL*, const void*, UINT, UINT*);   /* Write data to a file */
00214 FRESULT f_getfree (const TCHAR*, DWORD*, FATFS**);  /* Get number of free clusters on the drive */
00215 FRESULT f_truncate (FIL*);                          /* Truncate file */
00216 FRESULT f_sync (FIL*);                              /* Flush cached data of a writing file */
00217 FRESULT f_unlink (const TCHAR*);                    /* Delete an existing file or directory */
00218 FRESULT f_mkdir (const TCHAR*);                     /* Create a new directory */
00219 FRESULT f_chmod (const TCHAR*, BYTE, BYTE);         /* Change attribute of the file/dir */
00220 FRESULT f_utime (const TCHAR*, const FILINFO*);     /* Change times-tamp of the file/dir */
00221 FRESULT f_rename (const TCHAR*, const TCHAR*);      /* Rename/Move a file or directory */
00222 FRESULT f_chdrive (BYTE);                           /* Change current drive */
00223 FRESULT f_chdir (const TCHAR*);                     /* Change current directory */
00224 FRESULT f_getcwd (TCHAR*, UINT);                    /* Get current directory */
00225 FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*);   /* Forward data to the stream */
00226 FRESULT f_mkfs (BYTE, BYTE, UINT);                  /* Create a file system on the drive */
00227 FRESULT f_fdisk (BYTE, const DWORD[], void*);       /* Divide a physical drive into some partitions */
00228 int f_putc (TCHAR, FIL*);                           /* Put a character to the file */
00229 int f_puts (const TCHAR*, FIL*);                    /* Put a string to the file */
00230 int f_printf (FIL*, const TCHAR*, ...);             /* Put a formatted string to the file */
00231 TCHAR* f_gets (TCHAR*, int, FIL*);                  /* Get a string from the file */
00232 
00233 #define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
00234 #define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0)
00235 #define f_tell(fp) ((fp)->fptr)
00236 #define f_size(fp) ((fp)->fsize)
00237 
00238 #ifndef EOF
00239 #define EOF (-1)
00240 #endif
00241 
00242 
00243 
00244 
00245 /*--------------------------------------------------------------*/
00246 /* Additional user defined functions                            */
00247 
00248 /* RTC function */
00249 #if !_FS_READONLY
00250 DWORD get_fattime (void);
00251 #endif
00252 
00253 /* Unicode support functions */
00254 #if _USE_LFN                        /* Unicode - OEM code conversion */
00255 WCHAR ff_convert (WCHAR, UINT);     /* OEM-Unicode bidirectional conversion */
00256 WCHAR ff_wtoupper (WCHAR);          /* Unicode upper-case conversion */
00257 #if _USE_LFN == 3                   /* Memory functions */
00258 void* ff_memalloc (UINT);           /* Allocate memory block */
00259 void ff_memfree (void*);            /* Free memory block */
00260 #endif
00261 #endif
00262 
00263 /* Sync functions */
00264 #if _FS_REENTRANT
00265 int ff_cre_syncobj (BYTE, _SYNC_t*);/* Create a sync object */
00266 int ff_req_grant (_SYNC_t);         /* Lock sync object */
00267 void ff_rel_grant (_SYNC_t);        /* Unlock sync object */
00268 int ff_del_syncobj (_SYNC_t);       /* Delete a sync object */
00269 #endif
00270 
00271 
00272 
00273 
00274 /*--------------------------------------------------------------*/
00275 /* Flags and offset address                                     */
00276 
00277 
00278 /* File access control and file status flags (FIL.flag) */
00279 
00280 #define FA_READ             0x01
00281 #define FA_OPEN_EXISTING    0x00
00282 #define FA__ERROR           0x80
00283 
00284 #if !_FS_READONLY
00285 #define FA_WRITE            0x02
00286 #define FA_CREATE_NEW       0x04
00287 #define FA_CREATE_ALWAYS    0x08
00288 #define FA_OPEN_ALWAYS      0x10
00289 #define FA__WRITTEN         0x20
00290 #define FA__DIRTY           0x40
00291 #endif
00292 
00293 
00294 /* FAT sub type (FATFS.fs_type) */
00295 
00296 #define FS_FAT12    1
00297 #define FS_FAT16    2
00298 #define FS_FAT32    3
00299 
00300 
00301 /* File attribute bits for directory entry */
00302 
00303 #define AM_RDO  0x01    /* Read only */
00304 #define AM_HID  0x02    /* Hidden */
00305 #define AM_SYS  0x04    /* System */
00306 #define AM_VOL  0x08    /* Volume label */
00307 #define AM_LFN  0x0F    /* LFN entry */
00308 #define AM_DIR  0x10    /* Directory */
00309 #define AM_ARC  0x20    /* Archive */
00310 #define AM_MASK 0x3F    /* Mask of defined bits */
00311 
00312 
00313 /* Fast seek feature */
00314 #define CREATE_LINKMAP  0xFFFFFFFF
00315 
00316 
00317 
00318 /*--------------------------------*/
00319 /* Multi-byte word access macros  */
00320 
00321 #if _WORD_ACCESS == 1   /* Enable word access to the FAT structure */
00322 #define LD_WORD(ptr)        (WORD)(*(WORD*)(BYTE*)(ptr))
00323 #define LD_DWORD(ptr)       (DWORD)(*(DWORD*)(BYTE*)(ptr))
00324 #define ST_WORD(ptr,val)    *(WORD*)(BYTE*)(ptr)=(WORD)(val)
00325 #define ST_DWORD(ptr,val)   *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
00326 #else                   /* Use byte-by-byte access to the FAT structure */
00327 #define LD_WORD(ptr)        (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
00328 #define LD_DWORD(ptr)       (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
00329 #define ST_WORD(ptr,val)    *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
00330 #define ST_DWORD(ptr,val)   *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24)
00331 #endif
00332 
00333 #ifdef __cplusplus
00334 }
00335 #endif
00336 
00337 #endif /* _FATFS */