Try to wait if block device is not ready

Close #1459
This commit is contained in:
topjohnwu 2019-05-27 15:01:49 -07:00
parent 3b0f888407
commit ae24397793

View File

@ -52,9 +52,10 @@ static void collect_devices() {
closedir(dir); closedir(dir);
} }
static bool setup_block(const char *partname, char *block_dev) { static void setup_block(const char *partname, char *block_dev) {
if (dev_list.empty()) if (dev_list.empty())
collect_devices(); collect_devices();
for (;;) {
for (auto &dev : dev_list) { for (auto &dev : dev_list) {
if (strcasecmp(dev.partname, partname) == 0) { if (strcasecmp(dev.partname, partname) == 0) {
sprintf(block_dev, "/dev/block/%s", dev.devname); sprintf(block_dev, "/dev/block/%s", dev.devname);
@ -62,10 +63,14 @@ static bool setup_block(const char *partname, char *block_dev) {
xmkdir("/dev", 0755); xmkdir("/dev", 0755);
xmkdir("/dev/block", 0755); xmkdir("/dev/block", 0755);
mknod(block_dev, S_IFBLK | 0600, makedev(dev.major, dev.minor)); mknod(block_dev, S_IFBLK | 0600, makedev(dev.major, dev.minor));
return true; return;
} }
} }
return false; // Wait 10ms and try again
usleep(10000);
dev_list.clear();
collect_devices();
}
} }
bool MagiskInit::read_dt_fstab(const char *name, char *partname, char *fstype) { bool MagiskInit::read_dt_fstab(const char *name, char *partname, char *fstype) {