00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FAT_H
00023 #define FAT_H
00024
00025 #include "global.h"
00026
00027
00028
00029 #define MSDOSFSROOT 0 // cluster 0 means the root dir
00030 #define CLUST_FREE 0 // cluster 0 also means a free cluster
00031 #define MSDOSFSFREE CLUST_FREE
00032 #define CLUST_FIRST 2 // first legal cluster number
00033 #define CLUST_RSRVD 0xfffffff6 // reserved cluster range
00034 #define CLUST_BAD 0xfffffff7 // a cluster with a defect
00035 #define CLUST_EOFS 0xfffffff8 // start of eof cluster range
00036 #define CLUST_EOFE 0xffffffff // end of eof cluster range
00037
00038 #define FAT12_MASK 0x00000fff // mask for 12 bit cluster numbers
00039 #define FAT16_MASK 0x0000ffff // mask for 16 bit cluster numbers
00040 #define FAT32_MASK 0x0fffffff // mask for FAT32 cluster numbers
00041
00042
00043
00044 #define PART_TYPE_UNKNOWN 0x00
00045 #define PART_TYPE_FAT12 0x01
00046 #define PART_TYPE_XENIX 0x02
00047 #define PART_TYPE_DOSFAT16 0x04
00048 #define PART_TYPE_EXTDOS 0x05
00049 #define PART_TYPE_FAT16 0x06
00050 #define PART_TYPE_NTFS 0x07
00051 #define PART_TYPE_FAT32 0x0B
00052 #define PART_TYPE_FAT32LBA 0x0C
00053 #define PART_TYPE_FAT16LBA 0x0E
00054 #define PART_TYPE_EXTDOSLBA 0x0F
00055 #define PART_TYPE_ONTRACK 0x33
00056 #define PART_TYPE_NOVELL 0x40
00057 #define PART_TYPE_PCIX 0x4B
00058 #define PART_TYPE_PHOENIXSAVE 0xA0
00059 #define PART_TYPE_CPM 0xDB
00060 #define PART_TYPE_DBFS 0xE0
00061 #define PART_TYPE_BBT 0xFF
00062
00063 struct partrecord
00064 {
00065 BYTE prIsActive;
00066 BYTE prStartHead;
00067 WORD prStartCylSect;
00068 BYTE prPartType;
00069 BYTE prEndHead;
00070 WORD prEndCylSect;
00071 DWORD prStartLBA;
00072 DWORD prSize;
00073 };
00074
00075
00076 struct partsector
00077 {
00078 CHAR psPartCode[512-64-2];
00079 BYTE psPart[64];
00080 BYTE psBootSectSig0;
00081 BYTE psBootSectSig1;
00082 #define BOOTSIG0 0x55
00083 #define BOOTSIG1 0xaa
00084 };
00085
00086
00087
00088
00089
00090
00091 struct bootsector33 {
00092 BYTE bsJump[3];
00093 CHAR bsOemName[8];
00094 CHAR bsBPB[19];
00095 CHAR bsDriveNumber;
00096 CHAR bsBootCode[479];
00097 BYTE bsBootSectSig0;
00098 BYTE bsBootSectSig1;
00099 #define BOOTSIG0 0x55
00100 #define BOOTSIG1 0xaa
00101 };
00102
00103 struct extboot {
00104 CHAR exDriveNumber;
00105 CHAR exReserved1;
00106 CHAR exBootSignature;
00107 #define EXBOOTSIG 0x29
00108 CHAR exVolumeID[4];
00109 CHAR exVolumeLabel[11];
00110 CHAR exFileSysType[8];
00111 };
00112
00113 struct bootsector50 {
00114 BYTE bsJump[3];
00115 CHAR bsOemName[8];
00116 CHAR bsBPB[25];
00117 CHAR bsExt[26];
00118 CHAR bsBootCode[448];
00119 BYTE bsBootSectSig0;
00120 BYTE bsBootSectSig1;
00121 #define BOOTSIG0 0x55
00122 #define BOOTSIG1 0xaa
00123 };
00124
00125 struct bootsector710 {
00126 BYTE bsJump[3];
00127 CHAR bsOEMName[8];
00128 CHAR bsBPB[53];
00129 CHAR bsExt[26];
00130 CHAR bsBootCode[418];
00131 BYTE bsBootSectSig2;
00132 BYTE bsBootSectSig3;
00133 BYTE bsBootSectSig0;
00134 BYTE bsBootSectSig1;
00135 #define BOOTSIG0 0x55
00136 #define BOOTSIG1 0xaa
00137 #define BOOTSIG2 0
00138 #define BOOTSIG3 0
00139 };
00140
00141
00142
00143
00144
00145
00146 struct bpb33 {
00147 WORD bpbBytesPerSec;
00148 BYTE bpbSecPerClust;
00149 WORD bpbResSectors;
00150 BYTE bpbFATs;
00151 WORD bpbRootDirEnts;
00152 WORD bpbSectors;
00153 BYTE bpbMedia;
00154 WORD bpbFATsecs;
00155 WORD bpbSecPerTrack;
00156 WORD bpbHeads;
00157 WORD bpbHiddenSecs;
00158 };
00159
00160
00161
00162
00163 struct bpb50 {
00164 WORD bpbBytesPerSec;
00165 BYTE bpbSecPerClust;
00166 WORD bpbResSectors;
00167 BYTE bpbFATs;
00168 WORD bpbRootDirEnts;
00169 WORD bpbSectors;
00170 BYTE bpbMedia;
00171 WORD bpbFATsecs;
00172 WORD bpbSecPerTrack;
00173 WORD bpbHeads;
00174 DWORD bpbHiddenSecs;
00175
00176 DWORD bpbHugeSectors;
00177 };
00178
00179
00180
00181 struct bpb710 {
00182 WORD bpbBytesPerSec;
00183 BYTE bpbSecPerClust;
00184 WORD bpbResSectors;
00185 BYTE bpbFATs;
00186 WORD bpbRootDirEnts;
00187 WORD bpbSectors;
00188 BYTE bpbMedia;
00189 WORD bpbFATsecs;
00190 WORD bpbSecPerTrack;
00191 WORD bpbHeads;
00192 DWORD bpbHiddenSecs;
00193
00194 DWORD bpbHugeSectors;
00195
00196 DWORD bpbBigFATsecs;
00197 WORD bpbExtFlags;
00198 #define FATNUM 0xf // mask for numbering active FAT
00199 #define FATMIRROR 0x80 // FAT is mirrored (like it always was)
00200 WORD bpbFSVers;
00201 #define FSVERS 0 // currently only 0 is understood
00202 DWORD bpbRootClust;
00203 WORD bpbFSInfo;
00204 WORD bpbBackup;
00205
00206 };
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217 struct byte_bpb33 {
00218 CHAR bpbBytesPerSec[2];
00219 CHAR bpbSecPerClust;
00220 CHAR bpbResSectors[2];
00221 CHAR bpbFATs;
00222 CHAR bpbRootDirEnts[2];
00223 CHAR bpbSectors[2];
00224 CHAR bpbMedia;
00225 CHAR bpbFATsecs[2];
00226 CHAR bpbSecPerTrack[2];
00227 CHAR bpbHeads[2];
00228 CHAR bpbHiddenSecs[2];
00229 };
00230
00231
00232
00233
00234 struct byte_bpb50 {
00235 CHAR bpbBytesPerSec[2];
00236 CHAR bpbSecPerClust;
00237 CHAR bpbResSectors[2];
00238 CHAR bpbFATs;
00239 CHAR bpbRootDirEnts[2];
00240 CHAR bpbSectors[2];
00241 CHAR bpbMedia;
00242 CHAR bpbFATsecs[2];
00243 CHAR bpbSecPerTrack[2];
00244 CHAR bpbHeads[2];
00245 CHAR bpbHiddenSecs[4];
00246 CHAR bpbHugeSectors[4];
00247 };
00248
00249
00250
00251 struct byte_bpb710 {
00252 BYTE bpbBytesPerSec[2];
00253 BYTE bpbSecPerClust;
00254 BYTE bpbResSectors[2];
00255 BYTE bpbFATs;
00256 BYTE bpbRootDirEnts[2];
00257 BYTE bpbSectors[2];
00258 BYTE bpbMedia;
00259 BYTE bpbFATsecs[2];
00260 BYTE bpbSecPerTrack[2];
00261 BYTE bpbHeads[2];
00262 BYTE bpbHiddenSecs[4];
00263 BYTE bpbHugeSectors[4];
00264 BYTE bpbBigFATsecs[4];
00265 BYTE bpbExtFlags[2];
00266 BYTE bpbFSVers[2];
00267 BYTE bpbRootClust[4];
00268 BYTE bpbFSInfo[2];
00269 BYTE bpbBackup[2];
00270
00271 };
00272
00273
00274 struct fsinfo {
00275 BYTE fsisig1[4];
00276 BYTE fsifill1[480];
00277 BYTE fsisig2[4];
00278 BYTE fsinfree[4];
00279 BYTE fsinxtfree[4];
00280 BYTE fsifill2[12];
00281 BYTE fsisig3[4];
00282 BYTE fsifill3[508];
00283 BYTE fsisig4[4];
00284 };
00285
00286
00287
00288
00289
00290
00291
00292 struct direntry {
00293 BYTE deName[8];
00294 #define SLOT_EMPTY 0x00 // slot has never been used
00295 #define SLOT_E5 0x05 // the real value is 0xe5
00296 #define SLOT_DELETED 0xe5 // file in this slot deleted
00297 BYTE deExtension[3];
00298 BYTE deAttributes;
00299 #define ATTR_NORMAL 0x00 // normal file
00300 #define ATTR_READONLY 0x01 // file is readonly
00301 #define ATTR_HIDDEN 0x02 // file is hidden
00302 #define ATTR_SYSTEM 0x04 // file is a system file
00303 #define ATTR_VOLUME 0x08 // entry is a volume label
00304 #define ATTR_LONG_FILENAME 0x0f // this is a long filename entry
00305 #define ATTR_DIRECTORY 0x10 // entry is a directory name
00306 #define ATTR_ARCHIVE 0x20 // file is new or modified
00307 BYTE deLowerCase;
00308 #define LCASE_BASE 0x08 // filename base in lower case
00309 #define LCASE_EXT 0x10 // filename extension in lower case
00310 BYTE deCHundredth;
00311 BYTE deCTime[2];
00312 BYTE deCDate[2];
00313 BYTE deADate[2];
00314 WORD deHighClust;
00315 BYTE deMTime[2];
00316 BYTE deMDate[2];
00317 WORD deStartCluster;
00318 DWORD deFileSize;
00319 };
00320
00321
00322 #define DIRENTRIES_PER_SECTOR 0x10
00323
00324
00325 struct winentry {
00326 BYTE weCnt;
00327 #define WIN_LAST 0x40
00328 #define WIN_CNT 0x3f
00329 BYTE wePart1[10];
00330 BYTE weAttributes;
00331 #define ATTR_WIN95 0x0f
00332 BYTE weReserved1;
00333 BYTE weChksum;
00334 BYTE wePart2[12];
00335 WORD weReserved2;
00336 BYTE wePart3[4];
00337 };
00338
00339 #define WIN_CHARS 13 // Number of chars per winentry
00340
00341
00342
00343 #define WIN_MAXLEN 255
00344
00345
00346
00347
00348
00349 #define DT_2SECONDS_MASK 0x1F // seconds divided by 2
00350 #define DT_2SECONDS_SHIFT 0
00351 #define DT_MINUTES_MASK 0x7E0 // minutes
00352 #define DT_MINUTES_SHIFT 5
00353 #define DT_HOURS_MASK 0xF800 // hours
00354 #define DT_HOURS_SHIFT 11
00355
00356
00357
00358 #define DD_DAY_MASK 0x1F // day of month
00359 #define DD_DAY_SHIFT 0
00360 #define DD_MONTH_MASK 0x1E0 // month
00361 #define DD_MONTH_SHIFT 5
00362 #define DD_YEAR_MASK 0xFE00 // year - 1980
00363 #define DD_YEAR_SHIFT 9
00364
00365
00366 unsigned char fatInit( unsigned char device);
00367 unsigned int fatClusterSize(void);
00368 unsigned long fatGetDirEntry(unsigned int entry, unsigned int count);
00369 unsigned long fatGetFilesize(void);
00370 char* fatGetFilename(void);
00371 char* fatGetDirname(void);
00372 void fatLoadCluster(unsigned long cluster, unsigned char *buffer);
00373 unsigned long fatNextCluster(unsigned long cluster);
00374
00375 #endif