Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
I decided it was time to implement the FAT16 filesystem in my OS. I have setup the BPB successfully.
I dd my bootsector (followed by 999.5KiB of zeroes) to a usb flash drive, then set the word directly after the bootsector (first FAT entry) to 0xFFF0 and the word at the second FAT entry to 0xFFFF (end of file). The first part of the flash drive then looks like this:
Then I mount the device in ubuntu, copy my stage 2 "STAGE2.BIN", which is 457 bytes in size, to the drive. This results in the third entry of the FAT being set to 0xFFF0???? What is going on here?
db 'SkuxOS',0x00,0x00 ;OEM identifier
bpbBytesPerSector dw 512 ;bytes per sector
bpbSectorsPerCluster db 1 ;sectors per cluster
bpbReservedSectors dw 1 ;number of reserved sectors
bpbNumberOfFATS db 2 ;number of FATs
bpbRootDirectoryEntries dw 512 ;number of root directory entries
dw 2048 ;number of sectors (1 MiB disk = 512*2048 bytes)
db 0xF0 ;media descriptor
bpbSectorsPerFAT dw 8 ;sectors per FAT
dw 0 ;sectors per track
dw 0 ;number of heads
dd 0 ;hidden sectors
dd 0 ;number of sectors (only used if disk size > 32MiB)
db 0x80 ;drive number
db 0 ;reserved
db 0x29 ;extended boot signature
dd 0x5301A70F ;serial number
db 'SkuxOS Disk' ;volume label
db 'FAT16', 0x00, 0x00, 0x00
Why are you expecting that a medium smaller than a floppy can be sanely formatted as FAT16?
You're violating the specification for FAT. Expect breakage.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Combuster wrote:Why are you expecting that a medium smaller than a floppy can be sanely formatted as FAT16?
You're violating the specification for FAT. Expect breakage.
Ah, thanks.
egos wrote:Combuster is right. Ubuntu thinks that it's FAT12.
Wow, an established system such as linux doesn't even have a decent FAT driver? Assuming its FAT12... honestly!!! Surely it's not that hard to check the file system type from the BPB.
egos wrote:Combuster is right. Ubuntu thinks that it's FAT12.
Wow, an established system such as linux doesn't even have a decent FAT driver? Assuming its FAT12... honestly!!! Surely it's not that hard to check the file system type from the BPB.
The type of FAT is determined by the total number of data clusters available, in your case this is 1999, which implies FAT12. The BS_FilSysType field in the BPB has no bearing on what type of filesystem is actually in the partition. See the wiki page or the FAT32 docs from Microsoft for more information.
BMW:
Microsoft EFI FAT32 File System Specification
In the following example, when it says <, it does not mean <=. Note also that the numbers are correct. The first number for FAT12 is 4085; the second number for FAT16 is 65525. These numbers and the ‘<’ signs are not wrong.
If(CountofClusters < 4085) {
/* Volume is FAT12 */
} else if(CountofClusters < 65525) {
/* Volume is FAT16 */
} else {
/* Volume is FAT32 */
}
This is the one and only way that FAT type is determined. There is no such thing as a FAT12 volume that has more than 4084 clusters. There is no such thing as a FAT16 volume that has less than 4085 clusters or more than 65,524 clusters.
HugeCode wrote:BMW:
Microsoft EFI FAT32 File System Specification
In the following example, when it says <, it does not mean <=. Note also that the numbers are correct. The first number for FAT12 is 4085; the second number for FAT16 is 65525. These numbers and the ‘<’ signs are not wrong.
If(CountofClusters < 4085) {
/* Volume is FAT12 */
} else if(CountofClusters < 65525) {
/* Volume is FAT16 */
} else {
/* Volume is FAT32 */
}
This is the one and only way that FAT type is determined. There is no such thing as a FAT12 volume that has more than 4084 clusters. There is no such thing as a FAT16 volume that has less than 4085 clusters or more than 65,524 clusters.
Oh, thanks. I have made the volume 16MB and it seems to have fixed the problem.... except for Ubuntu assuming there was only 1 FAT when I put 2 in the BPB. Or is this the same sort of idea, does the number of FATS depend on the type of media? E.g. 2 FATS for floppy 1 for hard disk?
HugeCode wrote:Check the specification (2000, 2005).
Ahh, thank you so much. I was going off some tutorials (not always a good idea). I guess I should have looked for that myself, but thanks anyway. That has cleared up a few things.