ksud: opti module mount

This commit is contained in:
tiann 2023-02-02 21:56:08 +08:00
parent 12f353a1ae
commit 7b32c0e37b
No known key found for this signature in database
GPG Key ID: 6D3F65FFD9559C06
3 changed files with 15 additions and 9 deletions

View File

@ -124,7 +124,8 @@ pub fn on_post_data_fs() -> Result<()> {
}
info!("mount {target_update_img} to {module_dir}");
mount::mount_ext4(target_update_img, module_dir, false)?;
mount::AutoMountExt4::try_new(target_update_img, module_dir, false)
.with_context(|| "mount module image failed".to_string())?;
// load sepolicy.rule
if crate::module::load_sepolicy_rule().is_err() {

View File

@ -11,9 +11,9 @@ use log::{debug, info, warn};
use std::{
collections::HashMap,
env::var as env_var,
fs::{remove_dir_all, File, OpenOptions, set_permissions, Permissions},
fs::{remove_dir_all, set_permissions, File, OpenOptions, Permissions},
io::{Cursor, Read, Write},
os::unix::{process::CommandExt, prelude::PermissionsExt},
os::unix::{prelude::PermissionsExt, process::CommandExt},
path::{Path, PathBuf},
process::{Command, Stdio},
str::FromStr,
@ -490,7 +490,7 @@ fn do_install_module(zip: String) -> Result<()> {
// mount the modules_update.img to mountpoint
println!("- Mounting image");
let _dontdrop = mount::AutoMountExt4::try_new(tmp_module_img, module_update_tmp_dir)?;
let _dontdrop = mount::AutoMountExt4::try_new(tmp_module_img, module_update_tmp_dir, true)?;
info!("mounted {} to {}", tmp_module_img, module_update_tmp_dir);
@ -573,7 +573,7 @@ where
ensure_clean_dir(update_dir)?;
// mount the modules_update img
let _dontdrop = mount::AutoMountExt4::try_new(defs::MODULE_UPDATE_TMP_IMG, update_dir)?;
let _dontdrop = mount::AutoMountExt4::try_new(defs::MODULE_UPDATE_TMP_IMG, update_dir, true)?;
// call the operation func
let result = func(id, update_dir);

View File

@ -12,12 +12,13 @@ pub struct AutoMountExt4 {
mnt: String,
#[cfg(target_os = "android")]
mount: Option<Mount>,
auto_umount: bool,
}
#[allow(dead_code)]
impl AutoMountExt4 {
#[cfg(target_os = "android")]
pub fn try_new(src: &str, mnt: &str) -> Result<Self> {
pub fn try_new(src: &str, mnt: &str, auto_umount: bool) -> Result<Self> {
let result = Mount::builder()
.fstype(FilesystemType::from("ext4"))
.flags(MountFlags::empty())
@ -26,6 +27,7 @@ impl AutoMountExt4 {
Ok(Self {
mnt: mnt.to_string(),
mount: Some(mount),
auto_umount
})
});
if let Err(e) = result {
@ -44,6 +46,7 @@ impl AutoMountExt4 {
Ok(Self {
mnt: mnt.to_string(),
mount: None,
auto_umount
})
}
} else {
@ -52,7 +55,7 @@ impl AutoMountExt4 {
}
#[cfg(not(target_os = "android"))]
pub fn try_new(_src: &str, _mnt: &str) -> Result<Self> {
pub fn try_new(_src: &str, _mnt: &str, _auto_umount: bool) -> Result<Self> {
unimplemented!()
}
@ -77,8 +80,10 @@ impl AutoMountExt4 {
#[cfg(target_os = "android")]
impl Drop for AutoMountExt4 {
fn drop(&mut self) {
log::info!("AutoMountExt4 drop: {}", self.mnt);
let _ = self.umount();
log::info!("AutoMountExt4 drop: {}, auto_umount: {}", self.mnt, self.auto_umount);
if self.auto_umount {
let _ = self.umount();
}
}
}