microCD
Fork of FATFileSystem by
ChaN/ff.h@8:0345cdc7efa5, 2017-02-17 (annotated)
- Committer:
- vnemera
- Date:
- Fri Feb 17 16:43:26 2017 +0000
- Revision:
- 8:0345cdc7efa5
- Parent:
- 6:a5fcdbf92056
1.4.4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 1:46ce1e16c870 | 1 | /*---------------------------------------------------------------------------/ |
mbed_official | 6:a5fcdbf92056 | 2 | / FatFs - FAT file system module include R0.11a (C)ChaN, 2015 |
emilmont | 1:46ce1e16c870 | 3 | /----------------------------------------------------------------------------/ |
mbed_official | 5:b3b3370574cf | 4 | / FatFs module is a free software that opened under license policy of |
mbed_official | 5:b3b3370574cf | 5 | / following conditions. |
mbed_official | 5:b3b3370574cf | 6 | / |
mbed_official | 5:b3b3370574cf | 7 | / Copyright (C) 2015, ChaN, all right reserved. |
emilmont | 1:46ce1e16c870 | 8 | / |
mbed_official | 5:b3b3370574cf | 9 | / 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 5:b3b3370574cf | 10 | / this condition and the following disclaimer. |
emilmont | 1:46ce1e16c870 | 11 | / |
mbed_official | 5:b3b3370574cf | 12 | / This software is provided by the copyright holder and contributors "AS IS" |
mbed_official | 5:b3b3370574cf | 13 | / and any warranties related to this software are DISCLAIMED. |
mbed_official | 5:b3b3370574cf | 14 | / The copyright owner or contributors be NOT LIABLE for any damages caused |
mbed_official | 5:b3b3370574cf | 15 | / by use of this software. |
mbed_official | 5:b3b3370574cf | 16 | /---------------------------------------------------------------------------*/ |
mbed_official | 5:b3b3370574cf | 17 | |
emilmont | 1:46ce1e16c870 | 18 | |
emilmont | 1:46ce1e16c870 | 19 | #ifndef _FATFS |
mbed_official | 6:a5fcdbf92056 | 20 | #define _FATFS 64180 /* Revision ID */ |
emilmont | 1:46ce1e16c870 | 21 | |
emilmont | 1:46ce1e16c870 | 22 | #ifdef __cplusplus |
emilmont | 1:46ce1e16c870 | 23 | extern "C" { |
emilmont | 1:46ce1e16c870 | 24 | #endif |
emilmont | 1:46ce1e16c870 | 25 | |
mbed_official | 5:b3b3370574cf | 26 | #include "integer.h" /* Basic integer types */ |
mbed_official | 5:b3b3370574cf | 27 | #include "ffconf.h" /* FatFs configuration options */ |
emilmont | 1:46ce1e16c870 | 28 | #if _FATFS != _FFCONF |
emilmont | 1:46ce1e16c870 | 29 | #error Wrong configuration file (ffconf.h). |
emilmont | 1:46ce1e16c870 | 30 | #endif |
emilmont | 1:46ce1e16c870 | 31 | |
emilmont | 1:46ce1e16c870 | 32 | /* Definitions of volume management */ |
emilmont | 1:46ce1e16c870 | 33 | |
mbed_official | 5:b3b3370574cf | 34 | #if _MULTI_PARTITION /* Multiple partition configuration */ |
emilmont | 1:46ce1e16c870 | 35 | typedef struct { |
mbed_official | 5:b3b3370574cf | 36 | BYTE pd; /* Physical drive number */ |
mbed_official | 5:b3b3370574cf | 37 | BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */ |
emilmont | 1:46ce1e16c870 | 38 | } PARTITION; |
mbed_official | 5:b3b3370574cf | 39 | extern PARTITION VolToPart[]; /* Volume - Partition resolution table */ |
mbed_official | 5:b3b3370574cf | 40 | #define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive number */ |
mbed_official | 5:b3b3370574cf | 41 | #define LD2PT(vol) (VolToPart[vol].pt) /* Get partition index */ |
emilmont | 1:46ce1e16c870 | 42 | |
mbed_official | 5:b3b3370574cf | 43 | #else /* Single partition configuration */ |
mbed_official | 5:b3b3370574cf | 44 | #define LD2PD(vol) (BYTE)(vol) /* Each logical drive is bound to the same physical drive number */ |
mbed_official | 5:b3b3370574cf | 45 | #define LD2PT(vol) 0 /* Find first valid partition or in SFD */ |
emilmont | 1:46ce1e16c870 | 46 | |
emilmont | 1:46ce1e16c870 | 47 | #endif |
emilmont | 1:46ce1e16c870 | 48 | |
emilmont | 1:46ce1e16c870 | 49 | |
emilmont | 1:46ce1e16c870 | 50 | |
emilmont | 1:46ce1e16c870 | 51 | /* Type of path name strings on FatFs API */ |
emilmont | 1:46ce1e16c870 | 52 | |
mbed_official | 5:b3b3370574cf | 53 | #if _LFN_UNICODE /* Unicode string */ |
emilmont | 1:46ce1e16c870 | 54 | #if !_USE_LFN |
mbed_official | 5:b3b3370574cf | 55 | #error _LFN_UNICODE must be 0 at non-LFN cfg. |
emilmont | 1:46ce1e16c870 | 56 | #endif |
emilmont | 1:46ce1e16c870 | 57 | #ifndef _INC_TCHAR |
emilmont | 1:46ce1e16c870 | 58 | typedef WCHAR TCHAR; |
emilmont | 1:46ce1e16c870 | 59 | #define _T(x) L ## x |
emilmont | 1:46ce1e16c870 | 60 | #define _TEXT(x) L ## x |
emilmont | 1:46ce1e16c870 | 61 | #endif |
emilmont | 1:46ce1e16c870 | 62 | |
mbed_official | 5:b3b3370574cf | 63 | #else /* ANSI/OEM string */ |
emilmont | 1:46ce1e16c870 | 64 | #ifndef _INC_TCHAR |
emilmont | 1:46ce1e16c870 | 65 | typedef char TCHAR; |
emilmont | 1:46ce1e16c870 | 66 | #define _T(x) x |
emilmont | 1:46ce1e16c870 | 67 | #define _TEXT(x) x |
emilmont | 1:46ce1e16c870 | 68 | #endif |
emilmont | 1:46ce1e16c870 | 69 | |
emilmont | 1:46ce1e16c870 | 70 | #endif |
emilmont | 1:46ce1e16c870 | 71 | |
emilmont | 1:46ce1e16c870 | 72 | |
emilmont | 1:46ce1e16c870 | 73 | |
emilmont | 1:46ce1e16c870 | 74 | /* File system object structure (FATFS) */ |
emilmont | 1:46ce1e16c870 | 75 | |
emilmont | 1:46ce1e16c870 | 76 | typedef struct { |
mbed_official | 5:b3b3370574cf | 77 | BYTE fs_type; /* FAT sub-type (0:Not mounted) */ |
mbed_official | 5:b3b3370574cf | 78 | BYTE drv; /* Physical drive number */ |
mbed_official | 5:b3b3370574cf | 79 | BYTE csize; /* Sectors per cluster (1,2,4...128) */ |
mbed_official | 5:b3b3370574cf | 80 | BYTE n_fats; /* Number of FAT copies (1 or 2) */ |
mbed_official | 5:b3b3370574cf | 81 | BYTE wflag; /* win[] flag (b0:dirty) */ |
mbed_official | 5:b3b3370574cf | 82 | BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */ |
mbed_official | 5:b3b3370574cf | 83 | WORD id; /* File system mount ID */ |
mbed_official | 5:b3b3370574cf | 84 | WORD n_rootdir; /* Number of root directory entries (FAT12/16) */ |
mbed_official | 5:b3b3370574cf | 85 | #if _MAX_SS != _MIN_SS |
mbed_official | 5:b3b3370574cf | 86 | WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */ |
emilmont | 1:46ce1e16c870 | 87 | #endif |
emilmont | 1:46ce1e16c870 | 88 | #if _FS_REENTRANT |
mbed_official | 5:b3b3370574cf | 89 | _SYNC_t sobj; /* Identifier of sync object */ |
emilmont | 1:46ce1e16c870 | 90 | #endif |
emilmont | 1:46ce1e16c870 | 91 | #if !_FS_READONLY |
mbed_official | 5:b3b3370574cf | 92 | DWORD last_clust; /* Last allocated cluster */ |
mbed_official | 5:b3b3370574cf | 93 | DWORD free_clust; /* Number of free clusters */ |
emilmont | 1:46ce1e16c870 | 94 | #endif |
emilmont | 1:46ce1e16c870 | 95 | #if _FS_RPATH |
mbed_official | 5:b3b3370574cf | 96 | DWORD cdir; /* Current directory start cluster (0:root) */ |
emilmont | 1:46ce1e16c870 | 97 | #endif |
mbed_official | 5:b3b3370574cf | 98 | DWORD n_fatent; /* Number of FAT entries, = number of clusters + 2 */ |
mbed_official | 5:b3b3370574cf | 99 | DWORD fsize; /* Sectors per FAT */ |
mbed_official | 5:b3b3370574cf | 100 | DWORD volbase; /* Volume start sector */ |
mbed_official | 5:b3b3370574cf | 101 | DWORD fatbase; /* FAT start sector */ |
mbed_official | 5:b3b3370574cf | 102 | DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */ |
mbed_official | 5:b3b3370574cf | 103 | DWORD database; /* Data start sector */ |
mbed_official | 5:b3b3370574cf | 104 | DWORD winsect; /* Current sector appearing in the win[] */ |
mbed_official | 5:b3b3370574cf | 105 | BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */ |
emilmont | 1:46ce1e16c870 | 106 | } FATFS; |
emilmont | 1:46ce1e16c870 | 107 | |
emilmont | 1:46ce1e16c870 | 108 | |
emilmont | 1:46ce1e16c870 | 109 | |
emilmont | 1:46ce1e16c870 | 110 | /* File object structure (FIL) */ |
emilmont | 1:46ce1e16c870 | 111 | |
emilmont | 1:46ce1e16c870 | 112 | typedef struct { |
mbed_official | 5:b3b3370574cf | 113 | FATFS* fs; /* Pointer to the related file system object (**do not change order**) */ |
mbed_official | 5:b3b3370574cf | 114 | WORD id; /* Owner file system mount ID (**do not change order**) */ |
mbed_official | 5:b3b3370574cf | 115 | BYTE flag; /* Status flags */ |
mbed_official | 5:b3b3370574cf | 116 | BYTE err; /* Abort flag (error code) */ |
mbed_official | 5:b3b3370574cf | 117 | DWORD fptr; /* File read/write pointer (Zeroed on file open) */ |
mbed_official | 5:b3b3370574cf | 118 | DWORD fsize; /* File size */ |
mbed_official | 5:b3b3370574cf | 119 | DWORD sclust; /* File start cluster (0:no cluster chain, always 0 when fsize is 0) */ |
mbed_official | 5:b3b3370574cf | 120 | DWORD clust; /* Current cluster of fpter (not valid when fprt is 0) */ |
mbed_official | 5:b3b3370574cf | 121 | DWORD dsect; /* Sector number appearing in buf[] (0:invalid) */ |
emilmont | 1:46ce1e16c870 | 122 | #if !_FS_READONLY |
mbed_official | 5:b3b3370574cf | 123 | DWORD dir_sect; /* Sector number containing the directory entry */ |
mbed_official | 5:b3b3370574cf | 124 | BYTE* dir_ptr; /* Pointer to the directory entry in the win[] */ |
emilmont | 1:46ce1e16c870 | 125 | #endif |
emilmont | 1:46ce1e16c870 | 126 | #if _USE_FASTSEEK |
mbed_official | 5:b3b3370574cf | 127 | DWORD* cltbl; /* Pointer to the cluster link map table (Nulled on file open) */ |
emilmont | 1:46ce1e16c870 | 128 | #endif |
emilmont | 1:46ce1e16c870 | 129 | #if _FS_LOCK |
mbed_official | 5:b3b3370574cf | 130 | UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */ |
emilmont | 1:46ce1e16c870 | 131 | #endif |
emilmont | 1:46ce1e16c870 | 132 | #if !_FS_TINY |
mbed_official | 5:b3b3370574cf | 133 | BYTE buf[_MAX_SS]; /* File private data read/write window */ |
emilmont | 1:46ce1e16c870 | 134 | #endif |
emilmont | 1:46ce1e16c870 | 135 | } FIL; |
emilmont | 1:46ce1e16c870 | 136 | |
emilmont | 1:46ce1e16c870 | 137 | |
emilmont | 1:46ce1e16c870 | 138 | |
mbed_official | 5:b3b3370574cf | 139 | /* Directory object structure (FATFS_DIR) */ |
emilmont | 1:46ce1e16c870 | 140 | |
emilmont | 1:46ce1e16c870 | 141 | typedef struct { |
mbed_official | 5:b3b3370574cf | 142 | FATFS* fs; /* Pointer to the owner file system object (**do not change order**) */ |
mbed_official | 5:b3b3370574cf | 143 | WORD id; /* Owner file system mount ID (**do not change order**) */ |
mbed_official | 5:b3b3370574cf | 144 | WORD index; /* Current read/write index number */ |
mbed_official | 6:a5fcdbf92056 | 145 | DWORD sclust; /* Table start cluster (0:Root dir) */ |
mbed_official | 5:b3b3370574cf | 146 | DWORD clust; /* Current cluster */ |
mbed_official | 5:b3b3370574cf | 147 | DWORD sect; /* Current sector */ |
mbed_official | 6:a5fcdbf92056 | 148 | BYTE* dir; /* Pointer to the current SFN entry in the win[] */ |
mbed_official | 5:b3b3370574cf | 149 | BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */ |
mbed_official | 5:b3b3370574cf | 150 | #if _FS_LOCK |
mbed_official | 5:b3b3370574cf | 151 | UINT lockid; /* File lock ID (index of file semaphore table Files[]) */ |
mbed_official | 5:b3b3370574cf | 152 | #endif |
emilmont | 1:46ce1e16c870 | 153 | #if _USE_LFN |
mbed_official | 5:b3b3370574cf | 154 | WCHAR* lfn; /* Pointer to the LFN working buffer */ |
mbed_official | 5:b3b3370574cf | 155 | WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */ |
mbed_official | 5:b3b3370574cf | 156 | #endif |
mbed_official | 5:b3b3370574cf | 157 | #if _USE_FIND |
mbed_official | 5:b3b3370574cf | 158 | const TCHAR* pat; /* Pointer to the name matching pattern */ |
emilmont | 1:46ce1e16c870 | 159 | #endif |
emilmont | 1:46ce1e16c870 | 160 | } FATFS_DIR; |
emilmont | 1:46ce1e16c870 | 161 | |
emilmont | 1:46ce1e16c870 | 162 | |
emilmont | 1:46ce1e16c870 | 163 | |
mbed_official | 5:b3b3370574cf | 164 | /* File information structure (FILINFO) */ |
emilmont | 1:46ce1e16c870 | 165 | |
emilmont | 1:46ce1e16c870 | 166 | typedef struct { |
mbed_official | 5:b3b3370574cf | 167 | DWORD fsize; /* File size */ |
mbed_official | 5:b3b3370574cf | 168 | WORD fdate; /* Last modified date */ |
mbed_official | 5:b3b3370574cf | 169 | WORD ftime; /* Last modified time */ |
mbed_official | 5:b3b3370574cf | 170 | BYTE fattrib; /* Attribute */ |
mbed_official | 5:b3b3370574cf | 171 | TCHAR fname[13]; /* Short file name (8.3 format) */ |
emilmont | 1:46ce1e16c870 | 172 | #if _USE_LFN |
mbed_official | 5:b3b3370574cf | 173 | TCHAR* lfname; /* Pointer to the LFN buffer */ |
mbed_official | 5:b3b3370574cf | 174 | UINT lfsize; /* Size of LFN buffer in TCHAR */ |
emilmont | 1:46ce1e16c870 | 175 | #endif |
emilmont | 1:46ce1e16c870 | 176 | } FILINFO; |
emilmont | 1:46ce1e16c870 | 177 | |
emilmont | 1:46ce1e16c870 | 178 | |
emilmont | 1:46ce1e16c870 | 179 | |
emilmont | 1:46ce1e16c870 | 180 | /* File function return code (FRESULT) */ |
emilmont | 1:46ce1e16c870 | 181 | |
emilmont | 1:46ce1e16c870 | 182 | typedef enum { |
mbed_official | 5:b3b3370574cf | 183 | FR_OK = 0, /* (0) Succeeded */ |
mbed_official | 5:b3b3370574cf | 184 | FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */ |
mbed_official | 5:b3b3370574cf | 185 | FR_INT_ERR, /* (2) Assertion failed */ |
mbed_official | 5:b3b3370574cf | 186 | FR_NOT_READY, /* (3) The physical drive cannot work */ |
mbed_official | 5:b3b3370574cf | 187 | FR_NO_FILE, /* (4) Could not find the file */ |
mbed_official | 5:b3b3370574cf | 188 | FR_NO_PATH, /* (5) Could not find the path */ |
mbed_official | 5:b3b3370574cf | 189 | FR_INVALID_NAME, /* (6) The path name format is invalid */ |
mbed_official | 5:b3b3370574cf | 190 | FR_DENIED, /* (7) Access denied due to prohibited access or directory full */ |
mbed_official | 5:b3b3370574cf | 191 | FR_EXIST, /* (8) Access denied due to prohibited access */ |
mbed_official | 5:b3b3370574cf | 192 | FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */ |
mbed_official | 5:b3b3370574cf | 193 | FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */ |
mbed_official | 5:b3b3370574cf | 194 | FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */ |
mbed_official | 5:b3b3370574cf | 195 | FR_NOT_ENABLED, /* (12) The volume has no work area */ |
mbed_official | 5:b3b3370574cf | 196 | FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */ |
mbed_official | 5:b3b3370574cf | 197 | FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */ |
mbed_official | 5:b3b3370574cf | 198 | FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */ |
mbed_official | 5:b3b3370574cf | 199 | FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */ |
mbed_official | 5:b3b3370574cf | 200 | FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */ |
mbed_official | 6:a5fcdbf92056 | 201 | FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_LOCK */ |
mbed_official | 5:b3b3370574cf | 202 | FR_INVALID_PARAMETER /* (19) Given parameter is invalid */ |
emilmont | 1:46ce1e16c870 | 203 | } FRESULT; |
emilmont | 1:46ce1e16c870 | 204 | |
emilmont | 1:46ce1e16c870 | 205 | |
emilmont | 1:46ce1e16c870 | 206 | |
emilmont | 1:46ce1e16c870 | 207 | /*--------------------------------------------------------------*/ |
emilmont | 1:46ce1e16c870 | 208 | /* FatFs module application interface */ |
emilmont | 1:46ce1e16c870 | 209 | |
mbed_official | 5:b3b3370574cf | 210 | FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */ |
mbed_official | 5:b3b3370574cf | 211 | FRESULT f_close (FIL* fp); /* Close an open file object */ |
mbed_official | 5:b3b3370574cf | 212 | FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from a file */ |
mbed_official | 5:b3b3370574cf | 213 | FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to a file */ |
mbed_official | 5:b3b3370574cf | 214 | FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */ |
mbed_official | 5:b3b3370574cf | 215 | FRESULT f_lseek (FIL* fp, DWORD ofs); /* Move file pointer of a file object */ |
mbed_official | 5:b3b3370574cf | 216 | FRESULT f_truncate (FIL* fp); /* Truncate file */ |
mbed_official | 5:b3b3370574cf | 217 | FRESULT f_sync (FIL* fp); /* Flush cached data of a writing file */ |
mbed_official | 5:b3b3370574cf | 218 | FRESULT f_opendir (FATFS_DIR* dp, const TCHAR* path); /* Open a directory */ |
mbed_official | 5:b3b3370574cf | 219 | FRESULT f_closedir (FATFS_DIR* dp); /* Close an open directory */ |
mbed_official | 5:b3b3370574cf | 220 | FRESULT f_readdir (FATFS_DIR* dp, FILINFO* fno); /* Read a directory item */ |
mbed_official | 5:b3b3370574cf | 221 | FRESULT f_findfirst (FATFS_DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */ |
mbed_official | 5:b3b3370574cf | 222 | FRESULT f_findnext (FATFS_DIR* dp, FILINFO* fno); /* Find next file */ |
mbed_official | 5:b3b3370574cf | 223 | FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */ |
mbed_official | 5:b3b3370574cf | 224 | FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */ |
mbed_official | 5:b3b3370574cf | 225 | FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */ |
mbed_official | 5:b3b3370574cf | 226 | FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */ |
mbed_official | 6:a5fcdbf92056 | 227 | FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of the file/dir */ |
mbed_official | 6:a5fcdbf92056 | 228 | FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change times-tamp of the file/dir */ |
mbed_official | 5:b3b3370574cf | 229 | FRESULT f_chdir (const TCHAR* path); /* Change current directory */ |
mbed_official | 5:b3b3370574cf | 230 | FRESULT f_chdrive (const TCHAR* path); /* Change current drive */ |
mbed_official | 5:b3b3370574cf | 231 | FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */ |
mbed_official | 5:b3b3370574cf | 232 | FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */ |
mbed_official | 5:b3b3370574cf | 233 | FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */ |
mbed_official | 5:b3b3370574cf | 234 | FRESULT f_setlabel (const TCHAR* label); /* Set volume label */ |
mbed_official | 5:b3b3370574cf | 235 | FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */ |
mbed_official | 5:b3b3370574cf | 236 | FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au); /* Create a file system on the volume */ |
mbed_official | 5:b3b3370574cf | 237 | FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work); /* Divide a physical drive into some partitions */ |
mbed_official | 5:b3b3370574cf | 238 | int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */ |
mbed_official | 5:b3b3370574cf | 239 | int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */ |
mbed_official | 5:b3b3370574cf | 240 | int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */ |
mbed_official | 5:b3b3370574cf | 241 | TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */ |
emilmont | 1:46ce1e16c870 | 242 | |
mbed_official | 5:b3b3370574cf | 243 | #define f_eof(fp) ((int)((fp)->fptr == (fp)->fsize)) |
mbed_official | 5:b3b3370574cf | 244 | #define f_error(fp) ((fp)->err) |
emilmont | 1:46ce1e16c870 | 245 | #define f_tell(fp) ((fp)->fptr) |
emilmont | 1:46ce1e16c870 | 246 | #define f_size(fp) ((fp)->fsize) |
mbed_official | 5:b3b3370574cf | 247 | #define f_rewind(fp) f_lseek((fp), 0) |
mbed_official | 5:b3b3370574cf | 248 | #define f_rewinddir(dp) f_readdir((dp), 0) |
emilmont | 1:46ce1e16c870 | 249 | |
emilmont | 1:46ce1e16c870 | 250 | #ifndef EOF |
emilmont | 1:46ce1e16c870 | 251 | #define EOF (-1) |
emilmont | 1:46ce1e16c870 | 252 | #endif |
emilmont | 1:46ce1e16c870 | 253 | |
emilmont | 1:46ce1e16c870 | 254 | |
emilmont | 1:46ce1e16c870 | 255 | |
emilmont | 1:46ce1e16c870 | 256 | |
emilmont | 1:46ce1e16c870 | 257 | /*--------------------------------------------------------------*/ |
emilmont | 1:46ce1e16c870 | 258 | /* Additional user defined functions */ |
emilmont | 1:46ce1e16c870 | 259 | |
emilmont | 1:46ce1e16c870 | 260 | /* RTC function */ |
mbed_official | 5:b3b3370574cf | 261 | #if !_FS_READONLY && !_FS_NORTC |
emilmont | 1:46ce1e16c870 | 262 | DWORD get_fattime (void); |
emilmont | 1:46ce1e16c870 | 263 | #endif |
emilmont | 1:46ce1e16c870 | 264 | |
emilmont | 1:46ce1e16c870 | 265 | /* Unicode support functions */ |
mbed_official | 5:b3b3370574cf | 266 | #if _USE_LFN /* Unicode - OEM code conversion */ |
mbed_official | 6:a5fcdbf92056 | 267 | WCHAR ff_convert (WCHAR chr, UINT dir); /* OEM-Unicode bidirectional conversion */ |
mbed_official | 5:b3b3370574cf | 268 | WCHAR ff_wtoupper (WCHAR chr); /* Unicode upper-case conversion */ |
mbed_official | 5:b3b3370574cf | 269 | #if _USE_LFN == 3 /* Memory functions */ |
mbed_official | 5:b3b3370574cf | 270 | void* ff_memalloc (UINT msize); /* Allocate memory block */ |
mbed_official | 5:b3b3370574cf | 271 | void ff_memfree (void* mblock); /* Free memory block */ |
emilmont | 1:46ce1e16c870 | 272 | #endif |
emilmont | 1:46ce1e16c870 | 273 | #endif |
emilmont | 1:46ce1e16c870 | 274 | |
emilmont | 1:46ce1e16c870 | 275 | /* Sync functions */ |
emilmont | 1:46ce1e16c870 | 276 | #if _FS_REENTRANT |
mbed_official | 5:b3b3370574cf | 277 | int ff_cre_syncobj (BYTE vol, _SYNC_t* sobj); /* Create a sync object */ |
mbed_official | 5:b3b3370574cf | 278 | int ff_req_grant (_SYNC_t sobj); /* Lock sync object */ |
mbed_official | 5:b3b3370574cf | 279 | void ff_rel_grant (_SYNC_t sobj); /* Unlock sync object */ |
mbed_official | 5:b3b3370574cf | 280 | int ff_del_syncobj (_SYNC_t sobj); /* Delete a sync object */ |
emilmont | 1:46ce1e16c870 | 281 | #endif |
emilmont | 1:46ce1e16c870 | 282 | |
emilmont | 1:46ce1e16c870 | 283 | |
emilmont | 1:46ce1e16c870 | 284 | |
emilmont | 1:46ce1e16c870 | 285 | |
emilmont | 1:46ce1e16c870 | 286 | /*--------------------------------------------------------------*/ |
emilmont | 1:46ce1e16c870 | 287 | /* Flags and offset address */ |
emilmont | 1:46ce1e16c870 | 288 | |
emilmont | 1:46ce1e16c870 | 289 | |
emilmont | 1:46ce1e16c870 | 290 | /* File access control and file status flags (FIL.flag) */ |
emilmont | 1:46ce1e16c870 | 291 | |
mbed_official | 5:b3b3370574cf | 292 | #define FA_READ 0x01 |
mbed_official | 5:b3b3370574cf | 293 | #define FA_OPEN_EXISTING 0x00 |
emilmont | 1:46ce1e16c870 | 294 | |
emilmont | 1:46ce1e16c870 | 295 | #if !_FS_READONLY |
mbed_official | 5:b3b3370574cf | 296 | #define FA_WRITE 0x02 |
mbed_official | 5:b3b3370574cf | 297 | #define FA_CREATE_NEW 0x04 |
mbed_official | 5:b3b3370574cf | 298 | #define FA_CREATE_ALWAYS 0x08 |
mbed_official | 5:b3b3370574cf | 299 | #define FA_OPEN_ALWAYS 0x10 |
mbed_official | 5:b3b3370574cf | 300 | #define FA__WRITTEN 0x20 |
mbed_official | 5:b3b3370574cf | 301 | #define FA__DIRTY 0x40 |
emilmont | 1:46ce1e16c870 | 302 | #endif |
emilmont | 1:46ce1e16c870 | 303 | |
emilmont | 1:46ce1e16c870 | 304 | |
emilmont | 1:46ce1e16c870 | 305 | /* FAT sub type (FATFS.fs_type) */ |
emilmont | 1:46ce1e16c870 | 306 | |
mbed_official | 5:b3b3370574cf | 307 | #define FS_FAT12 1 |
mbed_official | 5:b3b3370574cf | 308 | #define FS_FAT16 2 |
mbed_official | 5:b3b3370574cf | 309 | #define FS_FAT32 3 |
emilmont | 1:46ce1e16c870 | 310 | |
emilmont | 1:46ce1e16c870 | 311 | |
emilmont | 1:46ce1e16c870 | 312 | /* File attribute bits for directory entry */ |
emilmont | 1:46ce1e16c870 | 313 | |
mbed_official | 5:b3b3370574cf | 314 | #define AM_RDO 0x01 /* Read only */ |
mbed_official | 5:b3b3370574cf | 315 | #define AM_HID 0x02 /* Hidden */ |
mbed_official | 5:b3b3370574cf | 316 | #define AM_SYS 0x04 /* System */ |
mbed_official | 5:b3b3370574cf | 317 | #define AM_VOL 0x08 /* Volume label */ |
mbed_official | 5:b3b3370574cf | 318 | #define AM_LFN 0x0F /* LFN entry */ |
mbed_official | 5:b3b3370574cf | 319 | #define AM_DIR 0x10 /* Directory */ |
mbed_official | 5:b3b3370574cf | 320 | #define AM_ARC 0x20 /* Archive */ |
mbed_official | 5:b3b3370574cf | 321 | #define AM_MASK 0x3F /* Mask of defined bits */ |
emilmont | 1:46ce1e16c870 | 322 | |
emilmont | 1:46ce1e16c870 | 323 | |
emilmont | 1:46ce1e16c870 | 324 | /* Fast seek feature */ |
mbed_official | 5:b3b3370574cf | 325 | #define CREATE_LINKMAP 0xFFFFFFFF |
emilmont | 1:46ce1e16c870 | 326 | |
emilmont | 1:46ce1e16c870 | 327 | |
emilmont | 1:46ce1e16c870 | 328 | |
emilmont | 1:46ce1e16c870 | 329 | /*--------------------------------*/ |
emilmont | 1:46ce1e16c870 | 330 | /* Multi-byte word access macros */ |
emilmont | 1:46ce1e16c870 | 331 | |
mbed_official | 5:b3b3370574cf | 332 | #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */ |
mbed_official | 5:b3b3370574cf | 333 | #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr)) |
mbed_official | 5:b3b3370574cf | 334 | #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr)) |
mbed_official | 5:b3b3370574cf | 335 | #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val) |
mbed_official | 5:b3b3370574cf | 336 | #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val) |
mbed_official | 5:b3b3370574cf | 337 | #else /* Use byte-by-byte access to the FAT structure */ |
mbed_official | 5:b3b3370574cf | 338 | #define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr)) |
mbed_official | 5:b3b3370574cf | 339 | #define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr)) |
mbed_official | 5:b3b3370574cf | 340 | #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8) |
mbed_official | 5:b3b3370574cf | 341 | #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) |
emilmont | 1:46ce1e16c870 | 342 | #endif |
emilmont | 1:46ce1e16c870 | 343 | |
emilmont | 1:46ce1e16c870 | 344 | #ifdef __cplusplus |
emilmont | 1:46ce1e16c870 | 345 | } |
emilmont | 1:46ce1e16c870 | 346 | #endif |
emilmont | 1:46ce1e16c870 | 347 | |
emilmont | 1:46ce1e16c870 | 348 | #endif /* _FATFS */ |