HowTo create 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.
Post Reply
User avatar
bscreator
Posts: 8
Joined: Wed Dec 17, 2008 11:22 am

HowTo create a filesystem ?

Post by bscreator »

welcome all osdeveloper,

first, a few things about my os:
- written in assembly code
- runs in real mode
- consists out of 2 files:
the bootloader
the simple kernel

Currently, i want to know a simple filesystem, which supports the basic functions, like
- create a new file
- load an existing file
- save an file

I know what a filesystem does, but i don't know how to start writing my own filesystem.

Thanks,
bscreator
User avatar
furryfreak
Member
Member
Posts: 28
Joined: Mon Nov 03, 2008 12:45 pm
Location: SW England

Re: HowTo create a filesystem ?

Post by furryfreak »

I'm sure there's been a topic on this before, but it depends on weather you want to make a file system or use an existing one.

If the goal your project is more or less to further your understanding of OS's I'd go with the former. If you do want to make your own, Theres many ways to go about it, I've been making my file system as what is effectively just a big linked list, which I think is the general approach that most use.
User avatar
samoz
Member
Member
Posts: 59
Joined: Sun Jun 01, 2008 1:16 pm

Re: HowTo create a filesystem ?

Post by samoz »

I've not started my file system yet so I'm just throwing some ideas out there right now.

You say you use a linked list for your file system? How does that work for you? How's speed on it, due to the nature of linked lists?
Hexciting: An open source hex editor for the command line.
https://sourceforge.net/projects/hexciting/
User avatar
bscreator
Posts: 8
Joined: Wed Dec 17, 2008 11:22 am

Re: HowTo create a filesystem ?

Post by bscreator »

I don't want to use an existing one.
I want to create my own.

My filesystem should work like the FAT, which uses an big table, where you can find all existing files.
I think, this should be the easiest solution, isn't it ?

My problem is, that there's no example code, how to write a filesystem.

Sure, the complete linux source code is available, but the unix-filesystem is really to big and written in C.

Thanks,
bsc
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: HowTo create a filesystem ?

Post by neon »

You dont "write" a filesystem; you write an "interface" for using it based on the file systems design. There are plenty of resources online that show you how to interface with particular file systems.

Because you are wanting to design your own filesystem, the details on the implimentation for interfacing with your filesystem depends on your design goals. In other words, there (as for as I know) is no tutorial for developing your own file system because it would not make much sense as it is not "your own" filesystem.

If you want your file system to have a design simular to FAT, then look at tutorials and resources for interfacing with FAT file systems to get ideas for your own.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
furryfreak
Member
Member
Posts: 28
Joined: Mon Nov 03, 2008 12:45 pm
Location: SW England

Re: HowTo create a filesystem ?

Post by furryfreak »

it would not make much sense as it is not "your own" filesystem.
couldn't agree with you more on that point, every example of file systems that I have seen just doesn't seem quite right from my perspective.
You say you use a linked list for your file system? How does that work for you? How's speed on it, due to the nature of linked lists?
Well, it hasn't actually been put into practice yet, but just as any other linked list, there'll be an overhead compared to an array, but a file system, needs to be scalable and be able to handle fragmentation etc, and linked lists are good at that. The way I've tried to minimize the overhead, is to use a linked list of arrays, a kind of best of both approach.

EDIT: I forgot to mention that I also use a few bitmaps to further simplify certain operations (e.g. locating whole unused sectors)
Last edited by furryfreak on Wed Dec 17, 2008 1:06 pm, edited 2 times in total.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: HowTo create a filesystem ?

Post by Dex »

To write a very simple file sys, you first need to design a sutable layout on paper or in your head, than unless your OS is well devloped, you need to write a program for a differant OS to format your floppy or hdd etc.
Now all this need to do is write markers at the right loction on the floppy, this could be zero or 0xff etc depending on your layout.
These markers will be read from your OS and maybe added to or actor on etc, depending on the way you designed your lay out.
Also it will need a boot sector if you want to boot from it, you are best stick with a standared one for now.
So a format program is the basic of a new file sys.

V2_OS made there own file sys (the site is down), i may have a example on a old cd some where, let me know if you want me to try and find it.
User avatar
furryfreak
Member
Member
Posts: 28
Joined: Mon Nov 03, 2008 12:45 pm
Location: SW England

Re: HowTo create a filesystem ?

Post by furryfreak »

you first need to design a sutable layout on paper or in your head
I agree 100%
Now all this need to do is write markers at the right loction on the floppy, this could be zero or 0xff etc depending on your layout.
This, I have to disagree with. For one, those bytes could easily be misread. Secondly, Its just unnecessary, as long as you keep a record of where everything is (and isn't), in some sort of database you don't need to use markers.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: HowTo create a filesystem ?

Post by Dex »

furryfreak wrote:
Now all this need to do is write markers at the right loction on the floppy, this could be zero or 0xff etc depending on your layout.
This, I have to disagree with. For one, those bytes could easily be misread. Secondly, Its just unnecessary, as long as you keep a record of where everything is (and isn't), in some sort of database you don't need to use markers.
You need marks, for example fat12 to find a file you scan through the root dir, first byte
00h = file has never been used
05h = first charactor of filename is actually e5h
2eh = file is a subdirectory
e5h = file has been deleted

The same with the "FAT"
000 = referenced cluster is currently unused
nnn = reative number of next cluster for file
ff0-ff6 = reserved cluster
ff7 = unsuable (bad track)
fff = last cluster of file

It is only by using these markers that you can use the file sys, the format program set these to a known state, in most case zero's.
User avatar
furryfreak
Member
Member
Posts: 28
Joined: Mon Nov 03, 2008 12:45 pm
Location: SW England

Re: HowTo create a filesystem ?

Post by furryfreak »

Oh, you mean flags #-o , yeah of course, goes without saying, I thought you meant to position files or something, but i get you now. Yeah flags are important, and they needn't only be applied to files. I have a qword near the very beginning of disk dedicated to turning certain features on/off to add some further flexibility, this is especially useful for tuning the file system to smaller/larger disks.
User avatar
bscreator
Posts: 8
Joined: Wed Dec 17, 2008 11:22 am

Re: HowTo create a filesystem ?

Post by bscreator »

Sorry, your right

But i thought that all the commands for the OS to interact with files IS CALLED FILESYSTEM.

I really thought about using the FAT, but then i decided to design my own.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: HowTo create a filesystem ?

Post by AJ »

Hi,

Are you possibly confusing the on-disk File Systems with the Virtual File System (VFS)?

"Creating a new file system" would indicate that you want to create a new on-disk file storage system - obviously you will need the supporting code. As has already been indicated, you would need to design the on-disk structures first, then think about the support code and how this fits in with your VFS design.

Cheers,
Adam

[Edit: Fixed broken wiki link]
User avatar
furryfreak
Member
Member
Posts: 28
Joined: Mon Nov 03, 2008 12:45 pm
Location: SW England

too many posts in split, trying to undo

Post by furryfreak »

One mistake I made when first writing my file system code, was making it part of the ATA driver, which isn't the right thing to do in most cases. The file system should really be an entirely separate entity which is used as a means to read/write from/to any block device.
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: HowTo create a filesystem ?

Post by Combuster »

Troll removed.
"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 ]
Post Reply