File Systems and Their Implementation

Jul 8, 2024

File Systems and Their Implementation

Introduction

  • Goal: Create a simplified file system.
  • Components: Super block, inodes, disk blocks, file allocation tables.

Super Block

  • Meta information about the file system.
  • Contains:
    • Number of inodes
    • Number of disk blocks
    • Size of the disk blocks

Inodes

  • Represents files in the file system.
  • Contains:
    • Size
    • Name

Disk Blocks

  • Storage units for file data.
  • Contains:
    • Next block number
    • Data (512 bytes)

Operations

Creating the File System

  • Initialize super block, inodes, and disk blocks.
  • Define global variables for managing the file system.
  • Functions:
    • create(): Initializes the file system structures.
    • sync(): Writes the file system data to disk using fopen and fwrite.
    • mount(): Reads file system data from disk using fread.

File Management

Allocate File

  • Finds an empty inode and disk block to store new file.
  • Returns a file descriptor.

Set File Size

  • Calculates the required number of disk blocks.
  • Allocates or frees disk blocks as necessary.

Write Byte

  • Calculates the block and offset based on position.
  • Writes byte to specified position in the file.

Testing

  • Tested creating, mounting, and syncing the file system.
  • Verified allocation of inodes and disk blocks.
  • Verified data writing to files.
  • Implemented test scenarios by setting file sizes and writing data.

Future Work

  • Implement deleting files.
  • Implement reading bytes from files.
  • Optimize using bitmap for inode and disk block management.

Notes on Coding Practices

  • Includes using malloc for memory allocation.
  • Usage of standard libraries: stdio.h, stdlib.h, string.h.
  • Error checking not emphasized due to time constraints.
  • Good habits mentioned: Always close a file after opening it.

Conclusion

  • Basic functionality achieved: Creating, mounting, syncing file system, and writing data to files.
  • Further operations like reading and deleting files can be implemented next.