fn file_offset_read(&mut self, address: u64) -> std::io::Result<Option<u64>> {
        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))?;

        if l2_addr_disk == 0 {
            // Reading from an unallocated cluster will return zeros.
            return Ok(None);
        }

        let l2_index = self.l2_table_index(address) as usize;

        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 {
            return Ok(None);
        }
        Ok(Some(cluster_addr + self.raw_file.cluster_offset(address)))
    }
// Gets the offset of the given guest address in the host file. If L1, L2, or data clusters have
// yet to be allocated, return None.
Gets the offset of the given guest address in the host file. If L1, L2, or data clusters have
yet to be allocated, return None.
Gets the offset of the given guest address in the host file . If L1 L2 or data clusters have yet to be allocated return None .
fn file_offset_read(&mut self, address: u64) -> std::io::Result<Option<u64>> {
        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))?;
        if l2_addr_disk == 0 {
            // Reading from an unallocated cluster will return zeros.
            return Ok(None);
        }
        let l2_index = self.l2_table_index(address) as usize;
        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 {
            return Ok(None);
        }
        Ok(Some(cluster_addr + self.raw_file.cluster_offset(address)))
    }
fn file_offset_read ( & mut self , address : u64 ) -> std :: io :: Result < Option < u64 > > { 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 ) ) ? ; if l2_addr_disk == 0 { // Reading from an unallocated cluster will return zeros. return Ok ( None ) ; } let l2_index = self . l2_table_index ( address ) as usize ; 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 { return Ok ( None ) ; } Ok ( Some ( cluster_addr + self . raw_file . cluster_offset ( address ) ) ) }
Gets the offset of the given guest address in the host file.
Gets the offset of the given guest address in the host file .
&mut self
address
u64
&mut self
address
u64