Step 5-1-1: No longer need to add unmounting for default mount points
This commit is contained in:
@@ -33,44 +33,12 @@ static struct umount_entry *find_entry_locked(const char *path)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int init_default_entries(void)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
const struct {
|
|
||||||
const char *path;
|
|
||||||
int flags;
|
|
||||||
} defaults[] = {
|
|
||||||
{ "/odm", 0 },
|
|
||||||
{ "/system", 0 },
|
|
||||||
{ "/vendor", 0 },
|
|
||||||
{ "/product", 0 },
|
|
||||||
{ "/system_ext", 0 },
|
|
||||||
{ "/data/adb/modules", MNT_DETACH },
|
|
||||||
{ "/debug_ramdisk", MNT_DETACH },
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int i = 0; i < ARRAY_SIZE(defaults); i++) {
|
|
||||||
ret = ksu_umount_manager_add(defaults[i].path,
|
|
||||||
defaults[i].flags,
|
|
||||||
true); // is_default = true
|
|
||||||
if (ret) {
|
|
||||||
pr_err("Failed to add default entry: %s, ret=%d\n",
|
|
||||||
defaults[i].path, ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pr_info("Initialized %zu default umount entries\n", ARRAY_SIZE(defaults));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ksu_umount_manager_init(void)
|
int ksu_umount_manager_init(void)
|
||||||
{
|
{
|
||||||
INIT_LIST_HEAD(&g_umount_mgr.entry_list);
|
INIT_LIST_HEAD(&g_umount_mgr.entry_list);
|
||||||
spin_lock_init(&g_umount_mgr.lock);
|
spin_lock_init(&g_umount_mgr.lock);
|
||||||
|
|
||||||
return init_default_entries();
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ksu_umount_manager_exit(void)
|
void ksu_umount_manager_exit(void)
|
||||||
|
|||||||
@@ -55,8 +55,7 @@ private val SPACING_LARGE = 16.dp
|
|||||||
|
|
||||||
data class UmountPathEntry(
|
data class UmountPathEntry(
|
||||||
val path: String,
|
val path: String,
|
||||||
val flags: Int,
|
val flags: Int
|
||||||
val isDefault: Boolean
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@Destination<RootGraph>
|
@Destination<RootGraph>
|
||||||
@@ -321,10 +320,7 @@ fun UmountPathCard(
|
|||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Outlined.Folder,
|
imageVector = Icons.Outlined.Folder,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
tint = if (entry.isDefault)
|
tint = colorScheme.primary,
|
||||||
colorScheme.primary
|
|
||||||
else
|
|
||||||
colorScheme.secondary,
|
|
||||||
modifier = Modifier.size(24.dp)
|
modifier = Modifier.size(24.dp)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -340,16 +336,11 @@ fun UmountPathCard(
|
|||||||
append(context.getString(R.string.flags))
|
append(context.getString(R.string.flags))
|
||||||
append(": ")
|
append(": ")
|
||||||
append(entry.flags.toUmountFlagName(context))
|
append(entry.flags.toUmountFlagName(context))
|
||||||
if (entry.isDefault) {
|
|
||||||
append(" | ")
|
|
||||||
append(context.getString(R.string.default_entry))
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
color = colorScheme.onSurfaceVariantSummary
|
color = colorScheme.onSurfaceVariantSummary
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!entry.isDefault) {
|
|
||||||
IconButton(
|
IconButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
@@ -370,7 +361,6 @@ fun UmountPathCard(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -451,11 +441,10 @@ private fun parseUmountPaths(output: String): List<UmountPathEntry> {
|
|||||||
|
|
||||||
return lines.drop(2).mapNotNull { line ->
|
return lines.drop(2).mapNotNull { line ->
|
||||||
val parts = line.trim().split(Regex("\\s+"))
|
val parts = line.trim().split(Regex("\\s+"))
|
||||||
if (parts.size >= 3) {
|
if (parts.size >= 2) {
|
||||||
UmountPathEntry(
|
UmountPathEntry(
|
||||||
path = parts[0],
|
path = parts[0],
|
||||||
flags = parts[1].toIntOrNull() ?: -1,
|
flags = parts[1].toIntOrNull() ?: -1
|
||||||
isDefault = parts[2].equals("Yes", ignoreCase = true)
|
|
||||||
)
|
)
|
||||||
} else null
|
} else null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -459,7 +459,7 @@ enum Umount {
|
|||||||
/// List all umount paths
|
/// List all umount paths
|
||||||
List,
|
List,
|
||||||
|
|
||||||
/// Clear all custom paths (keep defaults)
|
/// Clear all recorded umount paths
|
||||||
ClearCustom,
|
ClearCustom,
|
||||||
|
|
||||||
/// Save configuration to file
|
/// Save configuration to file
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ pub struct UmountConfig {
|
|||||||
pub struct UmountManager {
|
pub struct UmountManager {
|
||||||
config: UmountConfig,
|
config: UmountConfig,
|
||||||
config_path: PathBuf,
|
config_path: PathBuf,
|
||||||
defaults: Vec<UmountEntry>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
@@ -65,7 +64,6 @@ impl UmountManager {
|
|||||||
Ok(UmountManager {
|
Ok(UmountManager {
|
||||||
config,
|
config,
|
||||||
config_path: path,
|
config_path: path,
|
||||||
defaults: Vec::new(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,21 +108,15 @@ impl UmountManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_entry(&mut self, path: &str, flags: i32) -> Result<()> {
|
pub fn add_entry(&mut self, path: &str, flags: i32) -> Result<()> {
|
||||||
let exists = self
|
let exists = self.config.entries.iter().any(|e| e.path == path);
|
||||||
.defaults
|
|
||||||
.iter()
|
|
||||||
.chain(&self.config.entries)
|
|
||||||
.any(|e| e.path == path);
|
|
||||||
if exists {
|
if exists {
|
||||||
return Err(anyhow!("Entry already exists: {}", path));
|
return Err(anyhow!("Entry already exists: {}", path));
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_default = Self::get_default_paths().iter().any(|e| e.path == path);
|
|
||||||
|
|
||||||
let entry = UmountEntry {
|
let entry = UmountEntry {
|
||||||
path: path.to_string(),
|
path: path.to_string(),
|
||||||
flags,
|
flags,
|
||||||
is_default,
|
is_default: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.config.entries.push(entry);
|
self.config.entries.push(entry);
|
||||||
@@ -132,24 +124,17 @@ impl UmountManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_entry(&mut self, path: &str) -> Result<()> {
|
pub fn remove_entry(&mut self, path: &str) -> Result<()> {
|
||||||
let entry = self.config.entries.iter().find(|e| e.path == path);
|
let before = self.config.entries.len();
|
||||||
|
self.config.entries.retain(|e| e.path != path);
|
||||||
|
|
||||||
if let Some(entry) = entry {
|
if before == self.config.entries.len() {
|
||||||
if entry.is_default {
|
|
||||||
return Err(anyhow!("Cannot remove default entry: {}", path));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return Err(anyhow!("Entry not found: {}", path));
|
return Err(anyhow!("Entry not found: {}", path));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.config.entries.retain(|e| e.path != path);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_entries(&self) -> Vec<UmountEntry> {
|
pub fn list_entries(&self) -> Vec<UmountEntry> {
|
||||||
let mut all = self.defaults.clone();
|
self.config.entries.clone()
|
||||||
all.extend(self.config.entries.iter().cloned());
|
|
||||||
all
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_custom_entries(&mut self) -> Result<()> {
|
pub fn clear_custom_entries(&mut self) -> Result<()> {
|
||||||
@@ -157,55 +142,7 @@ impl UmountManager {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_default_paths() -> Vec<UmountEntry> {
|
|
||||||
vec![
|
|
||||||
UmountEntry {
|
|
||||||
path: "/odm".to_string(),
|
|
||||||
flags: 0,
|
|
||||||
is_default: true,
|
|
||||||
},
|
|
||||||
UmountEntry {
|
|
||||||
path: "/system".to_string(),
|
|
||||||
flags: 0,
|
|
||||||
is_default: true,
|
|
||||||
},
|
|
||||||
UmountEntry {
|
|
||||||
path: "/vendor".to_string(),
|
|
||||||
flags: 0,
|
|
||||||
is_default: true,
|
|
||||||
},
|
|
||||||
UmountEntry {
|
|
||||||
path: "/product".to_string(),
|
|
||||||
flags: 0,
|
|
||||||
is_default: true,
|
|
||||||
},
|
|
||||||
UmountEntry {
|
|
||||||
path: "/system_ext".to_string(),
|
|
||||||
flags: 0,
|
|
||||||
is_default: true,
|
|
||||||
},
|
|
||||||
UmountEntry {
|
|
||||||
path: "/data/adb/modules".to_string(),
|
|
||||||
flags: -1, // MNT_DETACH
|
|
||||||
is_default: true,
|
|
||||||
},
|
|
||||||
UmountEntry {
|
|
||||||
path: "/debug_ramdisk".to_string(),
|
|
||||||
flags: -1, // MNT_DETACH
|
|
||||||
is_default: true,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn init_defaults(&mut self) -> Result<()> {
|
|
||||||
self.defaults = Self::get_default_paths();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn apply_to_kernel(&self) -> Result<()> {
|
pub fn apply_to_kernel(&self) -> Result<()> {
|
||||||
for entry in &self.defaults {
|
|
||||||
let _ = Self::kernel_add_entry(entry);
|
|
||||||
}
|
|
||||||
for entry in &self.config.entries {
|
for entry in &self.config.entries {
|
||||||
Self::kernel_add_entry(entry)?;
|
Self::kernel_add_entry(entry)?;
|
||||||
}
|
}
|
||||||
@@ -234,7 +171,6 @@ impl UmountManager {
|
|||||||
|
|
||||||
pub fn init_umount_manager() -> Result<UmountManager> {
|
pub fn init_umount_manager() -> Result<UmountManager> {
|
||||||
let mut manager = UmountManager::new(None)?;
|
let mut manager = UmountManager::new(None)?;
|
||||||
manager.init_defaults()?;
|
|
||||||
|
|
||||||
if !Path::new(CONFIG_FILE).exists() {
|
if !Path::new(CONFIG_FILE).exists() {
|
||||||
manager.save_config()?;
|
manager.save_config()?;
|
||||||
|
|||||||
Reference in New Issue
Block a user