mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-04-21 13:31:27 +00:00
Support oplus.fstab
This commit is contained in:
parent
439d497a13
commit
acf166cf9d
@ -1,4 +1,5 @@
|
|||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
#include <magisk.hpp>
|
#include <magisk.hpp>
|
||||||
#include <utils.hpp>
|
#include <utils.hpp>
|
||||||
@ -17,6 +18,32 @@ void fstab_entry::to_file(FILE *fp) {
|
|||||||
line[val##1] = '\0'; \
|
line[val##1] = '\0'; \
|
||||||
entry.val = &line[val##0];
|
entry.val = &line[val##0];
|
||||||
|
|
||||||
|
static void read_fstab_file(const char *fstab_file, vector<fstab_entry> &fstab) {
|
||||||
|
file_readline(fstab_file, [&](string_view l) -> bool {
|
||||||
|
if (l[0] == '#' || l.length() == 1)
|
||||||
|
return true;
|
||||||
|
char *line = (char *) l.data();
|
||||||
|
|
||||||
|
int dev0, dev1, mnt_point0, mnt_point1, type0, type1,
|
||||||
|
mnt_flags0, mnt_flags1, fsmgr_flags0, fsmgr_flags1;
|
||||||
|
|
||||||
|
sscanf(line, "%n%*s%n %n%*s%n %n%*s%n %n%*s%n %n%*s%n",
|
||||||
|
&dev0, &dev1, &mnt_point0, &mnt_point1, &type0, &type1,
|
||||||
|
&mnt_flags0, &mnt_flags1, &fsmgr_flags0, &fsmgr_flags1);
|
||||||
|
|
||||||
|
fstab_entry entry;
|
||||||
|
|
||||||
|
set_info(dev)
|
||||||
|
set_info(mnt_point)
|
||||||
|
set_info(type)
|
||||||
|
set_info(mnt_flags)
|
||||||
|
set_info(fsmgr_flags)
|
||||||
|
|
||||||
|
fstab.emplace_back(move(entry));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#define FSR "/first_stage_ramdisk"
|
#define FSR "/first_stage_ramdisk"
|
||||||
|
|
||||||
extern uint32_t patch_verity(void *buf, uint32_t size);
|
extern uint32_t patch_verity(void *buf, uint32_t size);
|
||||||
@ -91,29 +118,40 @@ exit_loop:
|
|||||||
init.patch({ make_pair("android,fstab", "xxx") });
|
init.patch({ make_pair("android,fstab", "xxx") });
|
||||||
} else {
|
} else {
|
||||||
// Parse and load the fstab file
|
// Parse and load the fstab file
|
||||||
file_readline(fstab_file, [&](string_view l) -> bool {
|
read_fstab_file(fstab_file, fstab);
|
||||||
if (l[0] == '#' || l.length() == 1)
|
}
|
||||||
return true;
|
|
||||||
char *line = (char *) l.data();
|
|
||||||
|
|
||||||
int dev0, dev1, mnt_point0, mnt_point1, type0, type1,
|
// Append oppo's custom fstab
|
||||||
mnt_flags0, mnt_flags1, fsmgr_flags0, fsmgr_flags1;
|
if (access("oplus.fstab", F_OK) == 0) {
|
||||||
|
LOGD("Found fstab file: %s\n", "oplus.fstab");
|
||||||
|
vector<fstab_entry> oplus_fstab;
|
||||||
|
unordered_map<string, string> bind_map;
|
||||||
|
|
||||||
sscanf(line, "%n%*s%n %n%*s%n %n%*s%n %n%*s%n %n%*s%n",
|
read_fstab_file("oplus.fstab", oplus_fstab);
|
||||||
&dev0, &dev1, &mnt_point0, &mnt_point1, &type0, &type1,
|
|
||||||
&mnt_flags0, &mnt_flags1, &fsmgr_flags0, &fsmgr_flags1);
|
|
||||||
|
|
||||||
fstab_entry entry;
|
for (auto &entry : oplus_fstab) {
|
||||||
|
if (entry.mnt_flags.find("bind") != string::npos) {
|
||||||
|
bind_map.emplace(entry.dev, entry.mnt_point);
|
||||||
|
entry.dev = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
set_info(dev);
|
for (auto &entry : oplus_fstab) {
|
||||||
set_info(mnt_point);
|
// Merge bind entries
|
||||||
set_info(type);
|
if (entry.dev.empty())
|
||||||
set_info(mnt_flags);
|
continue;
|
||||||
set_info(fsmgr_flags);
|
auto got = bind_map.find(entry.mnt_point);
|
||||||
|
if (got != bind_map.end())
|
||||||
|
entry.mnt_point = got->second;
|
||||||
|
|
||||||
fstab.emplace_back(std::move(entry));
|
// Mount befor switch root, fix img path
|
||||||
return true;
|
if (str_starts(entry.dev, "loop@/system/"))
|
||||||
});
|
entry.dev.insert(5, "/system_root");
|
||||||
|
|
||||||
|
fstab.push_back(move(entry));
|
||||||
|
}
|
||||||
|
|
||||||
|
unlink("oplus.fstab");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -180,7 +218,7 @@ void SARInit::first_stage_prep() {
|
|||||||
sigprocmask(SIG_SETMASK, &old, nullptr);
|
sigprocmask(SIG_SETMASK, &old, nullptr);
|
||||||
} else {
|
} else {
|
||||||
// Establish socket for 2nd stage ack
|
// Establish socket for 2nd stage ack
|
||||||
struct sockaddr_un sun;
|
struct sockaddr_un sun{};
|
||||||
int sockfd = xsocket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
int sockfd = xsocket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
||||||
xbind(sockfd, (struct sockaddr*) &sun, setup_sockaddr(&sun, INIT_SOCKET));
|
xbind(sockfd, (struct sockaddr*) &sun, setup_sockaddr(&sun, INIT_SOCKET));
|
||||||
xlisten(sockfd, 1);
|
xlisten(sockfd, 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user