5

This may sound noobish, especially as I'm ( as you may have guessed ) trying to write an Operating System. At the moment I'm stuck on trying to make a file system.

What I want is a similar file system as Linux Ubuntu which is EXT4 ( at least mine is ). I want to try and also either write it in C.

Any idea's on how I can go about this? And/or any tutorials that you might have found that may help me ( I have tried searching with no luck ) :L

Thanks in advance!

Jamie.

  • 1
    You may want to consider trying to implement and older type of filesystem. ext4 provides a lot of durability guarantees that you probably don't need to start with. Try looking into ext2 which has the same basic ideas. – Michael Apr 15 '12 at 22:50
  • @Michael - Is there some sort of source code for generating/implementing an ext2 fs? If so, where can I find it? –  Apr 15 '12 at 23:07
  • 1
    @JamieEdwards: The source code for `mkfs.ext2` is publicly available, as well as the Linux kernel source code. – Dietrich Epp Apr 15 '12 at 23:18
  • 2
    Have you already made a booting kernel with a physical & virtual memory (and cache) manager? If so, that's really impressive. :) If not, then you might want to just worry about creating a "raw" kernel with no disk/file system whatsoever, just pure code (the first sector would be the boot sector, the rest would be the kernel)... after you have the system in place, *then* worry about implementing a file system. – user541686 Apr 16 '12 at 01:14

2 Answers2

4

Really smart and experienced people who have studied this problem extensively have made bugs that ate users' data. The difference between a bug in the computation layer (e.g. a kernel crash) and a bug in the storage layer is that silently eating users' data is very bad - much worse than giving wrong answers in spreadsheets (excel is buggy yet popular) or intermittently sigfaulting while preserving data on disk (this is easily mitigated by frequent autosave).

Start by studying simpler designs, like the minix filesystems from the old operating systems book [1] (the same one Linus Torvalds started with, twenty years ago).

Like others said, ext2 without journaling, extents or ACLs is a better starting point than ext4. The source code for it is in the Linux kernel and in the e2fsprogs userspace tools package[2]. The format is well documented.

As for tutorials, consider who makes them and why they spend effort on this task. Tutorials are generally made by stakeholders in platforms to bring in new people to develop using that platform, to use the network effect to grow the platform and profit from being already-established actors in a larger ecosystem.

Do you see a business model in growing the number of people who implement their own incompatible buggy[3] file systems? Only if you sell software engineering degrees. So Microsoft only writes tutorials on how to use NTFS, not on how to implement it. Same for Sun and ZFS, Red Hat and Google with EXT2/3/4, SGI with XFS, IBM with JFS, Oracle with BTRFS, etc.

If you want education instead of training, you need to read books and study smart peoples' code they use in production, not look for tutorials.

  1. http://en.wikipedia.org/wiki/Operating_Systems:_Design_and_Implementation
  2. http://e2fsprogs.sourceforge.net/
  3. How much use, in how many different use pattern with it see? Consider bugs discovered in production FSs after years of use on millions of computers. It is unlikely your code will be less buggy, even if you're as smart as Matthew Dillon.
Z.T.
  • 939
  • 8
  • 20
  • 1
    Believe it or not, sometimes people *do* write tutorials *just because they want to help others* who are in the same shoes they already were... e.g. see [here](http://www.osdever.net/tutorials/view/brans-kernel-development-tutorial) – user541686 Apr 16 '12 at 01:19
  • 1
    Yes, and people like me answer questions on SO just because they like to help others. But how much effort can you expect someone to expend on helping strangers? I sometimes see questions that can be summed up as "teach me to build facebook/android/etc." without the OP appearing to have done minimal research into the amount of work required. Reading about filesystems on wikipedia is not too much to ask. – Z.T. Apr 16 '12 at 01:26
0

Try looking at an existing implementation, like the one in Linux.

Michael Foukarakis
  • 39,737
  • 6
  • 87
  • 123