Hi,
I would like to use FAT32 in my OS. I tried formatting my flash disk, then put my bootloader (which omits the BPB structure) in appropriate place and in windows it seemed ok as long as the LBAStartingSector in partition table was set to 3fh where I found the BPB with FAT32 extended boot record and some little program (all produced by formatting tool including the value 3fh). When I copy-pasted this structure to other place and then changed the start of partition however made windows prompt me with "wanna format?" dialogue, so that is definitely wrong. Is there something not relocatable in BPB? To be honest I only read the description of fields I found as mandatory, but I was told except for information in extended boot record BPB is pretty needless structure.
Where can I put BPB?
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Where can I put BPB?
If you are using a partitioned USB device with a single FAT32 partition as you seem to do, there are several things that point to each other:
- The first sector must contain the partition table and the boot code. Windows and the bios will always start looking here and only here so you can't move it.
- The partition table must contain one partition with a valid start and size, the other partition entries should be zeroed.
- The first sector of that partition table will have to contain the BPB, and the FAT headers. They should be followed with by the FAT table, and the data portion should contain a directory listing for the root folder in the case of FAT32 (for FAT12/16, it is located immediately before the data area). If you simply move the partition, moving all the data in the partition is enough since all offsets are relative to either the start of the partition or relative to the start of the data area of the FAT filesystem. If you actually resize the partition, the BPB and FAT headers will have to change accordingly since they contain a copy of the size. If the length of the FAT tables in sectors changes, you'll either have to move the data part closer to the bootsector, or update all cluster offsets.
Technically, a FAT partition is never truly empty, so any resize operation requires filesystem-aware code to update sizes and offsets. Moving partitions does not require anything smart, but it does require that the entire partition contents is moved, and not just the superblock like what you seem to do.
- The first sector must contain the partition table and the boot code. Windows and the bios will always start looking here and only here so you can't move it.
- The partition table must contain one partition with a valid start and size, the other partition entries should be zeroed.
- The first sector of that partition table will have to contain the BPB, and the FAT headers. They should be followed with by the FAT table, and the data portion should contain a directory listing for the root folder in the case of FAT32 (for FAT12/16, it is located immediately before the data area). If you simply move the partition, moving all the data in the partition is enough since all offsets are relative to either the start of the partition or relative to the start of the data area of the FAT filesystem. If you actually resize the partition, the BPB and FAT headers will have to change accordingly since they contain a copy of the size. If the length of the FAT tables in sectors changes, you'll either have to move the data part closer to the bootsector, or update all cluster offsets.
Technically, a FAT partition is never truly empty, so any resize operation requires filesystem-aware code to update sizes and offsets. Moving partitions does not require anything smart, but it does require that the entire partition contents is moved, and not just the superblock like what you seem to do.
Re: Where can I put BPB?
It seems that you sliced the partition, but windows found that the partition contains no valid structure(eg. FATs mismatch or contain invalid chunk#, messed Root directory entry) - only the volume boot record is not sufficient.
Re: Where can I put BPB?
Uhuh yep that's exactly what it caused. I don't yet exactly know how I got there the entry 0x0 0x7fffffff 0x0 0x0 ... but windows are ok with it and now I have a simple working setting so I think I can handle it from now on. Anyway, thank you very much guys, no chance I would figure this out by myself.