Designing a Simple File System

202309300916
Status: #idea
Tags: DSTN

Designing a Simple File System

Overall Organisation

Pasted image 20230930093551.png

Info

OS only knows the inode of / and the inode of the pwd

Making a file system mkfs

Info

hdX was traditionally used for IDE drives. sdX is typically used for SCSI/SATA drives

Mounting a file system mount

Inode

Pasted image 20230930093616.png

Note

ext2/3 has multi-level indexing.
Each of the 15 data blocks act as pointers to other data blocks. This allows it to store files >60KiB

Pasted image 20230930094658.png

Info

Each inode has 12 direct pointers, 1 indirect block address, 1 double-indirect block address and 1 triple-indirect block address

Why use an imbalanced block allocation tree?

Extent-based Approach vs Pointer-based Approach

Pointer-based approach Extent-based approach
Most flexible Less flexible
Use a large amount of metadata per file (particularly for large files) More compact
Works when there is enough free space on disk and files can be laid out contigously

Directory Organisation

Info

When creating a file, based on the name, a suitable reclen is used. This indicates the maximum length for the file name.
TODO: This is relevant to allow for easy reuse of old inodes

Free Space Management

Reading a file

open("/path/to/directory/foo.txt", O_RDONLY);
  1. Find the inode of the root
  2. Read the data block to find the next step in the apth
  3. Repeat till we reach the desired file
    1. Read the appropriate inode
    2. Read the data block of the directory, to find the next suitable inode
  4. Read the inode of the file into memory
    1. FS does a permission check
    2. Allocates a file descriptor for this process in OFT
Warning

Every read call, the inode will be written to. This is used to update the access time metadata

Reducing File System I/O Costs

Note

First open call will generate a lot of I/O traffic. Subsequent calls will result in a cache hit and no disk I/Os will be performed.


References

  1. Slides