如何在内核scsi_device结构体中区分USB和(S)ATA设备?
根据SCSI驱动程序使用的内核结构struct scsi_device
(内核2.6.23):
http://lxr.linux.no/linux+v2.6.23/include/scsi/scsi_device.h#L49
有没有可靠的方法来区分设备是 USB 设备还是ATA 设备?
According to the kernel structure struct scsi_device
used by SCSI drivers (kernel 2.6.23):
http://lxr.linux.no/linux+v2.6.23/include/scsi/scsi_device.h#L49
Is there a reliable method to differentiate if the device is an USB device or a ATA device ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于每个
scsi_device
,您可以获取与其对应的scsi_host
,并从中获取scsi_host_template
,它是 SCSI LLD 的 vtable。从那里,您可以查看名称字段。 drivers/scsi/storage/usb.c 告诉我们字符串应该是“usb-storage”。因此,我认为给定“sdev”作为 scsi_device 指针,
sdev->shost->hostt->name
应该解析为“usb-storage”,以防它是来自 USB 海量的 LUN存储设备。从设计的角度来看,以这种方式完成任务可能被认为是一种“黑客”,但如果没有适当的 API,这是最简单的方法。For each
scsi_device
, you can get thescsi_host
that corresponds to it, and from there thescsi_host_template
, which is the vtable of the SCSI LLD. From there, you can look at the name field. drivers/scsi/storage/usb.c tells us the string should be "usb-storage".So, I think given 'sdev' as scsi_device pointer,
sdev->shost->hostt->name
should resolve to "usb-storage" in case it is a LUN from a USB mass storage device. From a design perspective, it might be considered a sort of a 'hack' to a accomplish the task this way, but without proper APIs that's the simplest way to go.