1 /*---------------------------------------------------------------------------/
\r
2 / Petit FatFs - FAT file system module include file R0.02a (C)ChaN, 2010
\r
3 /----------------------------------------------------------------------------/
\r
4 / Petit FatFs module is an open source software to implement FAT file system to
\r
5 / small embedded systems. This is a free software and is opened for education,
\r
6 / research and commercial developments under license policy of following trems.
\r
8 / Copyright (C) 2010, ChaN, all right reserved.
\r
10 / * The Petit FatFs module is a free software and there is NO WARRANTY.
\r
11 / * No restriction on use. You can use, modify and redistribute it for
\r
12 / personal, non-profit or commercial use UNDER YOUR RESPONSIBILITY.
\r
13 / * Redistributions of source code must retain the above copyright notice.
\r
15 /----------------------------------------------------------------------------*/
\r
17 #include "integer.h"
\r
19 /*---------------------------------------------------------------------------/
\r
20 / Petit FatFs Configuration Options
\r
22 / CAUTION! Do not forget to make clean the project after any changes to
\r
23 / the configuration options.
\r
25 /----------------------------------------------------------------------------*/
\r
29 #define _USE_READ 1 /* 1:Enable pf_read() */
\r
31 #define _USE_DIR 1 /* 1:Enable pf_opendir() and pf_readdir() */
\r
33 #define _USE_LSEEK 1 /* 1:Enable pf_lseek() */
\r
35 #define _USE_WRITE 1 /* 1:Enable pf_write() */
\r
37 #define _FS_FAT12 1 /* 1:Enable FAT12 support */
\r
38 #define _FS_FAT32 1 /* 1:Enable FAT32 support */
\r
41 #define _CODE_PAGE 1
\r
42 /* Defines which code page is used for path name. Supported code pages are:
\r
43 / 932, 936, 949, 950, 437, 720, 737, 775, 850, 852, 855, 857, 858, 862, 866,
\r
44 / 874, 1250, 1251, 1252, 1253, 1254, 1255, 1257, 1258 and 1 (ASCII only).
\r
45 / SBCS code pages except for 1 requiers a case conversion table. This
\r
46 / might occupy 128 bytes on the RAM on some platforms, e.g. avr-gcc. */
\r
49 #define _WORD_ACCESS 0
\r
50 /* The _WORD_ACCESS option defines which access method is used to the word
\r
51 / data in the FAT structure.
\r
53 / 0: Byte-by-byte access. Always compatible with all platforms.
\r
54 / 1: Word access. Do not choose this unless following condition is met.
\r
56 / When the byte order on the memory is big-endian or address miss-aligned
\r
57 / word access results incorrect behavior, the _WORD_ACCESS must be set to 0.
\r
58 / If it is not the case, the value can also be set to 1 to improve the
\r
59 / performance and code efficiency. */
\r
62 /* End of configuration options. Do not change followings without care. */
\r
63 /*--------------------------------------------------------------------------*/
\r
74 /* File system object structure */
\r
77 BYTE fs_type; /* FAT sub type */
\r
78 BYTE flag; /* File status flags */
\r
79 BYTE csize; /* Number of sectors per cluster */
\r
81 WORD n_rootdir; /* Number of root directory entries (0 on FAT32) */
\r
82 CLUST n_fatent; /* Number of FAT entries (= number of clusters + 2) */
\r
83 DWORD fatbase; /* FAT start sector */
\r
84 DWORD dirbase; /* Root directory start sector (Cluster# on FAT32) */
\r
85 DWORD database; /* Data start sector */
\r
86 DWORD fptr; /* File R/W pointer */
\r
87 DWORD fsize; /* File size */
\r
88 CLUST org_clust; /* File start cluster */
\r
89 CLUST curr_clust; /* File current cluster */
\r
90 DWORD dsect; /* File current data sector */
\r
95 /* Directory object structure */
\r
98 WORD index; /* Current read/write index number */
\r
99 BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
\r
100 CLUST sclust; /* Table start cluster (0:Static table) */
\r
101 CLUST clust; /* Current cluster */
\r
102 DWORD sect; /* Current sector */
\r
107 /* File status structure */
\r
110 DWORD fsize; /* File size */
\r
111 WORD fdate; /* Last modified date */
\r
112 WORD ftime; /* Last modified time */
\r
113 BYTE fattrib; /* Attribute */
\r
114 char fname[13]; /* File name */
\r
119 /* File function return code (FRESULT) */
\r
123 FR_DISK_ERR, /* 1 */
\r
124 FR_NOT_READY, /* 2 */
\r
125 FR_NO_FILE, /* 3 */
\r
126 FR_NO_PATH, /* 4 */
\r
127 FR_NOT_OPENED, /* 5 */
\r
128 FR_NOT_ENABLED, /* 6 */
\r
129 FR_NO_FILESYSTEM /* 7 */
\r
134 /*--------------------------------------------------------------*/
\r
135 /* Petit FatFs module application interface */
\r
137 FRESULT pf_mount (FATFS*); /* Mount/Unmount a logical drive */
\r
138 FRESULT pf_open (const char*); /* Open a file */
\r
139 FRESULT pf_read (void*, WORD, WORD*); /* Read data from the open file */
\r
140 FRESULT pf_write (const void*, WORD, WORD*); /* Write data to the open file */
\r
141 FRESULT pf_lseek (DWORD); /* Move file pointer of the open file */
\r
142 FRESULT pf_opendir (DIR*, const char*); /* Open a directory */
\r
143 FRESULT pf_readdir (DIR*, FILINFO*); /* Read a directory item from the open directory */
\r
147 /*--------------------------------------------------------------*/
\r
148 /* Flags and offset address */
\r
150 /* File status flag (FATFS.flag) */
\r
152 #define FA_OPENED 0x01
\r
153 #define FA_WPRT 0x02
\r
154 #define FA__WIP 0x40
\r
157 /* FAT sub type (FATFS.fs_type) */
\r
164 /* File attribute bits for directory entry */
\r
166 #define AM_RDO 0x01 /* Read only */
\r
167 #define AM_HID 0x02 /* Hidden */
\r
168 #define AM_SYS 0x04 /* System */
\r
169 #define AM_VOL 0x08 /* Volume label */
\r
170 #define AM_LFN 0x0F /* LFN entry */
\r
171 #define AM_DIR 0x10 /* Directory */
\r
172 #define AM_ARC 0x20 /* Archive */
\r
173 #define AM_MASK 0x3F /* Mask of defined bits */
\r
176 /*--------------------------------*/
\r
177 /* Multi-byte word access macros */
\r
179 #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
\r
180 #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
\r
181 #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
\r
182 #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
\r
183 #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
\r
184 #else /* Use byte-by-byte access to the FAT structure */
\r
185 #define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
\r
186 #define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
\r
187 #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
\r
188 #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)
\r
192 #endif /* _FATFS */
\r