Struct FileSystem

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

A FAT16, virtual filesystem.

FAT-16 IS NOT case sensitive. All the paths will be silently converted to uppercase, as in any FAT system. It’s a TODO to support ext4.

Implementations§

Source§

impl FileSystem

Source

pub fn new(size: usize) -> Result<Self>

Creates a new filesystem with the provided partition size.

The memory buffer of the filesystem is lazy loaded; that is, it will allocate bytes as they are consumed.

Source

pub fn try_to_bytes(&self) -> Result<Vec<u8>>

Serializes the structure into bytes.

Source

pub fn try_from_bytes(bytes: &[u8]) -> Result<Self>

Deserializes the structure from bytes.

Source

pub fn try_to_raw_device(&self) -> Result<Vec<u8>>

Serializes the raw device (MBR + FAT16) into bytes.

Note: this is a compatible filesystem that can be mounted elsewhere.

Source

pub fn from_raw_device_unchecked(device: Vec<u8>) -> Self

Deserializes the raw device (MBR + FAT16) from bytes.

Source

pub fn cwd(&self) -> &RelativePath

Returns the current work directory.

Source

pub fn cd<P: AsRef<RelativePath>>(&mut self, dir: P) -> Result<()>

Navigates into the provided directory.

Source

pub fn ls<P: AsRef<RelativePath>>(&self, path: P) -> Result<Vec<DirOrFile>>

List the contents of the path.

Source

pub fn mkdir<P: AsRef<RelativePath>>(&mut self, dir: P) -> Result<()>

Creates the provided path recursively from the current directory.

Source

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

Removes a file or an empty directory.

Source

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

Opens the file at the specified path.

If the file doesn’t exist, the flag File.new will be set to true.

Source

pub fn save(&mut self, file: File) -> Result<()>

Saves the file into the buffer.

Creates the path recursively, if it doesn’t exist.

Trait Implementations§

Source§

impl From<Device> for FileSystem

Source§

fn from(dev: Device) -> Self

Converts to this type from the input type.

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.