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