pub fn new(mut file: RawFile, version: u32, virtual_size: u64) -> Result<QcowFile> {
        let header = QcowHeader::create_for_size(version, virtual_size);
        file.seek(SeekFrom::Start(0)).map_err(Error::SeekingFile)?;
        header.write_to(&mut file)?;

        let mut qcow = Self::from(file)?;

        // Set the refcount for each refcount table cluster.
        let cluster_size = 0x01u64 << qcow.header.cluster_bits;
        let refcount_table_base = qcow.header.refcount_table_offset as u64;
        let end_cluster_addr =
            refcount_table_base + u64::from(qcow.header.refcount_table_clusters) * cluster_size;

        let mut cluster_addr = 0;
        while cluster_addr < end_cluster_addr {
            let mut unref_clusters = qcow
                .set_cluster_refcount(cluster_addr, 1)
                .map_err(Error::SettingRefcountRefcount)?;
            qcow.unref_clusters.append(&mut unref_clusters);
            cluster_addr += cluster_size;
        }

        Ok(qcow)
    }
/// Creates a new QcowFile at the given path.
Creates a new QcowFile at the given path.
Creates a new QcowFile at the given path .
pub fn new(mut file: RawFile, version: u32, virtual_size: u64) -> Result<QcowFile> {
        let header = QcowHeader::create_for_size(version, virtual_size);
        file.seek(SeekFrom::Start(0)).map_err(Error::SeekingFile)?;
        header.write_to(&mut file)?;
        let mut qcow = Self::from(file)?;
        // Set the refcount for each refcount table cluster.
        let cluster_size = 0x01u64 << qcow.header.cluster_bits;
        let refcount_table_base = qcow.header.refcount_table_offset as u64;
        let end_cluster_addr =
            refcount_table_base + u64::from(qcow.header.refcount_table_clusters) * cluster_size;
        let mut cluster_addr = 0;
        while cluster_addr < end_cluster_addr {
            let mut unref_clusters = qcow
                .set_cluster_refcount(cluster_addr, 1)
                .map_err(Error::SettingRefcountRefcount)?;
            qcow.unref_clusters.append(&mut unref_clusters);
            cluster_addr += cluster_size;
        }
        Ok(qcow)
    }
pub fn new ( mut file : RawFile , version : u32 , virtual_size : u64 ) -> Result < QcowFile > { let header = QcowHeader :: create_for_size ( version , virtual_size ) ; file . seek ( SeekFrom :: Start ( 0 ) ) . map_err ( Error :: SeekingFile ) ? ; header . write_to ( & mut file ) ? ; let mut qcow = Self :: from ( file ) ? ; // Set the refcount for each refcount table cluster. let cluster_size = 0x01u64 << qcow . header . cluster_bits ; let refcount_table_base = qcow . header . refcount_table_offset as u64 ; let end_cluster_addr = refcount_table_base + u64 :: from ( qcow . header . refcount_table_clusters ) * cluster_size ; let mut cluster_addr = 0 ; while cluster_addr < end_cluster_addr { let mut unref_clusters = qcow . set_cluster_refcount ( cluster_addr , 1 ) . map_err ( Error :: SettingRefcountRefcount ) ? ; qcow . unref_clusters . append ( & mut unref_clusters ) ; cluster_addr += cluster_size ; } Ok ( qcow ) }
Creates a new QcowFile at the given path.
Creates a new QcowFile at the given path .
file
RawFile
version
u32
virtual_size
u64
file
RawFile
version
u32
virtual_size
u64