You've already forked ReZygisk
mirror of
https://github.com/PerformanC/ReZygisk.git
synced 2025-09-06 06:37:01 +00:00
improve: ReZygiskd umount code by unifying; improve: umount system by making umount if less strict
This commit both improves ReZygiskd umount system by unifying all root implementations code into a single one, and also by making it less strict to umount.
This commit is contained in:
@@ -603,115 +603,57 @@ bool umount_root(struct root_impl impl) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (impl.impl) {
|
/* INFO: "Magisk" is the longest word that will ever be put in source_name */
|
||||||
case None: { break; }
|
char source_name[sizeof("magisk")];
|
||||||
case Multiple: { break; }
|
if (impl.impl == KernelSU) strcpy(source_name, "KSU");
|
||||||
|
else if (impl.impl == APatch) strcpy(source_name, "APatch");
|
||||||
|
else strcpy(source_name, "magisk");
|
||||||
|
|
||||||
case KernelSU:
|
LOGI("[%s] Unmounting root", source_name);
|
||||||
case APatch: {
|
|
||||||
char source_name[LONGEST_ROOT_IMPL_NAME];
|
|
||||||
if (impl.impl == KernelSU) strcpy(source_name, "KSU");
|
|
||||||
else strcpy(source_name, "APatch");
|
|
||||||
|
|
||||||
LOGI("[%s] Unmounting root", source_name);
|
const char **targets_to_unmount = NULL;
|
||||||
|
size_t num_targets = 0;
|
||||||
|
|
||||||
const char **targets_to_unmount = NULL;
|
for (size_t i = 0; i < mounts.length; i++) {
|
||||||
size_t num_targets = 0;
|
struct mountinfo mount = mounts.mounts[i];
|
||||||
|
|
||||||
for (size_t i = 0; i < mounts.length; i++) {
|
bool should_unmount = false;
|
||||||
struct mountinfo mount = mounts.mounts[i];
|
/* INFO: The root implementations have their own /system mounts, so we
|
||||||
|
only skip the mount if they are from a module, not Magisk itself.
|
||||||
|
*/
|
||||||
|
if (strncmp(mount.target, "/system/", strlen("/system/")) == 0 &&
|
||||||
|
strncmp(mount.root, "/adb/modules/", strlen("/adb/modules/")) == 0 &&
|
||||||
|
strncmp(mount.target, "/system/etc/", strlen("/system/etc/")) != 0) continue;
|
||||||
|
|
||||||
bool should_unmount = false;
|
if (strcmp(mount.source, source_name) == 0) should_unmount = true;
|
||||||
|
if (strncmp(mount.target, "/data/adb/modules", strlen("/data/adb/modules")) == 0) should_unmount = true;
|
||||||
|
if (strncmp(mount.root, "/adb/modules/", strlen("/adb/modules/")) == 0) should_unmount = true;
|
||||||
|
|
||||||
/* INFO: KernelSU has its own /system mounts, so we only skip the mount
|
if (!should_unmount) continue;
|
||||||
if they are from a module, not KSU itself.
|
|
||||||
*/
|
|
||||||
if (strncmp(mount.target, "/system/", strlen("/system/")) == 0 &&
|
|
||||||
strncmp(mount.root, "/adb/modules", strlen("/adb/modules")) == 0) continue;
|
|
||||||
|
|
||||||
if (strcmp(mount.source, source_name) == 0) should_unmount = true;
|
num_targets++;
|
||||||
if (strncmp(mount.root, "/adb/modules", strlen("/adb/modules")) == 0) should_unmount = true;
|
targets_to_unmount = realloc(targets_to_unmount, num_targets * sizeof(char*));
|
||||||
if (strncmp(mount.target, "/data/adb/modules", strlen("/data/adb/modules")) == 0) should_unmount = true;
|
if (targets_to_unmount == NULL) {
|
||||||
|
LOGE("[%s] Failed to allocate memory for targets_to_unmount\n", source_name);
|
||||||
|
|
||||||
if (!should_unmount) continue;
|
|
||||||
|
|
||||||
num_targets++;
|
|
||||||
targets_to_unmount = realloc(targets_to_unmount, num_targets * sizeof(char*));
|
|
||||||
if (targets_to_unmount == NULL) {
|
|
||||||
LOGE("[%s] Failed to allocate memory for targets_to_unmount\n", source_name);
|
|
||||||
|
|
||||||
free(targets_to_unmount);
|
|
||||||
free_mounts(&mounts);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
targets_to_unmount[num_targets - 1] = mount.target;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = num_targets; i > 0; i--) {
|
|
||||||
const char *target = targets_to_unmount[i - 1];
|
|
||||||
|
|
||||||
if (umount2(target, MNT_DETACH) == -1) {
|
|
||||||
LOGE("[%s] Failed to unmount %s: %s\n", source_name, target, strerror(errno));
|
|
||||||
} else {
|
|
||||||
LOGI("[%s] Unmounted %s\n", source_name, target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(targets_to_unmount);
|
free(targets_to_unmount);
|
||||||
|
free_mounts(&mounts);
|
||||||
|
|
||||||
break;
|
return false;
|
||||||
}
|
}
|
||||||
case Magisk: {
|
|
||||||
LOGI("[Magisk] Unmounting root");
|
|
||||||
|
|
||||||
const char **targets_to_unmount = NULL;
|
targets_to_unmount[num_targets - 1] = mount.target;
|
||||||
size_t num_targets = 0;
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < mounts.length; i++) {
|
for (size_t i = num_targets; i > 0; i--) {
|
||||||
struct mountinfo mount = mounts.mounts[i];
|
const char *target = targets_to_unmount[i - 1];
|
||||||
|
if (umount2(target, MNT_DETACH) == -1) {
|
||||||
bool should_unmount = false;
|
LOGE("[%s] Failed to unmount %s: %s\n", source_name, target, strerror(errno));
|
||||||
/* INFO: Magisk has its own /system mounts, so we only skip the mount
|
} else {
|
||||||
if they are from a module, not Magisk itself.
|
LOGI("[%s] Unmounted %s\n", source_name, target);
|
||||||
*/
|
|
||||||
if (strncmp(mount.target, "/system/", strlen("/system/")) == 0 &&
|
|
||||||
strncmp(mount.root, "/adb/modules", strlen("/adb/modules")) == 0) continue;
|
|
||||||
|
|
||||||
if (strcmp(mount.source, "magisk") == 0) should_unmount = true;
|
|
||||||
if (strncmp(mount.target, "/debug_ramdisk", strlen("/debug_ramdisk")) == 0) should_unmount = true;
|
|
||||||
if (strncmp(mount.target, "/data/adb/modules", strlen("/data/adb/modules")) == 0) should_unmount = true;
|
|
||||||
if (strncmp(mount.root, "/adb/modules", strlen("/adb/modules")) == 0) should_unmount = true;
|
|
||||||
|
|
||||||
if (!should_unmount) continue;
|
|
||||||
|
|
||||||
num_targets++;
|
|
||||||
targets_to_unmount = realloc(targets_to_unmount, num_targets * sizeof(char*));
|
|
||||||
if (targets_to_unmount == NULL) {
|
|
||||||
LOGE("[Magisk] Failed to allocate memory for targets_to_unmount\n");
|
|
||||||
|
|
||||||
free(targets_to_unmount);
|
|
||||||
free_mounts(&mounts);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
targets_to_unmount[num_targets - 1] = mount.target;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = num_targets; i > 0; i--) {
|
|
||||||
const char *target = targets_to_unmount[i - 1];
|
|
||||||
if (umount2(target, MNT_DETACH) == -1) {
|
|
||||||
LOGE("[Magisk] Failed to unmount %s: %s\n", target, strerror(errno));
|
|
||||||
} else {
|
|
||||||
LOGI("[Magisk] Unmounted %s\n", target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(targets_to_unmount);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
free(targets_to_unmount);
|
||||||
|
|
||||||
free_mounts(&mounts);
|
free_mounts(&mounts);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user