We will design and implement a highly simplified FS.
We will use a HD Driver, which is a TASK, to read/write the hard disk (see a/
, b/
, c/
).
Let's think about what is necessary in an FS:
- we need some place to store the information of each file, such as file name, size, which sectors belong to this file, etc.
- we need some place to store the index of the files
- we need some place to store the usage of each sector
- we need some place to store the metadata
These are the minimal needs. It can't be less. We don't need a product quality FS, so let's make it as simple and as stupid as possible.
Here's my design (see d/
):
- We use i-nodes (just like that in *nix, but highly simplified) to store the information of files.
- We use a special file to store the index of all other files.
This special file is called root directory (denoted as
/
), which is the only directory in the FS. In other words, this is a flat FS. - We use a sector-map to store the usage of all sectors.
- We use a special sector, which is called a superblock, to store all the metadata, such as where the sector-map is, where the root directory is, where the i-nodes are, etc.
Orange'S FS illustration ======================== files data | /------------------... +---+---+---+---+-...-+---+---+-...-+---+---+-...-+---+---+-... | | | | | ... | | | ... | | | ... | | | ... +---+---+---+---+-...-+---+---+-...-+---+---+-...-+---+---+-... | | | \-----------/ \-----------/ \-----------/ | | | | | | | | | | | root dir | | | | inode_array | | | sector-map | | inode map (sect2) | superblock (sect1) boot sector (sect0)
We will add several more system calls so that the TASKs and PROCs can use the FS:
open()
(seee/
)close()
(seee/
)read()
(seef/
)write()
(seef/
)unlink()
(seeh/
)
You know that everything in *nix is file.
Let's adopt this idea and treat TTYs as files.
See i/
.
Remember to modify printf()
when TTY is changed (see j/
).