Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Need to identify a physical USB hub port



Title: RE: Need to identify a physical USB hub port
A while back you answered my question about obtaining the locationID of a USB device(reader) into which a flash media is plugged. I just tried your suggestion with the following code:

SInt32    getLocationID(FSVolumeRefNum myFSVolumeRefNum) {
   SInt32  readerNumber;
   char* BSDNodeName;
   io_service_t   theWholeMedia;
   CFStringRef  locationIDCFString;
  
   BSDNodeName = getBSDNodeName(myFSVolumeRefNum);
   theWholeMedia = getWholeMedia(BSDNodeName);
   locationIDCFString = IORegistryEntrySearchCFProperty (theWholeMedia,
                                                         kIOServicePlane,
                                                         CFSTR(kUSBDevicePropertyLocationID),
                                                         kCFAllocatorDefault,
                                                         kIORegistryIterateParents);
   readerNumber = CFStringGetIntValue(locationIDCFString);
   return(readerNumber);
   }

The BSDNodeName is properly returned. getWholeMedia(...) is derived from the sample code at:
<http://developer.apple.com/samplecode/VolumeToBSDNode/VolumeToBSDNode.html>. After I iterate up to theWholeMedia and use that value in IORegistryEntrySearchCFProperty, that function returns 0 for assignment into locationIDCFString. I believe that that's wrong because the following function crashes the app as expected. Do you see anything wrong with my code? If not, I'll detail the function getWholeMedia.

Thank you.



At 9:25 AM -0500 5/26/05, Chris Reed wrote:
It's pretty easy, actually. Find the IOMedia object for the mounted volume, then walk up that object's parents until you hit an IOUSBDevice, which will have the locationID property. Or you can use IORegistryEntrySearchCFProperty() to do it in one call.
 
There are several ways to find the IOMedia object for the volume. Perhaps the easiest is to install a notification handler to watch for new IOMedia objects.
 
Another way would be to use the statfs() call to get the device path. It will be something like "/dev/disk0s4". Strip the "/dev/", and search for an IOMedia with a "BSD Name" property with that value.
 
There's other ways as well, but that should give you the basic idea.
 
Cheers
-chris
 


-- 



-----

B. Mitchell Loebel                                    408 425-9920 cell
       
Executive Director
The Tech Startup Connection
(formerly The PARALLEL Processing Connection)  
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Usb mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/usb/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.