Skip to content

Commit

Permalink
Merge pull request #830 from cloudy064/diskname-bugfix
Browse files Browse the repository at this point in the history
fix: got nvme0n when passing device name 'nvme0n1'
  • Loading branch information
GuillaumeGomez authored Sep 2, 2022
2 parents 830b7cc + 554f714 commit 234f68d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/linux/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,21 @@ fn find_type_for_device_name(device_name: &OsStr) -> DiskType {
real_path = real_path.trim_end_matches(|c| c >= '0' && c <= '9');
} else if device_name_path.starts_with("/dev/nvme") {
// Turn "nvme0n1p1" into "nvme0n1"
real_path = real_path.trim_start_matches("/dev/");
real_path = real_path.trim_end_matches(|c| c >= '0' && c <= '9');
real_path = real_path.trim_end_matches(|c| c == 'p');
real_path = match real_path.find('p') {
Some(idx) => &real_path["/dev/".len()..idx],
None => &real_path["/dev/".len()..],
};
} else if device_name_path.starts_with("/dev/root") {
// Recursively solve, for example /dev/mmcblk0p1
if real_path != device_name_path {
return find_type_for_device_name(OsStr::new(&real_path));
}
} else if device_name_path.starts_with("/dev/mmcblk") {
// Turn "mmcblk0p1" into "mmcblk0"
real_path = real_path.trim_start_matches("/dev/");
real_path = real_path.trim_end_matches(|c| c >= '0' && c <= '9');
real_path = real_path.trim_end_matches(|c| c == 'p');
real_path = match real_path.find('p') {
Some(idx) => &real_path["/dev/".len()..idx],
None => &real_path["/dev/".len()..],
};
} else {
// Default case: remove /dev/ and expects the name presents under /sys/block/
// For example, /dev/dm-0 to dm-0
Expand Down

0 comments on commit 234f68d

Please sign in to comment.