mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-24 02:25:28 +00:00
Fix coding errors and minor changes
This commit is contained in:
parent
d0b6318b90
commit
0feab753fb
@ -12,7 +12,7 @@
|
||||
using namespace std;
|
||||
|
||||
template<typename Func>
|
||||
static void parse_cmdline(Func fn) {
|
||||
static void parse_cmdline(const Func &fn) {
|
||||
char cmdline[4096];
|
||||
int fd = xopen("/proc/cmdline", O_RDONLY | O_CLOEXEC);
|
||||
cmdline[read(fd, cmdline, sizeof(cmdline))] = '\0';
|
||||
@ -140,7 +140,7 @@ void load_kernel_info(cmdline *cmd) {
|
||||
// Log to kernel
|
||||
setup_klog();
|
||||
|
||||
parse_cmdline([=](auto key, auto value) -> void {
|
||||
parse_cmdline([=](string_view key, const char *value) -> void {
|
||||
if (key == "androidboot.slot_suffix") {
|
||||
strcpy(cmd->slot, value);
|
||||
} else if (key == "androidboot.slot") {
|
||||
@ -161,6 +161,15 @@ void load_kernel_info(cmdline *cmd) {
|
||||
}
|
||||
});
|
||||
|
||||
LOGD("Device info:\n");
|
||||
LOGD("skip_initramfs=[%d]\n", cmd->skip_initramfs);
|
||||
LOGD("force_normal_boot=[%d]\n", cmd->force_normal_boot);
|
||||
LOGD("slot=[%s]\n", cmd->slot);
|
||||
LOGD("dt_dir=[%s]\n", cmd->dt_dir);
|
||||
LOGD("fstab_suffix=[%s]\n", cmd->fstab_suffix);
|
||||
LOGD("hardware=[%s]\n", cmd->hardware);
|
||||
LOGD("hardware.platform=[%s]\n", cmd->hardware_plat);
|
||||
|
||||
parse_prop_file("/.backup/.magisk", [=](auto key, auto value) -> bool {
|
||||
if (key == "RECOVERYMODE" && value == "true") {
|
||||
LOGD("Running in recovery mode, waiting for key...\n");
|
||||
@ -172,14 +181,6 @@ void load_kernel_info(cmdline *cmd) {
|
||||
|
||||
if (cmd->dt_dir[0] == '\0')
|
||||
strcpy(cmd->dt_dir, DEFAULT_DT_DIR);
|
||||
|
||||
LOGD("Device info:\n");
|
||||
LOGD("skip_initramfs=[%d]\n", cmd->skip_initramfs);
|
||||
LOGD("force_normal_boot=[%d]\n", cmd->force_normal_boot);
|
||||
LOGD("slot=[%s]\n", cmd->slot);
|
||||
LOGD("dt_dir=[%s]\n", cmd->dt_dir);
|
||||
LOGD("hardware=[%s]\n", cmd->hardware);
|
||||
LOGD("hardware.platform=[%s]\n", cmd->hardware_plat);
|
||||
}
|
||||
|
||||
bool check_two_stage() {
|
||||
|
@ -54,11 +54,10 @@ static void collect_devices() {
|
||||
continue;
|
||||
sprintf(path, "/sys/dev/block/%s/uevent", entry->d_name);
|
||||
parse_device(&dev, path);
|
||||
dev.dmname[0] = '\0';
|
||||
sprintf(path, "/sys/dev/block/%s/dm/name", entry->d_name);
|
||||
if (access(path, F_OK) == 0) {
|
||||
auto name = rtrim(full_read(path));
|
||||
strcpy(dev.dmname, name.c_str());
|
||||
strcpy(dev.dmname, name.data());
|
||||
}
|
||||
dev_list.push_back(dev);
|
||||
}
|
||||
@ -70,7 +69,7 @@ static struct {
|
||||
char block_dev[64];
|
||||
} blk_info;
|
||||
|
||||
static int64_t setup_block(bool write_block = true) {
|
||||
static int64_t setup_block(bool write_block) {
|
||||
if (dev_list.empty())
|
||||
collect_devices();
|
||||
xmkdir("/dev", 0755);
|
||||
@ -78,20 +77,19 @@ static int64_t setup_block(bool write_block = true) {
|
||||
|
||||
for (int tries = 0; tries < 3; ++tries) {
|
||||
for (auto &dev : dev_list) {
|
||||
if (strcasecmp(dev.partname, blk_info.partname) == 0) {
|
||||
if (write_block) {
|
||||
sprintf(blk_info.block_dev, "/dev/block/%s", dev.devname);
|
||||
}
|
||||
if (strcasecmp(dev.partname, blk_info.partname) == 0)
|
||||
LOGD("Setup %s: [%s] (%d, %d)\n", dev.partname, dev.devname, dev.major, dev.minor);
|
||||
dev_t rdev = makedev(dev.major, dev.minor);
|
||||
mknod(blk_info.block_dev, S_IFBLK | 0600, rdev);
|
||||
return rdev;
|
||||
} else if (strcasecmp(dev.dmname, blk_info.partname) == 0) {
|
||||
else if (strcasecmp(dev.dmname, blk_info.partname) == 0)
|
||||
LOGD("Setup %s: [%s] (%d, %d)\n", dev.dmname, dev.devname, dev.major, dev.minor);
|
||||
dev_t rdev = makedev(dev.major, dev.minor);
|
||||
mknod(blk_info.block_dev, S_IFBLK | 0600, rdev);
|
||||
return rdev;
|
||||
else
|
||||
continue;
|
||||
|
||||
if (write_block) {
|
||||
sprintf(blk_info.block_dev, "/dev/block/%s", dev.devname);
|
||||
}
|
||||
dev_t rdev = makedev(dev.major, dev.minor);
|
||||
mknod(blk_info.block_dev, S_IFBLK | 0600, rdev);
|
||||
return rdev;
|
||||
}
|
||||
// Wait 10ms and try again
|
||||
usleep(10000);
|
||||
@ -171,7 +169,7 @@ void MagiskInit::mount_with_dt() {
|
||||
continue;
|
||||
// Derive partname from dev
|
||||
sprintf(blk_info.partname, "%s%s", basename(entry.dev.data()), cmd->slot);
|
||||
setup_block();
|
||||
setup_block(true);
|
||||
xmkdir(entry.mnt_point.data(), 0755);
|
||||
xmount(blk_info.block_dev, entry.mnt_point.data(), entry.type.data(), MS_RDONLY, nullptr);
|
||||
mount_list.push_back(entry.mnt_point);
|
||||
|
Loading…
Reference in New Issue
Block a user