First working version of a FATFileSystem compatible Chan FAT v0.8 implementation. This is intended to use with long file names and RTOS support. For now long file names work but RTOS support is still untested.

Dependents:   USB_MSC USB_CDC_MSD_Hello TFTPServerTest DMXStation ... more

Committer:
NeoBelerophon
Date:
Fri Feb 04 21:14:33 2011 +0000
Revision:
2:629e4be333f3
Parent:
0:8ea634413549
getdir() did not work -> remove

Who changed what in which revision?

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