Treat magisk symlinks differently

This commit is contained in:
topjohnwu 2025-07-02 19:32:16 -07:00 committed by John Wu
parent 88541d6f49
commit d660401063

View File

@ -127,16 +127,10 @@ impl FilePaths<'_> {
} }
enum FsNode { enum FsNode {
Directory { Directory { children: FsNodeMap },
children: FsNodeMap, File { src: Utf8CString },
}, Symlink { target: Utf8CString },
File { MagiskLink,
src: Utf8CString,
},
Symlink {
target: Utf8CString,
is_magisk_bin: bool,
},
Whiteout, Whiteout,
} }
@ -168,7 +162,6 @@ impl FsNode {
.entry(entry.name().to_string()) .entry(entry.name().to_string())
.or_insert_with(|| FsNode::Symlink { .or_insert_with(|| FsNode::Symlink {
target: link.to_owned(), target: link.to_owned(),
is_magisk_bin: false,
}); });
} else { } else {
if entry.is_char_device() { if entry.is_char_device() {
@ -208,7 +201,7 @@ impl FsNode {
true true
} }
} }
FsNode::Symlink { .. } | FsNode::Whiteout => true, _ => true,
} }
} }
@ -263,7 +256,7 @@ impl FsNode {
FsNode::File { src } => { FsNode::File { src } => {
bind_mount("mount", src, path.real(), false)?; bind_mount("mount", src, path.real(), false)?;
} }
FsNode::Symlink { .. } | FsNode::Whiteout => { _ => {
error!("Unable to handle '{}': parent should be tmpfs", path.real()); error!("Unable to handle '{}': parent should be tmpfs", path.real());
} }
} }
@ -324,7 +317,6 @@ impl FsNode {
entry.name().to_string(), entry.name().to_string(),
FsNode::Symlink { FsNode::Symlink {
target: link.to_owned(), target: link.to_owned(),
is_magisk_bin: false,
}, },
); );
} else { } else {
@ -342,17 +334,24 @@ impl FsNode {
FsNode::File { src } => { FsNode::File { src } => {
mount_dummy("mount", src, path.worker(), false)?; mount_dummy("mount", src, path.worker(), false)?;
} }
FsNode::Symlink { FsNode::Symlink { target } => {
target,
is_magisk_bin,
} => {
module_log!("mklink", path.worker(), target); module_log!("mklink", path.worker(), target);
path.worker().create_symlink_to(target)?; path.worker().create_symlink_to(target)?;
// Avoid cloning existing su attributes to our su if path.real().exists() {
if !*is_magisk_bin && path.real().exists() {
clone_attr(path.real(), path.worker())?; clone_attr(path.real(), path.worker())?;
} }
} }
FsNode::MagiskLink => {
if let Some(name) = path.real().file_name()
&& name == "supolicy"
{
module_log!("mklink", path.worker(), "./magiskpolicy");
path.worker().create_symlink_to(cstr!("./magiskpolicy"))?;
} else {
module_log!("mklink", path.worker(), "./magisk");
path.worker().create_symlink_to(cstr!("./magisk"))?;
}
}
FsNode::Whiteout => { FsNode::Whiteout => {
module_log!("delete", path.real(), "null"); module_log!("delete", path.real(), "null");
} }
@ -392,28 +391,9 @@ fn inject_magisk_bins(system: &mut FsNode) {
); );
// Inject applet symlinks // Inject applet symlinks
children.insert("su".to_string(), FsNode::MagiskLink);
children.insert( children.insert("resetprop".to_string(), FsNode::MagiskLink);
"su".to_string(), children.insert("supolicy".to_string(), FsNode::MagiskLink);
FsNode::Symlink {
target: Utf8CString::from("./magisk"),
is_magisk_bin: true,
},
);
children.insert(
"resetprop".to_string(),
FsNode::Symlink {
target: Utf8CString::from("./magisk"),
is_magisk_bin: true,
},
);
children.insert(
"supolicy".to_string(),
FsNode::Symlink {
target: Utf8CString::from("./magiskpolicy"),
is_magisk_bin: true,
},
);
} }
// Strip /system prefix to insert correct node // Strip /system prefix to insert correct node