Rev 1 | Rev 41 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 24 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #ifndef __fat16_h |
1 | #ifndef __fat16_h |
2 | #define __fat16_h |
2 | #define __fat16_h |
Line -... | Line 3... | ||
- | 3 | ||
3 | 4 | ||
4 | 5 | ||
5 | //________________________________________________________________________________________________________________________________________ |
6 | //________________________________________________________________________________________________________________________________________ |
6 | // |
7 | // |
7 | // Definitions |
8 | // Userspecific definitions |
Line 8... | Line -... | ||
8 | // |
- | |
9 | //________________________________________________________________________________________________________________________________________ |
9 | // |
- | 10 | //________________________________________________________________________________________________________________________________________ |
|
Line -... | Line 11... | ||
- | 11 | ||
- | 12 | #define __MAX_FILES_USED 1 // The number of files that can be opened simultaneously. |
|
10 | 13 | ||
- | 14 | ||
- | 15 | //________________________________________________________________________________________________________________________________________ |
|
- | 16 | // |
|
11 | //#define __USE_TIME_DATE_ATTRIBUTE |
17 | // Structure of a filepointer |
12 | #define __MAX_FILES_USED 2 // The number of files that can accessed simultaneously. |
18 | // |
13 | 19 | //________________________________________________________________________________________________________________________________________ |
|
14 | #define MBR_SECTOR 0 // the masterboot record is located in sector 0. |
20 | |
15 | #define _UNUSED 1 // Bits used in the attribute of an directory entry. |
21 | #define _UNUSED 1 // Bits used in the attribute of an directory entry. |
16 | #define _USED 2 |
22 | #define _USED 2 |
17 | #define _ARCHIVE 2 |
23 | #define _ARCHIVE 2 |
Line -... | Line 24... | ||
- | 24 | #define _READ_ONLY 4 |
|
- | 25 | #define _SYSTEM 8 |
|
- | 26 | #define _DIRECTORY 16 |
|
- | 27 | #define _FILE 32 |
|
- | 28 | ||
- | 29 | ||
- | 30 | typedef struct afile |
|
- | 31 | { |
|
- | 32 | u32 start_cluster; // Sectorpointer to the first sector of the first datacluster of the file. |
|
- | 33 | u32 cluster_pointer; // Pointer to the cluster which is edited at the moment. |
|
- | 34 | u8 sector_index; // The sector which is edited at the moment (cluster_pointer + sector_index). |
|
- | 35 | u16 byte_index; // The bytelocation within the current sector (cluster_pointer + sector_index + byte_index). |
|
- | 36 | u8 mode; // mode of fileoperation (read,write) |
|
- | 37 | u32 filesize; // the size of the opend file in bytes. |
|
- | 38 | u32 fileposition; // pointer to a character within the file 0 < fileposition < filesize |
|
- | 39 | u32 sector_in_buffer; // the last sector read, wich is still in the sectorbuffer. |
|
- | 40 | u32 directory_root_sector; // pointer to the root of the |
|
- | 41 | u32 directory_sector; // the sectorposition where the directoryentry has been made. |
|
- | 42 | u8 directory_index; // the index to the directoryentry within the specified sector. |
|
- | 43 | u8 attribute; // the attribute of the file opened. |
|
- | 44 | u8 buffer[512]; // Buffer for read and write operation from or to the mmc. |
|
- | 45 | u8 state; // state of the filepointer (used/unused/...) |
|
- | 46 | } File; |
|
- | 47 | ||
Line 18... | Line 48... | ||
18 | #define _READ_ONLY 4 |
48 | |
19 | #define _SYSTEM 8 |
49 | typedef enum |
20 | #define _DIRECTORY 16 |
50 | { |
21 | #define _FILE 32 |
51 | NOT_INITIALIZED, |
22 | 52 | INITIALIZED |
|
Line 23... | Line 53... | ||
23 | 53 | }Fat16_VolumeState_t; |
|
24 | 54 | ||
25 | //________________________________________________________________________________________________________________________________________ |
- | |
26 | // |
- | |
27 | // Structure of a filepointer |
- | |
28 | // |
- | |
29 | //________________________________________________________________________________________________________________________________________ |
- | |
30 | - | ||
31 | typedef struct afile |
- | |
32 | { |
- | |
33 | u32 start_cluster; // Sectorpointer to the first sector of the first datacluster of the file. |
- | |
34 | u32 cluster_pointer; // Pointer to the cluster which is edited at the moment. |
- | |
35 | u8 sector_index; // The sector which is edited at the moment (cluster_pointer + sector_index). |
55 | //________________________________________________________________________________________________________________________________________ |
36 | u16 byte_index; // The bytelocation within the current sector (cluster_pointer + sector_index + byte_index). |
- | |
37 | u8 mode; // mode of fileoperation (read,write) |
- | |
38 | u32 filesize; // the size of the opend file in bytes. |
56 | // |
Line 39... | Line 57... | ||
39 | u32 fileposition; // pointer to a character within the file 0 < fileposition < filesize |
57 | // Structure of an item to find within the cwd |
40 | u32 sector_in_buffer; // the last sector read, wich is still in the sectorbuffer. |
58 | // |
41 | u32 directory_sector; // the sectorposition where the directoryentry has been made. |
59 | //________________________________________________________________________________________________________________________________________ |
42 | u8 directory_index; // the index to the directoryentry within the specified sector. |
60 | |
43 | u8 attribute; // the attribute of the file opened. |
61 | struct volume |
Line -... | Line 62... | ||
- | 62 | { |
|
- | 63 | Fat16_VolumeState_t state; // state of the volume |
|
- | 64 | } str_Volume; |
|
- | 65 | ||
- | 66 | //________________________________________________________________________________________________________________________________________ |
|
- | 67 | // |
|
- | 68 | // Structure of an item to find within the cwd |
|
- | 69 | // |
|
- | 70 | //________________________________________________________________________________________________________________________________________ |
|
- | 71 | ||
- | 72 | typedef struct find |
|
- | 73 | { |
|
- | 74 | s8 name[12]; // filename + extension or directoryname of the item found within the cwd. |
|
- | 75 | s8 searchstring[13]; |
|
- | 76 | u32 cluster_pointer; // Sectorpointer to the sector of the item searched within the cwd. |
|
- | 77 | u16 startcluster; // pointer to the first datacluster of the item found in the cwd. |
|
- | 78 | u32 filesize; // the size of the opend file in bytes. |
|
- | 79 | u32 directory_sector; // the sector within the actual cluster where the directoryentry was found. |
|
- | 80 | u8 directory_index; // the index to the directoryentry within the specified sector. |
|
- | 81 | u8 attribute; // the attribute of the file opened. |
|
44 | u8 buffer[512]; // Buffer for read and write operation from or to the mmc. |
82 | } Find; |
45 | u8 state; // state of the filepointer (used/unused/...) |
83 | |
46 | } File; |
84 | //________________________________________________________________________________________________________________________________________ |
47 | 85 | // |
|
48 | //________________________________________________________________________________________________________________________________________ |
86 | // Directoryentries |
49 | // |
87 | // |
50 | // Structure of an directoryentry |
88 | //________________________________________________________________________________________________________________________________________ |
51 | // |
89 | |
52 | //________________________________________________________________________________________________________________________________________ |
90 | |
53 | 91 | ||
54 | struct DirEntry |
92 | struct DirEntry |
Line 55... | Line 93... | ||
55 | { |
93 | { |
56 | u8 name[8]; // 8 bytes name. |
94 | u8 name[8]; // 8 bytes name. |
57 | u8 extension[3]; // 3 bytes extension. |
95 | u8 extension[3]; // 3 bytes extension. |
58 | u8 attribute; // attribute of the directory entry (unused,archive,read-only,system,directory,volume) |
96 | u8 attribute; // attribute of the directory entry (unused,archive,read-only,system,directory,volume) |
59 | u8 reserved[10]; // reserved bytes within the directory entry. |
97 | u8 reserved[10]; // reserved bytes within the directory entry. |
Line 60... | Line 98... | ||
60 | u16 time; // time and |
98 | u16 time; // time and |
61 | u16 date; // date of last write acces to the file or directory. |
99 | u16 date; // date of last write acces to the file or directory. |
62 | u16 startcluster; // first cluster of the file or directory. |
100 | u16 startcluster; // first cluster of the file or directory. |
63 | u32 size; // size of the file or directory in bytes. |
101 | u32 size; // size of the file or directory in bytes. |
Line 64... | Line 102... | ||
64 | }; |
102 | } __attribute__((packed)); |
65 | 103 | ||
66 | //________________________________________________________________________________________________________________________________________ |
104 | //________________________________________________________________________________________________________________________________________ |
67 | // |
105 | // |
68 | // Structure of an entry within the fileallocationtable. |
106 | // Structure of an entry within the fileallocationtable. |
Line -... | Line 107... | ||
- | 107 | // |
|
- | 108 | //________________________________________________________________________________________________________________________________________ |
|
- | 109 | ||
- | 110 | struct FatEntry |
|
- | 111 | { |
|
- | 112 | u16 next_cluster; // the next cluster of the file. |
|
- | 113 | } __attribute__((packed)); |
|
- | 114 | ||
- | 115 | ||
- | 116 | ||
- | 117 | ||
- | 118 | ||
- | 119 | //________________________________________________________________________________________________________________________________________ |
|
- | 120 | // |
|
- | 121 | // Partitions |
|
- | 122 | // |
|
- | 123 | //________________________________________________________________________________________________________________________________________ |
|
- | 124 | ||
- | 125 | #define _EMPTY 0x00 |
|
- | 126 | #define _FAT12 0x01 |
|
69 | // |
127 | #define _FAT16_ST_32_MB 0x04 |
70 | //________________________________________________________________________________________________________________________________________ |
128 | #define _EXTENDED 0x05 |
71 | 129 | #define _FAT16_LT_32_MB 0x06 |
|
72 | struct FatEntry |
130 | #define _HPFS 0x07 |
73 | { |
131 | #define _FAT32 0x0B |
Line 122... | Line 180... | ||
122 | // |
180 | // |
123 | // Structure of the MasterBootRecord |
181 | // Structure of the MasterBootRecord |
124 | // |
182 | // |
125 | //________________________________________________________________________________________________________________________________________ |
183 | //________________________________________________________________________________________________________________________________________ |
Line -... | Line 184... | ||
- | 184 | ||
- | 185 | #define _MBR_SECTOR 0 // The MasterBootRecord is located in sector 0 |
|
126 | 186 | ||
127 | struct MBR_Entry |
187 | struct MBR_Entry |
128 | { |
188 | { |
129 | u8 ExecutableCode[446]; |
189 | u8 ExecutableCode[446]; |
130 | struct PartitionEntry PartitionEntry1; |
190 | struct PartitionEntry PartitionEntry1; |
Line 142... | Line 202... | ||
142 | // API to the FAT16 filesystem |
202 | // API to the FAT16 filesystem |
143 | // |
203 | // |
144 | //________________________________________________________________________________________________________________________________________ |
204 | //________________________________________________________________________________________________________________________________________ |
Line 145... | Line 205... | ||
145 | 205 | ||
146 | extern u8 InitFat16(void); |
206 | extern u8 InitFat16(void); |
147 | extern File * fopen_(u8 *fname,s8 mode); |
207 | extern File * fopen_(s8 *fname,s8 mode); |
148 | extern s16 fflush_(File *file); |
208 | extern s16 fflush_(File *file); |
149 | extern void fclose_(File *file); |
209 | extern void fclose_(File *file); |
150 | extern u32 fread_(void *buffer, u32 size, u32 count, File *file); |
210 | extern u32 fread_(void *buffer, u32 size, u32 count, File *file); |
151 | extern u32 fwrite_(void *buffer, u32 size, u32 count, File *file); |
211 | extern u32 fwrite_(void *buffer, u32 size, u32 count, File *file); |
152 | extern s16 fseek_(File *file, s32 offset, s16 origin); |
212 | extern s16 fseek_(File *file, s32 offset, s16 origin); |
153 | extern s16 fgetchar_(File *file); |
213 | extern s16 fgetchar_(File *file); |
154 | extern u8 fputchar_(File *file,s8 c); |
214 | extern u8 fputchar_(File *file,s8 c); |
155 | extern u8 fputs_(File *file,s8 *string); |
215 | extern u8 fputs_(File *file,s8 *string); |
156 | extern s8 * fgets_(s8 *s, s16 count, File *file); |
216 | extern s8 * fgets_(s8 *s, s16 count, File *file); |
157 | extern s16 frename_(s8 *oldname, s8 *newname); |
217 | extern s16 frename_(s8 *oldname, s8 *newname); |
- | 218 | extern u8 fexist_(s8 *fname); |
|
- | 219 | extern u8 mkdir_(s8 *fname); |
|
- | 220 | extern u8 chdir_(s8 *fname); |
|
- | 221 | extern u8 findfirst_(s8 *fname, Find *item, u8 attribute); |
|
- | 222 | extern u8 findnext_(Find *item); |
|
- | 223 | extern u16 feof_(File *); |
|
- | 224 | ||
Line 158... | Line 225... | ||
158 | extern u8 fexist_(u8*fname); |
225 | |
159 | 226 | ||
160 | //________________________________________________________________________________________________________________________________________ |
227 | //________________________________________________________________________________________________________________________________________ |
161 | // |
228 | // |
162 | // Functions needed internaly for the fat16 implementation |
229 | // Functions needed internaly for the fat16 implementation |
Line -... | Line 230... | ||
- | 230 | // |
|
163 | // |
231 | //________________________________________________________________________________________________________________________________________ |
164 | //________________________________________________________________________________________________________________________________________ |
232 | |
165 | - | ||
166 | extern u8 CreateDirectoryEntry(u8*fname, u16 cluster, File *file,u8 attrib); |
233 | extern u8 SeekFileInDirectory(s8*fname, File *file); |
167 | extern u16 FindNextFreeCluster(File *file); |
234 | extern u8 CreateFileInDirectory(s8*fname, File *file); |
168 | extern u8 SeekDirectoryEntry(u8*fname, File *file); |
235 | extern u16 FindNextFreeCluster(File *file); |
169 | extern void SeperateFileName(u8*fname, u8*name); |
236 | extern void SeperateFileName(s8*fname, s8*name); |
170 | extern u8 ScanSubDirectories(u8*fname, File *file); |
237 | extern u8 ScanSubDirectories(s8*fname, File *file); |
171 | extern u16 GetNextCluster(File *file); |
238 | extern u16 GetNextCluster(File *file); |
172 | extern u8 AppendCluster(File *file); |
- | |
- | 239 | extern u8 AppendCluster(File *file); |
|
- | 240 | extern u16 GetFatClusterOffset(File *file); |
|
- | 241 | extern u16 GetFatSectorIndex(File *file); |
|
- | 242 | extern File * ReserveFilePointer(void); |
|
- | 243 | extern u16 SeekSubDirectory(s8 *fname); |
|
Line 173... | Line 244... | ||
173 | extern u16 GetFatClusterOffset(File *file); |
244 | extern u8 CreateSubDirectory_(s8 *fname); |
174 | extern u16 GetFatSectorIndex(File *file); |
245 | extern u8 FindItem(Find *); |
175 | 246 | extern void FreeFilePointer(File *file); |
|
176 | 247 | ||
177 | //________________________________________________________________________________________________________________________________________ |
248 | //________________________________________________________________________________________________________________________________________ |
Line 178... | Line 249... | ||
178 | // |
249 | // |
179 | // Vaiables needed internaly for the fat16 implementation |
250 | // Vaiables needed internaly for the fat16 implementation |
- | 251 | // |
|
- | 252 | //________________________________________________________________________________________________________________________________________ |
|
Line 180... | Line -... | ||
180 | // |
- | |
181 | //________________________________________________________________________________________________________________________________________ |
253 |