Commit ba55e2bc authored by topjohnwu's avatar topjohnwu

Backup proper magiskinit in A-only 2SI

parent 0a2c99f1
......@@ -68,7 +68,7 @@ protected:
raw_data config;
dev_t system_dev;
void backup_files();
void backup_files(const char *self_path);
void patch_rootdir();
public:
SARBase(char *argv[], cmdline *cmd) : MagiskInit(argv, cmd) {
......
......@@ -183,11 +183,11 @@ void RootFSInit::early_mount() {
mount_list.emplace_back("/dev/mnt/cache");
}
void SARBase::backup_files() {
void SARBase::backup_files(const char *self_path) {
if (access("/overlay.d", F_OK) == 0)
cp_afc("/overlay.d", "/dev/overlay.d");
full_read("/init", self.buf, self.sz);
full_read(self_path, self.buf, self.sz);
full_read("/.backup/.magisk", config.buf, config.sz);
}
......@@ -197,7 +197,7 @@ void SARInit::early_mount() {
xmount("tmpfs", "/dev", "tmpfs", 0, "mode=755");
mount_list.emplace_back("/dev");
backup_files();
backup_files("/init");
LOGD("Cleaning rootfs\n");
int root = xopen("/", O_RDONLY | O_CLOEXEC);
......@@ -232,7 +232,7 @@ void SARInit::early_mount() {
void SecondStageInit::early_mount() {
// Early mounts should already be done by first stage init
backup_files();
backup_files("/system/bin/init");
rm_rf("/system");
rm_rf("/.backup");
rm_rf("/overlay.d");
......
......@@ -407,9 +407,10 @@ static void patch_fstab(const string &fstab) {
#define FSR "/first_stage_ramdisk"
void ABFirstStageInit::prepare() {
auto dir = xopen_dir(FSR);
if (!dir)
return;
// It is actually possible to NOT have FSR, create it just in case
xmkdir(FSR, 0755);
if (auto dir = xopen_dir(FSR); dir) {
string fstab(FSR "/");
for (dirent *de; (de = xreaddir(dir.get()));) {
if (strstr(de->d_name, "fstab")) {
......@@ -421,6 +422,9 @@ void ABFirstStageInit::prepare() {
return;
patch_fstab(fstab);
} else {
return;
}
// Move stuffs for next stage
xmkdir(FSR "/system", 0755);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment