aboutsummaryrefslogtreecommitdiff
path: root/inc/bpb.h
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2026-09-29 23:40:31 +0200
committerJavier <dev.git@javispedro.com>2026-09-29 23:40:31 +0200
commit0a656a4a84f920194958d339d61ed567eba9c03c (patch)
tree0feecbddf0150e02fe7a2fa619dc232c50ced4c8 /inc/bpb.h
downloadchu-0a656a4a84f920194958d339d61ed567eba9c03c.tar.gz
chu-0a656a4a84f920194958d339d61ed567eba9c03c.zip
initial import
Diffstat (limited to 'inc/bpb.h')
-rw-r--r--inc/bpb.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/inc/bpb.h b/inc/bpb.h
new file mode 100644
index 0000000..8df04a1
--- /dev/null
+++ b/inc/bpb.h
@@ -0,0 +1,83 @@
+#ifndef BPB_H
+#define BPB_H
+
+#include <stdint.h>
+#include "sassert.h"
+
+#define DOS_BPB_OFFSET_ON_DISK 0x0B
+
+typedef _Packed struct DOS_BPB_DOS3
+{
+ /** Number of bytes per sector. */
+ uint16_t bytesPerSector;
+ /** Number of sectors per cluster. Must be power of 2. */
+ uint8_t sectorsPerCluster;
+ /** Number of reserved sectors. */
+ uint16_t reservedSectors;
+ /** Number of FATs. */
+ uint8_t numberOfFATs;
+ /** Maximum number of entries in the root directory. */
+ uint16_t rootDirEntries;
+ /** Total number of sectors on the drive. If drive larger than 32MB, this field is zero, see numberOfSectorsLarge. */
+ uint16_t numberOfSectors;
+ /** Media descriptor byte. */
+ uint8_t mediaType;
+ /** Number of sectors used by a FAT. */
+ uint16_t sectorsPerFAT;
+ /** Number of sectors per track. */
+ uint16_t sectorsPerTrack;
+ /** Number of heads. */
+ uint16_t numberOfHeads;
+ /** Number of hidden sectors on the drive, from the start of the drive. */
+ uint32_t hiddenSectors;
+ /** Number of sectors, only used if drive > 32MB. */
+ uint32_t numberOfSectorsLarge;
+} DOS_BPB_DOS3;
+STATIC_ASSERT(sizeof(DOS_BPB_DOS3) == 25);
+
+typedef _Packed struct DOS_BPB_DOS4
+{
+ struct DOS_BPB_DOS3;
+ uint8_t physicalDriveNumber;
+ uint8_t flags;
+ uint8_t extendedBootSignature;
+ uint32_t volumeSerialNumber;
+ char volumeLabel[11];
+ char fsType[8];
+} DOS_BPB_DOS4;
+STATIC_ASSERT(sizeof(DOS_BPB_DOS4) == 25 + 26);
+
+typedef _Packed struct DOS_BPB_FAT32
+{
+ struct DOS_BPB_DOS3;
+ uint32_t sectorPerFatLarge;
+ uint16_t extendedFlags;
+ uint16_t version;
+ uint32_t rootDirCluster;
+ uint16_t infoSector;
+ uint16_t backupBootSector;
+
+ char bootFileName[12];
+ uint8_t physicalDriveNumber;
+ uint8_t flags;
+ uint8_t extendedBootSignature;
+ uint32_t volumeSerialNumber;
+ char volumeLabel[11];
+ char fsType[8];
+} DOS_BPB_FAT32;
+STATIC_ASSERT(sizeof(DOS_BPB_FAT32) == 25 + 54);
+
+/** Union of all BPB types. Default is DOS4 / FAT16. */
+typedef union DOS_BPB
+{
+ struct DOS_BPB_DOS3;
+ struct DOS_BPB_DOS4 fat16;
+ struct DOS_BPB_FAT32 fat32;
+} DOS_BPB;
+
+typedef enum DOS_BPB_MEDIA_TYPE
+{
+ DOS_BPB_MEDIA_HDD = 0xF8
+} DOS_BPB_MEDIA_TYPE;
+
+#endif // BPB_H