- (BOOL) ownsMediaService: (io_service_t) inMediaService
{
// Retain inMediaService, to balance the release we'll generate
// as we step up the registry.
IOObjectRetain(inMediaService);
// scan up the registry to see if we own the specified media service.
io_service_t theService = inMediaService;
while (theService != IO_OBJECT_NULL)
{
NSLog(@" ownsMediaService: lX lX\n", theService, service);
if (IOObjectIsEqualTo(theService, service))
{
IOObjectRelease(theService);
return YES;
}
io_service_t theParentService = IO_OBJECT_NULL;
kern_return_t theKernelResult;
theKernelResult = IORegistryEntryGetParentEntry(theService,
kIOServicePlane,
&theParentService);
IOObjectRelease(theService);
theService = theParentService;
NSLog(@" theParentService: lX\n", theParentService);
NSLog(@" theKernelResult: lX - lX lX lX\n",
theKernelResult,
err_get_system(theKernelResult),
err_get_sub(theKernelResult),
err_get_code(theKernelResult));
if (theKernelResult != KERN_SUCCESS)
{
if (theService != IO_OBJECT_NULL)
IOObjectRelease(theService);
return NO;
}
}
return NO;
}
I have a function , ownsMediaService which is supposed to return true, if a particular io_service_t is a child of my device. It does this by iterating up the parent chain of the input service, checking to see if it finds the device's service object.
Normally, when I run this function, it works as expected, but when I call it from inside my doDiskPeeked callback function, IORegistryEntryGetParentEntry returns an error code of 0x10000003.
Hunting around, I found:
#define MACH_SEND_INVALID_DEST 0x10000003 /* Bogus destination port. */
So, apparently I can't use IORegistryEntryGetParentEntry to determine ownership of the ioMedia object, at least not while my doDiskPeeked callback is being called.
The device I'm working with is a USB Thumbdrive that supports a password protected area which is accessible only through login commands. Basically, the operating system is presented with either the public area of the drive, or the private area.
The function I'm working on is the ability to change the relative sizes of the public area and the private area of the device.
First, I use diskutil to (logically, but not physically) eject the media.
Then I issue a series of commands to the device to set it's new partition sizes, and to tell the device to act as if the media was reinserted. This results (eventually) in the private area of the device becoming ready, and my diskPeeked function being called.
At this point, I want to ensure that the IOMedia object that just appeared is indeed the one which is associated with the Thumbdrive that I'm working on. I certainly don't want to accidently erase the wrong drive.
So, how do I determine if the DADiskRef object that was handed to my diskPeeked function is the one that I'm actually interested in?
Thanks again for your time,
Ron Aldrich
Software Architects, Inc.