Summary
BIOS interrupt 0x13 does NOT depend on the BPB to determine the number of bytes per sector during raw sector reads. The BIOS interrupt 0x13 function 0x02 (Read Sectors from Disk) reads the disk geometry parameters (including Bytes Per Sector) from the disk drive controller or CMOS settings, not from the BPB stored in the MBR or boot sector. Omitting the BPB from your custom filesystem will not affect the ability to read or write sectors via BIOS interrupts, but it may affect other operating systems or boot loaders that rely on that data structure.
Root Cause
The misconception arises from confusing Disk Geometry (physical/logical characteristics the BIOS uses to talk to the hardware) with Filesystem Metadata (logical organization stored in the BPB).
- Hardware Dependency: When the BIOS executes interrupt 0x13, it uses the Disk Drive Parameter Table (DDPT). This table contains values like Sectors Per Track, Number of Heads, and Bytes Per Sector. These values are loaded into memory when the system boots (via INT 0x13 function 0x08 or from CMOS/EEPROM).
- Parameter Passing: To read a sector, you pass the Logical Block Address (LBA) or CHS coordinates to the interrupt. The BIOS translates these using the DDPT geometry.
- BPB Isolation: The BPB is a data structure located at the beginning of a disk (in the MBR or VBR) intended for the Operating System or file system driver. The BIOS firmware does not parse the BPB during a raw disk read operation; it relies solely on the hardware interface parameters.
Why This Happens in Real Systems
In legacy x86 PC architecture, the separation of concerns between hardware abstraction and data management is strict.
- Boot Strapping: The BIOS initializes the disk controller and establishes a communication protocol. It queries the drive for its geometry (via ATA commands or floppy controller commands) and caches this in the Extended BIOS Data Area (EBDA) or the BDA (BIOS Data Area).
- CHS vs. LBA: Historically, BIOS used Cylinder-Head-Sector (CHS) addressing. The BIOS calculates the offset based on the drive geometry (SPT, Heads). Even with LBA, the BIOS performs a translation using the drive geometry parameters.
- OS Responsibility: Once the BIOS loads the first sector (boot sector) into memory, control passes to the bootloader. The bootloader (or OS kernel) then reads the BPB to understand how the file system is organized (FAT clusters, NTFS MFT, etc.). The BIOS is unaware of file systems.
Real-World Impact
Omitting the BPB in a custom filesystem has specific implications:
-
Positive Impact:
- BIOS Operations Unaffected: You can read/write sectors freely using interrupt 0x13. The BIOS will correctly calculate the number of bytes to read because it uses the drive’s physical geometry, not your filesystem’s BPB.
- Flexibility: You can define custom sector sizes (e.g., 2048 bytes for modern SSD efficiency) without conflicting with standard BPB definitions, provided your driver handles the non-standard geometry correctly.
-
Negative Impact:
- No Standard Mounting: Windows, Linux, or macOS will likely fail to mount the volume because they rely on a valid BPB (or equivalent superblock) to identify the filesystem type and parameters.
- Bootloader Issues: If you are writing a bootloader, it may need to read the BPB to locate the next stage of the boot process. If you omit the BPB, standard bootloaders (like GRUB) will fail to interpret your disk.
Example or Code
The following assembly code snippet demonstrates reading a sector using INT 0x13. Note that no BPB lookup is performed; the geometry is handled implicitly by the BIOS based on the drive number.
; Example: Read 1 sector using BIOS INT 0x13 AH=0x02
; Inputs:
; DL = Drive Number (0x80 for first hard disk)
; CH = Cylinder (lower 8 bits of 10-bit number)
; CL = Sector (bits 0-5) and Cylinder bits 8-9 (bits 6-7)
; DH = Head
; ES:BX = Buffer Address
MOV AH, 0x02 ; Function 0x02: Read Sectors
MOV AL, 0x01 ; Number of sectors to read (1)
MOV DL, 0x80 ; Drive 0x80 (first HDD)
MOV CH, 0x00 ; Cylinder 0
MOV CL, 0x02 ; Sector 2 (Sector numbers are 1-based)
MOV DH, 0x00 ; Head 0
MOV BX, 0x7E00 ; Buffer at 0x7E00 (just after bootloader)
MOV ES, BX
XOR BX, BX ; Clear BX (Offset 0x0000)
INT 0x13 ; Call BIOS Interrupt
JC disk_error ; Jump if carry flag set (error)
disk_error:
; Handle error
How Senior Engineers Fix It
Senior engineers address the confusion between hardware geometry and logical file structures:
- Isolate Hardware Layers: They treat the BIOS interrupts (or AHCI/SATA drivers) strictly as a block device interface. The disk is viewed simply as an array of sectors.
- Implement a Proper Superblock: Instead of a BPB, they create a custom Superblock or Volume Header located at a fixed offset (usually Sector 0 or 1). This superblock contains the filesystem’s specific metadata (magic numbers, block size, inode count).
- Dynamic Geometry Handling: When writing a custom driver, they do not hardcode the Bytes Per Sector. They query the BIOS or hardware controller (via INT 0x13 function 0x08 or ATA Identify) to retrieve the physical sector size and alignment.
- Compatibility Shims: If the goal is compatibility with existing systems, they generate a standard BPB (e.g., for FAT32) that resides in the first sector but is ignored by their custom driver, allowing standard tools to mount the disk while their custom OS uses the extended data structures.
Why Juniors Miss It
Junior engineers often struggle with this distinction due to historical context and documentation overlap:
- Legacy Documentation: Many older programming tutorials (e.g., DOS assembly) discuss the BPB and disk interrupts in close proximity. Juniors often assume the interrupt reads the BPB to determine how to read the disk.
- “Chicken and Egg” Logic: They understand that the OS needs the BPB to read files, but fail to realize that the hardware layer (BIOS) is distinct from the software layer (OS/Filesystem).
- Over-reliance on “Magic” Parameters: Juniors often hardcode sector sizes (assuming 512 bytes) without querying the drive. While this works for floppy disks and older hard drives, it breaks on modern Advanced Format drives (4K physical sectors) where the BIOS handles the translation, but the software must be aware of the logical geometry provided by the BIOS.
- Confusion of “Parameter”: They interpret “BIOS Parameter Block” as a system configuration parameter required by the BIOS, rather than a filesystem configuration parameter required by the OS.