Subversion Repositories NaviCtrl

Rev

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

Rev Author Line No. Line
1 ingob 1
#ifndef __fat16_h
2
#define __fat16_h
3
 
4
 
5
//________________________________________________________________________________________________________________________________________
6
// 
7
// Definitions
8
//                              
9
//________________________________________________________________________________________________________________________________________
10
 
11
//#define               __USE_TIME_DATE_ATTRIBUTE
12
#define         __MAX_FILES_USED        2                               // The number of files that can accessed simultaneously. 
13
 
14
#define         MBR_SECTOR      0                                               // the masterboot record is located in sector 0.
15
#define         _UNUSED         1                                               // Bits used in the attribute of an directory entry.
16
#define         _USED           2
17
#define         _ARCHIVE        2
18
#define         _READ_ONLY      4
19
#define         _SYSTEM         8
20
#define         _DIRECTORY      16
21
#define         _FILE           32
22
 
23
 
24
 
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).
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.
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
// 
50
// Structure of an directoryentry
51
//                              
52
//________________________________________________________________________________________________________________________________________
53
 
54
struct DirEntry
55
{
56
        u8 name[8];                                             // 8 bytes name.
57
        u8 extension[3];                                // 3 bytes extension.
58
        u8 attribute;                                   // attribute of the directory entry (unused,archive,read-only,system,directory,volume)
59
        u8 reserved[10];                                // reserved bytes within the directory entry.
60
        u16  time;                                              // time and
61
        u16  date;                                              // date of last write acces to the file or directory.
62
        u16  startcluster;                              // first cluster of the file or directory.
63
        u32 size;                                               // size of the file or directory in bytes.
64
};
65
 
66
//________________________________________________________________________________________________________________________________________
67
// 
68
// Structure of an entry within the fileallocationtable.
69
//                              
70
//________________________________________________________________________________________________________________________________________
71
 
72
struct FatEntry
73
{
74
        u16  next_cluster;                              // the next cluster of the file.
75
};
76
 
77
 
78
 
79
 
80
 
81
//________________________________________________________________________________________________________________________________________
82
// 
83
// Structure of an partitionentry
84
//                              
85
//________________________________________________________________________________________________________________________________________
86
 
87
struct PartitionEntry
88
{
89
        u8      PartitionState;
90
        u8      BeginningHead;
91
        u16     BeginningCylinder;
92
        u8      Type;
93
        u8      EndHead;
94
        u16     EndCylinder;
95
        u32     NoSectorsBeforePartition;
96
        u32     NoSectorsPartition      ;
97
} __attribute__((packed));
98
 
99
 
100
//________________________________________________________________________________________________________________________________________
101
// 
102
// Structure of the VolumeBootRecord
103
//                              
104
//________________________________________________________________________________________________________________________________________
105
 
106
struct VBR_Entry
107
{
108
        u8  dummy[11];                                         
109
        u16 bps;
110
        u8  SectorsPerCluster;
111
        u16 ReservedSectors;
112
        u8  NoFATCopies;
113
        u16 MaxRootEntries;
114
        u16 dummy2;
115
        u8  dummy3;
116
        u16 SectorsPerFAT;
117
} __attribute__((packed));
118
 
119
 
120
 
121
//________________________________________________________________________________________________________________________________________
122
// 
123
// Structure of the MasterBootRecord
124
//                              
125
//________________________________________________________________________________________________________________________________________
126
 
127
struct MBR_Entry
128
{
129
        u8  ExecutableCode[446];                                               
130
        struct  PartitionEntry  PartitionEntry1;                                               
131
        struct  PartitionEntry  PartitionEntry2;                                               
132
        struct  PartitionEntry  PartitionEntry3;                                               
133
        struct  PartitionEntry  PartitionEntry4;                                               
134
        u16             ExecutableMarker;      
135
} __attribute__((packed));
136
 
137
 
138
 
139
 
140
//________________________________________________________________________________________________________________________________________
141
// 
142
// API to the FAT16 filesystem
143
//                              
144
//________________________________________________________________________________________________________________________________________
145
 
146
extern u8               InitFat16(void);               
147
extern File *   fopen_(u8 *fname,s8 mode);
148
extern s16              fflush_(File *file);
149
extern void     fclose_(File *file);
150
extern u32              fread_(void *buffer, u32 size, u32 count, File *file);
151
extern u32              fwrite_(void *buffer, u32 size, u32 count, File *file);
152
extern s16      fseek_(File *file, s32 offset, s16 origin);
153
extern          s16     fgetchar_(File *file);
154
extern u8               fputchar_(File *file,s8 c);
155
extern u8               fputs_(File *file,s8 *string);
156
extern s8 *     fgets_(s8 *s, s16 count, File *file);
157
extern s16              frename_(s8 *oldname, s8 *newname);
158
extern u8               fexist_(u8*fname);
159
 
160
//________________________________________________________________________________________________________________________________________
161
// 
162
// Functions needed internaly for the fat16 implementation 
163
//                              
164
//________________________________________________________________________________________________________________________________________
165
 
166
extern u8               CreateDirectoryEntry(u8*fname, u16 cluster, File *file,u8 attrib);
167
extern u16              FindNextFreeCluster(File *file);
168
extern u8               SeekDirectoryEntry(u8*fname, File *file);
169
extern void     SeperateFileName(u8*fname, u8*name);
170
extern u8               ScanSubDirectories(u8*fname, File *file);
171
extern u16      GetNextCluster(File *file);
172
extern u8               AppendCluster(File *file);
173
extern u16              GetFatClusterOffset(File *file);
174
extern u16              GetFatSectorIndex(File *file);
175
 
176
 
177
//________________________________________________________________________________________________________________________________________
178
// 
179
// Vaiables needed internaly for the fat16 implementation 
180
//                              
181
//________________________________________________________________________________________________________________________________________
182
 
183
extern u8               SectorsPerCluster;
184
extern u8               SectorsPerCluster;
185
 
186
extern struct   time    rtctime;
187
#endif
188
 
189
 
190
 
191