aboutsummaryrefslogtreecommitdiff
path: root/inc/bpb.h
blob: 8df04a14268a97063db972bdab29f595be362b66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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