Subversion Repositories NaviCtrl

Rev

Rev 1 | Rev 41 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1 Rev 24
1
#ifndef __fat16_h
1
#ifndef __fat16_h
2
#define __fat16_h
2
#define __fat16_h
3
 
3
 
-
 
4
 
4
 
5
 
5
//________________________________________________________________________________________________________________________________________
6
//________________________________________________________________________________________________________________________________________
6
// 
7
// 
7
// Definitions
8
// Userspecific definitions
8
//                              
9
//                              
9
//________________________________________________________________________________________________________________________________________
10
//________________________________________________________________________________________________________________________________________
10
 
-
 
11
//#define               __USE_TIME_DATE_ATTRIBUTE
11
 
-
 
12
#define         __MAX_FILES_USED        1       // The number of files that can be opened simultaneously. 
-
 
13
 
-
 
14
 
12
#define         __MAX_FILES_USED        2                               // The number of files that can accessed simultaneously. 
15
//________________________________________________________________________________________________________________________________________
-
 
16
// 
-
 
17
// Structure of a filepointer
-
 
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
18
#define         _READ_ONLY      4
24
#define         _READ_ONLY      4
19
#define         _SYSTEM         8
25
#define         _SYSTEM         8
20
#define         _DIRECTORY      16
26
#define         _DIRECTORY      16
21
#define         _FILE           32
27
#define         _FILE           32
22
 
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
 
-
 
48
 
-
 
49
typedef enum
-
 
50
{
-
 
51
        NOT_INITIALIZED,
-
 
52
        INITIALIZED
23
 
53
}Fat16_VolumeState_t;
24
 
54
 
25
//________________________________________________________________________________________________________________________________________
55
//________________________________________________________________________________________________________________________________________
26
// 
56
// 
27
// Structure of a filepointer
57
// Structure of an item to find within the cwd
28
//                              
58
//                              
29
//________________________________________________________________________________________________________________________________________
59
//________________________________________________________________________________________________________________________________________
30
 
60
 
31
typedef struct afile
61
struct volume
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).
-
 
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.
-
 
39
        u32 fileposition;                       // pointer to a character within the file 0 < fileposition < filesize
-
 
40
        u32 sector_in_buffer;           // the last sector read, wich is still in the sectorbuffer.
-
 
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.
62
{
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/...) 
63
        Fat16_VolumeState_t     state;  // state of the volume
46
} File;
64
} str_Volume;
47
 
65
 
48
//________________________________________________________________________________________________________________________________________
66
//________________________________________________________________________________________________________________________________________
49
// 
67
// 
50
// Structure of an directoryentry
68
// Structure of an item to find within the cwd
51
//                              
69
//                              
52
//________________________________________________________________________________________________________________________________________
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.
-
 
82
} Find;
-
 
83
 
-
 
84
//________________________________________________________________________________________________________________________________________
-
 
85
// 
-
 
86
// Directoryentries
-
 
87
//                              
-
 
88
//________________________________________________________________________________________________________________________________________
-
 
89
 
-
 
90
 
53
 
91
 
54
struct DirEntry
92
struct DirEntry
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.
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.
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.
69
//                              
107
//                              
70
//________________________________________________________________________________________________________________________________________
108
//________________________________________________________________________________________________________________________________________
71
 
109
 
72
struct FatEntry
110
struct FatEntry
73
{
111
{
74
        u16  next_cluster;                              // the next cluster of the file.
112
        u16  next_cluster;                              // the next cluster of the file.
75
};
113
}  __attribute__((packed));
76
 
114
 
77
 
115
 
78
 
116
 
79
 
117
 
80
 
118
 
81
//________________________________________________________________________________________________________________________________________
119
//________________________________________________________________________________________________________________________________________
82
// 
120
// 
83
// Structure of an partitionentry
121
// Partitions
84
//                              
122
//                              
85
//________________________________________________________________________________________________________________________________________
123
//________________________________________________________________________________________________________________________________________
-
 
124
 
-
 
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
 
86
 
144
 
87
struct PartitionEntry
145
struct PartitionEntry
88
{
146
{
89
        u8      PartitionState;
147
        u8      PartitionState;
90
        u8      BeginningHead;
148
        u8      BeginningHead;
91
        u16     BeginningCylinder;
149
        u16     BeginningCylinder;
92
        u8      Type;
150
        u8      Type;
93
        u8      EndHead;
151
        u8      EndHead;
94
        u16     EndCylinder;
152
        u16     EndCylinder;
95
        u32     NoSectorsBeforePartition;
153
        u32     NoSectorsBeforePartition;
96
        u32     NoSectorsPartition      ;
154
        u32     NoSectorsPartition      ;
97
} __attribute__((packed));
155
} __attribute__((packed));
98
 
156
 
99
 
157
 
100
//________________________________________________________________________________________________________________________________________
158
//________________________________________________________________________________________________________________________________________
101
// 
159
// 
102
// Structure of the VolumeBootRecord
160
// Structure of the VolumeBootRecord
103
//                              
161
//                              
104
//________________________________________________________________________________________________________________________________________
162
//________________________________________________________________________________________________________________________________________
105
 
163
 
106
struct VBR_Entry
164
struct VBR_Entry
107
{
165
{
108
        u8  dummy[11];                                         
166
        u8  dummy[11];                                         
109
        u16 bps;
167
        u16 bps;
110
        u8  SectorsPerCluster;
168
        u8  SectorsPerCluster;
111
        u16 ReservedSectors;
169
        u16 ReservedSectors;
112
        u8  NoFATCopies;
170
        u8  NoFATCopies;
113
        u16 MaxRootEntries;
171
        u16 MaxRootEntries;
114
        u16 dummy2;
172
        u16 dummy2;
115
        u8  dummy3;
173
        u8  dummy3;
116
        u16 SectorsPerFAT;
174
        u16 SectorsPerFAT;
117
} __attribute__((packed));
175
} __attribute__((packed));
118
 
176
 
119
 
177
 
120
 
178
 
121
//________________________________________________________________________________________________________________________________________
179
//________________________________________________________________________________________________________________________________________
122
// 
180
// 
123
// Structure of the MasterBootRecord
181
// Structure of the MasterBootRecord
124
//                              
182
//                              
125
//________________________________________________________________________________________________________________________________________
183
//________________________________________________________________________________________________________________________________________
-
 
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;                                               
131
        struct  PartitionEntry  PartitionEntry2;                                               
191
        struct  PartitionEntry  PartitionEntry2;                                               
132
        struct  PartitionEntry  PartitionEntry3;                                               
192
        struct  PartitionEntry  PartitionEntry3;                                               
133
        struct  PartitionEntry  PartitionEntry4;                                               
193
        struct  PartitionEntry  PartitionEntry4;                                               
134
        u16             ExecutableMarker;      
194
        u16             ExecutableMarker;      
135
} __attribute__((packed));
195
} __attribute__((packed));
136
 
196
 
137
 
197
 
138
 
198
 
139
 
199
 
140
//________________________________________________________________________________________________________________________________________
200
//________________________________________________________________________________________________________________________________________
141
// 
201
// 
142
// API to the FAT16 filesystem
202
// API to the FAT16 filesystem
143
//                              
203
//                              
144
//________________________________________________________________________________________________________________________________________
204
//________________________________________________________________________________________________________________________________________
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);
158
extern u8               fexist_(u8*fname);
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
 
-
 
225
 
159
 
226
 
160
//________________________________________________________________________________________________________________________________________
227
//________________________________________________________________________________________________________________________________________
161
// 
228
// 
162
// Functions needed internaly for the fat16 implementation 
229
// Functions needed internaly for the fat16 implementation 
163
//                              
230
//                              
164
//________________________________________________________________________________________________________________________________________
231
//________________________________________________________________________________________________________________________________________
-
 
232
 
165
 
233
extern u8               SeekFileInDirectory(s8*fname, File *file);
166
extern u8               CreateDirectoryEntry(u8*fname, u16 cluster, File *file,u8 attrib);
234
extern u8               CreateFileInDirectory(s8*fname, File *file);
167
extern u16              FindNextFreeCluster(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);
173
extern u16              GetFatClusterOffset(File *file);
240
extern u16              GetFatClusterOffset(File *file);
174
extern u16              GetFatSectorIndex(File *file);
241
extern u16              GetFatSectorIndex(File *file);
175
 
-
 
-
 
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);
176
 
247
 
177
//________________________________________________________________________________________________________________________________________
248
//________________________________________________________________________________________________________________________________________
178
// 
249
// 
179
// Vaiables needed internaly for the fat16 implementation 
250
// Vaiables needed internaly for the fat16 implementation 
180
//                              
251
//                              
181
//________________________________________________________________________________________________________________________________________
252
//________________________________________________________________________________________________________________________________________
182
 
253
 
183
extern u8               SectorsPerCluster;
254
extern u8               SectorsPerCluster;
184
extern u8               SectorsPerCluster;
255
extern u32              CWD;
-
 
256
 
-
 
257
 
185
 
-
 
186
extern struct   time    rtctime;
258
 
187
#endif
259
#endif
188
 
260
 
189
 
261
 
190
 
262
 
191
 
263
 
192
 
264