-
- #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
|