mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-30 13:35:27 +00:00
Backup proper magiskinit in A-only 2SI
This commit is contained in:
parent
0a2c99f1dc
commit
ba55e2bc32
@ -68,7 +68,7 @@ protected:
|
|||||||
raw_data config;
|
raw_data config;
|
||||||
dev_t system_dev;
|
dev_t system_dev;
|
||||||
|
|
||||||
void backup_files();
|
void backup_files(const char *self_path);
|
||||||
void patch_rootdir();
|
void patch_rootdir();
|
||||||
public:
|
public:
|
||||||
SARBase(char *argv[], cmdline *cmd) : MagiskInit(argv, cmd) {
|
SARBase(char *argv[], cmdline *cmd) : MagiskInit(argv, cmd) {
|
||||||
|
@ -183,11 +183,11 @@ void RootFSInit::early_mount() {
|
|||||||
mount_list.emplace_back("/dev/mnt/cache");
|
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)
|
if (access("/overlay.d", F_OK) == 0)
|
||||||
cp_afc("/overlay.d", "/dev/overlay.d");
|
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);
|
full_read("/.backup/.magisk", config.buf, config.sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +197,7 @@ void SARInit::early_mount() {
|
|||||||
xmount("tmpfs", "/dev", "tmpfs", 0, "mode=755");
|
xmount("tmpfs", "/dev", "tmpfs", 0, "mode=755");
|
||||||
mount_list.emplace_back("/dev");
|
mount_list.emplace_back("/dev");
|
||||||
|
|
||||||
backup_files();
|
backup_files("/init");
|
||||||
|
|
||||||
LOGD("Cleaning rootfs\n");
|
LOGD("Cleaning rootfs\n");
|
||||||
int root = xopen("/", O_RDONLY | O_CLOEXEC);
|
int root = xopen("/", O_RDONLY | O_CLOEXEC);
|
||||||
@ -232,7 +232,7 @@ void SARInit::early_mount() {
|
|||||||
void SecondStageInit::early_mount() {
|
void SecondStageInit::early_mount() {
|
||||||
// Early mounts should already be done by first stage init
|
// Early mounts should already be done by first stage init
|
||||||
|
|
||||||
backup_files();
|
backup_files("/system/bin/init");
|
||||||
rm_rf("/system");
|
rm_rf("/system");
|
||||||
rm_rf("/.backup");
|
rm_rf("/.backup");
|
||||||
rm_rf("/overlay.d");
|
rm_rf("/overlay.d");
|
||||||
|
@ -407,20 +407,24 @@ static void patch_fstab(const string &fstab) {
|
|||||||
#define FSR "/first_stage_ramdisk"
|
#define FSR "/first_stage_ramdisk"
|
||||||
|
|
||||||
void ABFirstStageInit::prepare() {
|
void ABFirstStageInit::prepare() {
|
||||||
auto dir = xopen_dir(FSR);
|
// It is actually possible to NOT have FSR, create it just in case
|
||||||
if (!dir)
|
xmkdir(FSR, 0755);
|
||||||
return;
|
|
||||||
string fstab(FSR "/");
|
|
||||||
for (dirent *de; (de = xreaddir(dir.get()));) {
|
|
||||||
if (strstr(de->d_name, "fstab")) {
|
|
||||||
fstab += de->d_name;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fstab.length() == sizeof(FSR))
|
|
||||||
return;
|
|
||||||
|
|
||||||
patch_fstab(fstab);
|
if (auto dir = xopen_dir(FSR); dir) {
|
||||||
|
string fstab(FSR "/");
|
||||||
|
for (dirent *de; (de = xreaddir(dir.get()));) {
|
||||||
|
if (strstr(de->d_name, "fstab")) {
|
||||||
|
fstab += de->d_name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fstab.length() == sizeof(FSR))
|
||||||
|
return;
|
||||||
|
|
||||||
|
patch_fstab(fstab);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Move stuffs for next stage
|
// Move stuffs for next stage
|
||||||
xmkdir(FSR "/system", 0755);
|
xmkdir(FSR "/system", 0755);
|
||||||
|
Loading…
Reference in New Issue
Block a user