Minor update for parsing uevent
This commit is contained in:
parent
845d1e02b0
commit
3b0f888407
@ -10,30 +10,35 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static void parse_device(device *dev, const char *uevent) {
|
struct devinfo {
|
||||||
dev->partname[0] = '\0';
|
int major;
|
||||||
FILE *fp = xfopen(uevent, "re");
|
int minor;
|
||||||
char buf[64];
|
char devname[32];
|
||||||
while (fgets(buf, sizeof(buf), fp)) {
|
char partname[32];
|
||||||
if (strncmp(buf, "MAJOR", 5) == 0) {
|
};
|
||||||
sscanf(buf, "MAJOR=%d", &dev->major);
|
|
||||||
} else if (strncmp(buf, "MINOR", 5) == 0) {
|
|
||||||
sscanf(buf, "MINOR=%d", &dev->minor);
|
|
||||||
} else if (strncmp(buf, "DEVNAME", 7) == 0) {
|
|
||||||
sscanf(buf, "DEVNAME=%s", dev->devname);
|
|
||||||
} else if (strncmp(buf, "PARTNAME", 8) == 0) {
|
|
||||||
sscanf(buf, "PARTNAME=%s", dev->partname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static vector<device> dev_list;
|
static vector<devinfo> dev_list;
|
||||||
|
|
||||||
|
static void parse_device(devinfo *dev, const char *uevent) {
|
||||||
|
dev->partname[0] = '\0';
|
||||||
|
parse_prop_file(uevent, [=](string_view key, string_view value) -> bool {
|
||||||
|
if (key == "MAJOR")
|
||||||
|
dev->major = atoi(value.data());
|
||||||
|
else if (key == "MINOR")
|
||||||
|
dev->minor = atoi(value.data());
|
||||||
|
else if (key == "DEVNAME")
|
||||||
|
strcpy(dev->devname, value.data());
|
||||||
|
else if (key == "PARTNAME")
|
||||||
|
strcpy(dev->partname, value.data());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
static void collect_devices() {
|
static void collect_devices() {
|
||||||
char path[128];
|
char path[128];
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
device dev;
|
devinfo dev;
|
||||||
DIR *dir = xopendir("/sys/dev/block");
|
DIR *dir = xopendir("/sys/dev/block");
|
||||||
if (dir == nullptr)
|
if (dir == nullptr)
|
||||||
return;
|
return;
|
||||||
@ -63,7 +68,7 @@ static bool setup_block(const char *partname, char *block_dev) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MagiskInit::read_dt_fstab(const char *name, char *partname, char *partfs) {
|
bool MagiskInit::read_dt_fstab(const char *name, char *partname, char *fstype) {
|
||||||
char path[128];
|
char path[128];
|
||||||
int fd;
|
int fd;
|
||||||
sprintf(path, "%s/fstab/%s/dev", cmd.dt_dir, name);
|
sprintf(path, "%s/fstab/%s/dev", cmd.dt_dir, name);
|
||||||
@ -75,7 +80,7 @@ bool MagiskInit::read_dt_fstab(const char *name, char *partname, char *partfs) {
|
|||||||
sprintf(partname, "%s%s", part, strend(part, cmd.slot) ? cmd.slot : "");
|
sprintf(partname, "%s%s", part, strend(part, cmd.slot) ? cmd.slot : "");
|
||||||
sprintf(path, "%s/fstab/%s/type", cmd.dt_dir, name);
|
sprintf(path, "%s/fstab/%s/type", cmd.dt_dir, name);
|
||||||
if ((fd = xopen(path, O_RDONLY | O_CLOEXEC)) >= 0) {
|
if ((fd = xopen(path, O_RDONLY | O_CLOEXEC)) >= 0) {
|
||||||
read(fd, partfs, 32);
|
read(fd, fstype, 32);
|
||||||
close(fd);
|
close(fd);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,6 @@ struct raw_data {
|
|||||||
size_t sz;
|
size_t sz;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct device {
|
|
||||||
int major;
|
|
||||||
int minor;
|
|
||||||
char devname[32];
|
|
||||||
char partname[32];
|
|
||||||
};
|
|
||||||
|
|
||||||
class MagiskInit {
|
class MagiskInit {
|
||||||
private:
|
private:
|
||||||
cmdline cmd{};
|
cmdline cmd{};
|
||||||
@ -35,7 +28,7 @@ private:
|
|||||||
void preset();
|
void preset();
|
||||||
void early_mount();
|
void early_mount();
|
||||||
void setup_rootfs();
|
void setup_rootfs();
|
||||||
bool read_dt_fstab(const char *name, char *partname, char *partfs);
|
bool read_dt_fstab(const char *name, char *partname, char *fstype);
|
||||||
bool patch_sepolicy();
|
bool patch_sepolicy();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
void re_exec_init();
|
void re_exec_init();
|
||||||
|
Loading…
Reference in New Issue
Block a user