pub fn new(
        disk_spec: &DiskSpec,
        bat: &[BatEntry],
        sector_index: u64,
        sector_count: u64,
    ) -> Result<Sector> {
        let mut sector = Sector::default();

        sector.bat_index = sector_index / disk_spec.sectors_per_block as u64;
        sector.block_offset = sector_index % disk_spec.sectors_per_block as u64;
        sector.free_sectors = disk_spec.sectors_per_block as u64 - sector.block_offset;
        if sector.free_sectors > sector_count {
            sector.free_sectors = sector_count;
        }

        sector.free_bytes = sector.free_sectors * disk_spec.logical_sector_size as u64;
        sector.block_offset *= disk_spec.logical_sector_size as u64;

        let bat_entry = match bat.get(sector.bat_index as usize) {
            Some(entry) => entry.0,
            None => {
                return Err(VhdxIoError::InvalidBatIndex);
            }
        };
        sector.file_offset = bat_entry & vhdx_bat::BAT_FILE_OFF_MASK;
        if sector.file_offset != 0 {
            sector.file_offset += sector.block_offset;
        }

        Ok(sector)
    }
/// Translate sector index and count of data in file to actual offsets and
/// BAT index.
Translate sector index and count of data in file to actual offsets and
BAT index.
Translate sector index and count of data in file to actual offsets and BAT index .
pub fn new(
        disk_spec: &DiskSpec,
        bat: &[BatEntry],
        sector_index: u64,
        sector_count: u64,
    ) -> Result<Sector> {
        let mut sector = Sector::default();
        sector.bat_index = sector_index / disk_spec.sectors_per_block as u64;
        sector.block_offset = sector_index % disk_spec.sectors_per_block as u64;
        sector.free_sectors = disk_spec.sectors_per_block as u64 - sector.block_offset;
        if sector.free_sectors > sector_count {
            sector.free_sectors = sector_count;
        }
        sector.free_bytes = sector.free_sectors * disk_spec.logical_sector_size as u64;
        sector.block_offset *= disk_spec.logical_sector_size as u64;
        let bat_entry = match bat.get(sector.bat_index as usize) {
            Some(entry) => entry.0,
            None => {
                return Err(VhdxIoError::InvalidBatIndex);
            }
        };
        sector.file_offset = bat_entry & vhdx_bat::BAT_FILE_OFF_MASK;
        if sector.file_offset != 0 {
            sector.file_offset += sector.block_offset;
        }
        Ok(sector)
    }
pub fn new ( disk_spec : & DiskSpec , bat : & [ BatEntry ] , sector_index : u64 , sector_count : u64 , ) -> Result < Sector > { let mut sector = Sector :: default ( ) ; sector . bat_index = sector_index / disk_spec . sectors_per_block as u64 ; sector . block_offset = sector_index % disk_spec . sectors_per_block as u64 ; sector . free_sectors = disk_spec . sectors_per_block as u64 - sector . block_offset ; if sector . free_sectors > sector_count { sector . free_sectors = sector_count ; } sector . free_bytes = sector . free_sectors * disk_spec . logical_sector_size as u64 ; sector . block_offset *= disk_spec . logical_sector_size as u64 ; let bat_entry = match bat . get ( sector . bat_index as usize ) { Some ( entry ) => entry . 0 , None => { return Err ( VhdxIoError :: InvalidBatIndex ) ; } } ; sector . file_offset = bat_entry & vhdx_bat :: BAT_FILE_OFF_MASK ; if sector . file_offset != 0 { sector . file_offset += sector . block_offset ; } Ok ( sector ) }
Translate sector index and count of data in file to actual offsets and
BAT index.
Translate sector index and count of data in file to actual offsets and BAT index .
disk_spec
&DiskSpec
bat
&[BatEntry]
sector_index
u64
sector_count
u64
disk_spec
&DiskSpec
bat
&[BatEntry]
sector_index
u64
sector_count
u64