Subversion Repositories NaviCtrl

Rev

Rev 1 | Rev 41 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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