Skip to content

nadaaladdin/SimpleFS

Repository files navigation

Verifying SimpleFS Functionality


This project verifies that SimpleFS works correctly before building additional features on top of it.

Repository:

Original repository: https://github.com/cadesalaberry/SimpleFS


Output Before Editing:

Compiling...

Running...
Five files created with zero length:

Error: File #3 does not exist.Error: File #4 does not exist.
Thu May 8 19:46:07 2025 18KB ZKVWOZQS.OJC
Thu May 8 19:46:07 2025 18KB TDMAYTZH.EYH
Thu May 8 19:46:07 2025 10KB RJMVSCVT.MSP
Thu May 8 19:46:07 2025 20KB SHVGTAEM.DSP
Thu May 8 19:46:07 2025 25KB MOLSMSVG.EID
Reopened the files again.. the read/write pointers should be set to front
out of bound error
ERROR: data error at offset 0 in file ZKVWOZQS.OJC (-80,0)
out of bound error
ERROR: data error at offset 14344 in file ZKVWOZQS.OJC (-16,8)
out of bound error
ERROR: data error at offset 16657 in file ZKVWOZQS.OJC (-78,17)
out of bound error
ERROR: data error at offset 18437 in file ZKVWOZQS.OJC (-64,5)
out of bound error
ERROR: data error at offset 18586 in file ZKVWOZQS.OJC (-32,-102)
out of bound error
ERROR: data error at offset 18590 in file ZKVWOZQS.OJC (47,-98)
out of bound error
ERROR: data error at offset 18635 in file ZKVWOZQS.OJC (-64,-53)
out of bound error
ERROR: data error at offset 18653 in file ZKVWOZQS.OJC (48,-35)
out of bound error
ERROR: data error at offset 1 in file TDMAYTZH.EYH (0,1)
./test.sh: line 15: 6321 Segmentation fault (core dumped) ./$P

Challenges and Debugging

While developing and integrating SimpleFS with our \textit{io_uring} emulator, we faced several technical issues that impacted the correctness of the system.

  • Incorrect FAT Chain Allocation:

The original sfs_open() sometimes created duplicate FAT chains for the same file name, resulting in inconsistencies and data loss. We fixed this by checking for an existing file entry in the root directory before allocating a new FAT node. If the file already exists, we simply reopen it and reuse its chain.

  • Broken Write Logic:

\hspace*{2em}Early versions of \textit{sfs_write()} could not handle partial block writes or offsets properly, often overwriting the start of blocks and corrupting existing data. Our solution was:

  • Add support for arbitrary offsets (so random writes and appends work correctly).
  • Read and merge the existing block content before writing, to preserve data outside the modified region.
  • Correctly update the file size and ensure FAT chains are extended only as needed.
  • Read Errors:

sfs_read() sometimes returned incomplete, zeroed, or corrupt data, especially near file boundaries. We fixed this by carefully checking buffer sizes and offsets, validating that all reads are within the file’s true size, and making sure FAT traversal does not stray beyond allocated blocks.

  • Missing Metadata Persistence:

File size updates and FAT chain changes would sometimes disappear after reopening a file, due to metadata not being persisted to disk after each write. We fixed it by writing both the root directory and FAT table back to disk write_blocks(0, 1, (void*)&root and write_blocks(1, 1, (void*)&fat) after every write or metadata change.

  • Segmentation Faults:

Early versions suffered from segmentation faults due to uninitialized pointers and incorrect EOF checks in FAT chains, sometimes resulting in infinite loops during file writes or reads. We added boundary checks, initialized all FAT nodes with next=EOF, and implemented safe iteration with maximum block limits to prevent infinite traversal.


New step (After Fixes): Output Results: (test 1):

Compiling...

Running...
New FAT alloc: returning node 0
New File ZZNPYDYO.GQP created with fat_index = 1
Warning: 'ZZNPYDYO.GQP' is already open.
New FAT alloc: returning node 1
New File URLFXOYY.THR created with fat_index = 2
Warning: 'URLFXOYY.THR' is already open.
New FAT alloc: returning node 2
New File QLCMZPHB.RVS created with fat_index = 3
Warning: 'QLCMZPHB.RVS' is already open.
New FAT alloc: returning node 3
New File AQGJIXJC.QUJ created with fat_index = 4
Warning: 'AQGJIXJC.QUJ' is already open.
New FAT alloc: returning node 4
New File LJOGSGGL.RIX created with fat_index = 5
Warning: 'LJOGSGGL.RIX' is already open.
Five files created with zero length:


New FAT alloc: returning node 5

 Sat May 10 00:33:48 2025	24KB	ZZNPYDYO.GQP
 Sat May 10 00:33:48 2025	15KB	URLFXOYY.THR
 Sat May 10 00:33:48 2025	15KB	QLCMZPHB.RVS
 Sat May 10 00:33:48 2025	28KB	AQGJIXJC.QUJ
 Sat May 10 00:33:48 2025	17KB	LJOGSGGL.RIX
Reopening existing file: ZZNPYDYO.GQP (ID = 1)
Reopening existing file: URLFXOYY.THR (ID = 2)
Reopening existing file: QLCMZPHB.RVS (ID = 3)
Reopening existing file: AQGJIXJC.QUJ (ID = 4)
Reopening existing file: LJOGSGGL.RIX (ID = 5)
Reopened the files again.. the read/write pointers should be set to front
Test program exiting with 0 errors

Test 2:

  1. Create a new small test file "simple_test.c".
  2. Compile it: gcc -Wall simple_test.c disk_emu.c -o simple_test
  3. Run: ./simple_test

The results:

New FAT alloc: returning node 0
New File testfile.txt created with fat_index = 1
New FAT alloc: returning node 1
Reopening existing file: testfile.txt (ID = 1)
Read from file: Hello, SimpleFS!

About

Edit the implementation of a simple file system (SFS).

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages