IOKit: getting optical drive type
IOKit: getting optical drive type
- Subject: IOKit: getting optical drive type
- From: Jonathan Guy <email@hidden>
- Date: Wed, 11 Sep 2002 11:23:42 +0100
Hi,
I need to know how the Apple System Profiler obtains the optical drive
type.
It tells me mine is of type "CD-ROM/DVD-ROM" which of course is correct.
I know I can use the IOKit to obtain device information and I can use
the following code to get the "Product Name".
NSString* getOpticalDrive()
{
kern_return_t kernResult;
mach_port_t machPort;
io_iterator_t iterator;
io_object_t serviceObj;
CFMutableDictionaryRef classesToMatch;
NSDictionary* characteristics;
NSString* type = @"Unknown";
kernResult = IOMasterPort( MACH_PORT_NULL, &machPort );
if ( kernResult == KERN_SUCCESS ) {
classesToMatch = IOServiceMatching(
"IODVDBlockStorageDevice" ); //or IOCDBlockStorageDevice
if ( classesToMatch ) {
kernResult = IOServiceGetMatchingServices( machPort,
classesToMatch, &iterator );
if ( kernResult == KERN_SUCCESS ) {
serviceObj = IOIteratorNext( iterator );
if ( serviceObj ) {
characteristics = (NSDictionary
*)IORegistryEntryCreateCFProperty( serviceObj, CFSTR( "Device
Characteristics" ), kCFAllocatorDefault, 0 );
[type release];
type = [characteristics objectForKey:@"Product
Name"];
}
IOObjectRelease(serviceObj);
}
IOObjectRelease(iterator);
}
}
mach_port_deallocate(mach_task_self(), machPort);
return type;
}
This returns "DVD-ROM SR-8186" so how does the system profiler get
"CD-ROM/DVD-ROM"? I'm assuming they have some kind of device name
lookup table.
Any help appreciated.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.