Subversion Repositories Projects

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
231 killagreg 1
#ifndef __fat16_h
2
#define __fat16_h
3
 
4
 
5
 
6
 
7
 
8
//________________________________________________________________________________________________________________________________________
9
//
10
// Userspecific definitions
11
//
12
//________________________________________________________________________________________________________________________________________
13
 
14
#define         __MAX_FILES_USED        1       // The number of files that can be opened simultaneously.
15
 
16
 
17
 
18
 
19
 
20
 
21
 
22
 
23
//________________________________________________________________________________________________________________________________________
24
//
25
// Datatype definitions
26
//
27
//________________________________________________________________________________________________________________________________________
28
 
29
typedef unsigned char  u8;
30
typedef   signed char  s8;
31
typedef unsigned short u16;
32
typedef   signed short s16;
33
typedef unsigned long  u32;
34
typedef   signed long  s32;
35
 
36
 
37
 
38
//________________________________________________________________________________________________________________________________________
39
//
40
// Structure of a filepointer
41
//
42
//________________________________________________________________________________________________________________________________________
43
 
44
#define         _UNUSED         1               // Bits used in the attribute of an directory entry.
45
#define         _USED           2
46
#define         _ARCHIVE        2
47
#define         _READ_ONLY      4
48
#define         _SYSTEM         8
49
#define         _DIRECTORY      16
50
#define         _FILE           32
51
 
52
 
53
typedef struct afile
54
{
55
        u32 start_cluster;                              // Sectorpointer to the first sector of the first datacluster of the file.
56
        u32 cluster_pointer;                    // Pointer to the cluster which is edited at the moment.
57
        u8      sector_index;                           // The sector which is edited at the moment (cluster_pointer + sector_index).
58
        u16 byte_index;                                 // The bytelocation within the current sector (cluster_pointer + sector_index + byte_index).
59
        u8      mode;                                           // mode of fileoperation (read,write)
60
        u32 filesize;                                   // the size of the opend file in bytes.
61
        u32 fileposition;                               // pointer to a character within the file 0 < fileposition < filesize
62
        u32 sector_in_buffer;                   // the last sector read, wich is still in the sectorbuffer.
63
        u32 directory_root_sector;              // pointer to the root of the
64
        u32 directory_sector;                   // the sectorposition where the directoryentry has been made.
65
        u8      directory_index;                        // the index to the directoryentry within the specified sector.
66
        u8      attribute;                                      // the attribute of the file opened.
67
        u8  buffer[512];                                // Buffer for read and write operation from or to the mmc.
68
        u8      state;                                          // state of the filepointer (used/unused/...)
69
} File;
70
 
71
//________________________________________________________________________________________________________________________________________
72
//
73
// Structure of an item to find within the cwd
74
//
75
//________________________________________________________________________________________________________________________________________
76
 
77
typedef struct find
78
{
79
        u8      name[12];                                       // filename + extension or directoryname of the item found within the cwd.
80
        u8  searchstring[13];
81
        u32 cluster_pointer;                    // Sectorpointer to the sector of the item searched within the cwd.
82
        u16     startcluster;                           // pointer to the first datacluster of the item found in the cwd.
83
        u32 filesize;                                   // the size of the opend file in bytes.
84
        u32 directory_sector;                   // the sector within the actual cluster where the directoryentry was found.
85
        u8      directory_index;                        // the index to the directoryentry within the specified sector.
86
        u8      attribute;                                      // the attribute of the file opened.
87
} Find;
88
 
89
//________________________________________________________________________________________________________________________________________
90
//
91
// Directoryentries
92
//
93
//________________________________________________________________________________________________________________________________________
94
 
95
 
96
 
97
struct DirEntry
98
{
99
        u8   name[8];                                   // 8 bytes name.
100
        u8   extension[3];                              // 3 bytes extension.
101
        u8   attribute;                                 // attribute of the directory entry (unused,archive,read-only,system,directory,volume)
102
        u8   reserved[10];                              // reserved bytes within the directory entry.
103
        u16  time;                                              // time and
104
        u16  date;                                              // date of last write acces to the file or directory.
105
        u16  startcluster;                              // first cluster of the file or directory.
106
        u32  size;                                              // size of the file or directory in bytes.
107
} __attribute__((packed));
108
 
109
//________________________________________________________________________________________________________________________________________
110
//
111
// Structure of an entry within the fileallocationtable.
112
//
113
//________________________________________________________________________________________________________________________________________
114
 
115
struct FatEntry
116
{
117
        u16  next_cluster;                              // the next cluster of the file.
118
}  __attribute__((packed));
119
 
120
 
121
 
122
 
123
 
124
//________________________________________________________________________________________________________________________________________
125
//
126
// Partitions
127
//
128
//________________________________________________________________________________________________________________________________________
129
 
130
#define _EMPTY                                                  0x00
131
#define _FAT12                                                  0x01
132
#define _FAT16_ST_32_MB                                 0x04
133
#define _EXTENDED                                               0x05
134
#define _FAT16_LT_32_MB                                 0x06
135
#define _HPFS                                                   0x07
136
#define _FAT32                                                  0x0B
137
#define _FAT32_BIOS_Extension                   0x0C
138
#define _FAT16_32_MB_BIOS_Extension             0x0E
139
#define _EXTENDED_BIOS_Extension                0x0F
140
#define _EISA                                                   0x12
141
#define _DYNAMIC                                                0x42
142
#define _Linux_Swap                                             0x82
143
#define _Linux_Native                                   0x83
144
#define _Linux_LVM                                              0x8E
145
#define _FreeBSD                                                0xA5
146
#define _OpenBSD                                                0xA6
147
#define _NetBSD                                                 0xA9
148
 
149
 
150
struct PartitionEntry
151
{
152
        u8      PartitionState;
153
        u8      BeginningHead;
154
        u16     BeginningCylinder;
155
        u8      Type;
156
        u8      EndHead;
157
        u16     EndCylinder;
158
        u32     NoSectorsBeforePartition;
159
        u32     NoSectorsPartition      ;
160
} __attribute__((packed));
161
 
162
 
163
//________________________________________________________________________________________________________________________________________
164
//
165
// Structure of the VolumeBootRecord
166
//
167
//________________________________________________________________________________________________________________________________________
168
 
169
struct VBR_Entry
170
{
171
        u8  dummy[11];
172
        u16 bps;
173
        u8  SectorsPerCluster;
174
        u16 ReservedSectors;
175
        u8  NoFATCopies;
176
        u16 MaxRootEntries;
177
        u16 dummy2;
178
        u8  dummy3;
179
        u16 SectorsPerFAT;
180
} __attribute__((packed));
181
 
182
 
183
 
184
//________________________________________________________________________________________________________________________________________
185
//
186
// Structure of the MasterBootRecord
187
//
188
//________________________________________________________________________________________________________________________________________
189
 
190
#define         _MBR_SECTOR     0               // The MasterBootRecord is located in sector 0
191
 
192
struct MBR_Entry
193
{
194
        u8  ExecutableCode[446];
195
        struct  PartitionEntry  PartitionEntry1;
196
        struct  PartitionEntry  PartitionEntry2;
197
        struct  PartitionEntry  PartitionEntry3;
198
        struct  PartitionEntry  PartitionEntry4;
199
        u16             ExecutableMarker;
200
} __attribute__((packed));
201
 
202
 
203
 
204
 
205
//________________________________________________________________________________________________________________________________________
206
//
207
// API to the FAT16 filesystem
208
//
209
//________________________________________________________________________________________________________________________________________
210
 
211
extern u8               FAT16_Init(void);
212
extern File *   fopen_(s8 *fname,s8 mode);
213
extern s16              fflush_(File *file);
214
extern void     fclose_(File *file);
215
extern u32              fread_(void *buffer, u32 size, u32 count, File *file);
216
extern u32              fwrite_(void *buffer, u32 size, u32 count, File *file);
217
extern s16      fseek_(File *file, s32 offset, s16 origin);
218
extern s16              fgetchar_(File *file);
219
extern u8               fputchar_(File *file,s8 c);
220
extern u8               fputs_(File *file,s8 *string);
221
extern s8 *     fgets_(s8 *s, s16 count, File *file);
222
extern s16              frename_(s8 *oldname, s8 *newname);
223
extern u8               fexist_(s8*fname);
224
extern u8               mkdir_(s8*fname);
225
extern u8               chdir_(s8 *fname);
226
extern u8               findfirst_(s8 *fname, Find *item, u8 attribute);
227
extern u8               findnext_(Find *item);
228
 
229
 
230
 
231
//________________________________________________________________________________________________________________________________________
232
//
233
// Functions needed internaly for the fat16 implementation
234
//
235
//________________________________________________________________________________________________________________________________________
236
 
237
extern u8               SeekFileInDirectory(s8*fname, File *file);
238
extern u8               CreateFileInDirectory(s8*fname, File *file);
239
extern u16              FindNextFreeCluster(File *file);
240
extern void     SeperateFileName(s8*fname, s8*name);
241
extern u8               ScanSubDirectories(s8*fname, File *file);
242
extern u16      GetNextCluster(File *file);
243
extern u8               AppendCluster(File *file);
244
extern u16              GetFatClusterOffset(File *file);
245
extern u16              GetFatSectorIndex(File *file);
246
extern File *   ReserveFilePointer(void);
247
extern u16              SeekSubDirectory(s8 *fname);
248
extern u8               CreateSubDirectory_(s8 *fname);
249
extern u8               FindItem(Find *);
250
extern void     FreeFilePointer(File *file);
251
 
252
//________________________________________________________________________________________________________________________________________
253
//
254
// Vaiables needed internaly for the fat16 implementation
255
//
256
//________________________________________________________________________________________________________________________________________
257
 
258
extern u8               SectorsPerCluster;
259
extern u32              CWD;
260
 
261
 
262
 
263
#endif
264
 
265
 
266
 
267