fn cluster_allocated(&mut self, address: u64) -> std::io::Result<bool> {
        if address >= self.virtual_size() as u64 {
            return Err(std::io::Error::from_raw_os_error(EINVAL));
        }

        let l1_index = self.l1_table_index(address) as usize;
        let l2_addr_disk = *self
            .l1_table
            .get(l1_index)
            .ok_or_else(|| std::io::Error::from_raw_os_error(EINVAL))?;
        let l2_index = self.l2_table_index(address) as usize;

        if l2_addr_disk == 0 {
            // The whole L2 table for this address is not allocated yet,
            // so the cluster must also be unallocated.
            return Ok(false);
        }

        if !self.l2_cache.contains_key(l1_index) {
            // Not in the cache.
            let table =
                VecCache::from_vec(Self::read_l2_cluster(&mut self.raw_file, l2_addr_disk)?);
            let l1_table = &self.l1_table;
            let raw_file = &mut self.raw_file;
            self.l2_cache.insert(l1_index, table, |index, evicted| {
                raw_file.write_pointer_table(
                    l1_table[index],
                    evicted.get_values(),
                    CLUSTER_USED_FLAG,
                )
            })?;
        }

        let cluster_addr = self.l2_cache.get(l1_index).unwrap()[l2_index];
        // If cluster_addr != 0, the cluster is allocated.
        Ok(cluster_addr != 0)
    }
// Returns true if the cluster containing `address` is already allocated.
Returns true if the cluster containing `address` is already allocated.
Returns true if the cluster containing ` address ` is already allocated .
fn cluster_allocated(&mut self, address: u64) -> std::io::Result<bool> {
        if address >= self.virtual_size() as u64 {
            return Err(std::io::Error::from_raw_os_error(EINVAL));
        }
        let l1_index = self.l1_table_index(address) as usize;
        let l2_addr_disk = *self
            .l1_table
            .get(l1_index)
            .ok_or_else(|| std::io::Error::from_raw_os_error(EINVAL))?;
        let l2_index = self.l2_table_index(address) as usize;
        if l2_addr_disk == 0 {
            // The whole L2 table for this address is not allocated yet,
            // so the cluster must also be unallocated.
            return Ok(false);
        }
        if !self.l2_cache.contains_key(l1_index) {
            // Not in the cache.
            let table =
                VecCache::from_vec(Self::read_l2_cluster(&mut self.raw_file, l2_addr_disk)?);
            let l1_table = &self.l1_table;
            let raw_file = &mut self.raw_file;
            self.l2_cache.insert(l1_index, table, |index, evicted| {
                raw_file.write_pointer_table(
                    l1_table[index],
                    evicted.get_values(),
                    CLUSTER_USED_FLAG,
                )
            })?;
        }
        let cluster_addr = self.l2_cache.get(l1_index).unwrap()[l2_index];
        // If cluster_addr != 0, the cluster is allocated.
        Ok(cluster_addr != 0)
    }
fn cluster_allocated ( & mut self , address : u64 ) -> std :: io :: Result < bool > { if address >= self . virtual_size ( ) as u64 { return Err ( std :: io :: Error :: from_raw_os_error ( EINVAL ) ) ; } let l1_index = self . l1_table_index ( address ) as usize ; let l2_addr_disk = * self . l1_table . get ( l1_index ) . ok_or_else ( | | std :: io :: Error :: from_raw_os_error ( EINVAL ) ) ? ; let l2_index = self . l2_table_index ( address ) as usize ; if l2_addr_disk == 0 { // The whole L2 table for this address is not allocated yet, // so the cluster must also be unallocated. return Ok ( false ) ; } if ! self . l2_cache . contains_key ( l1_index ) { // Not in the cache. let table = VecCache :: from_vec ( Self :: read_l2_cluster ( & mut self . raw_file , l2_addr_disk ) ? ) ; let l1_table = & self . l1_table ; let raw_file = & mut self . raw_file ; self . l2_cache . insert ( l1_index , table , | index , evicted | { raw_file . write_pointer_table ( l1_table [ index ] , evicted . get_values ( ) , CLUSTER_USED_FLAG , ) } ) ? ; } let cluster_addr = self . l2_cache . get ( l1_index ) . unwrap ( ) [ l2_index ] ; // If cluster_addr != 0, the cluster is allocated. Ok ( cluster_addr != 0 ) }
Returns true if the cluster containing `address` is already allocated.
Returns true if the cluster containing ` address ` is already allocated .
&mut self
address
u64
&mut self
address
u64