Ways to implement partitions in drives
Posted: Mon Mar 29, 2021 7:07 pm
I'm implementing the filesystem in my operating system at the moment, and have been wondering what various ways people implement partitions within drives.
My filesystem implementation at the moment basically consists of several tables:
- A table of different types of physical drive, where each type contains function pointers for reading and writing sectors in that type of drive.
- A table of "filesystem descriptor" structs, which contain function pointers for manipulating a filesystem.
- A table of drives. Each drive has an index into the drive type table, and an index into the filesystem type table. Each drive also has a void pointer to store arbitrary metadata about that specific drive.
Now, I want the system to be able to handle partitioned drives, but I'm unsure of the best way to do this. What I'm thinking is that, for example if I have a physical drive called A, and it has two partitions which I'll call B and C, then I will have an entry in my drive table for A, and also one for B and one for C. For each drive I'll store a value in its metadata to represent the first sector to read from (so, and offset to add when reading or writing sectors), and for A that would be 0, to represent the whole drive. Then for each partition it would be mostly the same metadata except that the offset would be the beginning of the partition, and the sector count would be the amount of sectors in the partition.
I think this would work, but I'm interested to see how other people would go about doing this. Any ideas?
My filesystem implementation at the moment basically consists of several tables:
- A table of different types of physical drive, where each type contains function pointers for reading and writing sectors in that type of drive.
- A table of "filesystem descriptor" structs, which contain function pointers for manipulating a filesystem.
- A table of drives. Each drive has an index into the drive type table, and an index into the filesystem type table. Each drive also has a void pointer to store arbitrary metadata about that specific drive.
Now, I want the system to be able to handle partitioned drives, but I'm unsure of the best way to do this. What I'm thinking is that, for example if I have a physical drive called A, and it has two partitions which I'll call B and C, then I will have an entry in my drive table for A, and also one for B and one for C. For each drive I'll store a value in its metadata to represent the first sector to read from (so, and offset to add when reading or writing sectors), and for A that would be 0, to represent the whole drive. Then for each partition it would be mostly the same metadata except that the offset would be the beginning of the partition, and the sector count would be the amount of sectors in the partition.
I think this would work, but I'm interested to see how other people would go about doing this. Any ideas?