Skip to content

Commit ed42e3d

Browse files
arter97ersascape
authored andcommitted
init: mount_handler: detect main block device more reliably
Current code is not portable beyond SCSI devices (e.g., UFS). For example, eMMC and NVMe devices fail due to their extra postfix. Change its logic to rewind each character until "queue" directory appears. Test: Confirm md0p1, sda20, nvme0n1p3, mmcblk0p3 are all handled well. Change-Id: I585ccf2d4a72f6ef8ecb203acdd72a1e32d3e749 Signed-off-by: Juhyung Park <qkrwngud825@gmail.com>
1 parent 4ad89b8 commit ed42e3d

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

init/mount_handler.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,33 @@ void SetMountProperty(const MountHandlerEntry& entry, bool add) {
7373
std::string value;
7474
if (add) {
7575
value = entry.blk_device.substr(strlen(devblock));
76-
if (android::base::StartsWith(value, "sd")) {
77-
// All sd partitions inherit their queue characteristics
78-
// from the whole device reference. Strip partition number.
79-
auto it = std::find_if(value.begin(), value.end(), [](char c) { return isdigit(c); });
80-
if (it != value.end()) value.erase(it, value.end());
81-
}
82-
auto queue = "/sys/block/" + value + "/queue";
76+
8377
struct stat sb;
84-
if (stat(queue.c_str(), &sb) || !S_ISDIR(sb.st_mode)) value = "";
8578
if (stat(entry.mount_point.c_str(), &sb) || !S_ISDIR(sb.st_mode)) value = "";
8679
// Clear the noise associated with loopback and APEX.
8780
if (android::base::StartsWith(value, "loop")) value = "";
8881
if (android::base::StartsWith(entry.mount_point, "/apex/")) value = "";
82+
83+
if (!value.empty()) {
84+
auto value_tmp = value;
85+
std::string queue;
86+
while (true) {
87+
// Partitioned device don't have its own queue settings.
88+
// Rewind each character until the main device appears.
89+
queue = "/sys/block/" + value + "/queue";
90+
91+
if (!stat(queue.c_str(), &sb) && S_ISDIR(sb.st_mode)) {
92+
// Found device sysfs name
93+
break;
94+
}
95+
96+
value.pop_back();
97+
if (value.empty()) {
98+
LOG(ERROR) << "Failed to find block path for " << value_tmp;
99+
break;
100+
}
101+
}
102+
}
89103
}
90104
auto mount_prop = entry.mount_point;
91105
if (mount_prop == "/") mount_prop = "/root";

0 commit comments

Comments
 (0)