pub fn open_dir(
        &mut self,
        volume: &Volume,
        parent_dir: &Directory,
        name: &str,
    ) -> Result<Directory, Error<D::Error>> {
        // Find a free open directory table row
        let mut open_dirs_row = None;
        for (i, d) in self.open_dirs.iter().enumerate() {
            if d.1 == Cluster::INVALID {
                open_dirs_row = Some(i);
            }
        }
        let open_dirs_row = open_dirs_row.ok_or(Error::TooManyOpenDirs)?;

        // Open the directory
        let dir_entry = match &volume.volume_type {
            VolumeType::Fat16(fat) => fat.find_directory_entry(self, parent_dir, name)?,
            VolumeType::Fat32(fat) => fat.find_directory_entry(self, parent_dir, name)?,
        };

        if !dir_entry.attributes.is_directory() {
            return Err(Error::OpenedDirAsFile);
        }

        // Check it's not already open
        for (_i, dir_table_row) in self.open_dirs.iter().enumerate() {
            if *dir_table_row == (volume.idx, dir_entry.cluster) {
                return Err(Error::DirAlreadyOpen);
            }
        }
        // Remember this open directory
        self.open_dirs[open_dirs_row] = (volume.idx, dir_entry.cluster);
        Ok(Directory {
            cluster: dir_entry.cluster,
            entry: Some(dir_entry),
        })
    }
/// Open a directory. You can then read the directory entries in a random
/// order using `get_directory_entry`.
///
/// 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.
Open a directory. You can then read the directory entries in a random
order using `get_directory_entry`.

Work out how to prevent damage occuring to the file system while
this directory handle is open. In particular, stop this directory
being unlinked.
Open a directory . You can then read the directory entries in a random order using ` get_directory_entry ` . Work out how to prevent damage occuring to the file system while this directory handle is open . In particular stop this directory being unlinked .
pub fn open_dir(
        &mut self,
        volume: &Volume,
        parent_dir: &Directory,
        name: &str,
    ) -> Result<Directory, Error<D::Error>> {
        // Find a free open directory table row
        let mut open_dirs_row = None;
        for (i, d) in self.open_dirs.iter().enumerate() {
            if d.1 == Cluster::INVALID {
                open_dirs_row = Some(i);
            }
        }
        let open_dirs_row = open_dirs_row.ok_or(Error::TooManyOpenDirs)?;
        // Open the directory
        let dir_entry = match &volume.volume_type {
            VolumeType::Fat16(fat) => fat.find_directory_entry(self, parent_dir, name)?,
            VolumeType::Fat32(fat) => fat.find_directory_entry(self, parent_dir, name)?,
        };
        if !dir_entry.attributes.is_directory() {
            return Err(Error::OpenedDirAsFile);
        }
        // Check it's not already open
        for (_i, dir_table_row) in self.open_dirs.iter().enumerate() {
            if *dir_table_row == (volume.idx, dir_entry.cluster) {
                return Err(Error::DirAlreadyOpen);
            }
        }
        // Remember this open directory
        self.open_dirs[open_dirs_row] = (volume.idx, dir_entry.cluster);
        Ok(Directory {
            cluster: dir_entry.cluster,
            entry: Some(dir_entry),
        })
    }
pub fn open_dir ( & mut self , volume : & Volume , parent_dir : & Directory , name : & str , ) -> Result < Directory , Error < D :: Error > > { // Find a free open directory table row let mut open_dirs_row = None ; for ( i , d ) in self . open_dirs . iter ( ) . enumerate ( ) { if d . 1 == Cluster :: INVALID { open_dirs_row = Some ( i ) ; } } let open_dirs_row = open_dirs_row . ok_or ( Error :: TooManyOpenDirs ) ? ; // Open the directory let dir_entry = match & volume . volume_type { VolumeType :: Fat16 ( fat ) => fat . find_directory_entry ( self , parent_dir , name ) ? , VolumeType :: Fat32 ( fat ) => fat . find_directory_entry ( self , parent_dir , name ) ? , } ; if ! dir_entry . attributes . is_directory ( ) { return Err ( Error :: OpenedDirAsFile ) ; } // Check it's not already open for ( _i , dir_table_row ) in self . open_dirs . iter ( ) . enumerate ( ) { if * dir_table_row == ( volume . idx , dir_entry . cluster ) { return Err ( Error :: DirAlreadyOpen ) ; } } // Remember this open directory self . open_dirs [ open_dirs_row ] = ( volume . idx , dir_entry . cluster ) ; Ok ( Directory { cluster : dir_entry . cluster , entry : Some ( dir_entry ) , } ) }
Open a directory.
Open a directory .
&mut self
volume
&Volume
parent_dir
&Directory
name
&str
&mut self
volume
&Volume
parent_dir
&Directory
name
&str