pub fn create_for_size(version: u32, size: u64) -> QcowHeader {
        let cluster_bits: u32 = DEFAULT_CLUSTER_BITS;
        let cluster_size: u32 = 0x01 << cluster_bits;
        // L2 blocks are always one cluster long. They contain cluster_size/sizeof(u64) addresses.
        let l2_size: u32 = cluster_size / size_of::<u64>() as u32;
        let num_clusters: u32 = div_round_up_u64(size, u64::from(cluster_size)) as u32;
        let num_l2_clusters: u32 = div_round_up_u32(num_clusters, l2_size);
        let l1_clusters: u32 = div_round_up_u32(num_l2_clusters, cluster_size);
        let header_clusters = div_round_up_u32(size_of::<QcowHeader>() as u32, cluster_size);
        QcowHeader {
            magic: QCOW_MAGIC,
            version,
            backing_file_offset: 0,
            backing_file_size: 0,
            cluster_bits: DEFAULT_CLUSTER_BITS,
            size,
            crypt_method: 0,
            l1_size: num_l2_clusters,
            l1_table_offset: u64::from(cluster_size),
            // The refcount table is after l1 + header.
            refcount_table_offset: u64::from(cluster_size * (l1_clusters + 1)),
            refcount_table_clusters: {
                // Pre-allocate enough clusters for the entire refcount table as it must be
                // continuous in the file. Allocate enough space to refcount all clusters, including
                // the refcount clusters.
                let max_refcount_clusters = max_refcount_clusters(
                    DEFAULT_REFCOUNT_ORDER,
                    cluster_size,
                    num_clusters + l1_clusters + num_l2_clusters + header_clusters,
                ) as u32;
                // The refcount table needs to store the offset of each refcount cluster.
                div_round_up_u32(
                    max_refcount_clusters * size_of::<u64>() as u32,
                    cluster_size,
                )
            },
            nb_snapshots: 0,
            snapshots_offset: 0,
            incompatible_features: 0,
            compatible_features: 0,
            autoclear_features: 0,
            refcount_order: DEFAULT_REFCOUNT_ORDER,
            header_size: if version == 2 {
                V2_BARE_HEADER_SIZE
            } else {
                V3_BARE_HEADER_SIZE
            },
        }
    }
/// Create a header for the given `size`.
Create a header for the given `size`.
Create a header for the given ` size ` .
pub fn create_for_size(version: u32, size: u64) -> QcowHeader {
        let cluster_bits: u32 = DEFAULT_CLUSTER_BITS;
        let cluster_size: u32 = 0x01 << cluster_bits;
        // L2 blocks are always one cluster long. They contain cluster_size/sizeof(u64) addresses.
        let l2_size: u32 = cluster_size / size_of::<u64>() as u32;
        let num_clusters: u32 = div_round_up_u64(size, u64::from(cluster_size)) as u32;
        let num_l2_clusters: u32 = div_round_up_u32(num_clusters, l2_size);
        let l1_clusters: u32 = div_round_up_u32(num_l2_clusters, cluster_size);
        let header_clusters = div_round_up_u32(size_of::<QcowHeader>() as u32, cluster_size);
        QcowHeader {
            magic: QCOW_MAGIC,
            version,
            backing_file_offset: 0,
            backing_file_size: 0,
            cluster_bits: DEFAULT_CLUSTER_BITS,
            size,
            crypt_method: 0,
            l1_size: num_l2_clusters,
            l1_table_offset: u64::from(cluster_size),
            // The refcount table is after l1 + header.
            refcount_table_offset: u64::from(cluster_size * (l1_clusters + 1)),
            refcount_table_clusters: {
                // Pre-allocate enough clusters for the entire refcount table as it must be
                // continuous in the file. Allocate enough space to refcount all clusters, including
                // the refcount clusters.
                let max_refcount_clusters = max_refcount_clusters(
                    DEFAULT_REFCOUNT_ORDER,
                    cluster_size,
                    num_clusters + l1_clusters + num_l2_clusters + header_clusters,
                ) as u32;
                // The refcount table needs to store the offset of each refcount cluster.
                div_round_up_u32(
                    max_refcount_clusters * size_of::<u64>() as u32,
                    cluster_size,
                )
            },
            nb_snapshots: 0,
            snapshots_offset: 0,
            incompatible_features: 0,
            compatible_features: 0,
            autoclear_features: 0,
            refcount_order: DEFAULT_REFCOUNT_ORDER,
            header_size: if version == 2 {
                V2_BARE_HEADER_SIZE
            } else {
                V3_BARE_HEADER_SIZE
            },
        }
    }
pub fn create_for_size ( version : u32 , size : u64 ) -> QcowHeader { let cluster_bits : u32 = DEFAULT_CLUSTER_BITS ; let cluster_size : u32 = 0x01 << cluster_bits ; // L2 blocks are always one cluster long. They contain cluster_size/sizeof(u64) addresses. let l2_size : u32 = cluster_size / size_of :: < u64 > ( ) as u32 ; let num_clusters : u32 = div_round_up_u64 ( size , u64 :: from ( cluster_size ) ) as u32 ; let num_l2_clusters : u32 = div_round_up_u32 ( num_clusters , l2_size ) ; let l1_clusters : u32 = div_round_up_u32 ( num_l2_clusters , cluster_size ) ; let header_clusters = div_round_up_u32 ( size_of :: < QcowHeader > ( ) as u32 , cluster_size ) ; QcowHeader { magic : QCOW_MAGIC , version , backing_file_offset : 0 , backing_file_size : 0 , cluster_bits : DEFAULT_CLUSTER_BITS , size , crypt_method : 0 , l1_size : num_l2_clusters , l1_table_offset : u64 :: from ( cluster_size ) , // The refcount table is after l1 + header. refcount_table_offset : u64 :: from ( cluster_size * ( l1_clusters + 1 ) ) , refcount_table_clusters : { // Pre-allocate enough clusters for the entire refcount table as it must be // continuous in the file. Allocate enough space to refcount all clusters, including // the refcount clusters. let max_refcount_clusters = max_refcount_clusters ( DEFAULT_REFCOUNT_ORDER , cluster_size , num_clusters + l1_clusters + num_l2_clusters + header_clusters , ) as u32 ; // The refcount table needs to store the offset of each refcount cluster. div_round_up_u32 ( max_refcount_clusters * size_of :: < u64 > ( ) as u32 , cluster_size , ) } , nb_snapshots : 0 , snapshots_offset : 0 , incompatible_features : 0 , compatible_features : 0 , autoclear_features : 0 , refcount_order : DEFAULT_REFCOUNT_ORDER , header_size : if version == 2 { V2_BARE_HEADER_SIZE } else { V3_BARE_HEADER_SIZE } , } }
Create a header for the given `size`.
Create a header for the given ` size ` .
version
u32
size
u64
version
u32
size
u64