桃井くん機体 高田くん仕様キー
Dependencies: mbed
Fork of PS3_BlueUSB_user by
FatFileSystem/ff.h@0:736c76a75def, 2015-04-30 (annotated)
- Committer:
- hirokimineshita
- Date:
- Thu Apr 30 05:59:05 2015 +0000
- Revision:
- 0:736c76a75def
2015/04/30 PM 2 upload
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hirokimineshita | 0:736c76a75def | 1 | /*--------------------------------------------------------------------------/ |
hirokimineshita | 0:736c76a75def | 2 | / FatFs - FAT file system module include file R0.06 (C)ChaN, 2008 |
hirokimineshita | 0:736c76a75def | 3 | /---------------------------------------------------------------------------/ |
hirokimineshita | 0:736c76a75def | 4 | / FatFs module is an experimenal project to implement FAT file system to |
hirokimineshita | 0:736c76a75def | 5 | / cheap microcontrollers. This is a free software and is opened for education, |
hirokimineshita | 0:736c76a75def | 6 | / research and development under license policy of following trems. |
hirokimineshita | 0:736c76a75def | 7 | / |
hirokimineshita | 0:736c76a75def | 8 | / Copyright (C) 2008, ChaN, all right reserved. |
hirokimineshita | 0:736c76a75def | 9 | / |
hirokimineshita | 0:736c76a75def | 10 | / * The FatFs module is a free software and there is no warranty. |
hirokimineshita | 0:736c76a75def | 11 | / * You can use, modify and/or redistribute it for personal, non-profit or |
hirokimineshita | 0:736c76a75def | 12 | / commercial use without any restriction under your responsibility. |
hirokimineshita | 0:736c76a75def | 13 | / * Redistributions of source code must retain the above copyright notice. |
hirokimineshita | 0:736c76a75def | 14 | / |
hirokimineshita | 0:736c76a75def | 15 | /---------------------------------------------------------------------------*/ |
hirokimineshita | 0:736c76a75def | 16 | |
hirokimineshita | 0:736c76a75def | 17 | #ifndef _FATFS |
hirokimineshita | 0:736c76a75def | 18 | |
hirokimineshita | 0:736c76a75def | 19 | #define _MCU_ENDIAN 2 |
hirokimineshita | 0:736c76a75def | 20 | /* The _MCU_ENDIAN defines which access method is used to the FAT structure. |
hirokimineshita | 0:736c76a75def | 21 | / 1: Enable word access. |
hirokimineshita | 0:736c76a75def | 22 | / 2: Disable word access and use byte-by-byte access instead. |
hirokimineshita | 0:736c76a75def | 23 | / When the architectural byte order of the MCU is big-endian and/or address |
hirokimineshita | 0:736c76a75def | 24 | / miss-aligned access results incorrect behavior, the _MCU_ENDIAN must be set to 2. |
hirokimineshita | 0:736c76a75def | 25 | / If it is not the case, it can also be set to 1 for good code efficiency. */ |
hirokimineshita | 0:736c76a75def | 26 | |
hirokimineshita | 0:736c76a75def | 27 | #define _FS_READONLY 0 |
hirokimineshita | 0:736c76a75def | 28 | /* Setting _FS_READONLY to 1 defines read only configuration. This removes |
hirokimineshita | 0:736c76a75def | 29 | / writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename, |
hirokimineshita | 0:736c76a75def | 30 | / f_truncate and useless f_getfree. */ |
hirokimineshita | 0:736c76a75def | 31 | |
hirokimineshita | 0:736c76a75def | 32 | #define _FS_MINIMIZE 0 |
hirokimineshita | 0:736c76a75def | 33 | /* The _FS_MINIMIZE option defines minimization level to remove some functions. |
hirokimineshita | 0:736c76a75def | 34 | / 0: Full function. |
hirokimineshita | 0:736c76a75def | 35 | / 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod, f_truncate and f_rename are removed. |
hirokimineshita | 0:736c76a75def | 36 | / 2: f_opendir and f_readdir are removed in addition to level 1. |
hirokimineshita | 0:736c76a75def | 37 | / 3: f_lseek is removed in addition to level 2. */ |
hirokimineshita | 0:736c76a75def | 38 | |
hirokimineshita | 0:736c76a75def | 39 | #define _USE_STRFUNC 0 |
hirokimineshita | 0:736c76a75def | 40 | /* To enable string functions, set _USE_STRFUNC to 1 or 2. */ |
hirokimineshita | 0:736c76a75def | 41 | |
hirokimineshita | 0:736c76a75def | 42 | #define _USE_MKFS 1 |
hirokimineshita | 0:736c76a75def | 43 | /* When _USE_MKFS is set to 1 and _FS_READONLY is set to 0, f_mkfs function is |
hirokimineshita | 0:736c76a75def | 44 | / enabled. */ |
hirokimineshita | 0:736c76a75def | 45 | |
hirokimineshita | 0:736c76a75def | 46 | #define _DRIVES 4 |
hirokimineshita | 0:736c76a75def | 47 | /* Number of logical drives to be used. This affects the size of internal table. */ |
hirokimineshita | 0:736c76a75def | 48 | |
hirokimineshita | 0:736c76a75def | 49 | #define _MULTI_PARTITION 0 |
hirokimineshita | 0:736c76a75def | 50 | /* When _MULTI_PARTITION is set to 0, each logical drive is bound to same |
hirokimineshita | 0:736c76a75def | 51 | / physical drive number and can mount only 1st primaly partition. When it is |
hirokimineshita | 0:736c76a75def | 52 | / set to 1, each logical drive can mount a partition listed in Drives[]. */ |
hirokimineshita | 0:736c76a75def | 53 | |
hirokimineshita | 0:736c76a75def | 54 | #define _USE_FSINFO 0 |
hirokimineshita | 0:736c76a75def | 55 | /* To enable FSInfo support on FAT32 volume, set _USE_FSINFO to 1. */ |
hirokimineshita | 0:736c76a75def | 56 | |
hirokimineshita | 0:736c76a75def | 57 | #define _USE_SJIS 1 |
hirokimineshita | 0:736c76a75def | 58 | /* When _USE_SJIS is set to 1, Shift-JIS code transparency is enabled, otherwise |
hirokimineshita | 0:736c76a75def | 59 | / only US-ASCII(7bit) code can be accepted as file/directory name. */ |
hirokimineshita | 0:736c76a75def | 60 | |
hirokimineshita | 0:736c76a75def | 61 | #define _USE_NTFLAG 1 |
hirokimineshita | 0:736c76a75def | 62 | /* When _USE_NTFLAG is set to 1, upper/lower case of the file name is preserved. |
hirokimineshita | 0:736c76a75def | 63 | / Note that the files are always accessed in case insensitive. */ |
hirokimineshita | 0:736c76a75def | 64 | |
hirokimineshita | 0:736c76a75def | 65 | |
hirokimineshita | 0:736c76a75def | 66 | #include "integer.h" |
hirokimineshita | 0:736c76a75def | 67 | |
hirokimineshita | 0:736c76a75def | 68 | #ifdef __cplusplus |
hirokimineshita | 0:736c76a75def | 69 | extern "C" { |
hirokimineshita | 0:736c76a75def | 70 | #endif |
hirokimineshita | 0:736c76a75def | 71 | |
hirokimineshita | 0:736c76a75def | 72 | /* Definitions corresponds to multiple sector size (not tested) */ |
hirokimineshita | 0:736c76a75def | 73 | #define S_MAX_SIZ 512U /* Do not change */ |
hirokimineshita | 0:736c76a75def | 74 | #if S_MAX_SIZ > 512U |
hirokimineshita | 0:736c76a75def | 75 | #define SS(fs) ((fs)->s_size) |
hirokimineshita | 0:736c76a75def | 76 | #else |
hirokimineshita | 0:736c76a75def | 77 | #define SS(fs) 512U |
hirokimineshita | 0:736c76a75def | 78 | #endif |
hirokimineshita | 0:736c76a75def | 79 | |
hirokimineshita | 0:736c76a75def | 80 | |
hirokimineshita | 0:736c76a75def | 81 | /* File system object structure */ |
hirokimineshita | 0:736c76a75def | 82 | typedef struct _FATFS { |
hirokimineshita | 0:736c76a75def | 83 | WORD id; /* File system mount ID */ |
hirokimineshita | 0:736c76a75def | 84 | WORD n_rootdir; /* Number of root directory entries */ |
hirokimineshita | 0:736c76a75def | 85 | DWORD winsect; /* Current sector appearing in the win[] */ |
hirokimineshita | 0:736c76a75def | 86 | DWORD sects_fat; /* Sectors per fat */ |
hirokimineshita | 0:736c76a75def | 87 | DWORD max_clust; /* Maximum cluster# + 1 */ |
hirokimineshita | 0:736c76a75def | 88 | DWORD fatbase; /* FAT start sector */ |
hirokimineshita | 0:736c76a75def | 89 | DWORD dirbase; /* Root directory start sector (cluster# for FAT32) */ |
hirokimineshita | 0:736c76a75def | 90 | DWORD database; /* Data start sector */ |
hirokimineshita | 0:736c76a75def | 91 | #if !_FS_READONLY |
hirokimineshita | 0:736c76a75def | 92 | DWORD last_clust; /* Last allocated cluster */ |
hirokimineshita | 0:736c76a75def | 93 | DWORD free_clust; /* Number of free clusters */ |
hirokimineshita | 0:736c76a75def | 94 | #if _USE_FSINFO |
hirokimineshita | 0:736c76a75def | 95 | DWORD fsi_sector; /* fsinfo sector */ |
hirokimineshita | 0:736c76a75def | 96 | BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */ |
hirokimineshita | 0:736c76a75def | 97 | BYTE pad2; |
hirokimineshita | 0:736c76a75def | 98 | #endif |
hirokimineshita | 0:736c76a75def | 99 | #endif |
hirokimineshita | 0:736c76a75def | 100 | BYTE fs_type; /* FAT sub type */ |
hirokimineshita | 0:736c76a75def | 101 | BYTE csize; /* Number of sectors per cluster */ |
hirokimineshita | 0:736c76a75def | 102 | #if S_MAX_SIZ > 512U |
hirokimineshita | 0:736c76a75def | 103 | WORD s_size; /* Sector size */ |
hirokimineshita | 0:736c76a75def | 104 | #endif |
hirokimineshita | 0:736c76a75def | 105 | BYTE n_fats; /* Number of FAT copies */ |
hirokimineshita | 0:736c76a75def | 106 | BYTE drive; /* Physical drive number */ |
hirokimineshita | 0:736c76a75def | 107 | BYTE winflag; /* win[] dirty flag (1:must be written back) */ |
hirokimineshita | 0:736c76a75def | 108 | BYTE pad1; |
hirokimineshita | 0:736c76a75def | 109 | BYTE win[S_MAX_SIZ]; /* Disk access window for Directory/FAT */ |
hirokimineshita | 0:736c76a75def | 110 | } FATFS; |
hirokimineshita | 0:736c76a75def | 111 | |
hirokimineshita | 0:736c76a75def | 112 | |
hirokimineshita | 0:736c76a75def | 113 | /* Directory object structure */ |
hirokimineshita | 0:736c76a75def | 114 | typedef struct _DIR { |
hirokimineshita | 0:736c76a75def | 115 | WORD id; /* Owner file system mount ID */ |
hirokimineshita | 0:736c76a75def | 116 | WORD index; /* Current index */ |
hirokimineshita | 0:736c76a75def | 117 | FATFS* fs; /* Pointer to the owner file system object */ |
hirokimineshita | 0:736c76a75def | 118 | DWORD sclust; /* Start cluster */ |
hirokimineshita | 0:736c76a75def | 119 | DWORD clust; /* Current cluster */ |
hirokimineshita | 0:736c76a75def | 120 | DWORD sect; /* Current sector */ |
hirokimineshita | 0:736c76a75def | 121 | } FATFS_DIR; |
hirokimineshita | 0:736c76a75def | 122 | |
hirokimineshita | 0:736c76a75def | 123 | |
hirokimineshita | 0:736c76a75def | 124 | /* File object structure */ |
hirokimineshita | 0:736c76a75def | 125 | typedef struct _FIL { |
hirokimineshita | 0:736c76a75def | 126 | WORD id; /* Owner file system mount ID */ |
hirokimineshita | 0:736c76a75def | 127 | BYTE flag; /* File status flags */ |
hirokimineshita | 0:736c76a75def | 128 | BYTE csect; /* Sector address in the cluster */ |
hirokimineshita | 0:736c76a75def | 129 | FATFS* fs; /* Pointer to the owner file system object */ |
hirokimineshita | 0:736c76a75def | 130 | DWORD fptr; /* File R/W pointer */ |
hirokimineshita | 0:736c76a75def | 131 | DWORD fsize; /* File size */ |
hirokimineshita | 0:736c76a75def | 132 | DWORD org_clust; /* File start cluster */ |
hirokimineshita | 0:736c76a75def | 133 | DWORD curr_clust; /* Current cluster */ |
hirokimineshita | 0:736c76a75def | 134 | DWORD curr_sect; /* Current sector */ |
hirokimineshita | 0:736c76a75def | 135 | #if _FS_READONLY == 0 |
hirokimineshita | 0:736c76a75def | 136 | DWORD dir_sect; /* Sector containing the directory entry */ |
hirokimineshita | 0:736c76a75def | 137 | BYTE* dir_ptr; /* Ponter to the directory entry in the window */ |
hirokimineshita | 0:736c76a75def | 138 | #endif |
hirokimineshita | 0:736c76a75def | 139 | BYTE buffer[S_MAX_SIZ]; /* File R/W buffer */ |
hirokimineshita | 0:736c76a75def | 140 | } FIL; |
hirokimineshita | 0:736c76a75def | 141 | |
hirokimineshita | 0:736c76a75def | 142 | |
hirokimineshita | 0:736c76a75def | 143 | /* File status structure */ |
hirokimineshita | 0:736c76a75def | 144 | typedef struct _FILINFO { |
hirokimineshita | 0:736c76a75def | 145 | DWORD fsize; /* Size */ |
hirokimineshita | 0:736c76a75def | 146 | WORD fdate; /* Date */ |
hirokimineshita | 0:736c76a75def | 147 | WORD ftime; /* Time */ |
hirokimineshita | 0:736c76a75def | 148 | BYTE fattrib; /* Attribute */ |
hirokimineshita | 0:736c76a75def | 149 | char fname[8+1+3+1]; /* Name (8.3 format) */ |
hirokimineshita | 0:736c76a75def | 150 | } FILINFO; |
hirokimineshita | 0:736c76a75def | 151 | |
hirokimineshita | 0:736c76a75def | 152 | |
hirokimineshita | 0:736c76a75def | 153 | |
hirokimineshita | 0:736c76a75def | 154 | /* Definitions corresponds to multi partition */ |
hirokimineshita | 0:736c76a75def | 155 | |
hirokimineshita | 0:736c76a75def | 156 | #if _MULTI_PARTITION != 0 /* Multiple partition cfg */ |
hirokimineshita | 0:736c76a75def | 157 | |
hirokimineshita | 0:736c76a75def | 158 | typedef struct _PARTITION { |
hirokimineshita | 0:736c76a75def | 159 | BYTE pd; /* Physical drive # (0-255) */ |
hirokimineshita | 0:736c76a75def | 160 | BYTE pt; /* Partition # (0-3) */ |
hirokimineshita | 0:736c76a75def | 161 | } PARTITION; |
hirokimineshita | 0:736c76a75def | 162 | extern |
hirokimineshita | 0:736c76a75def | 163 | const PARTITION Drives[]; /* Logical drive# to physical location conversion table */ |
hirokimineshita | 0:736c76a75def | 164 | #define LD2PD(drv) (Drives[drv].pd) /* Get physical drive# */ |
hirokimineshita | 0:736c76a75def | 165 | #define LD2PT(drv) (Drives[drv].pt) /* Get partition# */ |
hirokimineshita | 0:736c76a75def | 166 | |
hirokimineshita | 0:736c76a75def | 167 | #else /* Single partition cfg */ |
hirokimineshita | 0:736c76a75def | 168 | |
hirokimineshita | 0:736c76a75def | 169 | #define LD2PD(drv) (drv) /* Physical drive# is equal to logical drive# */ |
hirokimineshita | 0:736c76a75def | 170 | #define LD2PT(drv) 0 /* Always mounts the 1st partition */ |
hirokimineshita | 0:736c76a75def | 171 | |
hirokimineshita | 0:736c76a75def | 172 | #endif |
hirokimineshita | 0:736c76a75def | 173 | |
hirokimineshita | 0:736c76a75def | 174 | |
hirokimineshita | 0:736c76a75def | 175 | /* File function return code (FRESULT) */ |
hirokimineshita | 0:736c76a75def | 176 | |
hirokimineshita | 0:736c76a75def | 177 | typedef enum { |
hirokimineshita | 0:736c76a75def | 178 | FR_OK = 0, /* 0 */ |
hirokimineshita | 0:736c76a75def | 179 | FR_NOT_READY, /* 1 */ |
hirokimineshita | 0:736c76a75def | 180 | FR_NO_FILE, /* 2 */ |
hirokimineshita | 0:736c76a75def | 181 | FR_NO_PATH, /* 3 */ |
hirokimineshita | 0:736c76a75def | 182 | FR_INVALID_NAME, /* 4 */ |
hirokimineshita | 0:736c76a75def | 183 | FR_INVALID_DRIVE, /* 5 */ |
hirokimineshita | 0:736c76a75def | 184 | FR_DENIED, /* 6 */ |
hirokimineshita | 0:736c76a75def | 185 | FR_EXIST, /* 7 */ |
hirokimineshita | 0:736c76a75def | 186 | FR_RW_ERROR, /* 8 */ |
hirokimineshita | 0:736c76a75def | 187 | FR_WRITE_PROTECTED, /* 9 */ |
hirokimineshita | 0:736c76a75def | 188 | FR_NOT_ENABLED, /* 10 */ |
hirokimineshita | 0:736c76a75def | 189 | FR_NO_FILESYSTEM, /* 11 */ |
hirokimineshita | 0:736c76a75def | 190 | FR_INVALID_OBJECT, /* 12 */ |
hirokimineshita | 0:736c76a75def | 191 | FR_MKFS_ABORTED /* 13 */ |
hirokimineshita | 0:736c76a75def | 192 | } FRESULT; |
hirokimineshita | 0:736c76a75def | 193 | |
hirokimineshita | 0:736c76a75def | 194 | |
hirokimineshita | 0:736c76a75def | 195 | |
hirokimineshita | 0:736c76a75def | 196 | /*-----------------------------------------------------*/ |
hirokimineshita | 0:736c76a75def | 197 | /* FatFs module application interface */ |
hirokimineshita | 0:736c76a75def | 198 | |
hirokimineshita | 0:736c76a75def | 199 | FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */ |
hirokimineshita | 0:736c76a75def | 200 | FRESULT f_open (FIL*, const char*, BYTE); /* Open or create a file */ |
hirokimineshita | 0:736c76a75def | 201 | FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */ |
hirokimineshita | 0:736c76a75def | 202 | FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */ |
hirokimineshita | 0:736c76a75def | 203 | FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */ |
hirokimineshita | 0:736c76a75def | 204 | FRESULT f_close (FIL*); /* Close an open file object */ |
hirokimineshita | 0:736c76a75def | 205 | FRESULT f_opendir (FATFS_DIR*, const char*); /* Open an existing directory */ |
hirokimineshita | 0:736c76a75def | 206 | FRESULT f_readdir (FATFS_DIR*, FILINFO*); /* Read a directory item */ |
hirokimineshita | 0:736c76a75def | 207 | FRESULT f_stat (const char*, FILINFO*); /* Get file status */ |
hirokimineshita | 0:736c76a75def | 208 | FRESULT f_getfree (const char*, DWORD*, FATFS**); /* Get number of free clusters on the drive */ |
hirokimineshita | 0:736c76a75def | 209 | FRESULT f_truncate (FIL*); /* Truncate file */ |
hirokimineshita | 0:736c76a75def | 210 | FRESULT f_sync (FIL*); /* Flush cached data of a writing file */ |
hirokimineshita | 0:736c76a75def | 211 | FRESULT f_unlink (const char*); /* Delete an existing file or directory */ |
hirokimineshita | 0:736c76a75def | 212 | FRESULT f_mkdir (const char*); /* Create a new directory */ |
hirokimineshita | 0:736c76a75def | 213 | FRESULT f_chmod (const char*, BYTE, BYTE); /* Change file/dir attriburte */ |
hirokimineshita | 0:736c76a75def | 214 | FRESULT f_utime (const char*, const FILINFO*); /* Change file/dir timestamp */ |
hirokimineshita | 0:736c76a75def | 215 | FRESULT f_rename (const char*, const char*); /* Rename/Move a file or directory */ |
hirokimineshita | 0:736c76a75def | 216 | FRESULT f_mkfs (BYTE, BYTE, WORD); /* Create a file system on the drive */ |
hirokimineshita | 0:736c76a75def | 217 | #if _USE_STRFUNC |
hirokimineshita | 0:736c76a75def | 218 | #define feof(fp) ((fp)->fptr == (fp)->fsize) |
hirokimineshita | 0:736c76a75def | 219 | #define EOF -1 |
hirokimineshita | 0:736c76a75def | 220 | int fputc (int, FIL*); /* Put a character to the file */ |
hirokimineshita | 0:736c76a75def | 221 | int fputs (const char*, FIL*); /* Put a string to the file */ |
hirokimineshita | 0:736c76a75def | 222 | int fprintf (FIL*, const char*, ...); /* Put a formatted string to the file */ |
hirokimineshita | 0:736c76a75def | 223 | char* fgets (char*, int, FIL*); /* Get a string from the file */ |
hirokimineshita | 0:736c76a75def | 224 | #endif |
hirokimineshita | 0:736c76a75def | 225 | |
hirokimineshita | 0:736c76a75def | 226 | /* User defined function to give a current time to fatfs module */ |
hirokimineshita | 0:736c76a75def | 227 | |
hirokimineshita | 0:736c76a75def | 228 | DWORD get_fattime (void); /* 31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */ |
hirokimineshita | 0:736c76a75def | 229 | /* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */ |
hirokimineshita | 0:736c76a75def | 230 | |
hirokimineshita | 0:736c76a75def | 231 | |
hirokimineshita | 0:736c76a75def | 232 | |
hirokimineshita | 0:736c76a75def | 233 | /* File access control and file status flags (FIL.flag) */ |
hirokimineshita | 0:736c76a75def | 234 | |
hirokimineshita | 0:736c76a75def | 235 | #define FA_READ 0x01 |
hirokimineshita | 0:736c76a75def | 236 | #define FA_OPEN_EXISTING 0x00 |
hirokimineshita | 0:736c76a75def | 237 | #if _FS_READONLY == 0 |
hirokimineshita | 0:736c76a75def | 238 | #define FA_WRITE 0x02 |
hirokimineshita | 0:736c76a75def | 239 | #define FA_CREATE_NEW 0x04 |
hirokimineshita | 0:736c76a75def | 240 | #define FA_CREATE_ALWAYS 0x08 |
hirokimineshita | 0:736c76a75def | 241 | #define FA_OPEN_ALWAYS 0x10 |
hirokimineshita | 0:736c76a75def | 242 | #define FA__WRITTEN 0x20 |
hirokimineshita | 0:736c76a75def | 243 | #define FA__DIRTY 0x40 |
hirokimineshita | 0:736c76a75def | 244 | #endif |
hirokimineshita | 0:736c76a75def | 245 | #define FA__ERROR 0x80 |
hirokimineshita | 0:736c76a75def | 246 | |
hirokimineshita | 0:736c76a75def | 247 | |
hirokimineshita | 0:736c76a75def | 248 | /* FAT sub type (FATFS.fs_type) */ |
hirokimineshita | 0:736c76a75def | 249 | |
hirokimineshita | 0:736c76a75def | 250 | #define FS_FAT12 1 |
hirokimineshita | 0:736c76a75def | 251 | #define FS_FAT16 2 |
hirokimineshita | 0:736c76a75def | 252 | #define FS_FAT32 3 |
hirokimineshita | 0:736c76a75def | 253 | |
hirokimineshita | 0:736c76a75def | 254 | |
hirokimineshita | 0:736c76a75def | 255 | /* File attribute bits for directory entry */ |
hirokimineshita | 0:736c76a75def | 256 | |
hirokimineshita | 0:736c76a75def | 257 | #define AM_RDO 0x01 /* Read only */ |
hirokimineshita | 0:736c76a75def | 258 | #define AM_HID 0x02 /* Hidden */ |
hirokimineshita | 0:736c76a75def | 259 | #define AM_SYS 0x04 /* System */ |
hirokimineshita | 0:736c76a75def | 260 | #define AM_VOL 0x08 /* Volume label */ |
hirokimineshita | 0:736c76a75def | 261 | #define AM_LFN 0x0F /* LFN entry */ |
hirokimineshita | 0:736c76a75def | 262 | #define AM_DIR 0x10 /* Directory */ |
hirokimineshita | 0:736c76a75def | 263 | #define AM_ARC 0x20 /* Archive */ |
hirokimineshita | 0:736c76a75def | 264 | |
hirokimineshita | 0:736c76a75def | 265 | |
hirokimineshita | 0:736c76a75def | 266 | |
hirokimineshita | 0:736c76a75def | 267 | /* Offset of FAT structure members */ |
hirokimineshita | 0:736c76a75def | 268 | |
hirokimineshita | 0:736c76a75def | 269 | #define BS_jmpBoot 0 |
hirokimineshita | 0:736c76a75def | 270 | #define BS_OEMName 3 |
hirokimineshita | 0:736c76a75def | 271 | #define BPB_BytsPerSec 11 |
hirokimineshita | 0:736c76a75def | 272 | #define BPB_SecPerClus 13 |
hirokimineshita | 0:736c76a75def | 273 | #define BPB_RsvdSecCnt 14 |
hirokimineshita | 0:736c76a75def | 274 | #define BPB_NumFATs 16 |
hirokimineshita | 0:736c76a75def | 275 | #define BPB_RootEntCnt 17 |
hirokimineshita | 0:736c76a75def | 276 | #define BPB_TotSec16 19 |
hirokimineshita | 0:736c76a75def | 277 | #define BPB_Media 21 |
hirokimineshita | 0:736c76a75def | 278 | #define BPB_FATSz16 22 |
hirokimineshita | 0:736c76a75def | 279 | #define BPB_SecPerTrk 24 |
hirokimineshita | 0:736c76a75def | 280 | #define BPB_NumHeads 26 |
hirokimineshita | 0:736c76a75def | 281 | #define BPB_HiddSec 28 |
hirokimineshita | 0:736c76a75def | 282 | #define BPB_TotSec32 32 |
hirokimineshita | 0:736c76a75def | 283 | #define BS_55AA 510 |
hirokimineshita | 0:736c76a75def | 284 | |
hirokimineshita | 0:736c76a75def | 285 | #define BS_DrvNum 36 |
hirokimineshita | 0:736c76a75def | 286 | #define BS_BootSig 38 |
hirokimineshita | 0:736c76a75def | 287 | #define BS_VolID 39 |
hirokimineshita | 0:736c76a75def | 288 | #define BS_VolLab 43 |
hirokimineshita | 0:736c76a75def | 289 | #define BS_FilSysType 54 |
hirokimineshita | 0:736c76a75def | 290 | |
hirokimineshita | 0:736c76a75def | 291 | #define BPB_FATSz32 36 |
hirokimineshita | 0:736c76a75def | 292 | #define BPB_ExtFlags 40 |
hirokimineshita | 0:736c76a75def | 293 | #define BPB_FSVer 42 |
hirokimineshita | 0:736c76a75def | 294 | #define BPB_RootClus 44 |
hirokimineshita | 0:736c76a75def | 295 | #define BPB_FSInfo 48 |
hirokimineshita | 0:736c76a75def | 296 | #define BPB_BkBootSec 50 |
hirokimineshita | 0:736c76a75def | 297 | #define BS_DrvNum32 64 |
hirokimineshita | 0:736c76a75def | 298 | #define BS_BootSig32 66 |
hirokimineshita | 0:736c76a75def | 299 | #define BS_VolID32 67 |
hirokimineshita | 0:736c76a75def | 300 | #define BS_VolLab32 71 |
hirokimineshita | 0:736c76a75def | 301 | #define BS_FilSysType32 82 |
hirokimineshita | 0:736c76a75def | 302 | |
hirokimineshita | 0:736c76a75def | 303 | #define FSI_LeadSig 0 |
hirokimineshita | 0:736c76a75def | 304 | #define FSI_StrucSig 484 |
hirokimineshita | 0:736c76a75def | 305 | #define FSI_Free_Count 488 |
hirokimineshita | 0:736c76a75def | 306 | #define FSI_Nxt_Free 492 |
hirokimineshita | 0:736c76a75def | 307 | |
hirokimineshita | 0:736c76a75def | 308 | #define MBR_Table 446 |
hirokimineshita | 0:736c76a75def | 309 | |
hirokimineshita | 0:736c76a75def | 310 | #define DIR_Name 0 |
hirokimineshita | 0:736c76a75def | 311 | #define DIR_Attr 11 |
hirokimineshita | 0:736c76a75def | 312 | #define DIR_NTres 12 |
hirokimineshita | 0:736c76a75def | 313 | #define DIR_CrtTime 14 |
hirokimineshita | 0:736c76a75def | 314 | #define DIR_CrtDate 16 |
hirokimineshita | 0:736c76a75def | 315 | #define DIR_FstClusHI 20 |
hirokimineshita | 0:736c76a75def | 316 | #define DIR_WrtTime 22 |
hirokimineshita | 0:736c76a75def | 317 | #define DIR_WrtDate 24 |
hirokimineshita | 0:736c76a75def | 318 | #define DIR_FstClusLO 26 |
hirokimineshita | 0:736c76a75def | 319 | #define DIR_FileSize 28 |
hirokimineshita | 0:736c76a75def | 320 | |
hirokimineshita | 0:736c76a75def | 321 | |
hirokimineshita | 0:736c76a75def | 322 | |
hirokimineshita | 0:736c76a75def | 323 | /* Multi-byte word access macros */ |
hirokimineshita | 0:736c76a75def | 324 | |
hirokimineshita | 0:736c76a75def | 325 | #if _MCU_ENDIAN == 1 /* Use word access */ |
hirokimineshita | 0:736c76a75def | 326 | #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr)) |
hirokimineshita | 0:736c76a75def | 327 | #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr)) |
hirokimineshita | 0:736c76a75def | 328 | #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val) |
hirokimineshita | 0:736c76a75def | 329 | #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val) |
hirokimineshita | 0:736c76a75def | 330 | #elif _MCU_ENDIAN == 2 /* Use byte-by-byte access */ |
hirokimineshita | 0:736c76a75def | 331 | #define LD_WORD(ptr) (WORD)(((WORD)*(volatile BYTE*)((ptr)+1)<<8)|(WORD)*(volatile BYTE*)(ptr)) |
hirokimineshita | 0:736c76a75def | 332 | #define LD_DWORD(ptr) (DWORD)(((DWORD)*(volatile BYTE*)((ptr)+3)<<24)|((DWORD)*(volatile BYTE*)((ptr)+2)<<16)|((WORD)*(volatile BYTE*)((ptr)+1)<<8)|*(volatile BYTE*)(ptr)) |
hirokimineshita | 0:736c76a75def | 333 | #define ST_WORD(ptr,val) *(volatile BYTE*)(ptr)=(BYTE)(val); *(volatile BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8) |
hirokimineshita | 0:736c76a75def | 334 | #define ST_DWORD(ptr,val) *(volatile BYTE*)(ptr)=(BYTE)(val); *(volatile BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8); *(volatile BYTE*)((ptr)+2)=(BYTE)((DWORD)(val)>>16); *(volatile BYTE*)((ptr)+3)=(BYTE)((DWORD)(val)>>24) |
hirokimineshita | 0:736c76a75def | 335 | #else |
hirokimineshita | 0:736c76a75def | 336 | #error Do not forget to set _MCU_ENDIAN properly! |
hirokimineshita | 0:736c76a75def | 337 | #endif |
hirokimineshita | 0:736c76a75def | 338 | |
hirokimineshita | 0:736c76a75def | 339 | #ifdef __cplusplus |
hirokimineshita | 0:736c76a75def | 340 | }; |
hirokimineshita | 0:736c76a75def | 341 | #endif |
hirokimineshita | 0:736c76a75def | 342 | |
hirokimineshita | 0:736c76a75def | 343 | #define _FATFS |
hirokimineshita | 0:736c76a75def | 344 | #endif /* _FATFS */ |