Make cleaner mount info

This commit is contained in:
topjohnwu 2020-04-18 18:50:25 -07:00
parent 69a9d7485b
commit d959c35723
4 changed files with 17 additions and 12 deletions

View File

@ -69,7 +69,6 @@ class SARBase : public MagiskInit {
protected:
raw_data config;
std::vector<raw_file> overlays;
std::string tmp_dir;
void backup_files();
void patch_rootdir();

View File

@ -153,11 +153,13 @@ static void switch_root(const string &path) {
static void mount_persist(const char *dev_base, const char *mnt_base) {
string mnt_point = mnt_base + "/persist"s;
strcpy(partname, "persist");
sprintf(block_dev, "%s/persist", dev_base);
xrealpath(dev_base, block_dev);
char *s = block_dev + strlen(block_dev);
strcpy(s, "/persist");
if (setup_block(false) < 0) {
// Fallback to cache
strcpy(partname, "cache");
sprintf(block_dev, "%s/cache", dev_base);
strcpy(s, "/cache");
if (setup_block(false) < 0) {
// Try NVIDIA's BS
strcpy(partname, "CAC");

View File

@ -222,24 +222,28 @@ static void magic_mount(const string &sdir, const string &ddir = "") {
#define LIBSELINUX "/system/" LIBNAME "/libselinux.so"
void SARBase::patch_rootdir() {
char tmp_dir[128];
// TODO: dynamic paths
tmp_dir = "/sbin";
char *p = tmp_dir + sprintf(tmp_dir, "%s", "/sbin");
setup_tmp(tmp_dir.data(), self, config);
persist_dir = tmp_dir + "/" MIRRDIR "/persist";
setup_tmp(tmp_dir, self, config);
persist_dir = string(tmp_dir) + "/" MIRRDIR "/persist";
chdir(tmp_dir.data());
chdir(tmp_dir);
// Mount system_root mirror
struct stat st;
xstat("/", &st);
xmkdir(ROOTMIR, 0755);
mknod(ROOTBLK, S_IFBLK | 0600, st.st_dev);
if (xmount(ROOTBLK, ROOTMIR, "ext4", MS_RDONLY, nullptr))
xmount(ROOTBLK, ROOTMIR, "erofs", MS_RDONLY, nullptr);
strcpy(p, "/" ROOTBLK);
if (xmount(tmp_dir, ROOTMIR, "ext4", MS_RDONLY, nullptr))
xmount(tmp_dir, ROOTMIR, "erofs", MS_RDONLY, nullptr);
*p = '\0';
// Recreate original sbin structure if necessary
if (tmp_dir == "/sbin")
if (tmp_dir == "/sbin"sv)
recreate_sbin(ROOTMIR "/sbin", true);
// Patch init
@ -303,7 +307,7 @@ void SARBase::patch_rootdir() {
if (connect(sockfd, (struct sockaddr*) &sun, setup_sockaddr(&sun, INIT_SOCKET)) == 0) {
LOGD("ACK init tracer to write backup files\n");
// Let tracer know where tmp_dir is
write_string(sockfd, tmp_dir.data());
write_string(sockfd, tmp_dir);
// Wait for tracer to finish copying files
int ack;
read(sockfd, &ack, sizeof(ack));