Skip to main content

Ext4Fs

Struct Ext4Fs 

Source
pub struct Ext4Fs { /* private fields */ }
Expand description

An ext4 filesystem instance.

This is the main entry point for filesystem operations. Create an instance by mounting a block device, then use the various methods to manipulate files and directories.

§Example

use ext4_lwext4::{Ext4Fs, FileBlockDevice, OpenFlags};

// Open a disk image and mount
let device = FileBlockDevice::open("disk.img").unwrap();
let fs = Ext4Fs::mount(device, false).unwrap();

// Create a directory
fs.mkdir("/data", 0o755).unwrap();

// Write a file (use a block to ensure file is dropped before umount)
{
    let mut file = fs.open("/data/hello.txt", OpenFlags::CREATE | OpenFlags::WRITE).unwrap();
    // ... write operations ...
}

// Unmount when done
fs.umount().unwrap();

Implementations§

Source§

impl Ext4Fs

Source

pub fn mount<B: BlockDevice + 'static>( device: B, read_only: bool, ) -> Result<Self>

Mount an ext4 filesystem from a block device.

§Arguments
  • device - The block device containing the filesystem
  • read_only - Whether to mount read-only
§Returns

A mounted Ext4Fs instance

Source

pub fn umount(self) -> Result<()>

Unmount the filesystem.

This flushes all pending writes and releases the block device.

Source

pub fn is_read_only(&self) -> bool

Check if filesystem is mounted read-only.

Source

pub fn stat(&self) -> Result<FsStats>

Get filesystem statistics.

Source

pub fn open(&self, path: &str, flags: OpenFlags) -> Result<File<'_>>

Open a file.

§Arguments
  • path - Path to the file
  • flags - Open flags (READ, WRITE, CREATE, etc.)
Source

pub fn open_dir(&self, path: &str) -> Result<Dir<'_>>

Open a directory for iteration.

Source

pub fn mkdir(&self, path: &str, mode: u32) -> Result<()>

Create a directory.

§Arguments
  • path - Path for the new directory
  • mode - Permissions (e.g., 0o755)
Source

pub fn remove(&self, path: &str) -> Result<()>

Remove a file.

Source

pub fn rmdir(&self, path: &str) -> Result<()>

Remove a directory (recursively).

Source

pub fn rename(&self, from: &str, to: &str) -> Result<()>

Rename a file or directory.

Create a hard link.

Create a symbolic link.

§Arguments
  • target - The path the symlink points to
  • path - Path for the new symlink

Read the target of a symbolic link.

Source

pub fn exists(&self, path: &str) -> bool

Check if a path exists.

Source

pub fn is_file(&self, path: &str) -> bool

Check if a path exists and is a file.

Source

pub fn is_dir(&self, path: &str) -> bool

Check if a path exists and is a directory.

Source

pub fn metadata(&self, path: &str) -> Result<Metadata>

Get file metadata.

Source

pub fn set_permissions(&self, path: &str, mode: u32) -> Result<()>

Set file permissions.

Source

pub fn set_owner(&self, path: &str, uid: u32, gid: u32) -> Result<()>

Set file owner.

Source

pub fn sync(&self) -> Result<()>

Flush all pending writes to disk.

Trait Implementations§

Source§

impl Drop for Ext4Fs

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.