Hi everyone!
I've got the following things on my hard disk:
1. Custom master boot record.
2. A FAT16 partition.
3. Custom bootsector on partition.
How can partition bootsector get the partition's start sector number (LBA), I've got two variants so far:
1. Read the MBR again, look up for bootable partition, and find the sector number (If no MBR is present (Example: some USB ThumbDrives) bootsector fails)
2. or MBR should pass the sector number as parameter to the bootsector (If no custom MBR is present the parameter will be NULL, so the bootsector fails here too)
Which one is whould be better? Or any other choice will be appreciated. Thanks.
Partition's start sector reading MBR
-
- Member
- Posts: 134
- Joined: Thu Aug 18, 2005 11:00 pm
- Location: Sol. Earth. Europe. Romania. Bucuresti
- Contact:
Re: Partition's start sector reading MBR
If you have your own custom MBR and your own custom BS then you can do as you please. The only limitation is what the BIOS does with your MBR.Archil wrote:Hi everyone!
I've got the following things on my hard disk:
1. Custom master boot record.
2. A FAT16 partition.
3. Custom bootsector on partition.
However in order to be consistent usually the MBR's and BS's do follow the same guidelines as the BIOS.
AFAIK the BIOS will provide you with the load drive number in DL register. You need this in order to read the MBR again from the BS if needed.
However one should never assume that other people will be willing to use your custom MBR.
It is very possible that the PC has a WinXP/Vista/Win7 or GRUB or a "boot manager" MBR already installed and you must obey their "rules" and not your rules if you intend to "coexist peacefully".
Again AFAIK the Microsoft MBR sends the address of the selected bootable partition in SI register to the BS. However I am unsure if this is a standard for other MBR's.
Reading the MBR again and parsing the partition table until you find the first bootable partition and using the LBA (or CHS) values from there is the only "safe" way.
Ambition is a lame excuse for the ones not brave enough to be lazy; Solar_OS http://www.oby.ro/os/
Re: Partition's start sector reading MBR
Generally, you want a customized MBR to still work with other OSes. To work with Windoze, as said above, you need to keep a valid copy of the 16 byte boot partition record stored somewhere in memory, and the MBR must point DS:SI at it when control is transferred to the boosector. This is usually a good enough "standard" to get the bootsector to work. It causes the kernel to have to play annoying guessing games later during the boot process, however. (And limits you to only booting from devices that the BIOS supports as boot devices.)
Re: Partition's start sector reading MBR
I've coded a fat bootsector parsing MBR, so I'm continuing to use it. For guid partition tables i'll have to write another bootsector I guess. Well, thanks for your suggestions!
Re: Partition's start sector reading MBR
First of all, many boot sectors contain info about self position. For example, FAT/NTFS boot sectors have the field BPB_HiddSec. Repeated detection of boot volume may be dangerous, because not all MBRs (boot managers) give control exactly to the partition, which has BOOTABLE flag in PT in active state (0x80). For example, some my MBRs give to user the possibility to choose the boot volume other than default. We can use ds:si pointer too, but in practice nobody does this. It could develop own extension, which will be transparent for other systems. For example, one my MBR additionally gives to boot loader the boot volume number in dh register (1-4 - primary, 5-255 - additional, 0 - default) and sets the byte cell addressed by ds:si with 0x55 value as an extension signature for detection (instead of bootable flag). All my boot loaders know about this.
If you have seen bad English in my words, tell me what's wrong, please.
Re: Partition's start sector reading MBR
I found HiddenSectors field quite useful, although neither http://en.wikipedia.org/wiki/File_Allocation_Table nor http://http://wiki.osdev.org/FAT provide full definition about what the field should be used for. Hopefully I found some sources on Google like that:
"Hidden Sectors: This is the number of sectors on the physical disk preceding the start of the volume. (that is, before the boot sector itself) It is used during the boot sequence in order to calculate the absolute offset to the root directory and data areas." - http://support.microsoft.com/kb/140418
"Hidden Sectors: This is the number of sectors on the physical disk preceding the start of the volume. (that is, before the boot sector itself) It is used during the boot sequence in order to calculate the absolute offset to the root directory and data areas." - http://support.microsoft.com/kb/140418
Re: Partition's start sector reading MBR
Yes, that value is supposed to be the start LBA of the partition. However, it is only 32 bits (and is therefore already obsolete), and is not exactly trustworthy. It should be verified as being accurate before you use it.
Re: Partition's start sector reading MBR
Likewise you can say that FAT itself is obsolate, but I'm not talking about that. So what other things whould your OS do instead of reading that 32 bit HiddenSectors field? Yet I'm satisfied by my bootsector as it boots the system from both hard disk partitions and USB thumb drives the size of which is not so big to fit in 32 bits.bewing wrote:However, it is only 32 bits (and is therefore already obsolete), and is not exactly trustworthy. It should be verified as being accurate before you use it.