Page 1 of 1

Making a File System

Posted: Mon Aug 01, 2011 8:05 pm
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?

Re: Making a File System

Posted: Mon Aug 01, 2011 8:28 pm
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

Re: Making a File System

Posted: Mon Aug 01, 2011 9:15 pm
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

Re: Making a File System

Posted: Tue Aug 02, 2011 12:55 am
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

Re: Making a File System

Posted: Tue Aug 02, 2011 10:44 am
by xleelz
Thanks for the quick and helpful responses. I think I figured it out now... hmm, learn something new every day :D

Re: Making a File System

Posted: Tue Aug 02, 2011 1:58 pm
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.

Re: Making a File System

Posted: Tue Aug 02, 2011 2:02 pm
by gravaera
Yea my bad with the floppy example :P