hi,
I am working on a fat16 bootloader, but i am coming across a strange off-by-one error. Ill describe the background
I am making an OS for USB sticks, where they have an MBR with a FAT16 partition.
The MBR code for the bootloader works fine, but when i try to lookup STARTUP.SYS the FAT16 loader cannot find it.
I know that the location of the root directory (LBA) is partition_start + reserved_sectors + (number_of_fats * sectors_per_fat). This should be sector 490 in my case, as the partition starts at LBA 1, there is a reserved sector for the fat boot record, there are 2 FATS with 244 sectors each.
However, when i mount the image in linux (mount -o loop -t vfat image mnt) and create a file STARTUP.SYS, and examine the image, i find that the root directory entry has been written to sector 489 instead, which should be the last sector of the second FAT.
This is weird, as I have verified that sector 0 is the MBR, 1 is the FAT boot record, and 2 is the first sector of the first FAT. But 489 is the root directory's start, instead of 490. I assumed this was a mistake in conversions between LBA and CHS, but I examined the image and it isn't. Linux seems to be writing to the sector before the one it should. Is this a bug or have I gone wrong somewhere?
Thanks
Linux FAT16 off-by-one
Re: Linux FAT16 off-by-one
Maybe it has to do that FAT filesystems take sectors as relative from the start of the partition, and thus is leaving the MBR LBA 0 out, so it is equal to 489 relative+MBR == 490.
That is if I remember correctly.
That is if I remember correctly.
YouTube:
http://youtube.com/@AltComp126
My x86 OS/software:
https://sourceforge.net/projects/api-simple-completa/
Donate to get more food/programming resources/computers:
https://www.paypal.com/donate/?hosted_b ... QS2YTW3V64
http://youtube.com/@AltComp126
My x86 OS/software:
https://sourceforge.net/projects/api-simple-completa/
Donate to get more food/programming resources/computers:
https://www.paypal.com/donate/?hosted_b ... QS2YTW3V64
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: Linux FAT16 off-by-one
Have you tried this?
Code: Select all
mount -t vfat -o loop,offset=512 image mnt
Re: Linux FAT16 off-by-one
@pcmattman aah that works perfectly, thanks a lot I guess mount does confuse its offsets if you leave the MBR in after all.