Page 1 of 1
How to "actually" implement the filesystem driver ?
Posted: Sun Oct 18, 2015 11:20 pm
by snasim2002
I have read the FAT article on the wiki, and I understand the datastructures of FAT. But my question is, how can I "READ" the root disk ?? I do have a function to switch to 16bit real mode, execute real mode stuff, and return to protected mode; but I think reading the disk through this method would be quite inefficient.
I read about an initrd. What is it ?? how can it help me ??
PS: I don't have paging enabled.
Re: How to "actually" implement the filesystem driver ?
Posted: Sun Oct 18, 2015 11:25 pm
by Brendan
Hi,
snasim2002 wrote:I have read the FAT article on the wiki, and I understand the datastructures of FAT. But my question is, how can I "READ" the root disk ?? I do have a function to switch to 16bit real mode, execute real mode stuff, and return to protected mode; but I think reading the disk through this method would be quite inefficient.
I read about an initrd. What is it ?? how can it help me ??
PS: I don't have paging enabled.
An OS is built in layers. For example, it's reasonable to have the following layers:
- Storage device drivers
- (optional) A layer to map logical disks to physical disks (e.g. software RAID)
- File system/s
- Virtual file system
The storage device driver/s provide an abstraction interface (e.g. to read/write blocks) that the next higher layer relies on; and uses whatever interface the hardware itself provides (e.g. AHCI, ATAI/ATAPI, USB mass storage driver, ...).
Cheers,
Brendan
Re: How to "actually" implement the filesystem driver ?
Posted: Mon Oct 19, 2015 5:40 am
by embryo2
snasim2002 wrote:I have read the FAT article on the wiki, and I understand the datastructures of FAT. But my question is, how can I "READ" the root disk ?? I do have a function to switch to 16bit real mode, execute real mode stuff, and return to protected mode; but I think reading the disk through this method would be quite inefficient.
After reading about FAT the next thing you have to read is HDD hardware description (
you can start here). It is very useful to understand how it works if you want to write an efficient HDD driver. But performance often isn't the main goal of beginner OSdevers, so your real mode switch can work as magic just because it relieves you from reading about storage hardware. You just should to decide what do you really want - to read from disk quickly (in terms of your time spent) or to read from disk efficiently. First option leads you to the switch and the second introduces you into the world of tricky hardware interfaces.
Re: How to "actually" implement the filesystem driver ?
Posted: Tue Oct 20, 2015 2:49 am
by snasim2002
I think you are right. I will concentrate on a disk driver later on, for now, I should just stick to the "switch".
Re: How to "actually" implement the filesystem driver ?
Posted: Tue Oct 20, 2015 3:06 am
by iansjack
Be sure that when switching to protected mode and back to real mode you preserve everything that will allow the real mode interrupts to run correctly.
It's actually very simple to write a basic IDE disk driver.
Re: How to "actually" implement the filesystem driver ?
Posted: Tue Oct 20, 2015 3:55 am
by Ready4Dis
It's just as simple to write a driver for a PATA/SATA drive as it is to write a pmode->real mode->pmode switch. After you get done dealing with loading the stub into physical ram at a specific location, handling all the copying (are you going to do one sector, or copy to upper memory, or?), making sure you don't corrupt anything, etc, you could have already finished a real driver and not had to switch back and forth to real mode losing any interrupts in the mean time (you know, like completely halting multitasking while in real mode). I'm not saying it's useless to be able to call the bios, but what does he do once he gets into Long mode? This is one of those that it's just as simple to write properly the first time.
Re: How to "actually" implement the filesystem driver ?
Posted: Tue Oct 20, 2015 1:15 pm
by embryo2
iansjack wrote:It's actually very simple to write a basic IDE disk driver.
If it's about something efficient then simple part becomes an interesting quest for a beginner. Things like DMA and different storage types can be skipped for some time and high level API to access disk services can be tested and elaborated using simple "switch" based approach.
But yes, if a person wishes to create a good OS then there's no way without a good driver.
Re: How to "actually" implement the filesystem driver ?
Posted: Wed Oct 21, 2015 9:59 am
by snasim2002
And what about a cdrom driver ? Is it easier to implement than SATA ? Also, what FS are available for CDs and DVDs, except ISO 9660 ?
Re: How to "actually" implement the filesystem driver ?
Posted: Wed Oct 21, 2015 12:30 pm
by SpyderTL
The easiest way to communicate with a hard drive or CD rom drive is through the IDE controller. You will need to learn how to control the IDE controller using IN and OUT commands. Once you have this figured out, you can tell the IDE controller to send ATA commands to the hard drive, and send ATAPI commands to the CD-ROM drive. ATAPI simply allows you to send SCSI commands using the IDE controller.
Most CD-ROM discs use ISO 9660 as a file system, and most DVD and BluRay discs use the UDF file system. Neither of these file systems are particularly difficult to read. They are similar in structure, but not identical.
And, to answer your original question, and "initrd" is a file that is loaded into memory, that can then be used as a RAM disk. This is helpful during boot up because you may not have all of your device drivers loaded.