Skip loading Magisk when detecting DSU

Fix #4402

Co-authored-by: topjohnwu <topjohnwu@gmail.com>
This commit is contained in:
LoveSy
2021-12-29 13:04:09 +08:00
committed by GitHub
parent 3d88dd3123
commit 62ef8ade8f
3 changed files with 29 additions and 1 deletions

View File

@ -93,7 +93,7 @@ static int64_t setup_block(bool write_block) {
}
static bool is_lnk(const char *name) {
struct stat st;
struct stat st{};
if (lstat(name, &st))
return false;
return S_ISLNK(st.st_mode);
@ -196,6 +196,27 @@ static void switch_root(const string &path) {
frm_rf(root);
}
bool is_dsu() {
strcpy(blk_info.partname, "metadata");
xmkdir("/metadata", 0755);
if (setup_block(true) < 0 ||
xmount(blk_info.block_dev, "/metadata", "ext4", MS_RDONLY, nullptr)) {
PLOGE("Failed to mount /metadata");
return false;
} else {
run_finally f([]{ xumount2("/metadata", MNT_DETACH); });
constexpr auto dsu_status = "/metadata/gsi/dsu/install_status";
if (xaccess(dsu_status, F_OK) == 0) {
char status[PATH_MAX] = {0};
auto fp = xopen_file(dsu_status, "r");
fgets(status, sizeof(status), fp.get());
if (status == "ok"sv || status == "0"sv)
return true;
}
}
return false;
}
void MagiskInit::mount_rules_dir(const char *dev_base, const char *mnt_base) {
char path[128];
xrealpath(dev_base, blk_info.block_dev);