pub fn new(f: &mut RawFile) -> Result<QcowHeader> {
        f.seek(SeekFrom::Start(0)).map_err(Error::ReadingHeader)?;
        let magic = f.read_u32::<BigEndian>().map_err(Error::ReadingHeader)?;
        if magic != QCOW_MAGIC {
            return Err(Error::InvalidMagic);
        }

        // Reads the next u32 from the file.
        fn read_u32_from_file(f: &mut RawFile) -> Result<u32> {
            f.read_u32::<BigEndian>().map_err(Error::ReadingHeader)
        }

        // Reads the next u64 from the file.
        fn read_u64_from_file(f: &mut RawFile) -> Result<u64> {
            f.read_u64::<BigEndian>().map_err(Error::ReadingHeader)
        }

        let version = read_u32_from_file(f)?;

        Ok(QcowHeader {
            magic,
            version,
            backing_file_offset: read_u64_from_file(f)?,
            backing_file_size: read_u32_from_file(f)?,
            cluster_bits: read_u32_from_file(f)?,
            size: read_u64_from_file(f)?,
            crypt_method: read_u32_from_file(f)?,
            l1_size: read_u32_from_file(f)?,
            l1_table_offset: read_u64_from_file(f)?,
            refcount_table_offset: read_u64_from_file(f)?,
            refcount_table_clusters: read_u32_from_file(f)?,
            nb_snapshots: read_u32_from_file(f)?,
            snapshots_offset: read_u64_from_file(f)?,
            incompatible_features: if version == 2 {
                0
            } else {
                read_u64_from_file(f)?
            },
            compatible_features: if version == 2 {
                0
            } else {
                read_u64_from_file(f)?
            },
            autoclear_features: if version == 2 {
                0
            } else {
                read_u64_from_file(f)?
            },
            refcount_order: if version == 2 {
                DEFAULT_REFCOUNT_ORDER
            } else {
                read_u32_from_file(f)?
            },
            header_size: if version == 2 {
                V2_BARE_HEADER_SIZE
            } else {
                read_u32_from_file(f)?
            },
        })
    }
/// Creates a QcowHeader from a reference to a file.
Creates a QcowHeader from a reference to a file.
Creates a QcowHeader from a reference to a file .
pub fn new(f: &mut RawFile) -> Result<QcowHeader> {
        f.seek(SeekFrom::Start(0)).map_err(Error::ReadingHeader)?;
        let magic = f.read_u32::<BigEndian>().map_err(Error::ReadingHeader)?;
        if magic != QCOW_MAGIC {
            return Err(Error::InvalidMagic);
        }
        // Reads the next u32 from the file.
        fn read_u32_from_file(f: &mut RawFile) -> Result<u32> {
            f.read_u32::<BigEndian>().map_err(Error::ReadingHeader)
        }
        // Reads the next u64 from the file.
        fn read_u64_from_file(f: &mut RawFile) -> Result<u64> {
            f.read_u64::<BigEndian>().map_err(Error::ReadingHeader)
        }
        let version = read_u32_from_file(f)?;
        Ok(QcowHeader {
            magic,
            version,
            backing_file_offset: read_u64_from_file(f)?,
            backing_file_size: read_u32_from_file(f)?,
            cluster_bits: read_u32_from_file(f)?,
            size: read_u64_from_file(f)?,
            crypt_method: read_u32_from_file(f)?,
            l1_size: read_u32_from_file(f)?,
            l1_table_offset: read_u64_from_file(f)?,
            refcount_table_offset: read_u64_from_file(f)?,
            refcount_table_clusters: read_u32_from_file(f)?,
            nb_snapshots: read_u32_from_file(f)?,
            snapshots_offset: read_u64_from_file(f)?,
            incompatible_features: if version == 2 {
                0
            } else {
                read_u64_from_file(f)?
            },
            compatible_features: if version == 2 {
                0
            } else {
                read_u64_from_file(f)?
            },
            autoclear_features: if version == 2 {
                0
            } else {
                read_u64_from_file(f)?
            },
            refcount_order: if version == 2 {
                DEFAULT_REFCOUNT_ORDER
            } else {
                read_u32_from_file(f)?
            },
            header_size: if version == 2 {
                V2_BARE_HEADER_SIZE
            } else {
                read_u32_from_file(f)?
            },
        })
    }
pub fn new ( f : & mut RawFile ) -> Result < QcowHeader > { f . seek ( SeekFrom :: Start ( 0 ) ) . map_err ( Error :: ReadingHeader ) ? ; let magic = f . read_u32 :: < BigEndian > ( ) . map_err ( Error :: ReadingHeader ) ? ; if magic != QCOW_MAGIC { return Err ( Error :: InvalidMagic ) ; } // Reads the next u32 from the file. fn read_u32_from_file ( f : & mut RawFile ) -> Result < u32 > { f . read_u32 :: < BigEndian > ( ) . map_err ( Error :: ReadingHeader ) } // Reads the next u64 from the file. fn read_u64_from_file ( f : & mut RawFile ) -> Result < u64 > { f . read_u64 :: < BigEndian > ( ) . map_err ( Error :: ReadingHeader ) } let version = read_u32_from_file ( f ) ? ; Ok ( QcowHeader { magic , version , backing_file_offset : read_u64_from_file ( f ) ? , backing_file_size : read_u32_from_file ( f ) ? , cluster_bits : read_u32_from_file ( f ) ? , size : read_u64_from_file ( f ) ? , crypt_method : read_u32_from_file ( f ) ? , l1_size : read_u32_from_file ( f ) ? , l1_table_offset : read_u64_from_file ( f ) ? , refcount_table_offset : read_u64_from_file ( f ) ? , refcount_table_clusters : read_u32_from_file ( f ) ? , nb_snapshots : read_u32_from_file ( f ) ? , snapshots_offset : read_u64_from_file ( f ) ? , incompatible_features : if version == 2 { 0 } else { read_u64_from_file ( f ) ? } , compatible_features : if version == 2 { 0 } else { read_u64_from_file ( f ) ? } , autoclear_features : if version == 2 { 0 } else { read_u64_from_file ( f ) ? } , refcount_order : if version == 2 { DEFAULT_REFCOUNT_ORDER } else { read_u32_from_file ( f ) ? } , header_size : if version == 2 { V2_BARE_HEADER_SIZE } else { read_u32_from_file ( f ) ? } , } ) }
Creates a QcowHeader from a reference to a file.
Creates a QcowHeader from a reference to a file .
f
&mut RawFile
f
&mut RawFile