Page 1 of 1
Partition detection?
Posted: Fri Jul 23, 2010 6:30 am
by Candy
How do you detect what filesystem a partition is formatted in? What things do you take into account?
Why I'm asking:
I've got partition table reading in place, which now can tell me if something is type 0x06 (FAT16) or 0x0C (FAT32). For these two it's slightly oversufficient, as 0x04 and 0x0B are treated the exact same way as 0x06 and 0x0C - it's a FAT file system. If it says 0x07 however, that's NTFS, HPFS, HFS or HFS+. If it says 0x83, it could be just about anything. And then there's the option that somebody messed up their system config and has a 0x0C partition with an ext2 file system.
How do you determine what filesystem driver to load for what partition?
Re: Partition detection?
Posted: Fri Jul 23, 2010 7:16 am
by gerryg400
I guess there are little tricks to identify each fs type. For example, ext2/3/4 have a magic number in the superblock. I'm sure each fs has some sort of identifying signature.
Re: Partition detection?
Posted: Fri Jul 23, 2010 7:23 am
by Owen
Start up the FS driver and have it verify that you've detected the partition correctly. For 0x7, start an "OS/2 IFS partition" driver, which distinguishes based upon bytes 3-11 of the partition which type it is (By the way - 0x07 is a great place to cram new partition types into the MBR!)
This still leaves some problems - 0x86 could be either Linux swap or an old Solaris slice table. Which is problematic, because IIRC Linux Swap has no headers! (The other reason this is problematic is that many livecds automatically swapon any 0x86 partitions...)
Final conclusion: MBR is an absolute mess!
Re: Partition detection?
Posted: Fri Jul 23, 2010 7:36 am
by Candy
gerryg400 wrote:I guess there are little tricks to identify each fs type. For example, ext2/3/4 have a magic number in the superblock. I'm sure each fs has some sort of identifying signature.
So that's in general, assume the data is correct and move that FS to the head of the probe list. Otherwise, probe them all.
Re: Partition detection?
Posted: Fri Jul 23, 2010 7:44 am
by Solar
Owen wrote:Final conclusion: MBR is an absolute mess!
"For historical reasons..."
Whenever I read
that sentence I feel like going somewhere with a chainsaw under my arm...
On the other hand: Why has your OS to auto-detect all those file systems? Do you actually support booting off all of them? Personally, I would require my OS to be located on a selection of file systems (like, 0x83, ext2 or ext3 - you could expand the list later on), boot from there, and have the
user tell me which partition is in which format. He knows, doesn't he?
Re: Partition detection?
Posted: Fri Jul 23, 2010 7:59 am
by Candy
Solar wrote:Whenever I read
that sentence I feel like going somewhere with a chainsaw under my arm...
Same here. Especially if there's nobody to explain why it became this mess. The MBR wasn't such a bad idea but lacked central organisation - and had two pigheaded OSes which misused it. Microsoft OSes which took all to mean some variant of FAT, and then took 7 to mean anything but FAT. Linux which took 0x83 to mean "something we have to look at".
That just doesn't work.
On the other hand: Why has your OS to auto-detect all those file systems? Do you actually support booting off all of them? Personally, I would require my OS to be located on a selection of file systems (like, 0x83, ext2 or ext3 - you could expand the list later on), boot from there, and have the user tell me which partition is in which format. He knows, doesn't he?
Well... I'd like my users to not have to enter filesystems manually, not in the last case because configuration kept separately from the volume is going to desync if something changes without your OS knowing it. Add a new disk to your system and Linux may miss half the disks.
What should go where other than the root is predefined - your root contains your OS & programs. Part of the abstraction, I'll call it.
Re: Partition detection?
Posted: Fri Jul 23, 2010 9:21 am
by egos
FS association with device (kernel works with partitions as virtual devices) occures inside "mount" function. VFS subsystem transfers control to FS driver that had register specified FS. The driver checks that device contains the FS structure. Only if it's true the function will have successful result. If to specify NULL instead FS name kernel will search FS by calling every FS handler and analysing its result.
PT fields are not used for FS type detection.
Re: Partition detection?
Posted: Fri Jul 23, 2010 11:50 am
by Owen
My personal strategy would be to use the MBR ID as a first guess - after all, its probably right! For GPT I would use that strategy too (In fact doubly so: GPT doesn't have the collision issues)
Re: Partition detection?
Posted: Fri Jul 23, 2010 7:38 pm
by thepowersgang
Just GPT has the problem that the IDs don't usually denote a filesystem type, they denote what it is used for (in most cases)