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

disk.kind() reports USB flash drive as DiskKind::HDD #1197

Open
vExcess opened this issue Jan 4, 2024 · 2 comments
Open

disk.kind() reports USB flash drive as DiskKind::HDD #1197

vExcess opened this issue Jan 4, 2024 · 2 comments

Comments

@vExcess
Copy link

vExcess commented Jan 4, 2024

Describe the bug
I'm using Linux Mint and sysinfo v0.30.3. disk.kind() is reporting my USB flash drive as a HDD. I'd think it would report as DiskKind::SSD or DiskKind::Unknown because flash drives are more similiar to SSDs than they are to HDDs. Is this a bug or intentional?

To Reproduce

use sysinfo::{
    Disks, DiskKind
};

fn main() {
    let disks = Disks::new_with_refreshed_list();
    for disk in disks.list() {
        let kind = match disk.kind() {
            DiskKind::HDD => format!("{}", "HDD"),
            DiskKind::SSD => format!("{}", "SSD"),
            _ => format!("{}", "Unknown")
        };
        let name = match disk.name().to_str() {
            Some(res) => format!("{}", res),
            None => format!("{}", ""),
        };
        let file_system = match disk.file_system().to_str() {
            Some(res) => format!("{}", res),
            None => format!("{}", ""),
        };
        let total_space = format!("{}", disk.total_space());
        let available_space = format!("{}", disk.available_space());
        let mount_point = match disk.mount_point().to_str() {
            Some(path_str) => format!("{}", path_str),
            None => format!("{}", "ERR")
        };
        println!("{} {} {} {} {} {}", kind, name, file_system, total_space, available_space, mount_point);
    }
}

Output:

SSD /dev/sda3 ext4 982818799616 903877967872 /
SSD /dev/sda2 vfat 536834048 530464768 /boot/efi
HDD /dev/sdb1 exfat 62019076096 54214262784 /media/server/VINCENT USB
@GuillaumeGomez
Copy link
Owner

Would be nice to be able to recognize a flash drive indeed. I won't have much time in the coming weeks so don't hesitate to take a look!

@CarterLi
Copy link

CarterLi commented Jan 8, 2024

That's because /sys/block/sdb/queue/rotational is 0

See https://unix.stackexchange.com/questions/439109/set-usb-flash-drive-as-non-rotational-drive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants