From 6d198a353d2aebd29a10a2eb6d6139dbea72f455 Mon Sep 17 00:00:00 2001 From: 7a72 Date: Sun, 23 Nov 2025 20:01:26 +0800 Subject: [PATCH] fix: add fallback support for .replace marker file The replace-dir detection relied solely on the xattr, causing .replace marker files to be ignored. This commit restores the intended behavior by checking for /.replace when the xattr is missing or empty. --- src/magic_mount.c | 18 +++++++++++++----- src/magic_mount.h | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/magic_mount.c b/src/magic_mount.c index 3c69272..070a879 100644 --- a/src/magic_mount.c +++ b/src/magic_mount.c @@ -163,11 +163,19 @@ static bool dir_is_replace(const char *path) { char buf[8]; ssize_t len = lgetxattr(path, REPLACE_DIR_XATTR, buf, sizeof(buf) - 1); - if (len <= 0) - return false; - - buf[len] = '\0'; - return (strcmp(buf, "y") == 0); + + if (len > 0) { + buf[len] = '\0'; + if (strcmp(buf, "y") == 0) + return true; + } + + int dirfd = open(path, O_RDONLY | O_DIRECTORY); + if (dirfd < 0) return false; + + bool exists = (faccessat(dirfd, REPLACE_DIR_FILE_NAME, F_OK, 0) == 0); + close(dirfd); + return exists; } static Node *node_new_module(const char *name, const char *path, diff --git a/src/magic_mount.h b/src/magic_mount.h index 9710d7c..328a6c5 100644 --- a/src/magic_mount.h +++ b/src/magic_mount.h @@ -9,6 +9,7 @@ #define SKIP_MOUNT_FILE_NAME "skip_mount" #define REPLACE_DIR_XATTR "trusted.overlay.opaque" +#define REPLACE_DIR_FILE_NAME ".replace" #define DEFAULT_MOUNT_SOURCE "KSU" #define DEFAULT_MODULE_DIR "/data/adb/modules"