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
, ppnum_t base
, unsigned int size
, int phys
);
50 extern dev_t
mdevlookup(int devid
);
51 extern void mdevremoveall(void);
56 IOService::publishResource("IOBSD");
58 return( kIOReturnSuccess
);
62 IOServicePublishResource( const char * property
, boolean_t value
)
65 IOService::publishResource( property
, kOSBooleanTrue
);
67 IOService::getResourceService()->removeProperty( property
);
71 IOServiceWaitForMatchingResource( const char * property
, uint64_t timeout
)
73 OSDictionary
* dict
= 0;
74 IOService
* match
= 0;
75 boolean_t found
= false;
79 dict
= IOService::resourceMatching( property
);
82 match
= IOService::waitForMatchingService( dict
, timeout
);
97 IOCatalogueMatchingDriversPresent( const char * property
)
99 OSDictionary
* dict
= 0;
100 OSOrderedSet
* set
= 0;
101 SInt32 generationCount
= 0;
102 boolean_t found
= false;
106 dict
= OSDictionary::withCapacity(1);
109 dict
->setObject( property
, kOSBooleanTrue
);
110 set
= gIOCatalogue
->findDrivers( dict
, &generationCount
);
111 if ( set
&& (set
->getCount() > 0))
124 OSDictionary
* IOBSDNameMatching( const char * name
)
127 const OSSymbol
* str
= 0;
131 dict
= IOService::serviceMatching( gIOServiceKey
);
134 str
= OSSymbol::withCString( name
);
137 dict
->setObject( kIOBSDNameKey
, (OSObject
*) str
);
152 OSDictionary
* IOUUIDMatching( void )
154 return IOService::resourceMatching( "boot-uuid-media" );
158 OSDictionary
* IOCDMatching( void )
161 const OSSymbol
* str
;
163 dict
= IOService::serviceMatching( "IOMedia" );
165 IOLog("Unable to find IOMedia\n");
169 str
= OSSymbol::withCString( "CD_ROM_Mode_1" );
175 dict
->setObject( "Content Hint", (OSObject
*)str
);
180 OSDictionary
* IONetworkMatching( const char * path
,
181 char * buf
, int maxLen
)
183 OSDictionary
* matching
= 0;
192 len
= strlen( kIODeviceTreePlane
":" );
197 strlcpy( buf
, kIODeviceTreePlane
":", len
+ 1 );
200 // remove parameters following ':' from the path
201 skip
= strchr( path
, ':');
209 strlcpy( comp
, path
, len
+ 1 );
211 matching
= IOService::serviceMatching( "IONetworkInterface" );
214 dict
= IOService::addLocation( matching
);
218 str
= OSString::withCString( buf
);
221 dict
->setObject( kIOPathMatchKey
, str
);
234 OSDictionary
* IONetworkNamePrefixMatching( const char * prefix
)
236 OSDictionary
* matching
;
237 OSDictionary
* propDict
= 0;
238 const OSSymbol
* str
= 0;
239 char networkType
[128];
242 matching
= IOService::serviceMatching( "IONetworkInterface" );
246 propDict
= OSDictionary::withCapacity(1);
250 str
= OSSymbol::withCString( prefix
);
254 propDict
->setObject( "IOInterfaceNamePrefix", (OSObject
*) str
);
258 // see if we're contrained to netroot off of specific network type
259 if(PE_parse_boot_argn( "network-type", networkType
, 128 ))
261 str
= OSSymbol::withCString( networkType
);
264 propDict
->setObject( "IONetworkRootType", str
);
270 if ( matching
->setObject( gIOPropertyMatchKey
,
271 (OSObject
*) propDict
) != true )
281 if ( matching
) matching
->release();
282 if ( propDict
) propDict
->release();
283 if ( str
) str
->release();
288 static bool IORegisterNetworkInterface( IOService
* netif
)
290 // A network interface is typically named and registered
291 // with BSD after receiving a request from a user space
292 // "namer". However, for cases when the system needs to
293 // root from the network, this registration task must be
294 // done inside the kernel and completed before the root
295 // device is handed to BSD.
300 OSDictionary
* dict
= 0;
303 enum { kMaxPathLen
= 512 };
306 stack
= IOService::waitForService(
307 IOService::serviceMatching("IONetworkStack") );
308 if ( stack
== 0 ) break;
310 dict
= OSDictionary::withCapacity(3);
311 if ( dict
== 0 ) break;
313 zero
= OSNumber::withNumber((UInt64
) 0, 32);
314 if ( zero
== 0 ) break;
316 pathBuf
= (char *) IOMalloc( kMaxPathLen
);
317 if ( pathBuf
== 0 ) break;
320 if ( netif
->getPath( pathBuf
, &len
, gIOServicePlane
)
323 path
= OSString::withCStringNoCopy( pathBuf
);
324 if ( path
== 0 ) break;
326 dict
->setObject( "IOInterfaceUnit", zero
);
327 dict
->setObject( kIOPathMatchKey
, path
);
329 stack
->setProperties( dict
);
333 if ( zero
) zero
->release();
334 if ( path
) path
->release();
335 if ( dict
) dict
->release();
336 if ( pathBuf
) IOFree(pathBuf
, kMaxPathLen
);
338 return ( netif
->getProperty( kIOBSDNameKey
) != 0 );
341 OSDictionary
* IODiskMatching( const char * path
, char * buf
, int maxLen
)
352 // scan the tail of the path for "@unit:partition"
354 // Have to get the full path to the controller - an alias may
355 // tell us next to nothing, like "hd:8"
356 alias
= IORegistryEntry::dealiasPath( &path
, gIODTPlane
);
358 look
= path
+ strlen( path
);
360 while( look
!= path
) {
361 if( *(--look
) == c
) {
363 partition
= strtol( look
+ 1, 0, 0 );
365 } else if( c
== '@') {
366 unit
= strtol( look
+ 1, &comp
, 16 );
369 lun
= strtol( comp
+ 1, 0, 16 );
373 } else if( c
== '/') {
379 if( alias
&& (look
== path
)) {
381 look
= path
+ strlen( path
);
385 if( c
|| unit
== -1 || partition
== -1)
388 len
= strlen( "{" kIOPathMatchKey
"='" kIODeviceTreePlane
":" );
393 snprintf( buf
, len
+ 1, "{" kIOPathMatchKey
"='" kIODeviceTreePlane
":" );
397 len
= strlen( alias
);
402 strlcpy( comp
, alias
, len
+ 1 );
406 if ( (look
- path
)) {
412 strlcpy( comp
, path
, len
+ 1 );
418 len
= strlen( "/@hhhhhhhh,hhhhhhhh:dddddddddd';}" );
423 snprintf( comp
, len
+ 1, "/@%lx,%lx:%ld';}", unit
, lun
, partition
);
427 len
= strlen( "/@hhhhhhhh:dddddddddd';}" );
432 snprintf( comp
, len
+ 1, "/@%lx:%ld';}", unit
, partition
);
435 return( OSDynamicCast(OSDictionary
, OSUnserialize( buf
, 0 )) );
442 OSDictionary
* IOOFPathMatching( const char * path
, char * buf
, int maxLen
)
444 OSDictionary
* matching
;
449 /* need to look up path, get device type,
450 call matching help based on device type */
452 matching
= IODiskMatching( path
, buf
, maxLen
);
458 len
= strlen( kIODeviceTreePlane
":" );
463 strlcpy( buf
, kIODeviceTreePlane
":", len
+ 1 );
466 len
= strlen( path
);
470 strlcpy( comp
, path
, len
+ 1 );
472 matching
= OSDictionary::withCapacity( 1 );
476 str
= OSString::withCString( buf
);
479 matching
->setObject( kIOPathMatchKey
, str
);
492 IOService
* IOFindMatchingChild( IOService
* service
)
494 // find a matching child service
495 IOService
* child
= 0;
496 OSIterator
* iter
= service
->getClientIterator();
498 while( ( child
= (IOService
*) iter
->getNextObject() ) ) {
499 OSDictionary
* dict
= OSDictionary::withCapacity( 1 );
504 const OSSymbol
* str
= OSSymbol::withCString( "Apple_HFS" );
510 dict
->setObject( "Content", (OSObject
*)str
);
512 if ( child
->compareProperty( dict
, "Content" ) ) {
517 IOService
* subchild
= IOFindMatchingChild( child
);
528 static int didRam
= 0;
530 kern_return_t
IOFindBSDRoot( char * rootName
, unsigned int rootNameSize
,
531 dev_t
* root
, u_int32_t
* oflags
)
535 IORegistryEntry
* regEntry
;
536 OSDictionary
* matching
= 0;
540 UInt32
*ramdParms
= 0;
544 bool findHFSChild
= false;
545 char * mediaProperty
= 0;
547 enum { kMaxPathBuf
= 512, kMaxBootVar
= 128 };
549 const char * look
= 0;
551 bool forceNet
= false;
552 bool debugInfoPrintedOnce
= false;
553 const char * uuidStr
= NULL
;
555 static int mountAttempts
= 0;
563 str
= (char *) IOMalloc( kMaxPathBuf
+ kMaxBootVar
);
565 return( kIOReturnNoMemory
);
566 rdBootVar
= str
+ kMaxPathBuf
;
568 if (!PE_parse_boot_argn("rd", rdBootVar
, kMaxBootVar
)
569 && !PE_parse_boot_argn("rootdev", rdBootVar
, kMaxBootVar
))
573 if( (regEntry
= IORegistryEntry::fromPath( "/chosen", gIODTPlane
))) {
574 data
= OSDynamicCast(OSData
, regEntry
->getProperty( "root-matching" ));
576 matching
= OSDynamicCast(OSDictionary
, OSUnserializeXML((char *)data
->getBytesNoCopy()));
582 data
= (OSData
*) regEntry
->getProperty( "boot-uuid" );
584 uuidStr
= (const char*)data
->getBytesNoCopy();
585 OSString
*uuidString
= OSString::withCString( uuidStr
);
587 // match the boot-args boot-uuid processing below
589 IOLog("rooting via boot-uuid from /chosen: %s\n", uuidStr
);
590 IOService::publishResource( "boot-uuid", uuidString
);
591 uuidString
->release();
592 matching
= IOUUIDMatching();
593 mediaProperty
= "boot-uuid-media";
601 // else try for an OF Path
602 data
= (OSData
*) regEntry
->getProperty( "rootpath" );
606 if( (regEntry
= IORegistryEntry::fromPath( "/options", gIODTPlane
))) {
607 data
= (OSData
*) regEntry
->getProperty( "boot-file" );
613 if( data
&& !uuidStr
)
614 look
= (const char *) data
->getBytesNoCopy();
616 if( rdBootVar
[0] == '*') {
617 look
= rdBootVar
+ 1;
620 if( (regEntry
= IORegistryEntry::fromPath( "/", gIODTPlane
))) {
621 forceNet
= (0 != regEntry
->getProperty( "net-boot" ));
629 // See if we have a RAMDisk property in /chosen/memory-map. If so, make it into a device.
630 // It will become /dev/mdx, where x is 0-f.
633 if(!didRam
) { /* Have we already build this ram disk? */
634 didRam
= 1; /* Remember we did this */
635 if((regEntry
= IORegistryEntry::fromPath( "/chosen/memory-map", gIODTPlane
))) { /* Find the map node */
636 data
= (OSData
*)regEntry
->getProperty("RAMDisk"); /* Find the ram disk, if there */
637 if(data
) { /* We found one */
639 ramdParms
= (UInt32
*)data
->getBytesNoCopy(); /* Point to the ram disk base and size */
640 (void)mdevadd(-1, ml_static_ptovirt(ramdParms
[0]) >> 12, ramdParms
[1] >> 12, 0); /* Initialize it and pass back the device number */
642 regEntry
->release(); /* Toss the entry */
647 // Now check if we are trying to root on a memory device
650 if((rdBootVar
[0] == 'm') && (rdBootVar
[1] == 'd') && (rdBootVar
[3] == 0)) {
651 dchar
= xchar
= rdBootVar
[2]; /* Get the actual device */
652 if((xchar
>= '0') && (xchar
<= '9')) xchar
= xchar
- '0'; /* If digit, convert */
654 xchar
= xchar
& ~' '; /* Fold to upper case */
655 if((xchar
>= 'A') && (xchar
<= 'F')) { /* Is this a valid digit? */
656 xchar
= (xchar
& 0xF) + 9; /* Convert the hex digit */
657 dchar
= dchar
| ' '; /* Fold to lower case */
659 else xchar
= -1; /* Show bogus */
661 if(xchar
>= 0) { /* Do we have a valid memory device name? */
662 *root
= mdevlookup(xchar
); /* Find the device number */
663 if(*root
>= 0) { /* Did we find one? */
665 rootName
[0] = 'm'; /* Build root name */
666 rootName
[1] = 'd'; /* Build root name */
667 rootName
[2] = dchar
; /* Build root name */
668 rootName
[3] = 0; /* Build root name */
669 IOLog("BSD root: %s, major %d, minor %d\n", rootName
, major(*root
), minor(*root
));
670 *oflags
= 0; /* Show that this is not network */
671 goto iofrootx
; /* Join common exit... */
673 panic("IOFindBSDRoot: specified root memory device, %s, has not been configured\n", rdBootVar
); /* Not there */
678 // from OpenFirmware path
679 IOLog("From path: \"%s\", ", look
);
682 if( forceNet
|| (0 == strncmp( look
, "enet", strlen( "enet" ))) ) {
683 matching
= IONetworkMatching( look
, str
, kMaxPathBuf
);
685 matching
= IODiskMatching( look
, str
, kMaxPathBuf
);
690 if( (!matching
) && rdBootVar
[0] ) {
696 if ( strncmp( look
, "en", strlen( "en" )) == 0 ) {
697 matching
= IONetworkNamePrefixMatching( "en" );
698 } else if ( strncmp( look
, "cdrom", strlen( "cdrom" )) == 0 ) {
699 matching
= IOCDMatching();
701 } else if ( strncmp( look
, "uuid", strlen( "uuid" )) == 0 ) {
703 OSString
*uuidString
;
705 uuid
= (char *)IOMalloc( kMaxBootVar
);
708 if (!PE_parse_boot_argn( "boot-uuid", uuid
, kMaxBootVar
)) {
709 panic( "rd=uuid but no boot-uuid=<value> specified" );
711 uuidString
= OSString::withCString( uuid
);
713 IOService::publishResource( "boot-uuid", uuidString
);
714 uuidString
->release();
715 IOLog( "\nWaiting for boot volume with UUID %s\n", uuid
);
716 matching
= IOUUIDMatching();
717 mediaProperty
= "boot-uuid-media";
719 IOFree( uuid
, kMaxBootVar
);
722 matching
= IOBSDNameMatching( look
);
728 // Match any HFS media
730 matching
= IOService::serviceMatching( "IOMedia" );
731 astring
= OSString::withCStringNoCopy("Apple_HFS");
733 matching
->setObject("Content", astring
);
738 if( true && matching
) {
739 OSSerialize
* s
= OSSerialize::withCapacity( 5 );
741 if( matching
->serialize( s
)) {
742 IOLog( "Waiting on %s\n", s
->text() );
748 t
.tv_sec
= ROOTDEVICETIMEOUT
;
751 service
= IOService::waitForService( matching
, &t
);
752 if( (!service
) || (mountAttempts
== 10)) {
753 PE_display_icon( 0, "noroot");
754 IOLog( "Still waiting for root device\n" );
756 if( !debugInfoPrintedOnce
) {
757 debugInfoPrintedOnce
= true;
758 if( gIOKitDebug
& kIOLogDTree
) {
759 IOLog("\nDT plane:\n");
760 IOPrintPlane( gIODTPlane
);
762 if( gIOKitDebug
& kIOLogServiceTree
) {
763 IOLog("\nService plane:\n");
764 IOPrintPlane( gIOServicePlane
);
766 if( gIOKitDebug
& kIOLogMemory
)
773 if ( service
&& findHFSChild
) {
777 // wait for children services to finish registering
779 timeoutNS
= ROOTDEVICETIMEOUT
;
780 timeoutNS
*= kSecondScale
;
782 if ( (service
->waitQuiet(timeoutNS
) ) == kIOReturnSuccess
) {
785 IOLog( "Waiting for child registration\n" );
788 // look for a subservice with an Apple_HFS child
789 IOService
* subservice
= IOFindMatchingChild( service
);
790 if ( subservice
) service
= subservice
;
791 } else if ( service
&& mediaProperty
) {
792 service
= (IOService
*)service
->getProperty(mediaProperty
);
798 // If the IOService we matched to is a subclass of IONetworkInterface,
799 // then make sure it has been registered with BSD and has a BSD name
803 && service
->metaCast( "IONetworkInterface" )
804 && !IORegisterNetworkInterface( service
) )
812 service
->getPath( str
, &len
, gIOServicePlane
);
813 IOLog( "Got boot device = %s\n", str
);
815 iostr
= (OSString
*) service
->getProperty( kIOBSDNameKey
);
817 strlcpy( rootName
, iostr
->getCStringNoCopy(), rootNameSize
);
818 off
= (OSNumber
*) service
->getProperty( kIOBSDMajorKey
);
820 mjr
= off
->unsigned32BitValue();
821 off
= (OSNumber
*) service
->getProperty( kIOBSDMinorKey
);
823 mnr
= off
->unsigned32BitValue();
825 if( service
->metaCast( "IONetworkInterface" ))
830 IOLog( "Wait for root failed\n" );
831 strlcpy( rootName
, "en0", rootNameSize
);
835 IOLog( "BSD root: %s", rootName
);
837 IOLog(", major %d, minor %d\n", mjr
, mnr
);
841 *root
= makedev( mjr
, mnr
);
844 IOFree( str
, kMaxPathBuf
+ kMaxBootVar
);
847 if( (gIOKitDebug
& (kIOLogDTree
| kIOLogServiceTree
| kIOLogMemory
)) && !debugInfoPrintedOnce
) {
849 IOService::getPlatform()->waitQuiet();
850 if( gIOKitDebug
& kIOLogDTree
) {
851 IOLog("\nDT plane:\n");
852 IOPrintPlane( gIODTPlane
);
854 if( gIOKitDebug
& kIOLogServiceTree
) {
855 IOLog("\nService plane:\n");
856 IOPrintPlane( gIOServicePlane
);
858 if( gIOKitDebug
& kIOLogMemory
)
862 return( kIOReturnSuccess
);
865 void IOSecureBSDRoot(const char * rootName
)
869 IOPlatformExpert
*pe
;
870 const OSSymbol
*functionName
= OSSymbol::withCStringNoCopy("SecureRootName");
872 while ((pe
= IOService::getPlatform()) == 0) IOSleep(1 * 1000);
874 // Returns kIOReturnNotPrivileged is the root device is not secure.
875 // Returns kIOReturnUnsupported if "SecureRootName" is not implemented.
876 result
= pe
->callPlatformFunction(functionName
, false, (void *)rootName
, (void *)0, (void *)0, (void *)0);
878 functionName
->release();
880 if (result
== kIOReturnNotPrivileged
) mdevremoveall();
885 IOBSDRegistryEntryForDeviceTree(char * path
)
887 return (IORegistryEntry::fromPath(path
, gIODTPlane
));
891 IOBSDRegistryEntryRelease(void * entry
)
893 IORegistryEntry
* regEntry
= (IORegistryEntry
*)entry
;
901 IOBSDRegistryEntryGetData(void * entry
, char * property_name
,
905 IORegistryEntry
* regEntry
= (IORegistryEntry
*)entry
;
907 data
= (OSData
*) regEntry
->getProperty(property_name
);
909 *packet_length
= data
->getLength();
910 return (data
->getBytesNoCopy());
915 kern_return_t
IOBSDGetPlatformUUID( uuid_t uuid
, mach_timespec_t timeout
)
917 IOService
* resources
;
920 resources
= IOService::waitForService( IOService::resourceMatching( kIOPlatformUUIDKey
), &timeout
);
921 if ( resources
== 0 ) return KERN_OPERATION_TIMED_OUT
;
923 string
= ( OSString
* ) IOService::getPlatform( )->getProvider( )->getProperty( kIOPlatformUUIDKey
);
924 if ( string
== 0 ) return KERN_NOT_SUPPORTED
;
926 uuid_parse( string
->getCStringNoCopy( ), uuid
);
931 kern_return_t
IOBSDGetPlatformSerialNumber( char *serial_number_str
, u_int32_t len
)
933 OSDictionary
* platform_dict
;
940 serial_number_str
[0] = '\0';
942 platform_dict
= IOService::serviceMatching( "IOPlatformExpertDevice" );
943 if (platform_dict
== NULL
) {
944 return KERN_NOT_SUPPORTED
;
947 platform
= IOService::waitForService( platform_dict
);
949 string
= ( OSString
* ) platform
->getProperty( kIOPlatformSerialNumberKey
);
951 return KERN_NOT_SUPPORTED
;
953 strlcpy( serial_number_str
, string
->getCStringNoCopy( ), len
);
960 dev_t
IOBSDGetMediaWithUUID( const char *uuid_cstring
, char *bsd_name
, int bsd_name_len
, int timeout
)
963 OSDictionary
*dictionary
;
964 OSString
*uuid_string
;
966 if (bsd_name_len
< 1) {
971 dictionary
= IOService::serviceMatching( "IOMedia" );
973 uuid_string
= OSString::withCString( uuid_cstring
);
976 mach_timespec_t tv
= { timeout
, 0 }; // wait up to "timeout" seconds for the device
978 dictionary
->setObject( "UUID", uuid_string
);
979 dictionary
->retain();
980 service
= IOService::waitForService( dictionary
, &tv
);
982 OSNumber
*dev_major
= (OSNumber
*) service
->getProperty( kIOBSDMajorKey
);
983 OSNumber
*dev_minor
= (OSNumber
*) service
->getProperty( kIOBSDMinorKey
);
984 OSString
*iostr
= (OSString
*) service
->getProperty( kIOBSDNameKey
);
987 strlcpy( bsd_name
, iostr
->getCStringNoCopy(), bsd_name_len
);
989 if ( dev_major
&& dev_minor
)
990 dev
= makedev( dev_major
->unsigned32BitValue(), dev_minor
->unsigned32BitValue() );
992 uuid_string
->release();
994 dictionary
->release();
1001 void IOBSDIterateMediaWithContent(const char *content_uuid_cstring
, int (*func
)(const char *bsd_dev_name
, const char *uuid_str
, void *arg
), void *arg
)
1003 OSDictionary
*dictionary
;
1004 OSString
*content_uuid_string
;
1006 dictionary
= IOService::serviceMatching( "IOMedia" );
1008 content_uuid_string
= OSString::withCString( content_uuid_cstring
);
1009 if( content_uuid_string
) {
1013 dictionary
->setObject( "Content", content_uuid_string
);
1014 dictionary
->retain();
1016 iter
= IOService::getMatchingServices(dictionary
);
1017 while (iter
&& (service
= (IOService
*)iter
->getNextObject())) {
1019 OSString
*iostr
= (OSString
*) service
->getProperty( kIOBSDNameKey
);
1020 OSString
*uuidstr
= (OSString
*) service
->getProperty( "UUID" );
1025 uuid
= uuidstr
->getCStringNoCopy();
1027 uuid
= "00000000-0000-0000-0000-000000000000";
1030 // call the callback
1031 if (func
&& func(iostr
->getCStringNoCopy(), uuid
, arg
) == 0) {
1040 content_uuid_string
->release();
1042 dictionary
->release();
1047 int IOBSDIsMediaEjectable( const char *cdev_name
)
1050 OSDictionary
*dictionary
;
1053 if (strncmp(cdev_name
, "/dev/", 5) == 0) {
1057 dictionary
= IOService::serviceMatching( "IOMedia" );
1059 dev_name
= OSString::withCString( cdev_name
);
1062 mach_timespec_t tv
= { 5, 0 }; // wait up to "timeout" seconds for the device
1064 dictionary
->setObject( kIOBSDNameKey
, dev_name
);
1065 dictionary
->retain();
1066 service
= IOService::waitForService( dictionary
, &tv
);
1068 OSBoolean
*ejectable
= (OSBoolean
*) service
->getProperty( "Ejectable" );
1071 ret
= (int)ejectable
->getValue();
1075 dev_name
->release();
1077 dictionary
->release();