|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418 |
-
- #ifndef FatStructs_h
- #define FatStructs_h
-
-
-
-
- uint8_t const BOOTSIG0 = 0X55;
-
- uint8_t const BOOTSIG1 = 0XAA;
-
-
- struct partitionTable {
-
-
- uint8_t boot;
-
-
- uint8_t beginHead;
-
-
- unsigned beginSector : 6;
-
- unsigned beginCylinderHigh : 2;
-
-
- uint8_t beginCylinderLow;
-
-
- uint8_t type;
-
-
- uint8_t endHead;
-
-
- unsigned endSector : 6;
-
- unsigned endCylinderHigh : 2;
-
-
- uint8_t endCylinderLow;
-
- uint32_t firstSector;
-
- uint32_t totalSectors;
- } __attribute__((packed));
-
- typedef struct partitionTable part_t;
-
-
- struct masterBootRecord {
-
- uint8_t codeArea[440];
-
- uint32_t diskSignature;
-
- uint16_t usuallyZero;
-
- part_t part[4];
-
- uint8_t mbrSig0;
-
- uint8_t mbrSig1;
- } __attribute__((packed));
-
- typedef struct masterBootRecord mbr_t;
-
-
- struct biosParmBlock {
-
-
- uint16_t bytesPerSector;
-
-
- uint8_t sectorsPerCluster;
-
-
- uint16_t reservedSectorCount;
-
-
- uint8_t fatCount;
-
-
- uint16_t rootDirEntryCount;
-
-
- uint16_t totalSectors16;
-
-
- uint8_t mediaType;
-
-
- uint16_t sectorsPerFat16;
-
- uint16_t sectorsPerTrtack;
-
- uint16_t headCount;
-
-
- uint32_t hidddenSectors;
-
-
- uint32_t totalSectors32;
-
-
- uint32_t sectorsPerFat32;
-
-
- uint16_t fat32Flags;
-
-
- uint16_t fat32Version;
-
-
- uint32_t fat32RootCluster;
-
-
- uint16_t fat32FSInfo;
-
-
- uint16_t fat32BackBootBlock;
-
-
- uint8_t fat32Reserved[12];
- } __attribute__((packed));
-
- typedef struct biosParmBlock bpb_t;
-
-
- struct fat32BootSector {
-
- uint8_t jmpToBootCode[3];
-
- char oemName[8];
-
- bpb_t bpb;
-
- uint8_t driveNumber;
-
- uint8_t reserved1;
-
- uint8_t bootSignature;
-
- uint32_t volumeSerialNumber;
-
- char volumeLabel[11];
-
- char fileSystemType[8];
-
- uint8_t bootCode[420];
-
- uint8_t bootSectorSig0;
-
- uint8_t bootSectorSig1;
- } __attribute__((packed));
-
-
-
- uint16_t const FAT16EOC = 0XFFFF;
-
- uint16_t const FAT16EOC_MIN = 0XFFF8;
-
- uint32_t const FAT32EOC = 0X0FFFFFFF;
-
- uint32_t const FAT32EOC_MIN = 0X0FFFFFF8;
-
- uint32_t const FAT32MASK = 0X0FFFFFFF;
-
-
- typedef struct fat32BootSector fbs_t;
-
-
- struct directoryEntry {
-
-
- uint8_t name[11];
-
-
- uint8_t attributes;
-
-
- uint8_t reservedNT;
-
-
- uint8_t creationTimeTenths;
-
- uint16_t creationTime;
-
- uint16_t creationDate;
-
-
- uint16_t lastAccessDate;
-
-
- uint16_t firstClusterHigh;
-
- uint16_t lastWriteTime;
-
- uint16_t lastWriteDate;
-
- uint16_t firstClusterLow;
-
- uint32_t fileSize;
- } __attribute__((packed));
-
-
-
-
- typedef struct directoryEntry dir_t;
-
- uint8_t const DIR_NAME_0XE5 = 0X05;
-
- uint8_t const DIR_NAME_DELETED = 0XE5;
-
- uint8_t const DIR_NAME_FREE = 0X00;
-
- uint8_t const DIR_ATT_READ_ONLY = 0X01;
-
- uint8_t const DIR_ATT_HIDDEN = 0X02;
-
- uint8_t const DIR_ATT_SYSTEM = 0X04;
-
- uint8_t const DIR_ATT_VOLUME_ID = 0X08;
-
- uint8_t const DIR_ATT_DIRECTORY = 0X10;
-
- uint8_t const DIR_ATT_ARCHIVE = 0X20;
-
- uint8_t const DIR_ATT_LONG_NAME = 0X0F;
-
- uint8_t const DIR_ATT_LONG_NAME_MASK = 0X3F;
-
- uint8_t const DIR_ATT_DEFINED_BITS = 0X3F;
-
- static inline uint8_t DIR_IS_LONG_NAME(const dir_t* dir) {
- return (dir->attributes & DIR_ATT_LONG_NAME_MASK) == DIR_ATT_LONG_NAME;
- }
-
- uint8_t const DIR_ATT_FILE_TYPE_MASK = (DIR_ATT_VOLUME_ID | DIR_ATT_DIRECTORY);
-
- static inline uint8_t DIR_IS_FILE(const dir_t* dir) {
- return (dir->attributes & DIR_ATT_FILE_TYPE_MASK) == 0;
- }
-
- static inline uint8_t DIR_IS_SUBDIR(const dir_t* dir) {
- return (dir->attributes & DIR_ATT_FILE_TYPE_MASK) == DIR_ATT_DIRECTORY;
- }
-
- static inline uint8_t DIR_IS_FILE_OR_SUBDIR(const dir_t* dir) {
- return (dir->attributes & DIR_ATT_VOLUME_ID) == 0;
- }
- #endif
|