开发者

How to distinguish USB and (S)ATA device in the kernel scsi_device structure?

开发者 https://www.devze.com 2023-04-12 20:27 出处:网络
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

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 devi开发者_运维知识库ce or a ATA device ?


For each scsi_device, you can get the scsi_host that corresponds to it, and from there the scsi_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.

0

精彩评论

暂无评论...
验证码 换一张
取 消