Ext2

Struct Ext2 

Source
pub struct Ext2<T: Read + Seek + Write>(/* private fields */);
Expand description

This structure represents an entire ext2 filesystem.

Implementations§

Source§

impl<T> Ext2<T>
where T: Read + Seek + Write,

Source

pub fn new(disk: T) -> Result<Self>

Invocation of a new FileSystem instance: Take anything that implements Read + Seek + Write.

let f = std::fs::OpenOptions::new()
    .read(true)
    .write(true)
    .open(MY_DISK_OBJECT)
    .expect("open filesystem failed");
let ext2 = open_ext2_drive(f).unwrap();
Source

pub fn create<P: AsRef<Path>>(&mut self, path: P) -> Result<File<T>>

Opens a file in write-only mode.

This function will create a file if it does not exist, and will truncate it if it does.

Depending on the platform, this function may fail if the full directory path does not exist. See the OpenOptions::open function for more details.

Source

pub fn open<P: AsRef<Path>>(&mut self, path: P) -> Result<File<T>>

Attempts to open a file in read-only mode.

See the OpenOptions::open method for more details.

§Errors

This function will return an error if path does not already exist. Other errors may also be returned according to OpenOptions::open.

Source

pub fn read_dir<P: AsRef<Path>>(&self, path: P) -> Result<Vec<Entry>>

Returns a Vector over the entries within a directory.

The collection will yield instances of std::io::Result<Entry>. New errors may be encountered after an iterator is initially constructed.

let v = ext2.read_dir("/").unwrap();
for entry in v {
    dbg!(entry);
}
Source

pub fn create_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Creates a new, empty directory at the provided path.

ext2.create_dir("/bananes").unwrap();
Source

pub fn remove_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Removes an empty directory.

ext2.remove_dir("/bananes").unwrap();
Source

pub fn chmod<P: AsRef<Path>>(&mut self, path: P, mode: Mode) -> Result<()>

Change the file permission bits of the specified file.

let mode = Mode::S_IRWXU | Mode::S_IRWXG | Mode::S_IRWXO;
ext2.chmod("/bananes/toto.txt", mode).unwrap();
Source

pub fn chown<P: AsRef<Path>>( &mut self, path: P, owner: Uid, group: Gid, ) -> Result<()>

Change the ownership of the file at path to be owned by the specified owner (user) and group (see chown(2)).

ext2.chown("/bananes/toto.txt", Uid::from_raw(0), Gid::from_raw(0)).unwrap();
Source

pub fn stat<P: AsRef<Path>>(&self, path: P) -> Result<stat>

This function returns information about a file,

let s1 = ext2.stat("/bananes/toto.txt").unwrap();
Source

pub fn remove_file<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Removes a file from the filesystem.

§Platform-specific behavior

This function currently corresponds to the unlink function on Unix and the DeleteFile function on Windows. Note that, this may change in the future.

ext2.remove_file("/bananes/toto.txt").unwrap();
Source

pub fn utime<P: AsRef<Path>>( &mut self, path: P, time: Option<&utimbuf>, ) -> Result<()>

Change the access and modification times of a file.

ext2.utime("/bananes/toto.txt", Some(&libc::utimbuf {
    actime: 42,
    modtime: 42,
})).unwrap();
Source

pub fn rename<P: AsRef<Path>>(&mut self, path: P, new_path: P) -> Result<()>

Rename a file or directory to a new name, it cannot replace the original file if to already exists.

ext2.rename("/bananes/toto.txt", "/tata.txt").unwrap();

Make a new name for a file. It is also called “hard-link”.

ext2.link("/bananes/toto.txt", "/tata.txt").unwrap();

Make a new name for a file. It is symbolic links.

ext2.symlink("/bananes/toto.txt", "/tata.txt").unwrap();

Trait Implementations§

Source§

impl<T> Clone for Ext2<T>
where T: Read + Seek + Write,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Read + Seek + Write> Debug for Ext2<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Ext2<T>

§

impl<T> RefUnwindSafe for Ext2<T>

§

impl<T> Send for Ext2<T>
where T: Send,

§

impl<T> Sync for Ext2<T>
where T: Send,

§

impl<T> Unpin for Ext2<T>

§

impl<T> UnwindSafe for Ext2<T>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.