Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 50 additions & 26 deletions apd/src/magic_mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,32 @@ impl Node {
}
}

const MODULE_PARTITIONS: &[(&str, bool)] = &[
("system", false),
("vendor", true),
("system_ext", true),
("product", true),
("odm", false),
("oem", false),
("apex", true),
("mi_ext", true),
("my_bigball", true),
("my_carrier", true),
("my_company", true),
("my_engineering", true),
("my_heytap", true),
("my_manifest", true),
("my_preload", true),
("my_product", true),
("my_region", true),
("my_reserve", true),
("my_stock", true),
("optics", true),
("prism", true),
];

fn collect_module_files() -> Result<Option<Node>> {
let mut root = Node::new_root("");
let mut system = Node::new_root("system");
let module_root = Path::new(MODULE_DIR);
let mut has_file = false;

Expand Down Expand Up @@ -189,38 +212,39 @@ fn collect_module_files() -> Result<Option<Node>> {
continue;
}

let mod_system = entry.path().join("system");

if !mod_system.is_dir() {
continue;
}

log::debug!("collecting {}", entry.path().display());

has_file |= system.collect_module_files(mod_system)?;
}
for &(partition, require_symlink) in MODULE_PARTITIONS {
let module_partition_dir = entry.path().join(partition);

if has_file {
const BUILTIN_PARTITIONS: [(&str, bool); 5] = [
("vendor", true),
("system_ext", true),
("product", true),
("odm", false),
("oem", false),
];

for (partition, require_symlink) in BUILTIN_PARTITIONS {
let path_of_root = Path::new("/").join(partition);
let path_of_system = Path::new("/system").join(partition);
if path_of_root.is_dir() && (!require_symlink || path_of_system.is_symlink()) {
let name = partition.to_string();
if let Some(node) = system.children.remove(&name) {
root.children.insert(name, node);
if !module_partition_dir.is_dir() {
continue;
}

if require_symlink {
let path_of_root = Path::new("/").join(partition);
let path_of_system = Path::new("/system").join(partition);
if !path_of_root.is_dir() || !path_of_system.is_symlink() {
continue;
}
} else {
let path_of_root = Path::new("/").join(partition);
if !path_of_root.is_dir() {
continue;
}
}

let partition_node = root
.children
.entry(partition.to_string())
.or_insert_with(|| Node::new_root(partition));

let collected = partition_node.collect_module_files(&module_partition_dir)?;
has_file |= collected;
}
}

root.children.insert("system".to_string(), system);
if has_file {
Ok(Some(root))
} else {
Ok(None)
Expand Down