mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-07 21:38:28 +00:00
Use find_if
This commit is contained in:
parent
3a0becc783
commit
9a9e617c35
@ -229,14 +229,6 @@ kv_pairs load_partition_map() {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_partition_name_for_device(const kv_pairs &partition_map, const std::string &query_device){
|
|
||||||
for (const auto &[device, partition] : partition_map) {
|
|
||||||
if (query_device == device)
|
|
||||||
return partition;
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
bool check_two_stage() {
|
bool check_two_stage() {
|
||||||
if (access("/apex", F_OK) == 0)
|
if (access("/apex", F_OK) == 0)
|
||||||
return true;
|
return true;
|
||||||
|
@ -30,7 +30,6 @@ int magisk_proxy_main(int argc, char *argv[]);
|
|||||||
bool unxz(out_stream &strm, rust::Slice<const uint8_t> bytes);
|
bool unxz(out_stream &strm, rust::Slice<const uint8_t> bytes);
|
||||||
void load_kernel_info(BootConfig *config);
|
void load_kernel_info(BootConfig *config);
|
||||||
kv_pairs load_partition_map();
|
kv_pairs load_partition_map();
|
||||||
std::string get_partition_name_for_device(const kv_pairs &partition_map, const std::string &query_device);
|
|
||||||
bool check_two_stage();
|
bool check_two_stage();
|
||||||
const char *backup_init();
|
const char *backup_init();
|
||||||
void restore_ramdisk_init();
|
void restore_ramdisk_init();
|
||||||
|
@ -29,21 +29,23 @@ bool avd_hack = false;
|
|||||||
static void parse_device(devinfo *dev, const char *uevent) {
|
static void parse_device(devinfo *dev, const char *uevent) {
|
||||||
dev->partname[0] = '\0';
|
dev->partname[0] = '\0';
|
||||||
dev->devpath[0] = '\0';
|
dev->devpath[0] = '\0';
|
||||||
|
dev->dmname[0] = '\0';
|
||||||
|
dev->devname[0] = '\0';
|
||||||
parse_prop_file(uevent, [=](string_view key, string_view value) -> bool {
|
parse_prop_file(uevent, [=](string_view key, string_view value) -> bool {
|
||||||
if (key == "MAJOR")
|
if (key == "MAJOR")
|
||||||
dev->major = parse_int(value.data());
|
dev->major = parse_int(value.data());
|
||||||
else if (key == "MINOR")
|
else if (key == "MINOR")
|
||||||
dev->minor = parse_int(value.data());
|
dev->minor = parse_int(value.data());
|
||||||
else if (key == "DEVNAME")
|
else if (key == "DEVNAME")
|
||||||
strcpy(dev->devname, value.data());
|
strscpy(dev->devname, value.data(), sizeof(dev->devname));
|
||||||
else if (key == "PARTNAME")
|
else if (key == "PARTNAME")
|
||||||
strcpy(dev->partname, value.data());
|
strscpy(dev->partname, value.data(), sizeof(dev->devname));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static void collect_devices() {
|
static void collect_devices(const auto &partition_map) {
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
devinfo dev{};
|
devinfo dev{};
|
||||||
if (auto dir = xopen_dir("/sys/dev/block"); dir) {
|
if (auto dir = xopen_dir("/sys/dev/block"); dir) {
|
||||||
@ -55,9 +57,13 @@ static void collect_devices() {
|
|||||||
sprintf(path, "/sys/dev/block/%s/dm/name", entry->d_name);
|
sprintf(path, "/sys/dev/block/%s/dm/name", entry->d_name);
|
||||||
if (access(path, F_OK) == 0) {
|
if (access(path, F_OK) == 0) {
|
||||||
auto name = rtrim(full_read(path));
|
auto name = rtrim(full_read(path));
|
||||||
strcpy(dev.dmname, name.data());
|
strscpy(dev.dmname, name.data(), sizeof(dev.dmname));
|
||||||
} else {
|
}
|
||||||
dev.dmname[0] = '\0';
|
if (auto it = std::ranges::find_if(partition_map, [&](const auto &i) {
|
||||||
|
return i.first == dev.devname;
|
||||||
|
}); dev.partname[0] == '\0' && it != partition_map.end()) {
|
||||||
|
// use androidboot.partition_map as partname fallback.
|
||||||
|
strscpy(dev.partname, it->second.data(), sizeof(dev.partname));
|
||||||
}
|
}
|
||||||
sprintf(path, "/sys/dev/block/%s", entry->d_name);
|
sprintf(path, "/sys/dev/block/%s", entry->d_name);
|
||||||
xrealpath(path, dev.devpath, sizeof(dev.devpath));
|
xrealpath(path, dev.devpath, sizeof(dev.devpath));
|
||||||
@ -74,15 +80,10 @@ static struct {
|
|||||||
static dev_t setup_block() {
|
static dev_t setup_block() {
|
||||||
const auto partition_map = load_partition_map();
|
const auto partition_map = load_partition_map();
|
||||||
if (dev_list.empty())
|
if (dev_list.empty())
|
||||||
collect_devices();
|
collect_devices(partition_map);
|
||||||
|
|
||||||
for (int tries = 0; tries < 3; ++tries) {
|
for (int tries = 0; tries < 3; ++tries) {
|
||||||
for (auto &dev : dev_list) {
|
for (auto &dev : dev_list) {
|
||||||
// use androidboot.partition_map as partname fallback.
|
|
||||||
if (dev.partname[0] == '\0') {
|
|
||||||
auto partname = get_partition_name_for_device(partition_map, dev.devname);
|
|
||||||
strcpy(dev.partname, partname.c_str());
|
|
||||||
}
|
|
||||||
if (strcasecmp(dev.partname, blk_info.partname) == 0)
|
if (strcasecmp(dev.partname, blk_info.partname) == 0)
|
||||||
LOGD("Setup %s: [%s] (%d, %d)\n", dev.partname, dev.devname, dev.major, dev.minor);
|
LOGD("Setup %s: [%s] (%d, %d)\n", dev.partname, dev.devname, dev.major, dev.minor);
|
||||||
else if (strcasecmp(dev.dmname, blk_info.partname) == 0)
|
else if (strcasecmp(dev.dmname, blk_info.partname) == 0)
|
||||||
@ -101,7 +102,7 @@ static dev_t setup_block() {
|
|||||||
// Wait 10ms and try again
|
// Wait 10ms and try again
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
dev_list.clear();
|
dev_list.clear();
|
||||||
collect_devices();
|
collect_devices(partition_map);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The requested partname does not exist
|
// The requested partname does not exist
|
||||||
|
Loading…
x
Reference in New Issue
Block a user