The first rule is, when experimenting/creating your own file-system please use a blank pendrive to test, or may be a file which can act as virtual file system for the time being. Never ever test it on your own hard disk.
The method I would discuss here is a project I developed in a period of 4 months under Advanced data structure course. My thinking was very simple, a file-system is a big file which have all the files inside it. Just like a zip file. And this is true, actually a file system is a big file which is initially blank or we can say all the space is filled by either random data or filled by zeros. And we just have to find a method to allocate that space to some data so that the data is retrieval even if we don't know where it is. So we have to predefine a location where the location of files would be stored.
That means we must have a data structure for our file system and the data structure must be uniform through out the file system else we will get hard time finding the file and its location with in the disk. I used K-ary data structure but K was not defined because the children of a parent are linked to each other through a linked list so we can assume it more or or less like a B+ tree. Ok! it is really hard to explain this without a pictorial view, so here is the diagram:
As you can see I predefined(already decided) that there would be root directory and its child would be the folders which would be in linked list. That means all the sister nodes of the folder would be linked together and all the children are linked to its parents through a single child. But to make file system fast I used another link, a link which always has address of its parent. That means "Folder 8" would have a link to "folder 1" but "folder 1" would not have link to "folder 8" we can reach "folder 8" via "folder 6"->"folder 7".
typedef struct ffolder{
char name[32];
long sector;
long insector;
long upsector;
long next;
long prev;
long filesector;
char properties[3];
int size;
}ffolder;
//Folder structure
This was the structure of folder which has attributes like "sector" which has its own location in file system, "insector" would have location of the first folder inside that folder, "upsector" would have location of parent folder. We can understand what "next" and "prev" would store as it is a linked list. Now the two most important attributes of folder are:
1. "filesector"
Now even if we have a file system which can store multiple folders in it, it is still not complete because the basic purpose of a file system is to store files. So for that I used another structure:
typedef struct ffile{
char name[32];
long next;
long prev;
long sector;
long fsector;
char properties[4];
int size;
}ffile;
//file structure
So a folder can have link to first file and rest of the files would be linked list. Pictorially that means:
The attribute "fsector" will store location of content and the content will not be at a single place, it will also have a structure
typedef struct wfile{
char buff[16];
long next;
long prev;
long sector;
}wfile;
//content structure
So you can see that content will also be a liked list of a buffer which would store only 16 characters at a time.
2. "properties"
properties is a char set of 3 characters having some other permissions regarding a folder, like read/write/view.
So, finally we have a system where we can create folders/files and store content in files. But now we have a problem, and that is deletion. To understand deletion we need to understand that how we will insert these structures to a file.
I guess you know that can write a structure directly to file using fwrite. Hence each structure would be written sequentially(we will assume that no file is deleted until now).
Now if you delete any specific structure it will create a void and it can be filled only with the same kind of structure. We must maintain the list of all deleted files, at a separate location.
I will give link to download a working file-system for your understanding and testing. I hope you would have understood some basic concepts of creating a filesystem. Actually this topic is a vast topic and it can not be covered within a single article, if you have any query regarding the same please ask them in comments. I am writing a small e-book on it, stay tuned for the information. If you want to sponsor this project and want to get first out copies of the e-book you can mail me using contact us link.
Here is the link of the basic file-system (it may throw some errors as it was not fully tested) click here to download.