Struct Filesystem

Source
pub struct Filesystem<'a, Storage: Storage> { /* private fields */ }

Implementations§

Source§

impl<Storage: Storage> Filesystem<'_, Storage>

Source

pub fn allocate() -> Allocation<Storage>

Source

pub fn format(storage: &mut Storage) -> Result<()>

Source

pub fn is_mountable(storage: &mut Storage) -> bool

Source

pub unsafe fn borrow_storage_mut(&mut self) -> &mut Storage

Source

pub fn mount_and_then<R>( storage: &mut Storage, f: impl FnOnce(&Filesystem<'_, Storage>) -> Result<R>, ) -> Result<R>

This API avoids the need for using Allocation.

Source

pub fn total_blocks(&self) -> usize

Total number of blocks in the filesystem

Source

pub fn total_space(&self) -> usize

Total number of bytes in the filesystem

Source

pub fn available_blocks(&self) -> Result<usize>

Available number of unused blocks in the filesystem

Upstream littlefs documentation notes (on its “current size” function): “Result is best effort. If files share COW structures, the returned size may be larger than the filesystem actually is.”

So it would seem that there are at least the number of blocks returned by this method available, at any given time.

Source

pub fn available_space(&self) -> Result<usize>

Available number of unused bytes in the filesystem

This is a lower bound, more may be available. First, more blocks may be available as explained in available_blocks. Second, files may be inlined.

Source

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

Remove a file or directory.

Source

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

Remove a file or directory.

Source

pub fn remove_dir_all(&self, path: &Path) -> Result<()>

TODO: This method fails if some println! calls are removed. Whyy?

Source

pub fn remove_dir_all_where<P>( &self, path: &Path, predicate: &P, ) -> Result<usize>
where P: Fn(&DirEntry) -> bool,

Source

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

Rename or move a file or directory.

Source

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

Check whether a file or directory exists at a path.

This is equivalent to calling Filesystem::metadata and checking for an Ok return value.

Source

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

Given a path, query the filesystem to get information about a file or directory.

To read user attributes, use Filesystem::attribute

Source

pub fn create_file_and_then<R>( &self, path: &Path, f: impl FnOnce(&File<'_, '_, Storage>) -> Result<R>, ) -> Result<R>

Source

pub fn open_file_and_then<R>( &self, path: &Path, f: impl FnOnce(&File<'_, '_, Storage>) -> Result<R>, ) -> Result<R>

Source

pub fn with_options() -> OpenOptions

Source

pub fn open_file_with_options_and_then<R>( &self, o: impl FnOnce(&mut OpenOptions) -> &OpenOptions, path: &Path, f: impl FnOnce(&File<'_, '_, Storage>) -> Result<R>, ) -> Result<R>

Source

pub fn attribute<'a>( &self, path: &Path, id: u8, buffer: &'a mut [u8], ) -> Result<Option<Attribute<'a>>>

Read attribute.

Source

pub fn remove_attribute(&self, path: &Path, id: u8) -> Result<()>

Remove attribute.

Source

pub fn set_attribute(&self, path: &Path, id: u8, data: &[u8]) -> Result<()>

Set attribute.

Source§

impl<'a, Storage: Storage> Filesystem<'a, Storage>

Source

pub fn read_dir_and_then<R>( &self, path: &Path, f: impl FnOnce(&mut ReadDir<'_, '_, Storage>) -> Result<R>, ) -> Result<R>

Source

pub unsafe fn read_dir<'b>( &'b self, alloc: &'b mut ReadDirAllocation, path: &'b Path, ) -> Result<ReadDir<'a, 'b, Storage>>

Returns a pseudo-iterator over the entries within a directory.

This is unsafe since it can induce UB just like File::open.

Source§

impl<'a, Storage: Storage> Filesystem<'a, Storage>

Source

pub fn mount( alloc: &'a mut Allocation<Storage>, storage: &'a mut Storage, ) -> Result<Self>

Source

pub fn mount_or_else<F>( alloc: &'a mut Allocation<Storage>, storage: &'a mut Storage, f: F, ) -> Result<Self>

Mount the filesystem or, if that fails, call f with the mount error and the storage and then try again.

Source

pub fn into_inner(self) -> (&'a mut Allocation<Storage>, &'a mut Storage)

Deconstruct Filesystem, intention is to allow access to the underlying Flash peripheral in driver::Storage etc.

See also borrow_storage_mut.

Source

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

Creates a new, empty directory at the provided path.

Source

pub fn create_dir_all(&self, path: &Path) -> Result<()>

Recursively create a directory and all of its parent components if they are missing.

Source

pub fn read<const N: usize>(&self, path: &Path) -> Result<Vec<u8, N>>

Read the entire contents of a file into a bytes vector.

Source

pub fn read_chunk<const N: usize>( &self, path: &Path, pos: OpenSeekFrom, ) -> Result<(Vec<u8, N>, usize)>

Read a chunk of a file into a bytes vector Returns the data and the size of the file

Source

pub fn write(&self, path: &Path, contents: &[u8]) -> Result<()>

Write a slice as the entire contents of a file.

This function will create a file if it does not exist, and will entirely replace its contents if it does.

Source

pub fn write_chunk( &self, path: &Path, contents: &[u8], pos: OpenSeekFrom, ) -> Result<()>

Write a slice as a chunk of a file.

This function will not create a file if it does not exist, it will fail if the file is not already large enough with regard to the pos parameter

Trait Implementations§

Source§

impl<S: Storage> DynFilesystem for Filesystem<'_, S>

Source§

fn total_blocks(&self) -> usize

Source§

fn total_space(&self) -> usize

Source§

fn available_blocks(&self) -> Result<usize>

Source§

fn available_space(&self) -> Result<usize>

Source§

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

Source§

fn remove_dir(&self, path: &Path) -> Result<()>

Source§

fn remove_dir_all(&self, path: &Path) -> Result<()>

Source§

fn remove_dir_all_where( &self, path: &Path, predicate: Predicate<'_>, ) -> Result<usize>

Source§

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

Source§

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

Source§

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

Source§

fn create_file_and_then_unit( &self, path: &Path, f: FileCallback<'_>, ) -> Result<()>

Source§

fn open_file_and_then_unit( &self, path: &Path, f: FileCallback<'_>, ) -> Result<()>

Source§

fn open_file_with_flags_and_then_unit( &self, flags: FileOpenFlags, path: &Path, f: FileCallback<'_>, ) -> Result<()>

Source§

fn attribute<'a>( &self, path: &Path, id: u8, buffer: &'a mut [u8], ) -> Result<Option<Attribute<'a>>>

Source§

fn remove_attribute(&self, path: &Path, id: u8) -> Result<()>

Source§

fn set_attribute(&self, path: &Path, id: u8, data: &[u8]) -> Result<()>

Source§

fn read_dir_and_then_unit( &self, path: &Path, f: DirEntriesCallback<'_>, ) -> Result<()>

Source§

fn create_dir(&self, path: &Path) -> Result<()>

Source§

fn create_dir_all(&self, path: &Path) -> Result<()>

Source§

fn write(&self, path: &Path, contents: &[u8]) -> Result<()>

Source§

fn write_chunk( &self, path: &Path, contents: &[u8], pos: OpenSeekFrom, ) -> Result<()>

Auto Trait Implementations§

§

impl<'a, Storage> !Freeze for Filesystem<'a, Storage>

§

impl<'a, Storage> !RefUnwindSafe for Filesystem<'a, Storage>

§

impl<'a, Storage> !Send for Filesystem<'a, Storage>

§

impl<'a, Storage> !Sync for Filesystem<'a, Storage>

§

impl<'a, Storage> Unpin for Filesystem<'a, Storage>

§

impl<'a, Storage> !UnwindSafe for Filesystem<'a, Storage>

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> Same for T

Source§

type Output = T

Should always be Self
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.