Fork of Adam Green's library with .cpp fix for current compiler

Dependents:   MSCUsbHost mpod_nhk_english mpod_picasa_photoframe mpod_nhk_english_spxml ... more

Fork of FatFileSystem by Adam Green

Committer:
igorsk
Date:
Mon Jul 30 13:45:05 2012 +0000
Revision:
1:88f22c32a456
Parent:
0:6ceefe1c53e4
renamed .c to .cpp

Who changed what in which revision?

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