/ Published in: Objective C
This is a bit of a hack, but it works. If someone knows of a better way, please let me know!
Expand |
Embed | Plain Text
{ OSStatus err; FSRef ref; FSVolumeRefNum actualVolume; err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL ); // get a FSVolumeRefNum from mountPath if ( noErr == err ) { FSCatalogInfo catalogInfo; err = FSGetCatalogInfo ( &ref, kFSCatInfoVolume, &catalogInfo, NULL, NULL, NULL ); if ( noErr == err ) { actualVolume = catalogInfo.volume; } } // now let's get the device name GetVolParmsInfoBuffer volumeParms; HParamBlockRec pb; // Use the volume reference number to retrieve the volume parameters. See the documentation // on PBHGetVolParmsSync for other possible ways to specify a volume. pb.ioParam.ioNamePtr = NULL; pb.ioParam.ioVRefNum = actualVolume; pb.ioParam.ioBuffer = (Ptr) &volumeParms; // A version 4 GetVolParmsInfoBuffer contains the BSD node name in the vMDeviceID field. // It is actually a char * value. This is mentioned in the header CoreServices/CarbonCore/Files.h. err = PBHGetVolParmsSync(&pb); // after this we traverse the IORegistry to try to find the device that has the same BDS name CFDictionaryRef matchingDict = NULL; io_iterator_t devIter = nil; io_service_t ioDeviceObj = nil; IOReturn kr; CFTypeRef data; matchingDict = IOServiceMatching(kIOUSBDeviceClassName); if (matchingDict == NULL) { NSLog(@"BusProber: error in -refresh at IOServiceMatching() - dictionary was NULL"); return nil; } kr = IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, &devIter); if (kr != kIOReturnSuccess) { NSLog(@"BusProber: error in -refresh at IOServiceGetMatchingServices()"); return nil; } while (ioDeviceObj = IOIteratorNext(devIter)) { data = IORegistryEntrySearchCFProperty(ioDeviceObj, kIOServicePlane, CFSTR("BSD Name"), kCFAllocatorDefault, kIORegistryIterateRecursively); io_name_t devName; IORegistryEntryGetName(ioDeviceObj, devName); IOObjectRelease(ioDeviceObj); break; } IOObjectRelease(ioDeviceObj); } return deviceName; }
You need to login to post a comment.
