Compact Flash I/O test

Dependencies:   mbed

Committer:
emh203
Date:
Fri Dec 30 21:02:16 2011 +0000
Revision:
1:dc171f34db9b
Parent:
0:6b1e6c9e48ba

        

Who changed what in which revision?

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