• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
IOKit: getting optical drive type
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Prev by Date: Re: [newbie] NSString code so it won't leak
  • Next by Date: Re: [newbie] NSString code so it won't leak
  • Previous by thread: Re: Ignoring external monitors
  • Next by thread: Newbie question
  • Index(es):
    • Date
    • Thread