Migrate module mounting to Rust

This commit is contained in:
topjohnwu
2025-05-08 21:00:40 -07:00
committed by John Wu
parent 4c89c7e2b3
commit 527bbc0368
11 changed files with 615 additions and 675 deletions
+1 -1
View File
@@ -82,7 +82,7 @@ impl MagiskInit {
debug!("Mount [{}] -> [{}]", src, dest);
clone_attr(&dest, &src)?;
dest.get_secontext(&mut con)?;
src.bind_mount_to(&dest)?;
src.bind_mount_to(&dest, false)?;
self.overlay_con
.push(OverlayAttr(dest.to_owned(), con.to_owned()));
mount_list.push_str(dest.as_str());
+2 -2
View File
@@ -49,13 +49,13 @@ enum SePatchStrategy {
fn mock_fifo(target: &Utf8CStr, mock: &Utf8CStr) -> LoggedResult<()> {
debug!("Hijack [{}]", target);
mock.mkfifo(0o666)?;
mock.bind_mount_to(target).log()
mock.bind_mount_to(target, false).log()
}
fn mock_file(target: &Utf8CStr, mock: &Utf8CStr) -> LoggedResult<()> {
debug!("Hijack [{}]", target);
drop(mock.create(libc::O_RDONLY, 0o666)?);
mock.bind_mount_to(target).log()
mock.bind_mount_to(target, false).log()
}
impl MagiskInit {
+6 -3
View File
@@ -37,7 +37,7 @@ pub(crate) fn hexpatch_init_for_second_stage(writable: bool) {
}
let attr = src.follow_link().get_attr()?;
dest.set_attr(&attr)?;
dest.bind_mount_to(src)?;
dest.bind_mount_to(src, false)?;
};
}
}
@@ -89,12 +89,15 @@ impl MagiskInit {
cstr!("/init").rename_to(cstr!("/sdcard")).log_ok();
// First try to mount magiskinit from rootfs to workaround Samsung RKP
if cstr!("/sdcard").bind_mount_to(cstr!("/sdcard")).is_ok() {
if cstr!("/sdcard")
.bind_mount_to(cstr!("/sdcard"), false)
.is_ok()
{
debug!("Bind mount /sdcard -> /sdcard");
} else {
// Binding mounting from rootfs is not supported before Linux 3.12
cstr!("/data/magiskinit")
.bind_mount_to(cstr!("/sdcard"))
.bind_mount_to(cstr!("/sdcard"), false)
.log_ok();
debug!("Bind mount /data/magiskinit -> /sdcard");
}