pub(crate) fn find_directory_entry<D, T>(
        &self,
        controller: &mut Controller<D, T>,
        dir: &Directory,
        name: &str,
    ) -> Result<DirEntry, Error<D::Error>>
    where
        D: BlockDevice,
        T: TimeSource,
    {
        let match_name = ShortFileName::create_from_str(name).map_err(Error::FilenameError)?;
        let mut current_cluster = match dir.cluster {
            Cluster::ROOT_DIR => Some(self.first_root_dir_cluster),
            _ => Some(dir.cluster),
        };
        let mut blocks = [Block::new()];
        while let Some(cluster) = current_cluster {
            let block_idx = self.cluster_to_block(cluster);
            for block in block_idx.range(BlockCount(u32::from(self.blocks_per_cluster))) {
                controller
                    .block_device
                    .read(&mut blocks, block, "read_dir")
                    .map_err(Error::DeviceError)?;
                for entry in 0..Block::LEN / OnDiskDirEntry::LEN {
                    let start = entry * OnDiskDirEntry::LEN;
                    let end = (entry + 1) * OnDiskDirEntry::LEN;
                    let dir_entry = OnDiskDirEntry::new(&blocks[0][start..end]);
                    if dir_entry.is_end() {
                        // Can quit early
                        return Err(Error::FileNotFound);
                    } else if dir_entry.matches(&match_name) {
                        // Found it
                        // Safe, since Block::LEN always fits on a u32
                        let start = u32::try_from(start).unwrap();
                        return Ok(dir_entry.get_entry(FatType::Fat16, block, start));
                    }
                }
            }
            current_cluster = match self.next_cluster(controller, cluster) {
                Ok(n) => Some(n),
                _ => None,
            }
        }
        Err(Error::FileNotFound)
    }
/// Get an entry from the given directory
Get an entry from the given directory
Get an entry from the given directory
pub(crate) fn find_directory_entry<D, T>(
        &self,
        controller: &mut Controller<D, T>,
        dir: &Directory,
        name: &str,
    ) -> Result<DirEntry, Error<D::Error>>
    where
        D: BlockDevice,
        T: TimeSource,
    {
        let match_name = ShortFileName::create_from_str(name).map_err(Error::FilenameError)?;
        let mut current_cluster = match dir.cluster {
            Cluster::ROOT_DIR => Some(self.first_root_dir_cluster),
            _ => Some(dir.cluster),
        };
        let mut blocks = [Block::new()];
        while let Some(cluster) = current_cluster {
            let block_idx = self.cluster_to_block(cluster);
            for block in block_idx.range(BlockCount(u32::from(self.blocks_per_cluster))) {
                controller
                    .block_device
                    .read(&mut blocks, block, "read_dir")
                    .map_err(Error::DeviceError)?;
                for entry in 0..Block::LEN / OnDiskDirEntry::LEN {
                    let start = entry * OnDiskDirEntry::LEN;
                    let end = (entry + 1) * OnDiskDirEntry::LEN;
                    let dir_entry = OnDiskDirEntry::new(&blocks[0][start..end]);
                    if dir_entry.is_end() {
                        // Can quit early
                        return Err(Error::FileNotFound);
                    } else if dir_entry.matches(&match_name) {
                        // Found it
                        // Safe, since Block::LEN always fits on a u32
                        let start = u32::try_from(start).unwrap();
                        return Ok(dir_entry.get_entry(FatType::Fat16, block, start));
                    }
                }
            }
            current_cluster = match self.next_cluster(controller, cluster) {
                Ok(n) => Some(n),
                _ => None,
            }
        }
        Err(Error::FileNotFound)
    }
pub ( crate ) fn find_directory_entry < D , T > ( & self , controller : & mut Controller < D , T > , dir : & Directory , name : & str , ) -> Result < DirEntry , Error < D :: Error > > where D : BlockDevice , T : TimeSource , { let match_name = ShortFileName :: create_from_str ( name ) . map_err ( Error :: FilenameError ) ? ; let mut current_cluster = match dir . cluster { Cluster :: ROOT_DIR => Some ( self . first_root_dir_cluster ) , _ => Some ( dir . cluster ) , } ; let mut blocks = [ Block :: new ( ) ] ; while let Some ( cluster ) = current_cluster { let block_idx = self . cluster_to_block ( cluster ) ; for block in block_idx . range ( BlockCount ( u32 :: from ( self . blocks_per_cluster ) ) ) { controller . block_device . read ( & mut blocks , block , " " ) . map_err ( Error :: DeviceError ) ? ; for entry in 0 .. Block :: LEN / OnDiskDirEntry :: LEN { let start = entry * OnDiskDirEntry :: LEN ; let end = ( entry + 1 ) * OnDiskDirEntry :: LEN ; let dir_entry = OnDiskDirEntry :: new ( & blocks [ 0 ] [ start .. end ] ) ; if dir_entry . is_end ( ) { // Can quit early return Err ( Error :: FileNotFound ) ; } else if dir_entry . matches ( & match_name ) { // Found it // Safe, since Block::LEN always fits on a u32 let start = u32 :: try_from ( start ) . unwrap ( ) ; return Ok ( dir_entry . get_entry ( FatType :: Fat16 , block , start ) ) ; } } } current_cluster = match self . next_cluster ( controller , cluster ) { Ok ( n ) => Some ( n ) , _ => None , } } Err ( Error :: FileNotFound ) }
Get an entry from the given directory
Get an entry from the given directory
&self
controller
&mut Controller<D, T>
dir
&Directory
name
&str
&self
controller
&mut Controller<D, T>
dir
&Directory
name
&str