microCD

Fork of FATFileSystem by mbed official

Committer:
mbed_official
Date:
Thu Aug 13 10:15:39 2015 +0100
Revision:
5:b3b3370574cf
Parent:
1:46ce1e16c870
Child:
6:a5fcdbf92056
Synchronized with git revision ab6a668ec18ad1530649c4cf1067a42816c6a7f8

Full URL: https://github.com/mbedmicro/mbed/commit/ab6a668ec18ad1530649c4cf1067a42816c6a7f8/

FATFileSystem - Updated FatFs to R0.11

Who changed what in which revision?

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