Log File System

A virtually simulated file system built in C

Click here to see the code

What is the Log File System

A log-structured filesystem is a filesystem that operates on a disk that is structured as a list of blocks. For my virtual disk that my filesystem will operate on I use 4096 blocks of 512 bytes. The first 10 blocks are reserved. Block 0 is the 'superblock' which stores the metadata of the disk. Block 1 is our 'free node block' which has 4096 bits each representing the availability of the corresponding block address. '1' means available, '0' means unavailable. The first 10 blocks are reserved for our superblock, free node block, and INode mapping. Blocks 2 to 9 contain the INode mapping. The INode mapping uses big-endian hex values that are equivalent to the integer value of an INode block address. An INode contains the metadata associated with a file or directory including its block addresses.

The Code

The primary functionality of the file system can be found in io/file.c. All of these functions interact with the disk.c file which is responsible for making changes to the vdisk file otherwise called the "virtual disk". The code in file.c contains the following functions.

  • Creation of INodes
  • Find Free INode block
  • Find Free File Block
  • Find INode Address
  • Find Directory Address
  • Read File
  • Create File (including directories)
  • Write to File
  • Delete File.
The disk.c file contains the functions responsible for writing to a block on the disk, reading a block on the disk, and creating the virtual disk. For more detail on the functionality behind each feature of the file system see the readme