Using a struct for the FAT Bios Parameter Block
Posted: Mon Mar 31, 2008 7:12 am
Upon opening and reading the official FAT manual from (the one and only) Microsoft, and seeing their nicely formatted table that explains the Bios Parameter Block, I thought it would be nice to encase it in a structure for easy access. Basically what I wanted was syntax like:
So first I read the bytes from the disk (at the start of the first partition):
And then I allocate a new BPB and memcpy the data straight into it:
However, when I try to access part of the structure, for instance the signature:
It spews out the wrong value, and I can see no consistent pattern as to which value it spews (except that it spews the same wrong value each time).
Here is how I declare the structure:
I based this directly off of the manual, so there shouldn't be anything wrong with it.
Code: Select all
fat_boot->boot_signature;
Code: Select all
ata_read_bytes(drive, bs, partition_base_sector, 0, 512);
Code: Select all
fat_BS_t *fat_boot = (fat_BS_t*)kmalloc(sizeof(fat_BS_t));
memcpy(fat_boot,bs,sizeof(fat_BS_t));
Code: Select all
write_hex(fat_boot->boot_signature);
Here is how I declare the structure:
Code: Select all
typedef struct fat_BS
{
unsigned char bootjmp[3];
unsigned char oem_name[8];
unsigned short bytes_per_sector;
unsigned char sectors_per_cluster;
unsigned short reserved_sector_count;
unsigned char table_count;
unsigned short root_entry_count;
unsigned short total_sectors_16;
unsigned char media_type;
unsigned short table_size_16;
unsigned short sectors_per_track;
unsigned short head_side_count;
unsigned int hidden_sector_count;
unsigned int total_sectors_32;
//extended fat32 stuff
unsigned int table_size_32;
unsigned short extended_flags;
unsigned short fat_version;
unsigned int root_cluster;
unsigned short fat_info;
unsigned short backup_BS_sector;
unsigned char reserved_0[12];
unsigned char drive_number;
unsigned char reserved_1;
unsigned char boot_signature;
unsigned int volume_id;
unsigned char volume_label[11];
unsigned char fat_type_label[8];
}fat_BS_t;