Archives
- October 2025
- September 2025
- August 2025
- July 2025
- June 2025
- May 2025
- April 2025
- March 2025
- February 2025
- January 2025
- December 2024
- November 2024
- October 2024
- September 2024
- August 2024
- July 2024
- June 2024
- May 2024
- April 2024
- March 2024
- February 2024
- January 2024
- October 2023
- September 2023
- August 2023
- July 2023
- June 2023
- May 2023
- April 2023
- March 2023
- January 2023
- December 2022
- November 2022
- October 2022
- September 2022
- July 2022
- June 2022
- May 2022
- April 2022
- March 2022
- February 2022
- January 2022
- December 2021
- November 2021
- October 2021
- September 2021
- August 2021
- July 2021
- June 2021
- May 2021
- April 2021
- March 2021
- February 2021
- January 2021
- December 2020
- November 2020
- October 2020
- September 2020
- August 2020
- July 2020
- June 2020
- May 2020
- April 2020
- March 2020
- February 2020
- January 2020
- December 2019
- November 2019
- October 2019
- September 2019
- August 2019
- July 2019
- June 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019
- December 2018
- November 2018
- October 2018
- August 2018
- July 2018
- June 2018
- May 2018
- April 2018
- March 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- December 2016
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- May 2016
- April 2016
- March 2016
- February 2016
- January 2016
- December 2015
- November 2015
- October 2015
- September 2015
- August 2015
- July 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- November 2014
- October 2014
- September 2014
- August 2014
- July 2014
- June 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013
- October 2013
- September 2013
- August 2013
- July 2013
- June 2013
- May 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- November 2012
- October 2012
- September 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- January 2011
- November 2010
- October 2010
- August 2010
- July 2010
DOS boot sector, BPB, and the media descriptor byte
All DOS programmers know that DOS storage media (floppies, fixed disks, even RAM drives) have a BPB (BIOS Parameter Block) which describes the basic layout of the storage medium. All DOS programmers also know that every DOS disk contains a boot sector with a 0x55, 0xAA signature in the last two bytes and the BPB stored at offset 3 and starting with an 8-byte OEM identifier. Sadly, it’s not true. There are DOS disks with no signature in the boot sector and no BPB stored in the boot sector. Even when there is a BPB, it’s not necessarily correct.
The basic problem with BPBs is that they were only introduced in DOS 2.0; previous versions of DOS did not use the concept at all. It’s easy to see why: DOS 1.0 only supported a single storage medium format (a single-sided 51⁄4” floppy with 40 tracks and 8 sector per track, 160KB total capacity). There was no real need to distinguish between various formats, although there was a way to do so through the media descriptor byte in the FAT.
DOS 1.1 was shipped with updated PCs that had double-sided floppy drives. An additional format utilizing both sides was supported, with 320KB total capacity. The media descriptor byte was used to distinguish between the single-sided and double-sided formats.
When DOS 2.0 was shipped with the PC/XT, additional floppy formats with 9 sectors per track (180KB and 360KB) were introduced. The media descriptor byte could still be used to distinguish between 1/2 sides and 8/9 sectors per track. But the XT also supported fixed disks, and the media descriptor byte was woefully inadequate for describing fixed disk formats.
DOS 2.0 therefore created the concept of a BIOS Parameter Block—or BPB—which contained basic disk geometry information. It was stored in the disk’s boot sector. There was just one problem—none of the existing DOS 1.x disks contained any BPB.
Microsoft’s solution was to build the BPB on the fly. For fixed disks there was no problem; DOS 1.x could not work with them, hence there was no backwards compatibility to worry about. For floppies, only two BPB-less formats existed and were easy to distinguish from each other by the media descriptor byte. The upshot was that for fixed disks, the BPB had to be always correct, but for floppies, it was not always used.
When formatting disks, DOS 2.x and later always wrote the BPB, but the BPB was not always used when accessing floppies. This inconsistency led to an embarrassing bug: DOS versions starting with 2.0 and ending with 3.1 wrote incorrect BPBs in certain cases. I was recently bitten by this bug when working with a single-sided floppy formatted by DOS 2.0 (in a virtual machine, of course). The BPB claimed the disk used two sectors per cluster, but in reality it was just one. Any software which trusts the BPB is not going to work.
When adding 31⁄2” floppy support, Microsoft tried to use the BPBs whenever available (instead of the media descriptor byte which was no longer adequate even for floppies), the bug became obvious. Microsoft’s solution was a classic hack: use the OEM ID signature (which in theory was purely informational and might contain any data) and check for DOS versions older than 3.2. For old versions, fix up the BPB with presumably correct data. For newer versions, use the BPB as it exists on the disk. The solution worked since the PC-DOS and MS-DOS wrote OEM ID signatures containing the DOS version. Disks formatted by third party software hopefully had correct BPBs.
Years later, Microsoft forgot about how all that stuff had worked. Windows 9x reused the OEM ID signature as a hash and destroyed the original OEM identifier. In theory, a user might have a disk with an unusual format but a valid BPB, recognized as such by Windows. Then Windows would destroy the OEM ID and would no longer be able to access the data on the disk. Very clever!
To my knowledge, the relationship between the media descriptor bytes and BPBs was never documented by Microsoft, and the exact algorithms for building BPBs were not documented either. That led to third party software often getting things subtly wrong. Eventually Microsoft became the victim of its own design blunders, as if attempting to prove that quick hacks can in the long run cause more problems than they solve.
One Response to DOS boot sector, BPB, and the media descriptor byte
Ha, this triggers memories..
I can add a twist to this.
Long time ago a friend of mine an I built a PC-like computer, XT compatible, and with some mumbo-jumbo (that is a long story on itself) we got it to work with high density disks (1.2M) as well.
To support that we implemented the AT like BIOS calls (the set format, etc.) in a TSR (we could burn new ROMs, but I guess we took some shortcuts).
Anyway, one day, some disks started to misbehave, a DIR would show happy faces, etc. Same disks worked just fine on similar computers (without the AT tainting).
It turned out a boot virus (I think it was named Michelangelo) infected the disks and corrupted the BPBs as well since it didn’t care.
Our conclusion was that on regular XT computers MS-DOS was falling back to the descriptor from the first FAT sector, whereas on our computer it chose to obey the BPB.
This site uses Akismet to reduce spam. Learn how your comment data is processed.