0

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

RzCoDer
  • 145
  • 1
  • 7

6 Answers6

3

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
OneOfOne
  • 95,033
  • 20
  • 184
  • 185
3

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

Hardy Feng
  • 459
  • 4
  • 13
2

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.

arun_vj
  • 123
  • 1
  • 3
  • 13
1

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

a.saurabh
  • 1,163
  • 10
  • 15
1

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);
}
0

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

Diors
  • 1