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.
I'm at a stage where I'm reading from the MBR to get partition information (I'm working with FAT). This is successful so far, but I'm wondering what the best way to store this information is.
I can easily create a structure that stores information such as:
Whether the partition is active
The system ID
Starting sector
Total sectors
Total size in MB
However, if there are potentially four primary partitions per hard disk, and there are potentially four ATA disks attached, there is a possible 16 structures I would need to create (not counting extended partitions as yet).
That's a lot of structures to create statically, especially since it's a rare (yet possible) case for there to be 16 primary partitions.
Would an option be to just create a structure with 16 entries (one for each potential partition), and each entry represents whether that partition exists?
Then I just read the MBR each time it needs to be accessed to find the start, end, etc.
This would save creating multiple structures, but would be slower I guess.
You can malloc a structure for each partition as you discover it. You need to be able to find those structures so you should keep a linked list in each device structure that holds its partitions.
In addition each partition structure should be registered with your name service so that the user can find the partitions (like /dev/sda1) and mount them. The filesystem mounted on a partition should also have a pointer to the partition. And of course files have pointers to their filesystem. This means that whenever a file is operated on it is a simple matter to follow the pointers and find the fs, partition and untimately the device that needs to be read.
If a trainstation is where trains stop, what is a workstation ?
My partition manager registers every partition as virtual device providing to the kernel the pointers to device data structure and device handler. When kernel calls the handler it transfer back a pointer to device data structure associated with this device. To connect with whole device the structure holds the link to it. It's a virtual device index (handle). To well translate requests to whole device the structure holds partition location and size too.
Storage device can have not only primary partitions. I have support for maximum 255 partitions on each MBR-partitioned device.
If you have seen bad English in my words, tell me what's wrong, please.