This is SDFileSystem which corrected the bug for MiMicSDK.

Dependents:   MbedFileServer_1768MiniDK2 RedWireBridge IssueDebug_gcc MiMicRemoteMCU-for-Mbed ... more

Fork of SDFileSystem by mbed official

Committer:
nyatla
Date:
Tue Nov 12 03:41:14 2013 +0000
Revision:
9:b2ca0e66c1f7
Parent:
6:972a52e4d92c
fix warning.;

Who changed what in which revision?

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