Detecting the filesystem of a floppy

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.
Post Reply
PgrAm
Posts: 20
Joined: Fri Sep 26, 2014 12:19 pm

Detecting the filesystem of a floppy

Post by PgrAm »

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?
Last edited by PgrAm on Sun Aug 29, 2021 7:48 pm, edited 2 times in total.
davmac314
Member
Member
Posts: 121
Joined: Mon Jul 05, 2021 6:57 pm

Re: Detecting the format of a floppy

Post by davmac314 »

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?
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).

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... :lol: )
PgrAm
Posts: 20
Joined: Fri Sep 26, 2014 12:19 pm

Re: Detecting the format of a floppy

Post by PgrAm »

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.
davmac314
Member
Member
Posts: 121
Joined: Mon Jul 05, 2021 6:57 pm

Re: Detecting the format of a floppy

Post by davmac314 »

PgrAm 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.
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, see
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.
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Detecting the filesystem of a floppy

Post by Octocontrabass »

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!
PgrAm
Posts: 20
Joined: Fri Sep 26, 2014 12:19 pm

Re: Detecting the filesystem of a floppy

Post by PgrAm »

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
Post Reply