ksud: e2fsck check image before mount

This commit is contained in:
tiann 2023-01-05 11:13:31 +08:00
parent 0a1247b835
commit 279b591200
No known key found for this signature in database
GPG Key ID: 6D3F65FFD9559C06

View File

@ -95,11 +95,8 @@ fn get_minimal_image_size(img: &str) -> Result<u64> {
Ok(result) Ok(result)
} }
fn grow_image_size(img: &str, extra_size: u64) -> Result<()> { fn check_image(img: &str) -> Result<()> {
let minimal_size = get_minimal_image_size(img)?; // trim image
let target_size = minimal_size + extra_size;
// trim image
let result = Command::new("e2fsck") let result = Command::new("e2fsck")
.args(["-yf", img]) .args(["-yf", img])
.stdout(Stdio::null()) .stdout(Stdio::null())
@ -107,6 +104,15 @@ fn grow_image_size(img: &str, extra_size: u64) -> Result<()> {
.status() .status()
.with_context(|| format!("Failed exec e2fsck {}", img))?; .with_context(|| format!("Failed exec e2fsck {}", img))?;
ensure!(result.success(), "f2fsck exec failed."); ensure!(result.success(), "f2fsck exec failed.");
Ok(())
}
fn grow_image_size(img: &str, extra_size: u64) -> Result<()> {
let minimal_size = get_minimal_image_size(img)?;
let target_size = minimal_size + extra_size;
// check image
check_image(img)?;
let target_size = target_size / 1024 + 1; let target_size = target_size / 1024 + 1;
println!("- Target size: {}K", target_size); println!("- Target size: {}K", target_size);
@ -198,6 +204,8 @@ pub fn install_module(zip: String) -> Result<()> {
.stderr(subprocess::Redirection::Merge) .stderr(subprocess::Redirection::Merge)
.join()?; .join()?;
ensure!(result.success(), "format ext4 image failed!"); ensure!(result.success(), "format ext4 image failed!");
check_image(tmp_module_img)?;
} else if modules_update_exist { } else if modules_update_exist {
// modules_update.img exists, we should use it as tmp img // modules_update.img exists, we should use it as tmp img
std::fs::copy(modules_update_img, tmp_module_img)?; std::fs::copy(modules_update_img, tmp_module_img)?;