Search code examples
clinuxscsi

Get vendor name of SCSI


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


Solution

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