pub fn new(f: &mut File, start: u64) -> Result<RegionTableHeader> {
        // Read the whole header into a buffer. We will need it for calculating
        // checksum.
        let mut buffer = [0u8; REGION_SIZE as usize];
        f.seek(SeekFrom::Start(start))
            .map_err(VhdxHeaderError::SeekRegionTableHeader)?;
        f.read_exact(&mut buffer)
            .map_err(VhdxHeaderError::ReadRegionTableHeader)?;

        let region_table_header = unsafe { *(buffer.as_ptr() as *mut RegionTableHeader) };
        if region_table_header.signature != REGION_SIGN {
            return Err(VhdxHeaderError::InvalidRegionSign);
        }

        let new_checksum = calculate_checksum(&mut buffer, size_of::<u32>())?;
        if region_table_header.checksum != new_checksum {
            return Err(VhdxHeaderError::InvalidChecksum(String::from("Region")));
        }

        if region_table_header.entry_count > 2047 {
            return Err(VhdxHeaderError::InvalidEntryCount);
        }

        if region_table_header.reserved != 0 {
            return Err(VhdxHeaderError::ReservedIsNonZero);
        }

        Ok(region_table_header)
    }
/// Reads the Region Table Header structure from a reference VHDx file
Reads the Region Table Header structure from a reference VHDx file
Reads the Region Table Header structure from a reference VHDx file
pub fn new(f: &mut File, start: u64) -> Result<RegionTableHeader> {
        // Read the whole header into a buffer. We will need it for calculating
        // checksum.
        let mut buffer = [0u8; REGION_SIZE as usize];
        f.seek(SeekFrom::Start(start))
            .map_err(VhdxHeaderError::SeekRegionTableHeader)?;
        f.read_exact(&mut buffer)
            .map_err(VhdxHeaderError::ReadRegionTableHeader)?;
        let region_table_header = unsafe { *(buffer.as_ptr() as *mut RegionTableHeader) };
        if region_table_header.signature != REGION_SIGN {
            return Err(VhdxHeaderError::InvalidRegionSign);
        }
        let new_checksum = calculate_checksum(&mut buffer, size_of::<u32>())?;
        if region_table_header.checksum != new_checksum {
            return Err(VhdxHeaderError::InvalidChecksum(String::from("Region")));
        }
        if region_table_header.entry_count > 2047 {
            return Err(VhdxHeaderError::InvalidEntryCount);
        }
        if region_table_header.reserved != 0 {
            return Err(VhdxHeaderError::ReservedIsNonZero);
        }
        Ok(region_table_header)
    }
pub fn new ( f : & mut File , start : u64 ) -> Result < RegionTableHeader > { // Read the whole header into a buffer. We will need it for calculating // checksum. let mut buffer = [ 0u8 ; REGION_SIZE as usize ] ; f . seek ( SeekFrom :: Start ( start ) ) . map_err ( VhdxHeaderError :: SeekRegionTableHeader ) ? ; f . read_exact ( & mut buffer ) . map_err ( VhdxHeaderError :: ReadRegionTableHeader ) ? ; let region_table_header = unsafe { * ( buffer . as_ptr ( ) as * mut RegionTableHeader ) } ; if region_table_header . signature != REGION_SIGN { return Err ( VhdxHeaderError :: InvalidRegionSign ) ; } let new_checksum = calculate_checksum ( & mut buffer , size_of :: < u32 > ( ) ) ? ; if region_table_header . checksum != new_checksum { return Err ( VhdxHeaderError :: InvalidChecksum ( String :: from ( " " ) ) ) ; } if region_table_header . entry_count > 2047 { return Err ( VhdxHeaderError :: InvalidEntryCount ) ; } if region_table_header . reserved != 0 { return Err ( VhdxHeaderError :: ReservedIsNonZero ) ; } Ok ( region_table_header ) }
Reads the Region Table Header structure from a reference VHDx file
Reads the Region Table Header structure from a reference VHDx file
f
&mut File
start
u64
f
&mut File
start
u64