pub(crate) fn find_next_free_cluster<D, T>(
        &self,
        controller: &mut Controller<D, T>,
        start_cluster: Cluster,
        end_cluster: Cluster,
    ) -> Result<Cluster, Error<D::Error>>
    where
        D: BlockDevice,
        T: TimeSource,
    {
        let mut blocks = [Block::new()];
        let mut current_cluster = start_cluster;
        while current_cluster.0 < end_cluster.0 {
            trace!(
                "current_cluster={:?}, end_cluster={:?}",
                current_cluster,
                end_cluster
            );
            let fat_offset = current_cluster.0 * 4;
            trace!("fat_offset = {:?}", fat_offset);
            let this_fat_block_num = self.lba_start + self.fat_start.offset_bytes(fat_offset);
            trace!("this_fat_block_num = {:?}", this_fat_block_num);
            let mut this_fat_ent_offset =
                usize::try_from(fat_offset % Block::LEN_U32).map_err(|_| Error::ConversionError)?;
            trace!("Reading block {:?}", this_fat_block_num);
            controller
                .block_device
                .read(&mut blocks, this_fat_block_num, "next_cluster")
                .map_err(Error::DeviceError)?;

            while this_fat_ent_offset <= Block::LEN - 4 {
                let fat_entry = LittleEndian::read_u32(
                    &blocks[0][this_fat_ent_offset..=this_fat_ent_offset + 3],
                ) & 0x0FFF_FFFF;
                if fat_entry == 0 {
                    return Ok(current_cluster);
                }
                this_fat_ent_offset += 4;
                current_cluster += 1;
            }
        }
        warn!("Out of space...");
        Err(Error::NotEnoughSpace)
    }
/// Finds the next free cluster after the start_cluster and before end_cluster
Finds the next free cluster after the start_cluster and before end_cluster
Finds the next free cluster after the start_cluster and before end_cluster
pub(crate) fn find_next_free_cluster<D, T>(
        &self,
        controller: &mut Controller<D, T>,
        start_cluster: Cluster,
        end_cluster: Cluster,
    ) -> Result<Cluster, Error<D::Error>>
    where
        D: BlockDevice,
        T: TimeSource,
    {
        let mut blocks = [Block::new()];
        let mut current_cluster = start_cluster;
        while current_cluster.0 < end_cluster.0 {
            trace!(
                "current_cluster={:?}, end_cluster={:?}",
                current_cluster,
                end_cluster
            );
            let fat_offset = current_cluster.0 * 4;
            trace!("fat_offset = {:?}", fat_offset);
            let this_fat_block_num = self.lba_start + self.fat_start.offset_bytes(fat_offset);
            trace!("this_fat_block_num = {:?}", this_fat_block_num);
            let mut this_fat_ent_offset =
                usize::try_from(fat_offset % Block::LEN_U32).map_err(|_| Error::ConversionError)?;
            trace!("Reading block {:?}", this_fat_block_num);
            controller
                .block_device
                .read(&mut blocks, this_fat_block_num, "next_cluster")
                .map_err(Error::DeviceError)?;
            while this_fat_ent_offset <= Block::LEN - 4 {
                let fat_entry = LittleEndian::read_u32(
                    &blocks[0][this_fat_ent_offset..=this_fat_ent_offset + 3],
                ) & 0x0FFF_FFFF;
                if fat_entry == 0 {
                    return Ok(current_cluster);
                }
                this_fat_ent_offset += 4;
                current_cluster += 1;
            }
        }
        warn!("Out of space...");
        Err(Error::NotEnoughSpace)
    }
pub ( crate ) fn find_next_free_cluster < D , T > ( & self , controller : & mut Controller < D , T > , start_cluster : Cluster , end_cluster : Cluster , ) -> Result < Cluster , Error < D :: Error > > where D : BlockDevice , T : TimeSource , { let mut blocks = [ Block :: new ( ) ] ; let mut current_cluster = start_cluster ; while current_cluster . 0 < end_cluster . 0 { trace ! ( " " current_cluster end_cluster ) ; let fat_offset = current_cluster . 0 * 4 ; trace ! ( " " fat_offset ) ; let this_fat_block_num = self . lba_start + self . fat_start . offset_bytes ( fat_offset ) ; trace ! ( " " this_fat_block_num ) ; let mut this_fat_ent_offset = usize :: try_from ( fat_offset % Block :: LEN_U32 ) . map_err ( | _ | Error :: ConversionError ) ? ; trace ! ( " " this_fat_block_num ) ; controller . block_device . read ( & mut blocks , this_fat_block_num , " " ) . map_err ( Error :: DeviceError ) ? ; while this_fat_ent_offset <= Block :: LEN - 4 { let fat_entry = LittleEndian :: read_u32 ( & blocks [ 0 ] [ this_fat_ent_offset ..= this_fat_ent_offset + 3 ] , ) & 0x0FFF_FFFF ; if fat_entry == 0 { return Ok ( current_cluster ) ; } this_fat_ent_offset += 4 ; current_cluster += 1 ; } } warn ! ( " " ) ; Err ( Error :: NotEnoughSpace ) }
Finds the next free cluster after the start_cluster and before end_cluster
Finds the next free cluster after the start_cluster and before end_cluster
&self
controller
&mut Controller<D, T>
start_cluster
Cluster
end_cluster
Cluster
&self
controller
&mut Controller<D, T>
start_cluster
Cluster
end_cluster
Cluster