pub fn read(
    f: &mut File,
    buf: &mut [u8],
    disk_spec: &DiskSpec,
    bat: &[BatEntry],
    mut sector_index: u64,
    mut sector_count: u64,
) -> Result<usize> {
    let mut read_count: usize = 0;

    while sector_count > 0 {
        if disk_spec.has_parent {
            return Err(VhdxIoError::UnsupportedMode);
        } else {
            let sector = Sector::new(disk_spec, bat, sector_index, sector_count)?;

            let bat_entry = match bat.get(sector.bat_index as usize) {
                Some(entry) => entry.0,
                None => {
                    return Err(VhdxIoError::InvalidBatIndex);
                }
            };

            match bat_entry & vhdx_bat::BAT_STATE_BIT_MASK {
                vhdx_bat::PAYLOAD_BLOCK_NOT_PRESENT
                | vhdx_bat::PAYLOAD_BLOCK_UNDEFINED
                | vhdx_bat::PAYLOAD_BLOCK_UNMAPPED
                | vhdx_bat::PAYLOAD_BLOCK_ZERO => {}
                vhdx_bat::PAYLOAD_BLOCK_FULLY_PRESENT => {
                    f.seek(SeekFrom::Start(sector.file_offset))
                        .map_err(VhdxIoError::ReadSectorBlock)?;
                    f.read_exact(
                        &mut buf[read_count
                            ..(read_count + (sector.free_sectors * SECTOR_SIZE) as usize)],
                    )
                    .map_err(VhdxIoError::ReadSectorBlock)?;
                }
                vhdx_bat::PAYLOAD_BLOCK_PARTIALLY_PRESENT => {
                    return Err(VhdxIoError::UnsupportedMode);
                }
                _ => {
                    return Err(VhdxIoError::InvalidBatEntryState);
                }
            };
            sector_count -= sector.free_sectors;
            sector_index += sector.free_sectors;
            read_count = sector.free_bytes as usize;
        };
    }
    Ok(read_count)
}
/// VHDx IO read routine: requires relative sector index and count for the
/// requested data.
VHDx IO read routine: requires relative sector index and count for the
requested data.
VHDx IO read routine : requires relative sector index and count for the requested data .
pub fn read(
    f: &mut File,
    buf: &mut [u8],
    disk_spec: &DiskSpec,
    bat: &[BatEntry],
    mut sector_index: u64,
    mut sector_count: u64,
) -> Result<usize> {
    let mut read_count: usize = 0;
    while sector_count > 0 {
        if disk_spec.has_parent {
            return Err(VhdxIoError::UnsupportedMode);
        } else {
            let sector = Sector::new(disk_spec, bat, sector_index, sector_count)?;
            let bat_entry = match bat.get(sector.bat_index as usize) {
                Some(entry) => entry.0,
                None => {
                    return Err(VhdxIoError::InvalidBatIndex);
                }
            };
            match bat_entry & vhdx_bat::BAT_STATE_BIT_MASK {
                vhdx_bat::PAYLOAD_BLOCK_NOT_PRESENT
                | vhdx_bat::PAYLOAD_BLOCK_UNDEFINED
                | vhdx_bat::PAYLOAD_BLOCK_UNMAPPED
                | vhdx_bat::PAYLOAD_BLOCK_ZERO => {}
                vhdx_bat::PAYLOAD_BLOCK_FULLY_PRESENT => {
                    f.seek(SeekFrom::Start(sector.file_offset))
                        .map_err(VhdxIoError::ReadSectorBlock)?;
                    f.read_exact(
                        &mut buf[read_count
                            ..(read_count + (sector.free_sectors * SECTOR_SIZE) as usize)],
                    )
                    .map_err(VhdxIoError::ReadSectorBlock)?;
                }
                vhdx_bat::PAYLOAD_BLOCK_PARTIALLY_PRESENT => {
                    return Err(VhdxIoError::UnsupportedMode);
                }
                _ => {
                    return Err(VhdxIoError::InvalidBatEntryState);
                }
            };
            sector_count -= sector.free_sectors;
            sector_index += sector.free_sectors;
            read_count = sector.free_bytes as usize;
        };
    }
    Ok(read_count)
}
pub fn read ( f : & mut File , buf : & mut [ u8 ] , disk_spec : & DiskSpec , bat : & [ BatEntry ] , mut sector_index : u64 , mut sector_count : u64 , ) -> Result < usize > { let mut read_count : usize = 0 ; while sector_count > 0 { if disk_spec . has_parent { return Err ( VhdxIoError :: UnsupportedMode ) ; } else { let sector = Sector :: new ( disk_spec , bat , sector_index , sector_count ) ? ; let bat_entry = match bat . get ( sector . bat_index as usize ) { Some ( entry ) => entry . 0 , None => { return Err ( VhdxIoError :: InvalidBatIndex ) ; } } ; match bat_entry & vhdx_bat :: BAT_STATE_BIT_MASK { vhdx_bat :: PAYLOAD_BLOCK_NOT_PRESENT | vhdx_bat :: PAYLOAD_BLOCK_UNDEFINED | vhdx_bat :: PAYLOAD_BLOCK_UNMAPPED | vhdx_bat :: PAYLOAD_BLOCK_ZERO => { } vhdx_bat :: PAYLOAD_BLOCK_FULLY_PRESENT => { f . seek ( SeekFrom :: Start ( sector . file_offset ) ) . map_err ( VhdxIoError :: ReadSectorBlock ) ? ; f . read_exact ( & mut buf [ read_count .. ( read_count + ( sector . free_sectors * SECTOR_SIZE ) as usize ) ] , ) . map_err ( VhdxIoError :: ReadSectorBlock ) ? ; } vhdx_bat :: PAYLOAD_BLOCK_PARTIALLY_PRESENT => { return Err ( VhdxIoError :: UnsupportedMode ) ; } _ => { return Err ( VhdxIoError :: InvalidBatEntryState ) ; } } ; sector_count -= sector . free_sectors ; sector_index += sector . free_sectors ; read_count = sector . free_bytes as usize ; } ; } Ok ( read_count ) }
VHDx IO read routine: requires relative sector index and count for the
requested data.
VHDx IO read routine : requires relative sector index and count for the requested data .
f
&mut File
buf
&mut [u8]
disk_spec
&DiskSpec
bat
&[BatEntry]
sector_index
u64
sector_count
u64
f
&mut File
buf
&mut [u8]
disk_spec
&DiskSpec
bat
&[BatEntry]
sector_index
u64
sector_count
u64