Magisk/jni/daemon/post_fs_data.c

69 lines
1.4 KiB
C
Raw Normal View History

/* post_fs_data.c - post-fs-data actions
*/
2017-04-17 08:36:49 +00:00
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
2017-04-17 08:36:49 +00:00
#include <fcntl.h>
#include <string.h>
#include <linux/loop.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
2017-04-17 08:36:49 +00:00
#include "magisk.h"
#include "utils.h"
#include "daemon.h"
2017-04-17 08:36:49 +00:00
#include "resetprop.h"
static char *loopsetup(const char *img) {
char device[20];
struct loop_info64 info;
int i, lfd, ffd;
// First get an empty loop device
for (i = 0; i <= 7; ++i) {
sprintf(device, "/dev/block/loop%d", i);
lfd = xopen(device, O_RDWR);
if (ioctl(lfd, LOOP_GET_STATUS64, &info) == -1)
break;
close(lfd);
}
if (i == 8) return NULL;
ffd = xopen(img, O_RDWR);
if (ioctl(lfd, LOOP_SET_FD, ffd) == -1)
return NULL;
return strdup(device);
}
char *mount_image(const char *img, const char *target) {
char *device = loopsetup(img);
if (device)
2017-04-18 11:32:50 +00:00
xmount(device, target, "ext4", 0, NULL);
2017-04-17 08:36:49 +00:00
return device;
}
void post_fs_data(int client) {
// ack
write_int(client, 0);
close(client);
2017-04-17 08:36:49 +00:00
if (!check_data())
goto unblock;
LOGI("** post-fs-data mode running\n");
LOGI("* Mounting magisk.img\n");
// Mounting magisk image
char *magiskimg = mount_image("/data/magisk.img", "/magisk");
free(magiskimg);
// Start magiskhide if enabled
char *hide_prop = getprop("persist.magisk.hide");
if (hide_prop) {
if (strcmp(hide_prop, "1") == 0)
launch_magiskhide(-1);
free(hide_prop);
}
unblock:
unblock_boot_process();
2017-04-17 08:36:49 +00:00
return;
}