Crates.io | ext4fs |
lib.rs | ext4fs |
version | 0.1.0 |
source | src |
created_at | 2024-01-16 14:10:04.299982 |
updated_at | 2024-01-16 14:10:04.299982 |
description | Rust implementation of ext4 file system used in user space |
homepage | https://github.com/yybit/ext4fs-rs |
repository | https://github.com/yybit/ext4fs-rs |
max_upload_size | |
id | 1101610 |
size | 48,465 |
Rust implementation of ext4 file system in user space. The ext4 file system can be read directly without mounting, write operations are not supported yet. Your contributions are welcome.
:warning::warning::warning: The current api is not stable, it may be modified later, and more tests and documentation will need to be added.
// Read a raw ext4 image file.
let file = std::fs::File::open("testdata/test.ext4").unwrap();
let reader = BufReader::new(file);
let mut fs = ext4fs::FileSystem::from_reader(reader).unwrap();
let rd = fs.read_dir("/dir1").unwrap();
for x in rd {
println!("{}", x.unwrap().get_name_str());
}
let m = fs.metadata("/hello.txt").unwrap();
println!(
"uid={} gid={} permissions={:o} len={} created={:?} accessed={:?} modified={:?}",
m.uid(),
m.gid(),
m.permissions(),
m.len(),
m.created(),
m.accessed(),
m.modified(),
);
let p = fs.read_link("/hello.txt.lnk").unwrap();
println!("{}", p.to_str().unwrap());
let b = fs.read("/hello.txt").unwrap();
assert_eq!("hello\n", String::from_utf8_lossy(&b).to_string());
let mut f = fs.open("/hello.txt").unwrap();
f.seek(std::io::SeekFrom::Start(2)).unwrap();
let mut buf = String::new();
f.read_to_string(&mut buf).unwrap();