Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: got nvme0n when passing device name 'nvme0n1' #830

Merged
merged 1 commit into from
Sep 2, 2022

Conversation

cloudy064
Copy link

No description provided.

@GuillaumeGomez
Copy link
Owner

GuillaumeGomez commented Sep 1, 2022

Thanks for the patch! Can you describe a bit more what's the problem and how it's solved please?

@cloudy064
Copy link
Author

Sorry for least description first.
Problem is that I get the wrong disk type of value None for device /dev/nvme0n1, which should be SSD.
When I inspected the code, I found it evals the value of /sys/block/nvme0n/queue/rational, but the file didn't exist.
86b9bdac4bb88e1e59e462a2ec32c98

Providing device_name is /dev/nvme0n1:

fn find_type_for_device_name(device_name: &OsStr) -> DiskType {
// lots of code
    } else if device_name_path.starts_with("/dev/nvme") {
        // Turn "nvme0n1p1" into "nvme0n1"
        real_path = real_path.trim_start_matches("/dev/");                                          // real_path is *nvme0n1* here
        real_path = real_path.trim_end_matches(|c| c >= '0' && c <= '9');                  // real_path is *nvme0n* here
        real_path = real_path.trim_end_matches(|c| c == 'p');                                      // real_path is *nvme0n* here
    } 
// lots of code
}

The last number 1 is missing because of real_path.trim_end_matches(|c| c >= '0' && c <= '9');
8832a1870904524b0373198ca74d92a

I made some changes here as following:

fn find_type_for_device_name(device_name: &OsStr) -> DiskType {
// lots of code
        real_path = match real_path.find('p') {
            Some(idx) => &real_path["/dev/".len()..idx],
            None => &real_path["/dev/".len()..],
        };
// lots of code
}

And I got the right real_path /sys/block/nvme0n1 and right disk type SSD
cc1f3e30c7d1f171d0d858f143b7d36

All the same for device name of /dev/mmcblk0.

@cloudy064
Copy link
Author

Before:
869ad29fa05bf994740351bb066ee09

After:
101eb5a93b513990483b0e086951435

@GuillaumeGomez
Copy link
Owner

Thanks for the explanations! Merging it then.

@GuillaumeGomez GuillaumeGomez merged commit 234f68d into GuillaumeGomez:master Sep 2, 2022
@cloudy064 cloudy064 deleted the diskname-bugfix branch July 4, 2023 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants