Making a File System

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
xleelz
Posts: 8
Joined: Mon Aug 01, 2011 7:59 pm

Making a File System

Post by xleelz »

What would it take to create a file system? Do you need a driver for the hard drive to format it in a certain way? I've studied the design of file systems but never really figured out how to actually access or format the hard drive

Some enlightenment please?
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Re: Making a File System

Post by piranha »

You would need a driver that can access (read, at least) any block asked of it. It would need to expose something like read_block(int drive, long block, char *buffer). Something like that. Then, you start to look at the FS design. Read the superblock, read the root inode/directory/whatever, and give that back to the kernel. The driver for the FS would need to expose things like readfile(struct file *, int offset, int length, char *buffer), lookup_dirent(struct file *f, char *name), etc. Whatever you need to use the FS for. The implementation of those function would depend on the design of the file system.

You're gonna want a stable driver interface (or build it into the kernel), a stable disk driver, a kmalloc function or equivalent (they're really quite helpful, though you don't have to have it), and a VFS would be good as well to make use of the filesystem driver.

-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Making a File System

Post by gravaera »

"Formatting" isn't a hardware intrinsic. It's actually a software abstraction. When you "format" a floppy for example, no changes are made to the behaviour or stability of the storage media itself. All the OS does is write values to the drive to form the constructs necessary to use a certain file system with it. Drives can be used without formatting: that would be writing raw sectors to the drive. In such a case the abstraction of data known as a "file" would not exist for data stored on that drive. All there would be is cluttered together data dumped to the drive as it was placed when being stored.

To create your own file system, all you need to do is create a header that would be stored at the very beginning of the storage device. Something that would tell the number of free sectors on the device, and also give a method for you to keep track of which sectors are used and which aren't; along with that, if you require grouping of data by "file" for separate piece of data, you create a "file" naming and management abstraction.

Other considerations can be made, such as maximizing the format of the structures for optimal storage of large files, or for maximal speed of data retrieval etc. Different File systems are made with different intentions.

--Peace out
gravaera
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
Thomas
Member
Member
Posts: 281
Joined: Thu Jun 04, 2009 11:12 pm

Re: Making a File System

Post by Thomas »

Hi xleelz ,
What would it take to create a file system? Do you need a driver for the hard drive to format it in a certain way? I've studied the design of file systems but never really figured out how to actually access or format the hard drive
Some enlightenment please?
One easy way to try out and test file systems in a use mode environment is to just use a flat file and then implement your abstractions on top :) .

If you want to go a little further you can use an actual device like a usb drive. On VMS systems you can foreign mount a device and use sys$qio to read it block by block. Same thing should be possible in unix systems with ioctl or by doing a raw read () /write() to /dev/<whatever> .

How you actually access the hard drive basically depends on your hardware and that is where the driver part comes in . There is some good info here. http://wiki.osdev.org/Category:ATA

--Thomas
xleelz
Posts: 8
Joined: Mon Aug 01, 2011 7:59 pm

Re: Making a File System

Post by xleelz »

Thanks for the quick and helpful responses. I think I figured it out now... hmm, learn something new every day :D
Gigasoft
Member
Member
Posts: 855
Joined: Sat Nov 21, 2009 5:11 pm

Re: Making a File System

Post by Gigasoft »

gravaera wrote:"Formatting" isn't a hardware intrinsic. It's actually a software abstraction. When you "format" a floppy for example, no changes are made to the behaviour or stability of the storage media itself. All the OS does is write values to the drive to form the constructs necessary to use a certain file system with it. Drives can be used without formatting: that would be writing raw sectors to the drive. In such a case the abstraction of data known as a "file" would not exist for data stored on that drive. All there would be is cluttered together data dumped to the drive as it was placed when being stored.
"Formatting" can mean several things, it could mean setting up a file system or it could mean creating the actual tracks. A blank floppy does not have any tracks or sectors on it. There is a command that has to be sent to the floppy controller to format each track with the desired arrangement of sectors. If you try to issue a write command to a drive with an unformatted floppy inserted, it will just fail. For a hard drive, on the other hand, one doesn't have to worry about it, as they come preformatted from the factory.
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Making a File System

Post by gravaera »

Yea my bad with the floppy example :P
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
Post Reply