feat(ext4): file create, write, and delete with extent management

This commit is contained in:
2026-10-18 23:15:38 +02:00
parent bff18df349
commit 2ede01bdd2
2 changed files with 219 additions and 7 deletions

View File

@@ -368,6 +368,51 @@ fn list_dir_after_add() {
assert_eq!(count, 2);
}
#[test]
fn create_file_and_read_back() {
let mut fs = Ext4::mount(format_ext4_disk()).unwrap();
let h = fs.create(b"newfile").unwrap();
assert_eq!(fs.file_size(h), Some(0));
fs.close(h);
let mut entries = [DirEntry::empty(); 8];
let count = fs.list_dir(b"/", &mut entries).unwrap();
assert_eq!(count, 2);
}
#[test]
fn write_and_read_back() {
let mut fs = Ext4::mount(format_ext4_disk()).unwrap();
let h = fs.create(b"writable").unwrap();
let written = fs.write(h, b"Hello, world!").unwrap();
assert_eq!(written, 13);
fs.close(h);
let h = fs.open(b"writable").unwrap();
let mut buf = [0u8; 32];
let n = fs.read(h, &mut buf).unwrap();
assert_eq!(n, 13);
assert_eq!(&buf[..13], b"Hello, world!");
fs.close(h);
}
#[test]
fn delete_file_frees_resources() {
let mut fs = Ext4::mount(format_ext4_disk()).unwrap();
let h = fs.create(b"temp").unwrap();
fs.write(h, b"data").unwrap();
fs.close(h);
assert!(fs.delete(b"temp"));
assert!(fs.open(b"temp").is_none());
let h2 = fs.create(b"reuse").unwrap();
assert!(h2.raw() >= 0);
fs.close(h2);
}
#[test]
fn create_with_missing_parent_fails() {
let mut fs = Ext4::mount(format_ext4_disk()).unwrap();
assert!(fs.create(b"nodir/file.txt").is_none());
}
#[test]
fn read_past_eof_returns_zero() {
let mut fs = Ext4::mount(format_ext4_disk()).unwrap();