Hi everybody, I have to find the device file name of USB devices attached, I try different things that i find on the web but I'm not able to obtain it.
Here is my code:
int main (void){
io_iterator_t mediaIterator; /
kern_return_t kernResult;
mach_port_t masterPort;
CFMutableDictionaryRef classesToMatch;
kernResult = IOMasterPort (MACH_PORT_NULL , &masterPort);
if ( kernResult != KERN_SUCCESS ){
printf( "IOMasterPort returned %d\n", kernResult );
return kernResult;
}
/
classesToMatch = IOServiceMatching( kIOUSBDeviceClassName );
if ( !classesToMatch ){
/
printf("could not create dictionary\n");
return -1;
}
io_service_t usbDevice;
kernResult = IOServiceGetMatchingServices(masterPort,classesToMatch,&mediaIterator); /
while ( (usbDevice = IOIteratorNext( mediaIterator )) ){
/
/
/
/
/
if ( !IOObjectConformsTo( usbDevice, "IOUSBDevice" )) continue;
io_name_t deviceName;
IORegistryEntryGetName( usbDevice, deviceName ); /
printf("Device name is : %s\n",(char *)deviceName);
CFTypeRef deviceFilePathAsCFString;
CFIndex maxPathSize = 255;
char deviceFilePath[256];
* deviceFilePath = '\0';
/
kernResult = IORegistryEntryGetPath(usbDevice,kIOUSBPlane,deviceFilePath);
printf("\nprova 1 -> name %s\n",deviceFilePath);
/
deviceFilePathAsCFString = ( CFStringRef ) IORegistryEntryCreateCFProperty( usbDevice, CFSTR( kIOBSDNameKey ),kCFAllocatorDefault, 0 );
printf("prova3 -> path : %s\n",(char *)deviceFilePathAsCFString);
/
deviceFilePathAsCFString = ( CFStringRef ) IORegistryEntrySearchCFProperty (usbDevice,kIOServicePlane,CFSTR (kIOBSDNameKey ),kCFAllocatorDefault,kIORegistryIterateRecursively );
printf("prova2 -> path : %s\n",(char *)deviceFilePathAsCFString);
//other code here
I don't know if i forgot something or wathever, any help will be really appreciated.