当前位置: 技术问答>linux和unix
通过设备名,获取接口类型 SATA,USB, ESATA接口
来源: 互联网 发布时间:2017-04-23
本文导语: 有没有函数接口获取,存储设备的接口类型 例如: /dev/sda /dev/sdb 设备名的 接口类型有可能是USB,SATA的. 怎样通过一个函数获取 | 命令行下可以通过 readline /sys/block/sda等判断类型,所以内核态...
有没有函数接口获取,存储设备的接口类型
例如:
/dev/sda
/dev/sdb
设备名的
接口类型有可能是USB,SATA的.
怎样通过一个函数获取
例如:
/dev/sda
/dev/sdb
设备名的
接口类型有可能是USB,SATA的.
怎样通过一个函数获取
|
命令行下可以通过 readline /sys/block/sda等判断类型,所以内核态应该是有数据结构保存了这个信息的。
具体的函数需要看/sys文件系统中block设备驱动注册的回调函数
具体的函数需要看/sys文件系统中block设备驱动注册的回调函数
total 0
lrwxrwxrwx 1 root root 0 Sep 3 23:59 dm-0 -> ../devices/virtual/block/dm-0
lrwxrwxrwx 1 root root 0 Sep 3 23:59 dm-1 -> ../devices/virtual/block/dm-1
lrwxrwxrwx 1 root root 0 Sep 3 23:59 dm-2 -> ../devices/virtual/block/dm-2
lrwxrwxrwx 1 root root 0 Sep 4 00:02 fd0 -> ../devices/platform/floppy.0/block/fd0
lrwxrwxrwx 1 root root 0 Sep 4 00:02 loop0 -> ../devices/virtual/block/loop0
lrwxrwxrwx 1 root root 0 Sep 4 00:02 loop1 -> ../devices/virtual/block/loop1
lrwxrwxrwx 1 root root 0 Sep 4 00:02 loop2 -> ../devices/virtual/block/loop2
lrwxrwxrwx 1 root root 0 Sep 4 00:02 loop3 -> ../devices/virtual/block/loop3
lrwxrwxrwx 1 root root 0 Sep 4 00:02 loop4 -> ../devices/virtual/block/loop4
lrwxrwxrwx 1 root root 0 Sep 4 00:02 loop5 -> ../devices/virtual/block/loop5
lrwxrwxrwx 1 root root 0 Sep 4 00:02 loop6 -> ../devices/virtual/block/loop6
lrwxrwxrwx 1 root root 0 Sep 4 00:02 loop7 -> ../devices/virtual/block/loop7
lrwxrwxrwx 1 root root 0 Sep 4 00:02 ram0 -> ../devices/virtual/block/ram0
lrwxrwxrwx 1 root root 0 Sep 4 00:02 ram1 -> ../devices/virtual/block/ram1
lrwxrwxrwx 1 root root 0 Sep 4 00:02 ram10 -> ../devices/virtual/block/ram10
lrwxrwxrwx 1 root root 0 Sep 4 00:02 ram11 -> ../devices/virtual/block/ram11
lrwxrwxrwx 1 root root 0 Sep 4 00:02 ram12 -> ../devices/virtual/block/ram12
lrwxrwxrwx 1 root root 0 Sep 4 00:02 ram13 -> ../devices/virtual/block/ram13
lrwxrwxrwx 1 root root 0 Sep 4 00:02 ram14 -> ../devices/virtual/block/ram14
lrwxrwxrwx 1 root root 0 Sep 4 00:02 ram15 -> ../devices/virtual/block/ram15
lrwxrwxrwx 1 root root 0 Sep 4 00:02 ram2 -> ../devices/virtual/block/ram2
lrwxrwxrwx 1 root root 0 Sep 4 00:02 ram3 -> ../devices/virtual/block/ram3
lrwxrwxrwx 1 root root 0 Sep 4 00:02 ram4 -> ../devices/virtual/block/ram4
lrwxrwxrwx 1 root root 0 Sep 4 00:02 ram5 -> ../devices/virtual/block/ram5
lrwxrwxrwx 1 root root 0 Sep 4 00:02 ram6 -> ../devices/virtual/block/ram6
lrwxrwxrwx 1 root root 0 Sep 4 00:02 ram7 -> ../devices/virtual/block/ram7
lrwxrwxrwx 1 root root 0 Sep 4 00:02 ram8 -> ../devices/virtual/block/ram8
lrwxrwxrwx 1 root root 0 Sep 4 00:02 ram9 -> ../devices/virtual/block/ram9
lrwxrwxrwx 1 root root 0 Sep 3 23:59 sda -> ../devices/pci0000:00/0000:00:10.0/host2/target2:0:0/2:0:0:0/block/sda
lrwxrwxrwx 1 root root 0 Sep 4 00:01 sdb -> ../devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-1/1-1:1.0/host3/target3:0:0/3:0:0:0/block/sdb
lrwxrwxrwx 1 root root 0 Sep 4 00:02 sr0 -> ../devices/pci0000:00/0000:00:07.1/ata2/host1/target1:0:0/1:0:0:0/block/sr0
|
可以查查看类似hdparm等与硬盘信息相关的命令,有没有对应参数;然后用popen函数读出结果。
不过好像Linux对于SATA和USB是识别成同一接口类型的,SCSI好像是。
不过好像Linux对于SATA和USB是识别成同一接口类型的,SCSI好像是。
|
可以查查看类似hdparm等与硬盘信息相关的命令,有没有对应参数;然后用popen函数读出结果。
不过好像Linux对于SATA和USB是识别成同一接口类型的,SCSI好像是。
不过好像Linux对于SATA和USB是识别成同一接口类型的,SCSI好像是。