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

        let header = unsafe { *(buffer.as_ptr() as *mut Header) };
        if header.signature != HEADER_SIGN {
            return Err(VhdxHeaderError::InvalidHeaderSign);
        }

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

        Ok(header)
    }
/// Reads the Header structure from a reference VHDx file
Reads the Header structure from a reference VHDx file
Reads the Header structure from a reference VHDx file
pub fn new(f: &mut File, start: u64) -> Result<Header> {
        // Read the whole header in to a buffer. We will need it for
        // calculating checksum.
        let mut buffer = [0; HEADER_SIZE as usize];
        f.seek(SeekFrom::Start(start))
            .map_err(VhdxHeaderError::SeekHeader)?;
        f.read_exact(&mut buffer)
            .map_err(VhdxHeaderError::ReadHeader)?;
        let header = unsafe { *(buffer.as_ptr() as *mut Header) };
        if header.signature != HEADER_SIGN {
            return Err(VhdxHeaderError::InvalidHeaderSign);
        }
        let new_checksum = calculate_checksum(&mut buffer, size_of::<u32>())?;
        if header.checksum != new_checksum {
            return Err(VhdxHeaderError::InvalidChecksum(String::from("Header")));
        }
        Ok(header)
    }
pub fn new ( f : & mut File , start : u64 ) -> Result < Header > { // Read the whole header in to a buffer. We will need it for // calculating checksum. let mut buffer = [ 0 ; HEADER_SIZE as usize ] ; f . seek ( SeekFrom :: Start ( start ) ) . map_err ( VhdxHeaderError :: SeekHeader ) ? ; f . read_exact ( & mut buffer ) . map_err ( VhdxHeaderError :: ReadHeader ) ? ; let header = unsafe { * ( buffer . as_ptr ( ) as * mut Header ) } ; if header . signature != HEADER_SIGN { return Err ( VhdxHeaderError :: InvalidHeaderSign ) ; } let new_checksum = calculate_checksum ( & mut buffer , size_of :: < u32 > ( ) ) ? ; if header . checksum != new_checksum { return Err ( VhdxHeaderError :: InvalidChecksum ( String :: from ( " " ) ) ) ; } Ok ( header ) }
Reads the Header structure from a reference VHDx file
Reads the Header structure from a reference VHDx file
f
&mut File
start
u64
f
&mut File
start
u64