Library for SD card

Dependents:   City_Game_JSON saver-noenvio-1 SNOCC_V2 lab7_prog1 ... more

Committer:
AlexVC97
Date:
Wed Mar 29 07:00:22 2017 +0000
Revision:
0:3bdfc1556537
SDFileSystem Library

Who changed what in which revision?

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