In my OS I now have a few filesystems implemented, each has a driver which can be loaded dynamically. Right now I'm having a problem deciding which driver to load when the user inserts a disk. For most disks, this is fairly straightforward, check the ID byte from the partition table. However floppies do not have a partition table, how can the OS know to use the correct driver for how the disk is formatted?
For example, when a user inserts an ext2 disk how would the OS know to load that driver instead of the one for FAT?
Detecting the filesystem of a floppy
Detecting the filesystem of a floppy
Last edited by PgrAm on Sun Aug 29, 2021 7:48 pm, edited 2 times in total.
Re: Detecting the format of a floppy
IIRC you can't easily know the size of a floppy. You could probably try to read tracks/sectors at the limit of different sizes, in order to probe the size, but I'm not certain this would be reliable. Typically when the disks are formatted a filesystem is also created, and the filesystem header has information on the disk size. In DOS, size info was stored in the BPB inside the boot sector (see: https://en.wikipedia.org/wiki/BIOS_parameter_block).PgrAm wrote:In my OS I now have a few filesystems implemented, each has a driver which can be loaded dynamically. Right now I'm having a problem deciding which driver to load when the user inserts a disk. For most disks, this is fairly straightforward, check the ID byte from the partition table. However floppies do not have a partition table, how can the OS know to use the correct driver for how the disk is formatted?
Why would you use a different driver for different sized disks, though? A single driver should be able to handle disks of different sizes.
(And, uh, why bother with floppy disks... )
Re: Detecting the format of a floppy
When I said 'format' I really meant to say filesystem, meaning fat, ext2, etc. Sorry. I'll try to update the question.
The same driver deals with different sized disks, but a different driver is needed when the filesystem is different.
The same driver deals with different sized disks, but a different driver is needed when the filesystem is different.
Re: Detecting the format of a floppy
No problem, sorry for my confusion. Typically, a file system format has some kind of "magic" marker - a particular value or sequence of bytes, at a particular offset from the start of the disk. Eg for ext2, seePgrAm wrote:When I said 'format' I really meant to say filesystem, meaning fat, ext2, etc. Sorry. I'll try to update the question.
The same driver deals with different sized disks, but a different driver is needed when the filesystem is different.
https://www.nongnu.org/ext2-doc/ext2.html#superblock - the "magic number" in the superblock allows you to identify an ext2 filesystem. (Look for the bytes 0x53 0xEF at offset 1024+56 on the disk/partition).
So, either, you have a central resolver which looks for various of these markers, and dispatches the appropriate driver; or, you poll each driver in turn to see if it can recognize the filesystem on the device. Each method has particular benefits; for example, polling each driver in turn means you can keep the logic for identifying the filesystem within the driver, but it means you need to have drivers already loaded.
-
- Member
- Posts: 5567
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Detecting the filesystem of a floppy
Automatically detecting the filesystem is easy: just try all of them. Whichever one works is the right one.
Automatically detecting the format... might not be easy. If the filesystem is FAT, the BPB tells you the format. If the filesystem is something else, good luck!
Automatically detecting the format... might not be easy. If the filesystem is FAT, the BPB tells you the format. If the filesystem is something else, good luck!
Re: Detecting the filesystem of a floppy
Ok so I think I'll just check each driver to see if it knows what to do with the disk. In the case of a partition table I can just try the listed one first.
So for example for FAT right now I'm checking for the presence of the jmp/nop instructions in the first sector, as this seems to be the only way to identify whether what I'm reading is a BPB
So for example for FAT right now I'm checking for the presence of the jmp/nop instructions in the first sector, as this seems to be the only way to identify whether what I'm reading is a BPB