pub struct Ext2<T: Read + Seek + Write>(/* private fields */);Expand description
This structure represents an entire ext2 filesystem.
Implementations§
Source§impl<T> Ext2<T>
impl<T> Ext2<T>
Sourcepub fn new(disk: T) -> Result<Self>
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();Sourcepub fn create<P: AsRef<Path>>(&mut self, path: P) -> Result<File<T>>
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.
Sourcepub fn open<P: AsRef<Path>>(&mut self, path: P) -> Result<File<T>>
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.
Sourcepub fn read_dir<P: AsRef<Path>>(&self, path: P) -> Result<Vec<Entry>>
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);
}Sourcepub fn create_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
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();Sourcepub fn remove_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
pub fn remove_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
Removes an empty directory.
ext2.remove_dir("/bananes").unwrap();Sourcepub fn chmod<P: AsRef<Path>>(&mut self, path: P, mode: Mode) -> Result<()>
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();Sourcepub fn stat<P: AsRef<Path>>(&self, path: P) -> Result<stat>
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();Sourcepub fn utime<P: AsRef<Path>>(
&mut self,
path: P,
time: Option<&utimbuf>,
) -> Result<()>
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();Sourcepub fn rename<P: AsRef<Path>>(&mut self, path: P, new_path: P) -> Result<()>
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();