pub struct Filesystem { /* private fields */ }Expand description
RAII wrapper around an ext2_filsys handle.
Drop flushes and closes the filesystem, preventing resource leaks
even when operations fail or panic.
§Example
use std::path::Path;
use bux_e2fs::{Filesystem, CreateOptions};
let mut fs = Filesystem::create(
Path::new("/tmp/image.raw"),
512 * 1024 * 1024,
&CreateOptions::default(),
).unwrap();
fs.populate(Path::new("/tmp/rootfs")).unwrap();
fs.add_journal().unwrap();
// Drop closes the filesystem automatically.Implementations§
Source§impl Filesystem
impl Filesystem
Sourcepub fn create(
path: &Path,
size_bytes: u64,
opts: &CreateOptions,
) -> Result<Self>
pub fn create( path: &Path, size_bytes: u64, opts: &CreateOptions, ) -> Result<Self>
Creates a new ext4 filesystem image at path.
Equivalent to mke2fs -t ext4 -b <block_size> -m <reserved> <path> <size>.
Sourcepub fn open(path: &Path) -> Result<Self>
pub fn open(path: &Path) -> Result<Self>
Opens an existing ext4 image for read-write operations.
Sourcepub fn populate(&mut self, source_dir: &Path) -> Result<()>
pub fn populate(&mut self, source_dir: &Path) -> Result<()>
Populates the filesystem from a host directory.
Recursively copies all files, directories, symlinks, and permissions
from source_dir into the image root.
Sourcepub fn flush(&mut self) -> Result<()>
pub fn flush(&mut self) -> Result<()>
Flushes all pending changes to disk without closing the filesystem.
Sourcepub fn write_file(&mut self, host_path: &Path, guest_path: &str) -> Result<()>
pub fn write_file(&mut self, host_path: &Path, guest_path: &str) -> Result<()>
Writes a single host file into the filesystem image.
Equivalent to debugfs -w -R "write <host_path> <guest_path>".
Sourcepub fn mkdir(&mut self, name: &str) -> Result<()>
pub fn mkdir(&mut self, name: &str) -> Result<()>
Creates a directory inside the filesystem image.
Sourcepub fn symlink(&mut self, name: &str, target: &str) -> Result<()>
pub fn symlink(&mut self, name: &str, target: &str) -> Result<()>
Creates a symlink inside the filesystem image.
Sourcepub fn add_journal(&mut self) -> Result<()>
pub fn add_journal(&mut self) -> Result<()>
Adds an ext3/4 journal (size auto-calculated by libext2fs).
Sourcepub fn link(
&mut self,
dir: u32,
name: &str,
ino: u32,
file_type: FileType,
) -> Result<()>
pub fn link( &mut self, dir: u32, name: &str, ino: u32, file_type: FileType, ) -> Result<()>
Creates a directory entry linking name to inode ino in directory dir.
Sourcepub fn read_inode(&self, ino: u32) -> Result<ext2_inode>
pub fn read_inode(&self, ino: u32) -> Result<ext2_inode>
Reads the on-disk inode structure for the given inode number.
Sourcepub fn write_inode(&mut self, ino: u32, inode: &ext2_inode) -> Result<()>
pub fn write_inode(&mut self, ino: u32, inode: &ext2_inode) -> Result<()>
Writes the inode structure back to the filesystem.
Sourcepub fn write_new_inode(&mut self, ino: u32, inode: &ext2_inode) -> Result<()>
pub fn write_new_inode(&mut self, ino: u32, inode: &ext2_inode) -> Result<()>
Writes a freshly allocated inode (initializes the on-disk slot).