问题
How can I get the vendor name of SCSI device on linux & c?
回答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);
}
回答2:
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
回答3:
(1)open SCSI device. (2)Send SCSI command "inquiry" by ioctl. then you can get vendor name from the data returned.
回答4:
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.
回答5:
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
回答6:
you can use scsi inquiry by tools like sg3_utils or just find it under sys/bus/scsi/devices/xxxxx
来源:https://stackoverflow.com/questions/4441175/get-vendor-name-of-scsi