Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

ff.h

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

Generated on Tue Apr 7 20:07:43 2015 for BF592A Library by doxygen 1.3.1