How to "actually" implement the filesystem driver ?

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.
Post Reply
snasim2002
Member
Member
Posts: 37
Joined: Sat Apr 11, 2015 9:37 am

How to "actually" implement the filesystem driver ?

Post 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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: How to "actually" implement the filesystem driver ?

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
embryo2
Member
Member
Posts: 397
Joined: Wed Jun 03, 2015 5:03 am

Re: How to "actually" implement the filesystem driver ?

Post 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.
My previous account (embryo) was accidentally deleted, so I have no chance but to use something new. But may be it was a good lesson about software reliability :)
snasim2002
Member
Member
Posts: 37
Joined: Sat Apr 11, 2015 9:37 am

Re: How to "actually" implement the filesystem driver ?

Post 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".
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to "actually" implement the filesystem driver ?

Post 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.
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Re: How to "actually" implement the filesystem driver ?

Post 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.
embryo2
Member
Member
Posts: 397
Joined: Wed Jun 03, 2015 5:03 am

Re: How to "actually" implement the filesystem driver ?

Post 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.
My previous account (embryo) was accidentally deleted, so I have no chance but to use something new. But may be it was a good lesson about software reliability :)
snasim2002
Member
Member
Posts: 37
Joined: Sat Apr 11, 2015 9:37 am

Re: How to "actually" implement the filesystem driver ?

Post 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 ?
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: How to "actually" implement the filesystem driver ?

Post 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.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Post Reply