2 * Copyright (c) 1998-2008 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #include <IOKit/IOBSD.h>
29 #include <IOKit/IOLib.h>
30 #include <IOKit/IOService.h>
31 #include <IOKit/IOCatalogue.h>
32 #include <IOKit/IODeviceTreeSupport.h>
33 #include <IOKit/IOKitKeys.h>
34 #include <IOKit/IOPlatformExpert.h>
38 #include <pexpert/pexpert.h>
39 #include <kern/clock.h>
40 #include <uuid/uuid.h>
42 // how long to wait for matching root device, secs
44 #define ROOTDEVICETIMEOUT 120
46 #define ROOTDEVICETIMEOUT 60
49 extern dev_t
mdevadd(int devid
, uint64_t base
, unsigned int size
, int phys
);
50 extern dev_t
mdevlookup(int devid
);
51 extern void mdevremoveall(void);
52 extern void di_root_ramfile(IORegistryEntry
* entry
);
57 IOService::publishResource("IOBSD");
59 return( kIOReturnSuccess
);
63 IOServicePublishResource( const char * property
, boolean_t value
)
66 IOService::publishResource( property
, kOSBooleanTrue
);
68 IOService::getResourceService()->removeProperty( property
);
72 IOServiceWaitForMatchingResource( const char * property
, uint64_t timeout
)
74 OSDictionary
* dict
= 0;
75 IOService
* match
= 0;
76 boolean_t found
= false;
80 dict
= IOService::resourceMatching( property
);
83 match
= IOService::waitForMatchingService( dict
, timeout
);
98 IOCatalogueMatchingDriversPresent( const char * property
)
100 OSDictionary
* dict
= 0;
101 OSOrderedSet
* set
= 0;
102 SInt32 generationCount
= 0;
103 boolean_t found
= false;
107 dict
= OSDictionary::withCapacity(1);
110 dict
->setObject( property
, kOSBooleanTrue
);
111 set
= gIOCatalogue
->findDrivers( dict
, &generationCount
);
112 if ( set
&& (set
->getCount() > 0))
125 OSDictionary
* IOBSDNameMatching( const char * name
)
128 const OSSymbol
* str
= 0;
132 dict
= IOService::serviceMatching( gIOServiceKey
);
135 str
= OSSymbol::withCString( name
);
138 dict
->setObject( kIOBSDNameKey
, (OSObject
*) str
);
153 OSDictionary
* IOUUIDMatching( void )
155 return IOService::resourceMatching( "boot-uuid-media" );
159 OSDictionary
* IOCDMatching( void )
162 const OSSymbol
* str
;
164 dict
= IOService::serviceMatching( "IOMedia" );
166 IOLog("Unable to find IOMedia\n");
170 str
= OSSymbol::withCString( "CD_ROM_Mode_1" );
176 dict
->setObject( "Content Hint", (OSObject
*)str
);
181 OSDictionary
* IONetworkMatching( const char * path
,
182 char * buf
, int maxLen
)
184 OSDictionary
* matching
= 0;
193 len
= strlen( kIODeviceTreePlane
":" );
198 strlcpy( buf
, kIODeviceTreePlane
":", len
+ 1 );
201 // remove parameters following ':' from the path
202 skip
= strchr( path
, ':');
210 strlcpy( comp
, path
, len
+ 1 );
212 matching
= IOService::serviceMatching( "IONetworkInterface" );
215 dict
= IOService::addLocation( matching
);
219 str
= OSString::withCString( buf
);
222 dict
->setObject( kIOPathMatchKey
, str
);
235 OSDictionary
* IONetworkNamePrefixMatching( const char * prefix
)
237 OSDictionary
* matching
;
238 OSDictionary
* propDict
= 0;
239 const OSSymbol
* str
= 0;
240 char networkType
[128];
243 matching
= IOService::serviceMatching( "IONetworkInterface" );
247 propDict
= OSDictionary::withCapacity(1);
251 str
= OSSymbol::withCString( prefix
);
255 propDict
->setObject( "IOInterfaceNamePrefix", (OSObject
*) str
);
259 // see if we're contrained to netroot off of specific network type
260 if(PE_parse_boot_argn( "network-type", networkType
, 128 ))
262 str
= OSSymbol::withCString( networkType
);
265 propDict
->setObject( "IONetworkRootType", str
);
271 if ( matching
->setObject( gIOPropertyMatchKey
,
272 (OSObject
*) propDict
) != true )
282 if ( matching
) matching
->release();
283 if ( propDict
) propDict
->release();
284 if ( str
) str
->release();
289 static bool IORegisterNetworkInterface( IOService
* netif
)
291 // A network interface is typically named and registered
292 // with BSD after receiving a request from a user space
293 // "namer". However, for cases when the system needs to
294 // root from the network, this registration task must be
295 // done inside the kernel and completed before the root
296 // device is handed to BSD.
301 OSDictionary
* dict
= 0;
304 enum { kMaxPathLen
= 512 };
307 stack
= IOService::waitForService(
308 IOService::serviceMatching("IONetworkStack") );
309 if ( stack
== 0 ) break;
311 dict
= OSDictionary::withCapacity(3);
312 if ( dict
== 0 ) break;
314 zero
= OSNumber::withNumber((UInt64
) 0, 32);
315 if ( zero
== 0 ) break;
317 pathBuf
= (char *) IOMalloc( kMaxPathLen
);
318 if ( pathBuf
== 0 ) break;
321 if ( netif
->getPath( pathBuf
, &len
, gIOServicePlane
)
324 path
= OSString::withCStringNoCopy( pathBuf
);
325 if ( path
== 0 ) break;
327 dict
->setObject( "IOInterfaceUnit", zero
);
328 dict
->setObject( kIOPathMatchKey
, path
);
330 stack
->setProperties( dict
);
334 if ( zero
) zero
->release();
335 if ( path
) path
->release();
336 if ( dict
) dict
->release();
337 if ( pathBuf
) IOFree(pathBuf
, kMaxPathLen
);
339 return ( netif
->getProperty( kIOBSDNameKey
) != 0 );
342 OSDictionary
* IODiskMatching( const char * path
, char * buf
, int maxLen
)
353 // scan the tail of the path for "@unit:partition"
355 // Have to get the full path to the controller - an alias may
356 // tell us next to nothing, like "hd:8"
357 alias
= IORegistryEntry::dealiasPath( &path
, gIODTPlane
);
359 look
= path
+ strlen( path
);
361 while( look
!= path
) {
362 if( *(--look
) == c
) {
364 partition
= strtol( look
+ 1, 0, 0 );
366 } else if( c
== '@') {
367 unit
= strtol( look
+ 1, &comp
, 16 );
370 lun
= strtol( comp
+ 1, 0, 16 );
374 } else if( c
== '/') {
380 if( alias
&& (look
== path
)) {
382 look
= path
+ strlen( path
);
386 if( c
|| unit
== -1 || partition
== -1)
389 len
= strlen( "{" kIOPathMatchKey
"='" kIODeviceTreePlane
":" );
394 snprintf( buf
, len
+ 1, "{" kIOPathMatchKey
"='" kIODeviceTreePlane
":" );
398 len
= strlen( alias
);
403 strlcpy( comp
, alias
, len
+ 1 );
407 if ( (look
- path
)) {
413 strlcpy( comp
, path
, len
+ 1 );
419 len
= strlen( "/@hhhhhhhh,hhhhhhhh:dddddddddd';}" );
424 snprintf( comp
, len
+ 1, "/@%lx,%lx:%ld';}", unit
, lun
, partition
);
428 len
= strlen( "/@hhhhhhhh:dddddddddd';}" );
433 snprintf( comp
, len
+ 1, "/@%lx:%ld';}", unit
, partition
);
436 return( OSDynamicCast(OSDictionary
, OSUnserialize( buf
, 0 )) );
443 OSDictionary
* IOOFPathMatching( const char * path
, char * buf
, int maxLen
)
445 OSDictionary
* matching
;
450 /* need to look up path, get device type,
451 call matching help based on device type */
453 matching
= IODiskMatching( path
, buf
, maxLen
);
459 len
= strlen( kIODeviceTreePlane
":" );
464 strlcpy( buf
, kIODeviceTreePlane
":", len
+ 1 );
467 len
= strlen( path
);
471 strlcpy( comp
, path
, len
+ 1 );
473 matching
= OSDictionary::withCapacity( 1 );
477 str
= OSString::withCString( buf
);
480 matching
->setObject( kIOPathMatchKey
, str
);
493 IOService
* IOFindMatchingChild( IOService
* service
)
495 // find a matching child service
496 IOService
* child
= 0;
497 OSIterator
* iter
= service
->getClientIterator();
499 while( ( child
= (IOService
*) iter
->getNextObject() ) ) {
500 OSDictionary
* dict
= OSDictionary::withCapacity( 1 );
505 const OSSymbol
* str
= OSSymbol::withCString( "Apple_HFS" );
511 dict
->setObject( "Content", (OSObject
*)str
);
513 if ( child
->compareProperty( dict
, "Content" ) ) {
518 IOService
* subchild
= IOFindMatchingChild( child
);
529 static int didRam
= 0;
531 kern_return_t
IOFindBSDRoot( char * rootName
, unsigned int rootNameSize
,
532 dev_t
* root
, u_int32_t
* oflags
)
536 IORegistryEntry
* regEntry
;
537 OSDictionary
* matching
= 0;
541 UInt32
*ramdParms
= 0;
545 bool findHFSChild
= false;
546 const char * mediaProperty
= 0;
548 enum { kMaxPathBuf
= 512, kMaxBootVar
= 128 };
550 const char * look
= 0;
552 bool forceNet
= false;
553 bool debugInfoPrintedOnce
= false;
554 const char * uuidStr
= NULL
;
556 static int mountAttempts
= 0;
564 str
= (char *) IOMalloc( kMaxPathBuf
+ kMaxBootVar
);
566 return( kIOReturnNoMemory
);
567 rdBootVar
= str
+ kMaxPathBuf
;
569 if (!PE_parse_boot_argn("rd", rdBootVar
, kMaxBootVar
)
570 && !PE_parse_boot_argn("rootdev", rdBootVar
, kMaxBootVar
))
574 if( (regEntry
= IORegistryEntry::fromPath( "/chosen", gIODTPlane
))) {
575 di_root_ramfile(regEntry
);
576 data
= OSDynamicCast(OSData
, regEntry
->getProperty( "root-matching" ));
578 matching
= OSDynamicCast(OSDictionary
, OSUnserializeXML((char *)data
->getBytesNoCopy()));
584 data
= (OSData
*) regEntry
->getProperty( "boot-uuid" );
586 uuidStr
= (const char*)data
->getBytesNoCopy();
587 OSString
*uuidString
= OSString::withCString( uuidStr
);
589 // match the boot-args boot-uuid processing below
591 IOLog("rooting via boot-uuid from /chosen: %s\n", uuidStr
);
592 IOService::publishResource( "boot-uuid", uuidString
);
593 uuidString
->release();
594 matching
= IOUUIDMatching();
595 mediaProperty
= "boot-uuid-media";
603 // else try for an OF Path
604 data
= (OSData
*) regEntry
->getProperty( "rootpath" );
608 if( (regEntry
= IORegistryEntry::fromPath( "/options", gIODTPlane
))) {
609 data
= (OSData
*) regEntry
->getProperty( "boot-file" );
615 if( data
&& !uuidStr
)
616 look
= (const char *) data
->getBytesNoCopy();
618 if( rdBootVar
[0] == '*') {
619 look
= rdBootVar
+ 1;
622 if( (regEntry
= IORegistryEntry::fromPath( "/", gIODTPlane
))) {
623 forceNet
= (0 != regEntry
->getProperty( "net-boot" ));
631 // See if we have a RAMDisk property in /chosen/memory-map. If so, make it into a device.
632 // It will become /dev/mdx, where x is 0-f.
635 if(!didRam
) { /* Have we already build this ram disk? */
636 didRam
= 1; /* Remember we did this */
637 if((regEntry
= IORegistryEntry::fromPath( "/chosen/memory-map", gIODTPlane
))) { /* Find the map node */
638 data
= (OSData
*)regEntry
->getProperty("RAMDisk"); /* Find the ram disk, if there */
639 if(data
) { /* We found one */
641 ramdParms
= (UInt32
*)data
->getBytesNoCopy(); /* Point to the ram disk base and size */
642 (void)mdevadd(-1, ml_static_ptovirt(ramdParms
[0]) >> 12, ramdParms
[1] >> 12, 0); /* Initialize it and pass back the device number */
644 regEntry
->release(); /* Toss the entry */
649 // Now check if we are trying to root on a memory device
652 if((rdBootVar
[0] == 'm') && (rdBootVar
[1] == 'd') && (rdBootVar
[3] == 0)) {
653 dchar
= xchar
= rdBootVar
[2]; /* Get the actual device */
654 if((xchar
>= '0') && (xchar
<= '9')) xchar
= xchar
- '0'; /* If digit, convert */
656 xchar
= xchar
& ~' '; /* Fold to upper case */
657 if((xchar
>= 'A') && (xchar
<= 'F')) { /* Is this a valid digit? */
658 xchar
= (xchar
& 0xF) + 9; /* Convert the hex digit */
659 dchar
= dchar
| ' '; /* Fold to lower case */
661 else xchar
= -1; /* Show bogus */
663 if(xchar
>= 0) { /* Do we have a valid memory device name? */
664 *root
= mdevlookup(xchar
); /* Find the device number */
665 if(*root
>= 0) { /* Did we find one? */
667 rootName
[0] = 'm'; /* Build root name */
668 rootName
[1] = 'd'; /* Build root name */
669 rootName
[2] = dchar
; /* Build root name */
670 rootName
[3] = 0; /* Build root name */
671 IOLog("BSD root: %s, major %d, minor %d\n", rootName
, major(*root
), minor(*root
));
672 *oflags
= 0; /* Show that this is not network */
673 goto iofrootx
; /* Join common exit... */
675 panic("IOFindBSDRoot: specified root memory device, %s, has not been configured\n", rdBootVar
); /* Not there */
680 // from OpenFirmware path
681 IOLog("From path: \"%s\", ", look
);
684 if( forceNet
|| (0 == strncmp( look
, "enet", strlen( "enet" ))) ) {
685 matching
= IONetworkMatching( look
, str
, kMaxPathBuf
);
687 matching
= IODiskMatching( look
, str
, kMaxPathBuf
);
692 if( (!matching
) && rdBootVar
[0] ) {
698 if ( strncmp( look
, "en", strlen( "en" )) == 0 ) {
699 matching
= IONetworkNamePrefixMatching( "en" );
700 } else if ( strncmp( look
, "cdrom", strlen( "cdrom" )) == 0 ) {
701 matching
= IOCDMatching();
703 } else if ( strncmp( look
, "uuid", strlen( "uuid" )) == 0 ) {
705 OSString
*uuidString
;
707 uuid
= (char *)IOMalloc( kMaxBootVar
);
710 if (!PE_parse_boot_argn( "boot-uuid", uuid
, kMaxBootVar
)) {
711 panic( "rd=uuid but no boot-uuid=<value> specified" );
713 uuidString
= OSString::withCString( uuid
);
715 IOService::publishResource( "boot-uuid", uuidString
);
716 uuidString
->release();
717 IOLog( "\nWaiting for boot volume with UUID %s\n", uuid
);
718 matching
= IOUUIDMatching();
719 mediaProperty
= "boot-uuid-media";
721 IOFree( uuid
, kMaxBootVar
);
724 matching
= IOBSDNameMatching( look
);
730 // Match any HFS media
732 matching
= IOService::serviceMatching( "IOMedia" );
733 astring
= OSString::withCStringNoCopy("Apple_HFS");
735 matching
->setObject("Content", astring
);
740 if( true && matching
) {
741 OSSerialize
* s
= OSSerialize::withCapacity( 5 );
743 if( matching
->serialize( s
)) {
744 IOLog( "Waiting on %s\n", s
->text() );
750 t
.tv_sec
= ROOTDEVICETIMEOUT
;
753 service
= IOService::waitForService( matching
, &t
);
754 if( (!service
) || (mountAttempts
== 10)) {
755 PE_display_icon( 0, "noroot");
756 IOLog( "Still waiting for root device\n" );
758 if( !debugInfoPrintedOnce
) {
759 debugInfoPrintedOnce
= true;
760 if( gIOKitDebug
& kIOLogDTree
) {
761 IOLog("\nDT plane:\n");
762 IOPrintPlane( gIODTPlane
);
764 if( gIOKitDebug
& kIOLogServiceTree
) {
765 IOLog("\nService plane:\n");
766 IOPrintPlane( gIOServicePlane
);
768 if( gIOKitDebug
& kIOLogMemory
)
775 if ( service
&& findHFSChild
) {
779 // wait for children services to finish registering
781 timeoutNS
= ROOTDEVICETIMEOUT
;
782 timeoutNS
*= kSecondScale
;
784 if ( (service
->waitQuiet(timeoutNS
) ) == kIOReturnSuccess
) {
787 IOLog( "Waiting for child registration\n" );
790 // look for a subservice with an Apple_HFS child
791 IOService
* subservice
= IOFindMatchingChild( service
);
792 if ( subservice
) service
= subservice
;
793 } else if ( service
&& mediaProperty
) {
794 service
= (IOService
*)service
->getProperty(mediaProperty
);
800 // If the IOService we matched to is a subclass of IONetworkInterface,
801 // then make sure it has been registered with BSD and has a BSD name
805 && service
->metaCast( "IONetworkInterface" )
806 && !IORegisterNetworkInterface( service
) )
814 service
->getPath( str
, &len
, gIOServicePlane
);
815 IOLog( "Got boot device = %s\n", str
);
817 iostr
= (OSString
*) service
->getProperty( kIOBSDNameKey
);
819 strlcpy( rootName
, iostr
->getCStringNoCopy(), rootNameSize
);
820 off
= (OSNumber
*) service
->getProperty( kIOBSDMajorKey
);
822 mjr
= off
->unsigned32BitValue();
823 off
= (OSNumber
*) service
->getProperty( kIOBSDMinorKey
);
825 mnr
= off
->unsigned32BitValue();
827 if( service
->metaCast( "IONetworkInterface" ))
832 IOLog( "Wait for root failed\n" );
833 strlcpy( rootName
, "en0", rootNameSize
);
837 IOLog( "BSD root: %s", rootName
);
839 IOLog(", major %d, minor %d\n", mjr
, mnr
);
843 *root
= makedev( mjr
, mnr
);
846 IOFree( str
, kMaxPathBuf
+ kMaxBootVar
);
849 if( (gIOKitDebug
& (kIOLogDTree
| kIOLogServiceTree
| kIOLogMemory
)) && !debugInfoPrintedOnce
) {
851 IOService::getPlatform()->waitQuiet();
852 if( gIOKitDebug
& kIOLogDTree
) {
853 IOLog("\nDT plane:\n");
854 IOPrintPlane( gIODTPlane
);
856 if( gIOKitDebug
& kIOLogServiceTree
) {
857 IOLog("\nService plane:\n");
858 IOPrintPlane( gIOServicePlane
);
860 if( gIOKitDebug
& kIOLogMemory
)
864 return( kIOReturnSuccess
);
867 void IOSecureBSDRoot(const char * rootName
)
871 IOPlatformExpert
*pe
;
872 const OSSymbol
*functionName
= OSSymbol::withCStringNoCopy("SecureRootName");
874 while ((pe
= IOService::getPlatform()) == 0) IOSleep(1 * 1000);
876 // Returns kIOReturnNotPrivileged is the root device is not secure.
877 // Returns kIOReturnUnsupported if "SecureRootName" is not implemented.
878 result
= pe
->callPlatformFunction(functionName
, false, (void *)rootName
, (void *)0, (void *)0, (void *)0);
880 functionName
->release();
882 if (result
== kIOReturnNotPrivileged
) mdevremoveall();
887 IOBSDRegistryEntryForDeviceTree(char * path
)
889 return (IORegistryEntry::fromPath(path
, gIODTPlane
));
893 IOBSDRegistryEntryRelease(void * entry
)
895 IORegistryEntry
* regEntry
= (IORegistryEntry
*)entry
;
903 IOBSDRegistryEntryGetData(void * entry
, char * property_name
,
907 IORegistryEntry
* regEntry
= (IORegistryEntry
*)entry
;
909 data
= (OSData
*) regEntry
->getProperty(property_name
);
911 *packet_length
= data
->getLength();
912 return (data
->getBytesNoCopy());
917 kern_return_t
IOBSDGetPlatformUUID( uuid_t uuid
, mach_timespec_t timeout
)
919 IOService
* resources
;
922 resources
= IOService::waitForService( IOService::resourceMatching( kIOPlatformUUIDKey
), ( timeout
.tv_sec
|| timeout
.tv_nsec
) ? &timeout
: 0 );
923 if ( resources
== 0 ) return KERN_OPERATION_TIMED_OUT
;
925 string
= ( OSString
* ) IOService::getPlatform( )->getProvider( )->getProperty( kIOPlatformUUIDKey
);
926 if ( string
== 0 ) return KERN_NOT_SUPPORTED
;
928 uuid_parse( string
->getCStringNoCopy( ), uuid
);
933 kern_return_t
IOBSDGetPlatformSerialNumber( char *serial_number_str
, u_int32_t len
)
935 OSDictionary
* platform_dict
;
942 serial_number_str
[0] = '\0';
944 platform_dict
= IOService::serviceMatching( "IOPlatformExpertDevice" );
945 if (platform_dict
== NULL
) {
946 return KERN_NOT_SUPPORTED
;
949 platform
= IOService::waitForService( platform_dict
);
951 string
= ( OSString
* ) platform
->getProperty( kIOPlatformSerialNumberKey
);
953 return KERN_NOT_SUPPORTED
;
955 strlcpy( serial_number_str
, string
->getCStringNoCopy( ), len
);
962 dev_t
IOBSDGetMediaWithUUID( const char *uuid_cstring
, char *bsd_name
, int bsd_name_len
, int timeout
)
965 OSDictionary
*dictionary
;
966 OSString
*uuid_string
;
968 if (bsd_name_len
< 1) {
973 dictionary
= IOService::serviceMatching( "IOMedia" );
975 uuid_string
= OSString::withCString( uuid_cstring
);
978 mach_timespec_t tv
= { timeout
, 0 }; // wait up to "timeout" seconds for the device
980 dictionary
->setObject( "UUID", uuid_string
);
981 dictionary
->retain();
982 service
= IOService::waitForService( dictionary
, &tv
);
984 OSNumber
*dev_major
= (OSNumber
*) service
->getProperty( kIOBSDMajorKey
);
985 OSNumber
*dev_minor
= (OSNumber
*) service
->getProperty( kIOBSDMinorKey
);
986 OSString
*iostr
= (OSString
*) service
->getProperty( kIOBSDNameKey
);
989 strlcpy( bsd_name
, iostr
->getCStringNoCopy(), bsd_name_len
);
991 if ( dev_major
&& dev_minor
)
992 dev
= makedev( dev_major
->unsigned32BitValue(), dev_minor
->unsigned32BitValue() );
994 uuid_string
->release();
996 dictionary
->release();
1003 void IOBSDIterateMediaWithContent(const char *content_uuid_cstring
, int (*func
)(const char *bsd_dev_name
, const char *uuid_str
, void *arg
), void *arg
)
1005 OSDictionary
*dictionary
;
1006 OSString
*content_uuid_string
;
1008 dictionary
= IOService::serviceMatching( "IOMedia" );
1010 content_uuid_string
= OSString::withCString( content_uuid_cstring
);
1011 if( content_uuid_string
) {
1015 dictionary
->setObject( "Content", content_uuid_string
);
1016 dictionary
->retain();
1018 iter
= IOService::getMatchingServices(dictionary
);
1019 while (iter
&& (service
= (IOService
*)iter
->getNextObject())) {
1021 OSString
*iostr
= (OSString
*) service
->getProperty( kIOBSDNameKey
);
1022 OSString
*uuidstr
= (OSString
*) service
->getProperty( "UUID" );
1027 uuid
= uuidstr
->getCStringNoCopy();
1029 uuid
= "00000000-0000-0000-0000-000000000000";
1032 // call the callback
1033 if (func
&& func(iostr
->getCStringNoCopy(), uuid
, arg
) == 0) {
1042 content_uuid_string
->release();
1044 dictionary
->release();
1049 int IOBSDIsMediaEjectable( const char *cdev_name
)
1052 OSDictionary
*dictionary
;
1055 if (strncmp(cdev_name
, "/dev/", 5) == 0) {
1059 dictionary
= IOService::serviceMatching( "IOMedia" );
1061 dev_name
= OSString::withCString( cdev_name
);
1064 mach_timespec_t tv
= { 5, 0 }; // wait up to "timeout" seconds for the device
1066 dictionary
->setObject( kIOBSDNameKey
, dev_name
);
1067 dictionary
->retain();
1068 service
= IOService::waitForService( dictionary
, &tv
);
1070 OSBoolean
*ejectable
= (OSBoolean
*) service
->getProperty( "Ejectable" );
1073 ret
= (int)ejectable
->getValue();
1077 dev_name
->release();
1079 dictionary
->release();