pub fn construct_fvm(
    outdir: impl AsRef<Path>,
    fvm_config: &FvmConfig,
    blobfs_path: Option<impl AsRef<Path>>,
) -> Result<Fvms> {
    // Gather blobfs and minfs details.
    let mut blobfs: Option<Filesystem> = None;
    let mut minfs: Option<Filesystem> = None;
    for entry in &fvm_config.filesystems {
        match entry {
            FvmFilesystemEntry::BlobFS { attributes } => {
                let path = match &blobfs_path {
                    Some(path) => path.as_ref(),
                    None => {
                        anyhow::bail!("BlobFS configuration exists, but BlobFS was not generated");
                    }
                };
                blobfs =
                    Some(Filesystem { path: path.to_path_buf(), attributes: attributes.clone() });
            }
            FvmFilesystemEntry::MinFS { path, attributes } => {
                minfs =
                    Some(Filesystem { path: path.to_path_buf(), attributes: attributes.clone() });
            }
        };
    }
    let (blobfs, minfs) = match (blobfs, minfs) {
        (Some(blobfs), Some(minfs)) => (blobfs, minfs),
        _ => anyhow::bail!("Both blobfs and minfs must be supplied in the configuration"),
    };

    // Build a default FVM that is non-sparse.
    let default_path = outdir.as_ref().join("fvm.blk");
    let mut fvm_builder = FvmBuilder::new(
        &default_path,
        fvm_config.slice_size,
        fvm_config.reserved_slices,
        None,
        FvmType::Default,
    );
    fvm_builder.filesystem(blobfs.clone());
    fvm_builder.filesystem(minfs.clone());
    fvm_builder.build()?;

    // Build a sparse FVM for paving.
    let sparse_path = outdir.as_ref().join("fvm.sparse.blk");
    let mut sparse_fvm_builder = FvmBuilder::new(
        &sparse_path,
        fvm_config.slice_size,
        fvm_config.reserved_slices,
        fvm_config.max_disk_size,
        FvmType::Sparse { empty_minfs: false },
    );
    sparse_fvm_builder.filesystem(blobfs.clone());
    sparse_fvm_builder.filesystem(minfs.clone());
    sparse_fvm_builder.build()?;

    // Build a sparse FVM with an empty minfs.
    let sparse_blob_path = outdir.as_ref().join("fvm.blob.sparse.blk");
    let mut sparse_blob_fvm_builder = FvmBuilder::new(
        &sparse_blob_path,
        fvm_config.slice_size,
        fvm_config.reserved_slices,
        fvm_config.max_disk_size,
        FvmType::Sparse { empty_minfs: true },
    );
    sparse_blob_fvm_builder.filesystem(blobfs.clone());
    sparse_blob_fvm_builder.build()?;

    // Build a sparse fastboot-supported FVM if needed.
    let fastboot_path: Option<PathBuf> = match &fvm_config.fastboot {
        // EMMC formatted FVM.
        Some(FastbootConfig::Emmc { compression, length }) => {
            let emmc_path = outdir.as_ref().join("fvm.fastboot.blk");
            let mut emmc_fvm_builder = FvmBuilder::new(
                &emmc_path,
                fvm_config.slice_size,
                fvm_config.reserved_slices,
                fvm_config.max_disk_size,
                FvmType::Emmc { compression: compression.clone(), length: *length },
            );
            emmc_fvm_builder.filesystem(blobfs.clone());
            emmc_fvm_builder.filesystem(minfs.clone());
            emmc_fvm_builder.build()?;
            Some(emmc_path)
        }

        // NAND formatted FVM.
        Some(FastbootConfig::Nand {
            compression,
            page_size,
            oob_size,
            pages_per_block,
            block_count,
        }) => {
            let nand_path = outdir.as_ref().join("fvm.fastboot.blk");
            let nand_fvm_builder = NandFvmBuilder {
                output: nand_path.clone(),
                sparse_blob_fvm: sparse_blob_path.clone(),
                max_disk_size: fvm_config.max_disk_size,
                compression: compression.clone(),
                page_size: *page_size,
                oob_size: *oob_size,
                pages_per_block: *pages_per_block,
                block_count: *block_count,
            };
            nand_fvm_builder.build()?;
            Some(nand_path)
        }

        None => None,
    };

    Ok(Fvms {
        default: default_path,
        sparse: sparse_path,
        sparse_blob: sparse_blob_path,
        fastboot: fastboot_path,
    })
}
/// Constructs up-to four FVM files. Calling this function generates
/// a default FVM, a sparse FVM, a sparse blob-only FVM, and optionally a FVM
/// ready for fastboot flashing. This function returns the paths to each
/// generated FVM.
///
/// If the |fvm_config| includes information for an EMMC, then an EMMC-supported
/// sparse FVM will also be generated for fastboot flashing.
///
/// If the |fvm_config| includes information for a NAND, then an NAND-supported
/// sparse FVM will also be generated for fastboot flashing.
Constructs up-to four FVM files. Calling this function generates
a default FVM, a sparse FVM, a sparse blob-only FVM, and optionally a FVM
ready for fastboot flashing. This function returns the paths to each
generated FVM.

If the |fvm_config| includes information for an EMMC, then an EMMC-supported
sparse FVM will also be generated for fastboot flashing.

If the |fvm_config| includes information for a NAND, then an NAND-supported
sparse FVM will also be generated for fastboot flashing.
Constructs up - to four FVM files . Calling this function generates a default FVM a sparse FVM a sparse blob - only FVM and optionally a FVM ready for fastboot flashing . This function returns the paths to each generated FVM . If the |fvm_config| includes information for an EMMC then an EMMC - supported sparse FVM will also be generated for fastboot flashing . If the |fvm_config| includes information for a NAND then an NAND - supported sparse FVM will also be generated for fastboot flashing .
pub fn construct_fvm(
    outdir: impl AsRef<Path>,
    fvm_config: &FvmConfig,
    blobfs_path: Option<impl AsRef<Path>>,
) -> Result<Fvms> {
    // Gather blobfs and minfs details.
    let mut blobfs: Option<Filesystem> = None;
    let mut minfs: Option<Filesystem> = None;
    for entry in &fvm_config.filesystems {
        match entry {
            FvmFilesystemEntry::BlobFS { attributes } => {
                let path = match &blobfs_path {
                    Some(path) => path.as_ref(),
                    None => {
                        anyhow::bail!("BlobFS configuration exists, but BlobFS was not generated");
                    }
                };
                blobfs =
                    Some(Filesystem { path: path.to_path_buf(), attributes: attributes.clone() });
            }
            FvmFilesystemEntry::MinFS { path, attributes } => {
                minfs =
                    Some(Filesystem { path: path.to_path_buf(), attributes: attributes.clone() });
            }
        };
    }
    let (blobfs, minfs) = match (blobfs, minfs) {
        (Some(blobfs), Some(minfs)) => (blobfs, minfs),
        _ => anyhow::bail!("Both blobfs and minfs must be supplied in the configuration"),
    };
    // Build a default FVM that is non-sparse.
    let default_path = outdir.as_ref().join("fvm.blk");
    let mut fvm_builder = FvmBuilder::new(
        &default_path,
        fvm_config.slice_size,
        fvm_config.reserved_slices,
        None,
        FvmType::Default,
    );
    fvm_builder.filesystem(blobfs.clone());
    fvm_builder.filesystem(minfs.clone());
    fvm_builder.build()?;
    // Build a sparse FVM for paving.
    let sparse_path = outdir.as_ref().join("fvm.sparse.blk");
    let mut sparse_fvm_builder = FvmBuilder::new(
        &sparse_path,
        fvm_config.slice_size,
        fvm_config.reserved_slices,
        fvm_config.max_disk_size,
        FvmType::Sparse { empty_minfs: false },
    );
    sparse_fvm_builder.filesystem(blobfs.clone());
    sparse_fvm_builder.filesystem(minfs.clone());
    sparse_fvm_builder.build()?;
    // Build a sparse FVM with an empty minfs.
    let sparse_blob_path = outdir.as_ref().join("fvm.blob.sparse.blk");
    let mut sparse_blob_fvm_builder = FvmBuilder::new(
        &sparse_blob_path,
        fvm_config.slice_size,
        fvm_config.reserved_slices,
        fvm_config.max_disk_size,
        FvmType::Sparse { empty_minfs: true },
    );
    sparse_blob_fvm_builder.filesystem(blobfs.clone());
    sparse_blob_fvm_builder.build()?;
    // Build a sparse fastboot-supported FVM if needed.
    let fastboot_path: Option<PathBuf> = match &fvm_config.fastboot {
        // EMMC formatted FVM.
        Some(FastbootConfig::Emmc { compression, length }) => {
            let emmc_path = outdir.as_ref().join("fvm.fastboot.blk");
            let mut emmc_fvm_builder = FvmBuilder::new(
                &emmc_path,
                fvm_config.slice_size,
                fvm_config.reserved_slices,
                fvm_config.max_disk_size,
                FvmType::Emmc { compression: compression.clone(), length: *length },
            );
            emmc_fvm_builder.filesystem(blobfs.clone());
            emmc_fvm_builder.filesystem(minfs.clone());
            emmc_fvm_builder.build()?;
            Some(emmc_path)
        }
        // NAND formatted FVM.
        Some(FastbootConfig::Nand {
            compression,
            page_size,
            oob_size,
            pages_per_block,
            block_count,
        }) => {
            let nand_path = outdir.as_ref().join("fvm.fastboot.blk");
            let nand_fvm_builder = NandFvmBuilder {
                output: nand_path.clone(),
                sparse_blob_fvm: sparse_blob_path.clone(),
                max_disk_size: fvm_config.max_disk_size,
                compression: compression.clone(),
                page_size: *page_size,
                oob_size: *oob_size,
                pages_per_block: *pages_per_block,
                block_count: *block_count,
            };
            nand_fvm_builder.build()?;
            Some(nand_path)
        }
        None => None,
    };
    Ok(Fvms {
        default: default_path,
        sparse: sparse_path,
        sparse_blob: sparse_blob_path,
        fastboot: fastboot_path,
    })
}
pub fn construct_fvm ( outdir : impl AsRef < Path > , fvm_config : & FvmConfig , blobfs_path : Option < impl AsRef < Path > > , ) -> Result < Fvms > { // Gather blobfs and minfs details. let mut blobfs : Option < Filesystem > = None ; let mut minfs : Option < Filesystem > = None ; for entry in & fvm_config . filesystems { match entry { FvmFilesystemEntry :: BlobFS { attributes } => { let path = match & blobfs_path { Some ( path ) => path . as_ref ( ) , None => { anyhow :: bail ! ( " " ) ; } } ; blobfs = Some ( Filesystem { path : path . to_path_buf ( ) , attributes : attributes . clone ( ) } ) ; } FvmFilesystemEntry :: MinFS { path , attributes } => { minfs = Some ( Filesystem { path : path . to_path_buf ( ) , attributes : attributes . clone ( ) } ) ; } } ; } let ( blobfs , minfs ) = match ( blobfs , minfs ) { ( Some ( blobfs ) , Some ( minfs ) ) => ( blobfs , minfs ) , _ => anyhow :: bail ! ( " " ) , } ; // Build a default FVM that is non-sparse. let default_path = outdir . as_ref ( ) . join ( " " ) ; let mut fvm_builder = FvmBuilder :: new ( & default_path , fvm_config . slice_size , fvm_config . reserved_slices , None , FvmType :: Default , ) ; fvm_builder . filesystem ( blobfs . clone ( ) ) ; fvm_builder . filesystem ( minfs . clone ( ) ) ; fvm_builder . build ( ) ? ; // Build a sparse FVM for paving. let sparse_path = outdir . as_ref ( ) . join ( " " ) ; let mut sparse_fvm_builder = FvmBuilder :: new ( & sparse_path , fvm_config . slice_size , fvm_config . reserved_slices , fvm_config . max_disk_size , FvmType :: Sparse { empty_minfs : false } , ) ; sparse_fvm_builder . filesystem ( blobfs . clone ( ) ) ; sparse_fvm_builder . filesystem ( minfs . clone ( ) ) ; sparse_fvm_builder . build ( ) ? ; // Build a sparse FVM with an empty minfs. let sparse_blob_path = outdir . as_ref ( ) . join ( " " ) ; let mut sparse_blob_fvm_builder = FvmBuilder :: new ( & sparse_blob_path , fvm_config . slice_size , fvm_config . reserved_slices , fvm_config . max_disk_size , FvmType :: Sparse { empty_minfs : true } , ) ; sparse_blob_fvm_builder . filesystem ( blobfs . clone ( ) ) ; sparse_blob_fvm_builder . build ( ) ? ; // Build a sparse fastboot-supported FVM if needed. let fastboot_path : Option < PathBuf > = match & fvm_config . fastboot { // EMMC formatted FVM. Some ( FastbootConfig :: Emmc { compression , length } ) => { let emmc_path = outdir . as_ref ( ) . join ( " " ) ; let mut emmc_fvm_builder = FvmBuilder :: new ( & emmc_path , fvm_config . slice_size , fvm_config . reserved_slices , fvm_config . max_disk_size , FvmType :: Emmc { compression : compression . clone ( ) , length : * length } , ) ; emmc_fvm_builder . filesystem ( blobfs . clone ( ) ) ; emmc_fvm_builder . filesystem ( minfs . clone ( ) ) ; emmc_fvm_builder . build ( ) ? ; Some ( emmc_path ) } // NAND formatted FVM. Some ( FastbootConfig :: Nand { compression , page_size , oob_size , pages_per_block , block_count , } ) => { let nand_path = outdir . as_ref ( ) . join ( " " ) ; let nand_fvm_builder = NandFvmBuilder { output : nand_path . clone ( ) , sparse_blob_fvm : sparse_blob_path . clone ( ) , max_disk_size : fvm_config . max_disk_size , compression : compression . clone ( ) , page_size : * page_size , oob_size : * oob_size , pages_per_block : * pages_per_block , block_count : * block_count , } ; nand_fvm_builder . build ( ) ? ; Some ( nand_path ) } None => None , } ; Ok ( Fvms { default : default_path , sparse : sparse_path , sparse_blob : sparse_blob_path , fastboot : fastboot_path , } ) }
Constructs up-to four FVM files.
Constructs up - to four FVM files .
outdir
impl AsRef<Path>
fvm_config
&FvmConfig
blobfs_path
Option<impl AsRef<Path>>
outdir
impl AsRef<Path>
fvm_config
&FvmConfig
blobfs_path
Option<impl AsRef<Path>>