Add missing clean_doxygen phony targets to the project makefiles.
[pub/USBasp.git] / Projects / Incomplete / StandaloneProgrammer / Lib / PetiteFATFs / pff.h
1 /*---------------------------------------------------------------------------/
2 / Petit FatFs - FAT file system module include file R0.01a (C)ChaN, 2010
3 /----------------------------------------------------------------------------/
4 / Petit FatFs module is an open source software to implement FAT file system to
5 / small embedded systems. This is a free software and is opened for education,
6 / research and commercial developments under license policy of following trems.
7 /
8 / Copyright (C) 2010, ChaN, all right reserved.
9 /
10 / * The Petit FatFs module is a free software and there is NO WARRANTY.
11 / * No restriction on use. You can use, modify and redistribute it for
12 / personal, non-profit or commercial use UNDER YOUR RESPONSIBILITY.
13 / * Redistributions of source code must retain the above copyright notice.
14 /----------------------------------------------------------------------------*/
15
16 #include "integer.h"
17
18 /*---------------------------------------------------------------------------/
19 / Petit FatFs Configuration Options
20 /
21 / CAUTION! Do not forget to make clean the project after any changes to
22 / the configuration options.
23 /
24 /----------------------------------------------------------------------------*/
25 #ifndef _FATFS
26 #define _FATFS
27
28 #define _WORD_ACCESS 0
29 /* The _WORD_ACCESS option defines which access method is used to the word
30 / data in the FAT structure.
31 /
32 / 0: Byte-by-byte access. Always compatible with all platforms.
33 / 1: Word access. Do not choose this unless following condition is met.
34 /
35 / When the byte order on the memory is big-endian or address miss-aligned
36 / word access results incorrect behavior, the _WORD_ACCESS must be set to 0.
37 / If it is not the case, the value can also be set to 1 to improve the
38 / performance and code efficiency. */
39
40
41 #define _USE_DIR 0
42 /* To enable pf_opendir and pf_readdir function, set _USE_DIR to 1. */
43
44
45 #define _USE_LSEEK 0
46 /* To enable pf_lseek function, set _USE_LSEEK to 1. */
47
48
49 #define _FS_FAT32 1
50 /* To enable FAT32 support, set _FS_FAT32 to 1. */
51
52
53 /* End of configuration options. Do not change followings without care. */
54 /*--------------------------------------------------------------------------*/
55
56
57 #if _FS_FAT32
58 #define CLUST DWORD
59 #else
60 #define CLUST WORD
61 #endif
62
63
64 /* File system object structure */
65
66 typedef struct _FATFS_ {
67 BYTE fs_type; /* FAT sub type */
68 BYTE csize; /* Number of sectors per cluster */
69 BYTE flag; /* File status flags */
70 BYTE csect; /* File sector address in the cluster */
71 WORD n_rootdir; /* Number of root directory entries (0 on FAT32) */
72 BYTE* buf; /* Pointer to the disk access buffer */
73 CLUST max_clust; /* Maximum cluster# + 1. Number of clusters is max_clust - 2 */
74 DWORD fatbase; /* FAT start sector */
75 DWORD dirbase; /* Root directory start sector (Cluster# on FAT32) */
76 DWORD database; /* Data start sector */
77 DWORD fptr; /* File R/W pointer */
78 DWORD fsize; /* File size */
79 CLUST org_clust; /* File start cluster */
80 CLUST curr_clust; /* File current cluster */
81 DWORD dsect; /* File current data sector */
82 } FATFS;
83
84
85
86 /* Directory object structure */
87
88 typedef struct _DIR_ {
89 WORD index; /* Current read/write index number */
90 BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
91 CLUST sclust; /* Table start cluster (0:Static table) */
92 CLUST clust; /* Current cluster */
93 DWORD sect; /* Current sector */
94 } DIR;
95
96
97
98 /* File status structure */
99
100 typedef struct _FILINFO_ {
101 DWORD fsize; /* File size */
102 WORD fdate; /* Last modified date */
103 WORD ftime; /* Last modified time */
104 BYTE fattrib; /* Attribute */
105 char fname[13]; /* File name */
106 } FILINFO;
107
108
109
110 /* File function return code (FRESULT) */
111
112 typedef enum {
113 FR_OK = 0, /* 0 */
114 FR_DISK_ERR, /* 1 */
115 FR_NOT_READY, /* 2 */
116 FR_NO_FILE, /* 3 */
117 FR_NO_PATH, /* 4 */
118 FR_INVALID_NAME, /* 5 */
119 FR_STREAM_ERR, /* 6 */
120 FR_INVALID_OBJECT, /* 7 */
121 FR_NOT_ENABLED, /* 8 */
122 FR_NO_FILESYSTEM /* 9 */
123 } FRESULT;
124
125
126
127 /*--------------------------------------------------------------*/
128 /* Petit FatFs module application interface */
129
130 FRESULT pf_mount (FATFS*); /* Mount/Unmount a logical drive */
131 FRESULT pf_open (const char*); /* Open a file */
132 FRESULT pf_read (void*, WORD, WORD*); /* Read data from a file */
133 FRESULT pf_lseek (DWORD); /* Move file pointer of a file object */
134 FRESULT pf_opendir (DIR*, const char*); /* Open an existing directory */
135 FRESULT pf_readdir (DIR*, FILINFO*); /* Read a directory item */
136
137
138
139 /*--------------------------------------------------------------*/
140 /* Flags and offset address */
141
142 /* File status flag (FATFS.flag) */
143
144 #define FA_READ 0x01
145 #define FA_STREAM 0x40
146 #define FA__ERROR 0x80
147
148
149 /* FAT sub type (FATFS.fs_type) */
150
151 #define FS_FAT12 1
152 #define FS_FAT16 2
153 #define FS_FAT32 3
154
155
156 /* File attribute bits for directory entry */
157
158 #define AM_RDO 0x01 /* Read only */
159 #define AM_HID 0x02 /* Hidden */
160 #define AM_SYS 0x04 /* System */
161 #define AM_VOL 0x08 /* Volume label */
162 #define AM_LFN 0x0F /* LFN entry */
163 #define AM_DIR 0x10 /* Directory */
164 #define AM_ARC 0x20 /* Archive */
165 #define AM_MASK 0x3F /* Mask of defined bits */
166
167
168 /* FatFs refers the members in the FAT structures with byte offset instead
169 / of structure member because there are incompatibility of the packing option
170 / between various compilers. */
171
172 #define BS_jmpBoot 0
173 #define BS_OEMName 3
174 #define BPB_BytsPerSec 11
175 #define BPB_SecPerClus 13
176 #define BPB_RsvdSecCnt 14
177 #define BPB_NumFATs 16
178 #define BPB_RootEntCnt 17
179 #define BPB_TotSec16 19
180 #define BPB_Media 21
181 #define BPB_FATSz16 22
182 #define BPB_SecPerTrk 24
183 #define BPB_NumHeads 26
184 #define BPB_HiddSec 28
185 #define BPB_TotSec32 32
186 #define BS_55AA 510
187
188 #define BS_DrvNum 36
189 #define BS_BootSig 38
190 #define BS_VolID 39
191 #define BS_VolLab 43
192 #define BS_FilSysType 54
193
194 #define BPB_FATSz32 36
195 #define BPB_ExtFlags 40
196 #define BPB_FSVer 42
197 #define BPB_RootClus 44
198 #define BPB_FSInfo 48
199 #define BPB_BkBootSec 50
200 #define BS_DrvNum32 64
201 #define BS_BootSig32 66
202 #define BS_VolID32 67
203 #define BS_VolLab32 71
204 #define BS_FilSysType32 82
205
206 #define MBR_Table 446
207
208 #define DIR_Name 0
209 #define DIR_Attr 11
210 #define DIR_NTres 12
211 #define DIR_CrtTime 14
212 #define DIR_CrtDate 16
213 #define DIR_FstClusHI 20
214 #define DIR_WrtTime 22
215 #define DIR_WrtDate 24
216 #define DIR_FstClusLO 26
217 #define DIR_FileSize 28
218
219
220
221 /*--------------------------------*/
222 /* Multi-byte word access macros */
223
224 #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
225 #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
226 #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
227 #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
228 #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
229 #else /* Use byte-by-byte access to the FAT structure */
230 #define LD_WORD(ptr) (WORD)(((WORD)*(BYTE*)((ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
231 #define LD_DWORD(ptr) (DWORD)(((DWORD)*(BYTE*)((ptr)+3)<<24)|((DWORD)*(BYTE*)((ptr)+2)<<16)|((WORD)*(BYTE*)((ptr)+1)<<8)|*(BYTE*)(ptr))
232 #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8)
233 #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)
234 #endif
235
236
237 #endif /* _FATFS */