size of FAT12 boot sector structure

Programming, for all ages and all languages.
Post Reply
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

size of FAT12 boot sector structure

Post by AndrewAPrice »

sizeof(FATBootStructure) reports this struct is 520 bytes long:

Code: Select all

struct FATBootSector
{
	unsigned char BootStrapCode[3]; // code to jump to the bootstrap code
	unsigned char OEMID[8]; // name of the formatting OS
	unsigned short BytesPerSector;
	unsigned char SectorsPerCluster;
	unsigned short ReservedSectors;
	unsigned char FATCopies;
	unsigned short NumberOfPossibleRootEntries;
	unsigned short TotalSectors;
	unsigned char MediaDescriptor;
	unsigned short SectorsPerFAT;
	unsigned short SectorsPerTrack;
	unsigned short NumberOfHeads;
	unsigned int HiddenSectors;
	unsigned int LargeNumberOfSectors;
	union
	{
		struct
		{
			unsigned char FATDriveNumber;
			unsigned char FAT_Reserved;
			unsigned char FATExtendedBootSignature;
			unsigned int FATVolumeSerialNumber;
			unsigned char FATVolumeLabel[11];
			unsigned char FATFileSystemType[8];
			unsigned char FATBootstrapCode[448];
		};
		struct
		{
			unsigned int FAT32SectorsPerFAT;
			unsigned short FAT32FATFlags;
			unsigned short FAT32Version;
			unsigned int FAT32ClusterNumberOfRootDirectoryStart;
			unsigned short FAT32SectorNumberOfFSInformationSector;
			unsigned short FAT32SectorNumberOfFSInformationSectorCopy;
			unsigned char FAT32_Reserved[12];
			unsigned char FAT32DriveNumber;
			unsigned char FAT32_Reserved1;
			unsigned char FAT32ExtendedBootSignature;
			unsigned int FAT32ID;
			unsigned char FAT32VolumeLabel[11];
			unsigned char FAT32FileSystemType[8];
			unsigned char FAT32BootstrapCode[420];
		};
	};
	unsigned char FAT32BootSectorSignature;
};
If I use __attribute__((packed)) it becomes 511 bytes long. It is annoying since data near the beginning of the structure is aligned, but not near the end.
My OS is Perception.
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post by AndrewAPrice »

FAT32BootSectorSignature should occupy 2 bytes not 1.
My OS is Perception.
Post Reply