From c8fc6a0656b350999a49d03aeb97edf537efb45a Mon Sep 17 00:00:00 2001 From: weishu Date: Mon, 4 Mar 2024 13:50:00 +0800 Subject: [PATCH] ksud: resize image if it is shrinked --- userspace/ksud/src/module.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/userspace/ksud/src/module.rs b/userspace/ksud/src/module.rs index 75d16e4a..189306b6 100644 --- a/userspace/ksud/src/module.rs +++ b/userspace/ksud/src/module.rs @@ -12,6 +12,7 @@ use is_executable::is_executable; use java_properties::PropertiesIter; use log::{info, warn}; +use std::fs::OpenOptions; use std::{ collections::HashMap, env::var as env_var, @@ -398,6 +399,23 @@ fn _install_module(zip: &str) -> Result<()> { } else { utils::copy_sparse_file(modules_img, tmp_module_img, true) .with_context(|| "Failed to copy module image".to_string())?; + + if std::fs::metadata(tmp_module_img)?.len() < sparse_image_size { + // truncate the file to new size + OpenOptions::new() + .write(true) + .open(tmp_module_img) + .context("Failed to open ext4 image")? + .set_len(sparse_image_size) + .context("Failed to truncate ext4 image")?; + + // resize the image to new size + check_image(tmp_module_img)?; + Command::new("resize2fs") + .arg(tmp_module_img) + .stdout(Stdio::piped()) + .status()?; + } } }