Reputation: 145
How can I get the vendor name of SCSI device on linux & c?
Upvotes: 0
Views: 2789
Reputation: 1
you can use scsi inquiry by tools like sg3_utils or just find it under sys/bus/scsi/devices/xxxxx
Upvotes: 0
Reputation: 1231
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
Upvotes: 1
Reputation: 123
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.
Upvotes: 2
Reputation: 479
(1)open SCSI device. (2)Send SCSI command "inquiry" by ioctl. then you can get vendor name from the data returned.
Upvotes: 3
Reputation:
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);
}
Upvotes: 2