Discussion:
How to associate a USB device with a /dev path?
(too old to reply)
Starman
2005-03-06 15:45:06 UTC
Permalink
Hi all,
I've been trying to marry these two pieces of code I have with no
luck. First piece of code gets a list of all USB devices that have a
specific vendor and product. That works fine. The other piece of code
walks the list of mounted devices and gives me the name of the /dev
path they're on. The problem is that I can't seem to figure out how to
ask what /dev path the specific device is mounted on.

eg: FUJIFilm USB device is on /dev/disk2s2.

I can get a service ID for the USB device, and I can get a service ID
for the mount point, but the two service IDs don't seem to play well
together since they're different types.

Using ioreg from the command line, I see the devices, but that doesn't
even tell me what the mount points are.

Using IORegistryExplorer also tells me lots of information about the
device, but no mount points.

However, using System Profile, I DO get the information I need.

FUJIFilm
...
BSD Name: disk2

So there HAS to be a way to do it, I just don't see how. Also, the
"disk2" that System Profiler gives me doesn't match with the "disk2s2"
that I get from the other code I have.

Any help? Thanks.

Mike
David Phillip Oster
2005-03-06 16:22:56 UTC
Permalink
Post by Starman
I've been trying to marry these two pieces of code I have with no
luck. First piece of code gets a list of all USB devices that have a
specific vendor and product. That works fine. The other piece of code
walks the list of mounted devices and gives me the name of the /dev
path they're on. The problem is that I can't seem to figure out how to
ask what /dev path the specific device is mounted on.
Any help? Thanks.
Documented in:
http://developer.apple.com/documentation/DeviceDrivers/Conceptual/AccessingHardware/index.html?http://developer.apple.com/documentation/DeviceDrivers/Conceptual/AccessingHardware/AH_Device_Access_IOKit/chapter_3_section_2.html
--
David Phillip Oster
Starman
2005-03-06 19:08:48 UTC
Permalink
I read all that but there's still something I'm doing wrong.

Taking the "USB Example" code from Xcode 1.5, I added this when I find
a device:

deviceNameAsCFString = IORegistryEntryCreateCFProperty (
usbDeviceRef,
CFSTR(kIOBSDNameKey),
kCFAllocatorDefault,0);

The problem is that deviceNameAsCFString comes back NULL. Now, when I
use that same code in the VolumeToBSDNode.c sample, it works.

So I'm wondering if there's a step I'm missing. I got the device's
information. In fact, I added this code also and it all works:

IORegistryEntryGetName(usbDeviceRef, devName);
printf("Device's name = %s\n", devName);
IORegistryEntryGetPath(usbDeviceRef, kIOServicePlane, pathName);
printf("Device's path in IOService plane = %s\n", pathName);
IORegistryEntryGetPath(usbDeviceRef, kIOUSBPlane, pathName);
printf("Device's path in IOUSB plane = %s\n", pathName);

So I get all this technical info, but when it comes to getting the BSD
name, it returns a NULL string.

Mike
David Phillip Oster
2005-03-07 00:44:05 UTC
Permalink
Post by Starman
I read all that but there's still something I'm doing wrong.
Taking the "USB Example" code from Xcode 1.5, I added this when I find
deviceNameAsCFString = IORegistryEntryCreateCFProperty (
usbDeviceRef,
CFSTR(kIOBSDNameKey),
kCFAllocatorDefault,0);
The problem is that deviceNameAsCFString comes back NULL. Now, when I
use that same code in the VolumeToBSDNode.c sample, it works.
I've only actually done this for serial ports on USB adapters, and for
them, the unix name is retrieved using kIOTTYDeviceKey.
--
David Phillip Oster
Loading...