Get vendor name of SCSI

2019-09-17 09:46发布

How can I get the vendor name of SCSI device on linux & c?

标签: c linux scsi
6条回答
forever°为你锁心
2楼-- · 2019-09-17 10:01

Referring to the SCSI SPC-3 document & sg3_utils commands I can suggest you following:

1) Issue command: sg_inq -p 0x00 /dev/your_device_name

This will give you supported pages by your device.

2) If above command displays 0x83 as one of the supported page then issue command:

sudo sg_inq -p 0x83 /dev/your_device_name

This will display vendor information.

P.S -> your_device_name e.g. sr1, sda1

Please use this link to get script for getting these type of information:

http://a-saurabh.blogspot.in/2014/06/sometimes-we-want-to-query-about-our.html

查看更多
一纸荒年 Trace。
3楼-- · 2019-09-17 10:05

(1)open SCSI device. (2)Send SCSI command "inquiry" by ioctl. then you can get vendor name from the data returned.

查看更多
Lonely孤独者°
4楼-- · 2019-09-17 10:10

you can use scsi inquiry by tools like sg3_utils or just find it under sys/bus/scsi/devices/xxxxx

查看更多
Deceive 欺骗
5楼-- · 2019-09-17 10:12

You can use libudev to find SCSI devices and read the vendor attribute (untested):

struct udev *context = udev_new();
struct udev_enumerate *enumerator = udev_enumerate_new(context);
udev_enumerate_add_match_subsystem(enumerator, "scsi");
udev_enumerate_scan_devices(enumerator);
struct udev_list_entry *scsi_devices = udev_enumerate_get_list_entry(enumerator);
struct udev_list_entry *current = 0;
udev_list_entry_foreach(current, scsi_devices) {
    struct udev_device *device = udev_device_new_from_syspath(
            context, udev_list_entry_get_name(current));
    const char *vendor = udev_device_get_sysattr_value(device, "vendor");
    printf("%s\n", vendor);
}
查看更多
【Aperson】
6楼-- · 2019-09-17 10:17

You could look into reading /sys files if you know the device/bus id, also check lsscsi.

  -> cat /sys/bus/scsi/devices/target13:0:0/13:0:0:0/vendor 
Marvell
查看更多
家丑人穷心不美
7楼-- · 2019-09-17 10:18

The sg3_utils package contains utilities that send SCSI commands to devices.

Once we have sg3_utils installed, run sg_inq command on the device you are interested in.

For example: #sg_inq /dev/sda

The above command will run standard SCSI inquiry on the device and provide the Vendor name and other details.

查看更多
登录 后发表回答