Might I make a suggestion. You need to be writing your OS with layers. Here is a (minimal) example, kernel only, no user-space.
Direct media access:
1. kernel app: read bytes 200d to 399d. Call media driver (DOS uses a DPB)
2. media driver: convert byte offset and length to media specs
3. media hardware driver: read all sectors needed, returning to media driver.
2. media driver: extract bytes needed
1. kernel app: buffer now filled with bytes 200d to 399d
Media access via file system:
1. kernel app: read bytes 200d to 399d. call media driver
2. media driver: open media for read access
3. file system: find file on media
4. file system: open file on filesystem
5. media hardware driver: read all sectors needed, returning to media driver.
4. media driver: extract bytes needed
3. file system: close file on filesystem
2. file system: return buffer filled
1. kernel app: buffer now filled with bytes 200d to 399d
This is a complete generic layer system, but you get the idea. if you place it in layers, your kernel app, and later your user-space app, will not care one bit what kind of media you are trying to read from. All it does is call the media driver. The media driver takes care of the rest. However, the media driver has no care what kind of file system is used. The file system takes care of the rest. etc. etc.
In your kernel, when you find a media device (hard drive), create a kernel structure for this media. This structure will describe the media, and has a driver pointer that the kernel may call. Then scan for partitions on the media. When found, there will be at least one, create a BPB (DOS calls it a BPB, BIOS Parameter Block) for this partition. This BPB will also have a file system driver pointer. Then detect the file system on the partition and place a valid file system driver pointer in that BPB.
KERNEL APP --> MEDIA STRUCTURE --> BPB --> FILE SYSTEM
The File system calls its parent (BPB) to do the reading (physical media access) which in turn calls its parent (MEDIA STRUCTURE) to extract the data which returns to the KERNEL APP.
Now you can have any type of media with any type of file system and the KERNEL APP couldn't care less what it was, knowing that it will either receive a valid buffer filled with valid data or an error code. Period.
All you have to do is write drivers for various media devices and file systems.
My kernel uses the following:
1. Every time a device is detected, a DEVICE_STRUCT is created. This structure has a general format for all devices with a pointer to specific device attributes. The DEVICE driver doesn't care about anything but the general format (about 100 bytes worth). Within this general format is a pointer to the specific device attributes and a driver for that specific device. The kernel then tries to determine what kind of device it is. If it is a PCI device, this is fairly simple.
2. The kernel then loads a driver for that device and lets the driver fill the remaining (specific device attributes) area with information. If the device is a media device, the driver then creates a BPB (again, a familiar term for the purpose of this post). The DEVICE_STRUCT->SPECIFIC_ATTRBS has a pointer to this BPB. The driver then tries to find out what type of file system is on the partition.
3. Once the driver finds a file system, it loads that file system driver (if not already loaded) and fills the BPB with more data including a pointer to this file system driver.
At this point, when the kernel needs to access the file system, a call to the DEVICE_STRUCT is made. The DEVICE_STRUCT then makes the call to the BPB which then makes the call to the file system. The kernel can make a call to any DEVICE using the exact same calling parameters, no matter the device type.
Again, this is a generic abstract of what you should really have, but I hope you get the idea.
Ben
http://www.fysnet.net/osdesign_book_series.htm