pub struct Filesystem<'a, Storage: Storage> { /* private fields */ }
Implementations§
Source§impl<Storage: Storage> Filesystem<'_, Storage>
impl<Storage: Storage> Filesystem<'_, Storage>
pub fn allocate() -> Allocation<Storage>
pub fn format(storage: &mut Storage) -> Result<()>
pub fn is_mountable(storage: &mut Storage) -> bool
pub unsafe fn borrow_storage_mut(&mut self) -> &mut Storage
Sourcepub fn mount_and_then<R>(
storage: &mut Storage,
f: impl FnOnce(&Filesystem<'_, Storage>) -> Result<R>,
) -> Result<R>
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
.
Sourcepub fn total_blocks(&self) -> usize
pub fn total_blocks(&self) -> usize
Total number of blocks in the filesystem
Sourcepub fn total_space(&self) -> usize
pub fn total_space(&self) -> usize
Total number of bytes in the filesystem
Sourcepub fn available_blocks(&self) -> Result<usize>
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.
Sourcepub fn available_space(&self) -> Result<usize>
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.
Sourcepub fn remove_dir(&self, path: &Path) -> Result<()>
pub fn remove_dir(&self, path: &Path) -> Result<()>
Remove a file or directory.
Sourcepub fn remove_dir_all(&self, path: &Path) -> Result<()>
pub fn remove_dir_all(&self, path: &Path) -> Result<()>
TODO: This method fails if some println!
calls are removed.
Whyy?
pub fn remove_dir_all_where<P>( &self, path: &Path, predicate: &P, ) -> Result<usize>
Sourcepub fn exists(&self, path: &Path) -> bool
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.
Sourcepub fn metadata(&self, path: &Path) -> Result<Metadata>
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
pub fn create_file_and_then<R>( &self, path: &Path, f: impl FnOnce(&File<'_, '_, Storage>) -> Result<R>, ) -> Result<R>
pub fn open_file_and_then<R>( &self, path: &Path, f: impl FnOnce(&File<'_, '_, Storage>) -> Result<R>, ) -> Result<R>
pub fn with_options() -> OpenOptions
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§impl<'a, Storage: Storage> Filesystem<'a, Storage>
impl<'a, Storage: Storage> Filesystem<'a, Storage>
Source§impl<'a, Storage: Storage> Filesystem<'a, Storage>
impl<'a, Storage: Storage> Filesystem<'a, Storage>
pub fn mount( alloc: &'a mut Allocation<Storage>, storage: &'a mut Storage, ) -> Result<Self>
Sourcepub fn mount_or_else<F>(
alloc: &'a mut Allocation<Storage>,
storage: &'a mut Storage,
f: F,
) -> Result<Self>
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.
Sourcepub fn into_inner(self) -> (&'a mut Allocation<Storage>, &'a mut Storage)
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
.
Sourcepub fn create_dir(&self, path: &Path) -> Result<()>
pub fn create_dir(&self, path: &Path) -> Result<()>
Creates a new, empty directory at the provided path.
Sourcepub fn create_dir_all(&self, path: &Path) -> Result<()>
pub fn create_dir_all(&self, path: &Path) -> Result<()>
Recursively create a directory and all of its parent components if they are missing.
Sourcepub fn read<const N: usize>(&self, path: &Path) -> Result<Vec<u8, N>>
pub fn read<const N: usize>(&self, path: &Path) -> Result<Vec<u8, N>>
Read the entire contents of a file into a bytes vector.
Sourcepub fn read_chunk<const N: usize>(
&self,
path: &Path,
pos: OpenSeekFrom,
) -> Result<(Vec<u8, N>, usize)>
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
Sourcepub fn write(&self, path: &Path, contents: &[u8]) -> Result<()>
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.
Sourcepub fn write_chunk(
&self,
path: &Path,
contents: &[u8],
pos: OpenSeekFrom,
) -> Result<()>
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