I'm enumerating scsi_generic devices with udev to retrieve the /dev/sg*
filename so I can send an Inquiry to each device.
Can I also get the /dev/sd*
filename (the scsi_device) while I'm right there?
If not, how do I get the scsi_device given a scsi_generic path?
This is my udev code:
IntPtr udev = IntPtr.Zero;
IntPtr enumerate = IntPtr.Zero;
try
{
udev = Libudev.udev_new();
if (udev == IntPtr.Zero)
throw new UdevException("Failed to create udev");
enumerate = Libudev.udev_enumerate_new(udev);
if (enumerate == IntPtr.Zero)
throw new UdevException("Failed to enumerate udev");
Libudev.udev_enumerate_add_match_subsystem(enumerate, "scsi_generic");
Libudev.udev_enumerate_scan_devices(enumerate);
for (IntPtr listEntry = Libudev.udev_enumerate_get_list_entry(enumerate);
listEntry != IntPtr.Zero;
listEntry = Libudev.udev_list_entry_get_next(listEntry))
{
// Get the filename of the /sys entry for the device
string deviceSysPath = Libudev.udev_list_entry_get_name(listEntry);
IntPtr device = Libudev.udev_device_new_from_syspath(udev, deviceSysPath);
if (device == IntPtr.Zero)
continue;
// Get the /dev path of the device (/dev/sg*)
string deviceDevPath = Libudev.udev_device_get_devnode(device);
// Send Inquiry
// <snip>
Libudev.udev_device_unref(device);
}
}
catch (DllNotFoundException ex)
{
throw new DllNotFoundException("libudev is either not installed, or ldconfig has mapped it in an unexpected way. See source README file for information.", ex);
}
finally
{
if (enumerate != IntPtr.Zero)
Libudev.udev_enumerate_unref(enumerate);
if (udev != IntPtr.Zero)
Libudev.udev_unref(udev);
}