ksud: opti module mount

This commit is contained in:
tiann
2023-02-02 21:56:08 +08:00
parent 12f353a1ae
commit 7b32c0e37b
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}"); 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 // load sepolicy.rule
if crate::module::load_sepolicy_rule().is_err() { if crate::module::load_sepolicy_rule().is_err() {

View File

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

View File

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