Is it save to write a BPB with dummy values ?
Posted: Thu Dec 29, 2022 6:47 pm
It's my first post here so please be kind and please guide me reformatting my question if something seems wrong to you !
Hello there,
I'm having a hard time figuring out how a BPB is used within a bootloader... Let's take the example of a FAT-16 formatted disk.I understand that the BPB is giving informations about how many sectors per clusters they are, how many FAT's, ... But what I don't get it is why do many bootloaders use dummy values for the BPB ?!
Taken from The Limine bootsect.asm :
Let's say I write a bootloader with "default values" for a FAT16 disk, how can I be sure that my BPB perfectly reflects the BPB created with a partition-formatting tool such as GParted ?
Similarly, a disk that is 4gb and another that is 8Gb can't have the same BPB. Like the Total number of sectors is clearly different in both of them ! So how come using defaults/garbages values for a bpb is manageable for a bootloader ?
Isn't this a preferable way to use the BPB that was created by a partitioning tool ? :
Surely, I'm missing something here but I can't get my head around the BPB and why many bootloaders tends to overwrite a BPB created for a particular drive and prefer using one with defaults value that would potentially not reflect the real layout of the drive...
To add one more thing. I plan to write a bootloader that uses a FAT16 layout that's why I'm asking this question before getting my hands dirty and here is how I see things but apparently I'm wrong :
1. Format a disk using FAT16 (BPB is written in first sector)
2. Write my bootloader that keeps the BPB created before
3. Simply use dd or any other tool to overwrite the first sector (this operation should't modify the BPB)
4. Copy my kernel.bin to the drive
5. Find kernel.bin and load it since I have the BPB
Many thanks for your attention to my question !
Hello there,
I'm having a hard time figuring out how a BPB is used within a bootloader... Let's take the example of a FAT-16 formatted disk.I understand that the BPB is giving informations about how many sectors per clusters they are, how many FAT's, ... But what I don't get it is why do many bootloaders use dummy values for the BPB ?!
Taken from The Limine bootsect.asm :
Code: Select all
.bpb:
times 3-($-$$) db 0
.bpb_oem_id: db "LIMINE "
.bpb_sector_size: dw 512
.bpb_sects_per_cluster: db 0
.bpb_reserved_sects: dw 0
.bpb_fat_count: db 0
.bpb_root_dir_entries: dw 0
.bpb_sector_count: dw 0
.bpb_media_type: db 0
.bpb_sects_per_fat: dw 0
.bpb_sects_per_track: dw 18
.bpb_heads_count: dw 2
.bpb_hidden_sects: dd 0
.bpb_sector_count_big: dd 0
.bpb_drive_num: db 0
.bpb_reserved: db 0
.bpb_signature: db 0
.bpb_volume_id: dd 0
.bpb_volume_label: db "LIMINE "
.bpb_filesystem_type: times 8 db 0
Similarly, a disk that is 4gb and another that is 8Gb can't have the same BPB. Like the Total number of sectors is clearly different in both of them ! So how come using defaults/garbages values for a bpb is manageable for a bootloader ?
Isn't this a preferable way to use the BPB that was created by a partitioning tool ? :
Code: Select all
%define bsOemName bp+0x03 ; OEM label (dq)
%define bsBytesPerSec bp+0x0B ; bytes/sector (dw)
%define bsSecsPerClust bp+0x0D ; sectors/allocation unit (db)
%define bsResSectors bp+0x0E ; # reserved sectors (dw)
%define bsFATs bp+0x10 ; # of FATs (db)
%define bsRootDirEnts bp+0x11 ; Max # of root dir entries (dw)
%define bsSectors bp+0x13 ; # sectors total in image (dw)
%define bsMedia bp+0x15 ; media descriptor (db)
%define bsSecsPerFat bp+0x16 ; # sectors in a fat (dw)
%define bsSecsPerTrack bp+0x18 ; # sectors/track
%define bsHeads bp+0x1A ; # heads (dw)
%define bsHidden bp+0x1C ; # hidden sectors (dd)
%define bsSectorHuge bp+0x20 ; # sectors if > 65536 (dd)
%define bsDriveNumber bp+0x24 ; drive number, 0x80 of 0x81 for HDD(dw)
%define bsSigniture bp+0x26 ; reserved (db)
%define bsVolumeSerial bp+0x27 ; used for tracking volume between computers(dd)
%define bsVolumeLabel bp+0x2B ; disc label, padded with spaces(11)
%define bsSysID bp+0x36 ; filesystem id(8)
To add one more thing. I plan to write a bootloader that uses a FAT16 layout that's why I'm asking this question before getting my hands dirty and here is how I see things but apparently I'm wrong :
1. Format a disk using FAT16 (BPB is written in first sector)
2. Write my bootloader that keeps the BPB created before
3. Simply use dd or any other tool to overwrite the first sector (this operation should't modify the BPB)
4. Copy my kernel.bin to the drive
5. Find kernel.bin and load it since I have the BPB
Many thanks for your attention to my question !