pub struct Volume<D, T, const MAX_DIRS: usize = 4, const MAX_FILES: usize = 4>{ /* private fields */ }
Expand description
A VolumeManager
wraps a block device and gives access to the FAT-formatted
volumes within it.
Implementations§
Source§impl<D, T> Volume<D, T>
impl<D, T> Volume<D, T>
Sourcepub async fn new(
block_device: D,
time_source: T,
) -> Result<Volume<D, T>, Error<<D as BlockDevice>::Error>>
pub async fn new( block_device: D, time_source: T, ) -> Result<Volume<D, T>, Error<<D as BlockDevice>::Error>>
Create a new Volume Manager using a generic BlockDevice
. From this
object we can open volumes (partitions) and with those we can open
files.
This creates a VolumeManager
with default values
MAX_DIRS = 4, MAX_FILES = 4, MAX_VOLUMES = 1. Call VolumeManager::new_with_limits(block_device, time_source)
if you need different limits.
Source§impl<D, T, const MAX_DIRS: usize, const MAX_FILES: usize> Volume<D, T, MAX_DIRS, MAX_FILES>
impl<D, T, const MAX_DIRS: usize, const MAX_FILES: usize> Volume<D, T, MAX_DIRS, MAX_FILES>
Sourcepub async fn new_with_limits(
block_device: D,
time_source: T,
id_offset: u32,
) -> Result<Volume<D, T, MAX_DIRS, MAX_FILES>, Error<<D as BlockDevice>::Error>>
pub async fn new_with_limits( block_device: D, time_source: T, id_offset: u32, ) -> Result<Volume<D, T, MAX_DIRS, MAX_FILES>, Error<<D as BlockDevice>::Error>>
Create a new Volume Manager using a generic BlockDevice
. From this
object we can open volumes (partitions) and with those we can open
files.
You can also give an offset for all the IDs this volume manager generates, which might help you find the IDs in your logs when debugging.
Sourcepub fn open_root_dir(
&mut self,
) -> Result<Directory, Error<<D as BlockDevice>::Error>>
pub fn open_root_dir( &mut self, ) -> Result<Directory, Error<<D as BlockDevice>::Error>>
Open the volume’s root directory.
You can then read the directory entries with iterate_dir
, or you can
use open_file_in_dir
.
Sourcepub async fn open_dir<N>(
&mut self,
parent_dir: Directory,
name: N,
) -> Result<Directory, Error<<D as BlockDevice>::Error>>where
N: ToShortFileName,
pub async fn open_dir<N>(
&mut self,
parent_dir: Directory,
name: N,
) -> Result<Directory, Error<<D as BlockDevice>::Error>>where
N: ToShortFileName,
Open a directory.
You can then read the directory entries with iterate_dir
and open_file_in_dir
.
TODO: Work out how to prevent damage occuring to the file system while this directory handle is open. In particular, stop this directory being unlinked.
Sourcepub fn close_dir(
&mut self,
directory: Directory,
) -> Result<(), Error<<D as BlockDevice>::Error>>
pub fn close_dir( &mut self, directory: Directory, ) -> Result<(), Error<<D as BlockDevice>::Error>>
Close a directory. You cannot perform operations on an open directory and so must close it if you want to do something with it.
Sourcepub async fn find_directory_entry<N>(
&mut self,
directory: Directory,
name: N,
) -> Result<DirEntry, Error<<D as BlockDevice>::Error>>where
N: ToShortFileName,
pub async fn find_directory_entry<N>(
&mut self,
directory: Directory,
name: N,
) -> Result<DirEntry, Error<<D as BlockDevice>::Error>>where
N: ToShortFileName,
Look in a directory for a named file.
pub async fn find_lfn_directory_entry( &mut self, directory: Directory, name: &str, ) -> Result<DirEntry, Error<<D as BlockDevice>::Error>>
Sourcepub async fn iterate_dir<F, U>(
&mut self,
directory: Directory,
func: F,
) -> Result<Option<U>, Error<<D as BlockDevice>::Error>>where
F: FnMut(&DirEntry) -> ControlFlow<U>,
pub async fn iterate_dir<F, U>(
&mut self,
directory: Directory,
func: F,
) -> Result<Option<U>, Error<<D as BlockDevice>::Error>>where
F: FnMut(&DirEntry) -> ControlFlow<U>,
Call a callback function for each directory entry in a directory.
Sourcepub async fn iterate_lfn_dir<F, U>(
&mut self,
directory: Directory,
func: F,
) -> Result<Option<U>, Error<<D as BlockDevice>::Error>>where
F: FnMut(Option<&str>, &DirEntry) -> ControlFlow<U>,
pub async fn iterate_lfn_dir<F, U>(
&mut self,
directory: Directory,
func: F,
) -> Result<Option<U>, Error<<D as BlockDevice>::Error>>where
F: FnMut(Option<&str>, &DirEntry) -> ControlFlow<U>,
Call a callback function for each directory entry in a directory, with its LFN if it has one.
Sourcepub async fn open_file_in_dir<N>(
&mut self,
directory: Directory,
name: N,
mode: Mode,
) -> Result<File, Error<<D as BlockDevice>::Error>>where
N: ToShortFileName,
pub async fn open_file_in_dir<N>(
&mut self,
directory: Directory,
name: N,
mode: Mode,
) -> Result<File, Error<<D as BlockDevice>::Error>>where
N: ToShortFileName,
Open a file with the given full path. A file can only be opened once.
Sourcepub async fn delete_file_in_dir<N>(
&mut self,
directory: Directory,
name: N,
) -> Result<(), Error<<D as BlockDevice>::Error>>where
N: ToShortFileName,
pub async fn delete_file_in_dir<N>(
&mut self,
directory: Directory,
name: N,
) -> Result<(), Error<<D as BlockDevice>::Error>>where
N: ToShortFileName,
Delete a closed file with the given filename, if it exists.
Sourcepub async fn read(
&mut self,
file: File,
buffer: &mut [u8],
) -> Result<usize, Error<<D as BlockDevice>::Error>>
pub async fn read( &mut self, file: File, buffer: &mut [u8], ) -> Result<usize, Error<<D as BlockDevice>::Error>>
Read from an open file.
Sourcepub async fn write(
&mut self,
file: File,
buffer: &[u8],
) -> Result<usize, Error<<D as BlockDevice>::Error>>
pub async fn write( &mut self, file: File, buffer: &[u8], ) -> Result<usize, Error<<D as BlockDevice>::Error>>
Write to a open file.
Sourcepub async fn close_file(
&mut self,
file: File,
) -> Result<(), Error<<D as BlockDevice>::Error>>
pub async fn close_file( &mut self, file: File, ) -> Result<(), Error<<D as BlockDevice>::Error>>
Close a file with the given full path.
Sourcepub fn has_open_handles(&self) -> bool
pub fn has_open_handles(&self) -> bool
Check if any files or folders are open.
Sourcepub fn file_eof(
&self,
file: File,
) -> Result<bool, Error<<D as BlockDevice>::Error>>
pub fn file_eof( &self, file: File, ) -> Result<bool, Error<<D as BlockDevice>::Error>>
Check if a file is at End Of File.
Sourcepub fn file_seek_from_start(
&mut self,
file: File,
offset: u32,
) -> Result<(), Error<<D as BlockDevice>::Error>>
pub fn file_seek_from_start( &mut self, file: File, offset: u32, ) -> Result<(), Error<<D as BlockDevice>::Error>>
Seek a file with an offset from the start of the file.
Sourcepub fn file_seek_from_current(
&mut self,
file: File,
offset: i32,
) -> Result<(), Error<<D as BlockDevice>::Error>>
pub fn file_seek_from_current( &mut self, file: File, offset: i32, ) -> Result<(), Error<<D as BlockDevice>::Error>>
Seek a file with an offset from the current position.
Sourcepub fn file_seek_from_end(
&mut self,
file: File,
offset: u32,
) -> Result<(), Error<<D as BlockDevice>::Error>>
pub fn file_seek_from_end( &mut self, file: File, offset: u32, ) -> Result<(), Error<<D as BlockDevice>::Error>>
Seek a file with an offset back from the end of the file.
Sourcepub fn file_length(
&self,
file: File,
) -> Result<u32, Error<<D as BlockDevice>::Error>>
pub fn file_length( &self, file: File, ) -> Result<u32, Error<<D as BlockDevice>::Error>>
Get the length of a file
Sourcepub fn file_offset(
&self,
file: File,
) -> Result<u32, Error<<D as BlockDevice>::Error>>
pub fn file_offset( &self, file: File, ) -> Result<u32, Error<<D as BlockDevice>::Error>>
Get the current offset of a file