简体   繁体   English

如何区分USB硬盘驱动器和USB闪存驱动器?

[英]How to distinguish between USB Hard Disk Drive and USB flash drive?

In Windows, you can get GetDriveType return value to determine USB Hard Disk Drive or USB flash drive. 在Windows中,您可以获得GetDriveType返回值来确定USB硬盘驱动器或USB闪存驱动器。

DRIVE_REMOVABLE ==> USB flash drive DRIVE_REMOVABLE ==> USB闪存盘

DRIVE_FIXED ==> USB Hard Disk Drive DRIVE_FIXED ==> USB硬盘驱动器

How should I do it in linux? 我应该如何在linux中做到这一点?

how should I do it from a developer's point of view ? 从开发人员的角度来看,我应该怎么做?

You need to install lshw command using apt-get or yum command. 您需要使用apt-get或yum命令安装lshw命令。 To display all disks and storage controllers in the system, enter: 要显示系统中的所有磁盘和存储控制器,请输入:

# lshw -class disk -class storage

later you can also try the following, it will give complete details for particular... 稍后您也可以尝试以下操作,它将提供特定的完整详细信息...

# hdparm -I /dev/sda

OR 要么

$ sudo hdparm -I /dev/sda

Well, there is a "removable" flag implemented as a file underneath `/sys but.... 好吧,在“ / sys”下面有一个“可移动”标志实现为文件,但是....

For example, on my system, this file underneath /sys represents disk /dev/sde implemented by an attached USB hard disk (the USB device found on "bus 1 -> port 2 -> config 1 -> interface 0") 例如,在我的系统上, /sys下的该文件表示通过附加的USB硬盘(在“总线1->端口2->配置1->接口0”上找到的USB设备)实现的磁盘/dev/sde

/sys/devices/pci0000:00/0000:00:02.1/usb1/1-2/1-2:1.0/host9/target9:0:0/9:0:0:0/block/sde

The subpath 子路径

/sys/devices/pci0000:00/0000:00:02.1/usb1/1-2

which is the USB device found on "bus 1 -> port 2" seems to represent the USB device itself. 在“总线1->端口2”上找到的USB设备似乎代表USB设备本身。

Let's look for the "removable" files using find and print their contents using cat : 让我们使用find “可移动”文件,并使用cat打印它们的内容:

$ cd /sys/devices/pci0000:00/0000:00:02.1/usb1/1-2

$ find . -name removable -exec echo -n '{}: ' ";" -exec cat '{}' ";"

./1-2:1.0/host9/target9:0:0/9:0:0:0/block/sde/removable: 0
./removable: unknown

So, the "device" is not known to be removable, and the "disk" is not removable (assuming '0' means 'no'). 因此,“设备”不可移动,而“磁盘”不可移动(假设“ 0”表示“否”)。 Not very helpful. 不是很有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM