How to implement a filesystem

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

Re: How to implement a filesystem

Post by iansjack »

User avatar
deleted
Member
Member
Posts: 82
Joined: Mon Jul 21, 2014 7:23 pm

EXT2 help

Post by deleted »

Hello, now that I found how bad FAT is, in the sense of using up to much space on a floppy, I have moved on to EXT2.
My problem: I don't know where to start. If anyone has a tutorial, guide, etc. on the EXT2 fs that would be great. Thanks!!
madanra
Member
Member
Posts: 149
Joined: Mon Sep 07, 2009 12:01 pm

Re: EXT2 help

Post by madanra »

The wiki article on ext2 is pretty good. Wikipedia's article on ext2 has a helpful diagram explaining how indirect blocks work. I found this article, which the wiki article was based on, a useful complement to the wiki as well.
User avatar
deleted
Member
Member
Posts: 82
Joined: Mon Jul 21, 2014 7:23 pm

Re: EXT2 help

Post by deleted »

Thanks for the reply, but I am afraid I was looking for more of a "How to read sectors", etc. kind of tutorial.
FallenAvatar
Member
Member
Posts: 283
Joined: Mon Jan 03, 2011 6:58 pm

Re: EXT2 help

Post by FallenAvatar »

wxwsk8er wrote:Thanks for the reply, but I am afraid I was looking for more of a "How to read sectors", etc. kind of tutorial.
See linux source code.

- Monk

P.S. See http://wiki.osdev.org/Beginner_Mistakes ... al_on...3F
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: How to implement a filesystem

Post by sortie »

Please actually read the wiki and search the web. If you wish to know about floppies, you can for instance read http://wiki.osdev.org/Floppy_Disk_Controller.

Don't disguise your real question "How do I read a floppy or a harddisk?" as "How do I read a file from a filesystem?". The filesystem is an abstraction higher and it's pretty trivial to make a simple filesystem. It's the block device driver that's tricky as it involves hardware specifics rather than imagination.
User avatar
iansjack
Member
Member
Posts: 4709
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: EXT2 help

Post by iansjack »

wxwsk8er wrote:Thanks for the reply, but I am afraid I was looking for more of a "How to read sectors", etc. kind of tutorial.
That's easy - you read the sectors in exactly the same way that you would for a FAT filesystem.
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: How to implement a filesystem

Post by zhiayang »

Not to mention that, IMO, ext2 is a fair bit more complex than FAT32. If you can't understand FAT, don't dig yourself into a hole by starting on ext.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: How to implement a filesystem

Post by Candy »

ext2 is a fair bit more complex than FAT32
IMO it's easier. Same complexity in terms of looking up files, less legacy warts.
User avatar
deleted
Member
Member
Posts: 82
Joined: Mon Jul 21, 2014 7:23 pm

Re: How to implement a filesystem

Post by deleted »

Ok, so I have looked (not copyied) at a few other peoples driver code, but I don't see any interrupts called, bytes written, etc. of how they would comunicate to the disc.

Thats more what I was asking. Thanks for all the replys :D
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: How to implement a filesystem

Post by zhiayang »

wxwsk8er wrote:Ok, so I have looked (not copyied) at a few other peoples driver code, but I don't see any interrupts called, bytes written, etc. of how they would comunicate to the disc.

Thats more what I was asking. Thanks for all the replys :D
Which code exactly? Depending on who's code you read, there can be a few ways of 'communicating' with a hard disk drive (not floppy, i don't know about that)
1. ATA PIO with polling -- while loop checking the ATA disk until it's done
2. ATA PIO with interrupts -- use interrupts to tell you when the disk is done.
3. DMA (interrupts only) -- mostly async, don't need to wait -- send data, disk says 'okay i'll do it', then sends an interrupt when it's done -- transfers much more than one sector at a time.

If you're in protected mode (you should be), none of the three methods will have anything resembling 'int $0xYY', unlike real mode code where you call the BIOS.


Also:
Candy wrote: IMO it's easier. Same complexity in terms of looking up files, less legacy warts.
Eh perhaps, I was thrown off because I only had a long PDF to work with and not a convenient wikipedia article :p
User avatar
deleted
Member
Member
Posts: 82
Joined: Mon Jul 21, 2014 7:23 pm

Re: How to implement a filesystem

Post by deleted »

I just picked up a little. But what about yours? How do you communicate with the disk?
User avatar
iansjack
Member
Member
Posts: 4709
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to implement a filesystem

Post by iansjack »

Well, in very simple terms, I

1. Send the appropriate commands to the IDE controller to check that it is ready. Repeat until the controller indicates that it is ready.

2. Send the appropriate commands to ask it to read a sector from the disk.

3. Continue with other stuff. When the controller has read the sector from the disk and is ready to transfer them it will send an interrupt.

4. The interrupt handler for that interrupt then reads the bytes from the controller and copies them to a disk buffer.

5. Once everything is read the interrupt routine exits and we are ready to go again.

That's just a rough outline. There are, of course, a few more details to be filled in. It's really not that different to the keyboard handler.
User avatar
deleted
Member
Member
Posts: 82
Joined: Mon Jul 21, 2014 7:23 pm

Re: How to implement a filesystem

Post by deleted »

Ok, what about to read clusters/sectors? How do you do that?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: How to implement a filesystem

Post by Combuster »

Ok, after seeing the same question for the umpteenth time, I'm going to lock this as plain old spam.

We're not here to spoonfeed you. There is no tutorial. There is more than enough sample code and other reference material being pointed out for you. You are simply wasting everyone's time by not spending any effort, and breaking various written and unwritten rules of conduct.

What you have heard should be three times sufficient to write your own implementation, so that's what you are going to do first now.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Locked