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: protected:
raw_data config; raw_data config;
std::vector<raw_file> overlays; std::vector<raw_file> overlays;
std::string tmp_dir;
void backup_files(); void backup_files();
void patch_rootdir(); 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) { static void mount_persist(const char *dev_base, const char *mnt_base) {
string mnt_point = mnt_base + "/persist"s; string mnt_point = mnt_base + "/persist"s;
strcpy(partname, "persist"); 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) { if (setup_block(false) < 0) {
// Fallback to cache // Fallback to cache
strcpy(partname, "cache"); strcpy(partname, "cache");
sprintf(block_dev, "%s/cache", dev_base); strcpy(s, "/cache");
if (setup_block(false) < 0) { if (setup_block(false) < 0) {
// Try NVIDIA's BS // Try NVIDIA's BS
strcpy(partname, "CAC"); 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" #define LIBSELINUX "/system/" LIBNAME "/libselinux.so"
void SARBase::patch_rootdir() { void SARBase::patch_rootdir() {
char tmp_dir[128];
// TODO: dynamic paths // TODO: dynamic paths
tmp_dir = "/sbin"; char *p = tmp_dir + sprintf(tmp_dir, "%s", "/sbin");
setup_tmp(tmp_dir.data(), self, config); setup_tmp(tmp_dir, self, config);
persist_dir = tmp_dir + "/" MIRRDIR "/persist"; persist_dir = string(tmp_dir) + "/" MIRRDIR "/persist";
chdir(tmp_dir.data()); chdir(tmp_dir);
// Mount system_root mirror // Mount system_root mirror
struct stat st; struct stat st;
xstat("/", &st); xstat("/", &st);
xmkdir(ROOTMIR, 0755); xmkdir(ROOTMIR, 0755);
mknod(ROOTBLK, S_IFBLK | 0600, st.st_dev); mknod(ROOTBLK, S_IFBLK | 0600, st.st_dev);
if (xmount(ROOTBLK, ROOTMIR, "ext4", MS_RDONLY, nullptr)) strcpy(p, "/" ROOTBLK);
xmount(ROOTBLK, ROOTMIR, "erofs", MS_RDONLY, nullptr); 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 // Recreate original sbin structure if necessary
if (tmp_dir == "/sbin") if (tmp_dir == "/sbin"sv)
recreate_sbin(ROOTMIR "/sbin", true); recreate_sbin(ROOTMIR "/sbin", true);
// Patch init // Patch init
@ -303,7 +307,7 @@ void SARBase::patch_rootdir() {
if (connect(sockfd, (struct sockaddr*) &sun, setup_sockaddr(&sun, INIT_SOCKET)) == 0) { if (connect(sockfd, (struct sockaddr*) &sun, setup_sockaddr(&sun, INIT_SOCKET)) == 0) {
LOGD("ACK init tracer to write backup files\n"); LOGD("ACK init tracer to write backup files\n");
// Let tracer know where tmp_dir is // 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 // Wait for tracer to finish copying files
int ack; int ack;
read(sockfd, &ack, sizeof(ack)); read(sockfd, &ack, sizeof(ack));