OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 5:38 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Detecting the filesystem of a floppy
PostPosted: Sun Aug 29, 2021 3:59 pm 
Offline

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

Top
 Profile  
 
 Post subject: Re: Detecting the format of a floppy
PostPosted: Sun Aug 29, 2021 5:13 pm 
Offline
Member
Member

Joined: Mon Jul 05, 2021 6:57 pm
Posts: 118
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: )


Top
 Profile  
 
 Post subject: Re: Detecting the format of a floppy
PostPosted: Sun Aug 29, 2021 7:45 pm 
Offline

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


Top
 Profile  
 
 Post subject: Re: Detecting the format of a floppy
PostPosted: Sun Aug 29, 2021 8:30 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: Detecting the filesystem of a floppy
PostPosted: Sun Aug 29, 2021 9:02 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
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!


Top
 Profile  
 
 Post subject: Re: Detecting the filesystem of a floppy
PostPosted: Mon Aug 30, 2021 3:53 pm 
Offline

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 80 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group