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?
Partition detection?
Re: Partition detection?
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.
If a trainstation is where trains stop, what is a workstation ?
- Owen
- Member
- Posts: 1700
- Joined: Fri Jun 13, 2008 3:21 pm
- Location: Cambridge, United Kingdom
- Contact:
Re: Partition detection?
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!
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?
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.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.
Re: Partition detection?
"For historical reasons..."Owen wrote:Final conclusion: MBR is an absolute mess!
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?
Every good solution is obvious once you've found it.
Re: Partition detection?
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".Solar wrote:Whenever I read that sentence I feel like going somewhere with a chainsaw under my arm...
That just doesn't work.
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.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?
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?
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.
PT fields are not used for FS type detection.
If you have seen bad English in my words, tell me what's wrong, please.
- Owen
- Member
- Posts: 1700
- Joined: Fri Jun 13, 2008 3:21 pm
- Location: Cambridge, United Kingdom
- Contact:
Re: Partition detection?
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)
- thepowersgang
- Member
- Posts: 734
- Joined: Tue Dec 25, 2007 6:03 am
- Libera.chat IRC: thePowersGang
- Location: Perth, Western Australia
- Contact:
Re: Partition detection?
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)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc