From ae87f306800fa9e29905fc0cad37470f138ced50 Mon Sep 17 00:00:00 2001 From: backslashxx <118538522+backslashxx@users.noreply.github.com> Date: Fri, 21 Nov 2025 21:01:37 +0800 Subject: [PATCH] magic_mount: tell ksu about our mounts --- src/magic_mount.c | 30 +++++++++++++++++++++++++++++- src/magic_mount.h | 13 +++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/magic_mount.c b/src/magic_mount.c index 1c10207..edae7d9 100644 --- a/src/magic_mount.c +++ b/src/magic_mount.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include MountStats g_stats = { 0 }; @@ -26,6 +28,25 @@ int g_failed_modules_count = 0; char **g_extra_parts = NULL; int g_extra_parts_count = 0; +int global_fd = 0; + +static void grab_fd(void) { syscall(SYS_reboot, KSU_INSTALL_MAGIC1, KSU_INSTALL_MAGIC2, 0, (void *)&global_fd); } + +static void send_unmountable(const char *mntpoint) +{ + struct ksu_add_try_umount_cmd cmd = {0}; + + if (!global_fd) + return; + + cmd.arg = (uint64_t)mntpoint; + cmd.flags = 0x2; + cmd.mode = 1; + + ioctl(global_fd, KSU_IOCTL_ADD_TRY_UMOUNT, &cmd); + +} + static void register_module_failure(const char *module_name) { if (!module_name) @@ -496,7 +517,8 @@ static int do_magic(const char *base, const char *wbase, Node *node, LOGE("bind %s->%s: %s", node->module_path, target, strerror(errno)); return -1; - } + } else + send_unmountable(target); // tell ksu about this mount (void)mount(NULL, target, NULL, MS_REMOUNT | MS_BIND | MS_RDONLY, NULL); @@ -704,6 +726,10 @@ static int do_magic(const char *base, const char *wbase, Node *node, LOGI("move mountpoint success: %s -> %s", wpath, path); (void)mount(NULL, path, NULL, MS_REC | MS_PRIVATE, NULL); + + // tell ksu about this one too + send_unmountable(path); + } g_stats.nodes_mounted++; @@ -800,6 +826,8 @@ int magic_mount(const char *tmp_root) node_free(root); return -1; } + + grab_fd(); LOGI("starting magic_mount core logic: tmpfs_source=%s tmp_dir=%s", g_mount_source, tmp_dir); diff --git a/src/magic_mount.h b/src/magic_mount.h index a3e8e69..9710d7c 100644 --- a/src/magic_mount.h +++ b/src/magic_mount.h @@ -2,6 +2,7 @@ #define MAGIC_MOUNT_H #include +#include #define DISABLE_FILE_NAME "disable" #define REMOVE_FILE_NAME "remove" @@ -36,4 +37,16 @@ int magic_mount(const char *tmp_root); void add_extra_part_token(const char *start, size_t len); +// kernelsu api, atleast ones we care about +#define KSU_INSTALL_MAGIC1 0xDEADBEEF +#define KSU_INSTALL_MAGIC2 0xCAFEBABE + +struct ksu_add_try_umount_cmd { + uint64_t arg; // char ptr, this is the mountpoint + uint32_t flags; // this is the flag we use for it + uint8_t mode; // denotes what to do with it 0:wipe_list 1:add_to_list 2:delete_entry +}; + +#define KSU_IOCTL_ADD_TRY_UMOUNT _IOC(_IOC_WRITE, 'K', 18, 0) + #endif /* MAGIC_MOUNT_H */