fn write_disk(
    config: &InstallConfig,
    source: &mut ImageSource,
    dest: &mut File,
    table: &mut dyn PartTable,
    saved: &SavedPartitions,
    ignition: Option<File>,
    network_config: Option<&str>,
) -> Result<()> {
    // Get sector size of destination, for comparing with image
    let sector_size = get_sector_size(dest)?;

    // copy the image
    #[allow(clippy::match_bool, clippy::match_single_binding)]
    let image_copy = match is_dasd(&config.device, Some(dest))? {
        #[cfg(target_arch = "s390x")]
        true => s390x::image_copy_s390x,
        _ => image_copy_default,
    };
    write_image(
        source,
        dest,
        Path::new(&config.device),
        image_copy,
        true,
        Some(saved),
        Some(sector_size),
        VerifyKeys::Production,
    )?;
    table.reread()?;

    // postprocess
    if ignition.is_some()
        || config.firstboot_args.is_some()
        || !config.append_karg.is_empty()
        || !config.delete_karg.is_empty()
        || config.platform.is_some()
        || network_config.is_some()
        || cfg!(target_arch = "s390x")
    {
        let mount =
            Disk::new(&config.device)?.mount_partition_by_label("boot", mount::MsFlags::empty())?;
        if let Some(ignition) = ignition.as_ref() {
            write_ignition(mount.mountpoint(), &config.ignition_hash, ignition)
                .context("writing Ignition configuration")?;
        }
        if let Some(firstboot_args) = config.firstboot_args.as_ref() {
            write_firstboot_kargs(mount.mountpoint(), firstboot_args)
                .context("writing firstboot kargs")?;
        }
        if !config.append_karg.is_empty() || !config.delete_karg.is_empty() {
            eprintln!("Modifying kernel arguments");

            visit_bls_entry_options(mount.mountpoint(), |orig_options: &str| {
                bls_entry_options_delete_and_append_kargs(
                    orig_options,
                    config.delete_karg.as_slice(),
                    config.append_karg.as_slice(),
                    &[],
                )
            })
            .context("deleting and appending kargs")?;
        }
        if let Some(platform) = config.platform.as_ref() {
            write_platform(mount.mountpoint(), platform).context("writing platform ID")?;
        }
        if let Some(network_config) = network_config.as_ref() {
            copy_network_config(mount.mountpoint(), network_config)?;
        }
        #[cfg(target_arch = "s390x")]
        {
            s390x::zipl(mount.mountpoint())?;
            s390x::chreipl(&config.device)?;
        }
    }

    // detect any latent write errors
    dest.sync_all().context("syncing data to disk")?;

    Ok(())
}
/// Copy the image source to the target disk and do all post-processing.
/// If this function fails, the caller should wipe the partition table
/// to ensure the user doesn't boot from a partially-written disk.
Copy the image source to the target disk and do all post-processing.
If this function fails, the caller should wipe the partition table
to ensure the user doesn't boot from a partially-written disk.
Copy the image source to the target disk and do all post - processing . If this function fails the caller should wipe the partition table to ensure the user doesn ' t boot from a partially - written disk .
fn write_disk(
    config: &InstallConfig,
    source: &mut ImageSource,
    dest: &mut File,
    table: &mut dyn PartTable,
    saved: &SavedPartitions,
    ignition: Option<File>,
    network_config: Option<&str>,
) -> Result<()> {
    // Get sector size of destination, for comparing with image
    let sector_size = get_sector_size(dest)?;
    // copy the image
    #[allow(clippy::match_bool, clippy::match_single_binding)]
    let image_copy = match is_dasd(&config.device, Some(dest))? {
        #[cfg(target_arch = "s390x")]
        true => s390x::image_copy_s390x,
        _ => image_copy_default,
    };
    write_image(
        source,
        dest,
        Path::new(&config.device),
        image_copy,
        true,
        Some(saved),
        Some(sector_size),
        VerifyKeys::Production,
    )?;
    table.reread()?;
    // postprocess
    if ignition.is_some()
        || config.firstboot_args.is_some()
        || !config.append_karg.is_empty()
        || !config.delete_karg.is_empty()
        || config.platform.is_some()
        || network_config.is_some()
        || cfg!(target_arch = "s390x")
    {
        let mount =
            Disk::new(&config.device)?.mount_partition_by_label("boot", mount::MsFlags::empty())?;
        if let Some(ignition) = ignition.as_ref() {
            write_ignition(mount.mountpoint(), &config.ignition_hash, ignition)
                .context("writing Ignition configuration")?;
        }
        if let Some(firstboot_args) = config.firstboot_args.as_ref() {
            write_firstboot_kargs(mount.mountpoint(), firstboot_args)
                .context("writing firstboot kargs")?;
        }
        if !config.append_karg.is_empty() || !config.delete_karg.is_empty() {
            eprintln!("Modifying kernel arguments");
            visit_bls_entry_options(mount.mountpoint(), |orig_options: &str| {
                bls_entry_options_delete_and_append_kargs(
                    orig_options,
                    config.delete_karg.as_slice(),
                    config.append_karg.as_slice(),
                    &[],
                )
            })
            .context("deleting and appending kargs")?;
        }
        if let Some(platform) = config.platform.as_ref() {
            write_platform(mount.mountpoint(), platform).context("writing platform ID")?;
        }
        if let Some(network_config) = network_config.as_ref() {
            copy_network_config(mount.mountpoint(), network_config)?;
        }
        #[cfg(target_arch = "s390x")]
        {
            s390x::zipl(mount.mountpoint())?;
            s390x::chreipl(&config.device)?;
        }
    }
    // detect any latent write errors
    dest.sync_all().context("syncing data to disk")?;
    Ok(())
}
fn write_disk ( config : & InstallConfig , source : & mut ImageSource , dest : & mut File , table : & mut dyn PartTable , saved : & SavedPartitions , ignition : Option < File > , network_config : Option < & str > , ) -> Result < ( ) > { // Get sector size of destination, for comparing with image let sector_size = get_sector_size ( dest ) ? ; // copy the image # [ allow ( clippy match_bool clippy match_single_binding ) ] let image_copy = match is_dasd ( & config . device , Some ( dest ) ) ? { # [ cfg ( target_arch " " ) ] true => s390x :: image_copy_s390x , _ => image_copy_default , } ; write_image ( source , dest , Path :: new ( & config . device ) , image_copy , true , Some ( saved ) , Some ( sector_size ) , VerifyKeys :: Production , ) ? ; table . reread ( ) ? ; // postprocess if ignition . is_some ( ) || config . firstboot_args . is_some ( ) || ! config . append_karg . is_empty ( ) || ! config . delete_karg . is_empty ( ) || config . platform . is_some ( ) || network_config . is_some ( ) || cfg ! ( target_arch " " ) { let mount = Disk :: new ( & config . device ) ? . mount_partition_by_label ( " " , mount :: MsFlags :: empty ( ) ) ? ; if let Some ( ignition ) = ignition . as_ref ( ) { write_ignition ( mount . mountpoint ( ) , & config . ignition_hash , ignition ) . context ( " " ) ? ; } if let Some ( firstboot_args ) = config . firstboot_args . as_ref ( ) { write_firstboot_kargs ( mount . mountpoint ( ) , firstboot_args ) . context ( " " ) ? ; } if ! config . append_karg . is_empty ( ) || ! config . delete_karg . is_empty ( ) { eprintln ! ( " " ) ; visit_bls_entry_options ( mount . mountpoint ( ) , | orig_options : & str | { bls_entry_options_delete_and_append_kargs ( orig_options , config . delete_karg . as_slice ( ) , config . append_karg . as_slice ( ) , & [ ] , ) } ) . context ( " " ) ? ; } if let Some ( platform ) = config . platform . as_ref ( ) { write_platform ( mount . mountpoint ( ) , platform ) . context ( " " ) ? ; } if let Some ( network_config ) = network_config . as_ref ( ) { copy_network_config ( mount . mountpoint ( ) , network_config ) ? ; } # [ cfg ( target_arch " " ) ] { s390x :: zipl ( mount . mountpoint ( ) ) ? ; s390x :: chreipl ( & config . device ) ? ; } } // detect any latent write errors dest . sync_all ( ) . context ( " " ) ? ; Ok ( ( ) ) }
Copy the image source to the target disk and do all post-processing.
Copy the image source to the target disk and do all post - processing .
config
&InstallConfig
source
&mut ImageSource
dest
&mut File
table
&mut dyn PartTable
saved
&SavedPartitions
ignition
Option<File>
network_config
Option<&str>
config
&InstallConfig
source
&mut ImageSource
dest
&mut File
table
&mut dyn PartTable
saved
&SavedPartitions
ignition
Option<File>
network_config
Option<&str>