A tiny FAT file system
The problem
Build a small in-memory file system on a block table: create, show and delete files with a FAT, and resolve paths in a directory tree.
Requirements
- Keep a FAT for a disk of a fixed number of blocks, with free, end-of-file and next-block values
- Create files by taking the lowest free blocks, show the chain of a file and delete a file
- Store directories as tables of names and inode numbers, and resolve absolute paths with . and ..
- Report errors such as no space, missing file and not a directory
Technologies
- C
- Arrays and structs
- String handling
- Linked structures stored in tables
Step by step
- Design the FAT array and the file table with a name, a start block and a size.
- Write create, show and delete, and test them with a script of commands.
- Add directories as entries of name and inode number and write the path lookup.
- Add link counts and make the program print them.
- Test the error cases: a full disk, a missing name and a path through a file.
Expected result
A program that runs a script of file commands and prints the result of each, the block chains and the final free space.
How it is evaluated
- Creating and deleting files leaves the free count correct
- Chains list blocks in order
- Path lookup gives the right inode or the right error
- Every error is reported and the state is not damaged
Ways to improve it
- Add hard links and delete a file only when its link count reaches 0
- Add file permissions and check them on open
- Add a journal that records an operation before it is done