+bool IORamDiskBSDRoot(void)
+{
+ char rdBootVar[kMaxBootVar];
+ if (PE_parse_boot_argn("rd", rdBootVar, kMaxBootVar )
+ || PE_parse_boot_argn("rootdev", rdBootVar, kMaxBootVar )) {
+ if((rdBootVar[0] == 'm') && (rdBootVar[1] == 'd') && (rdBootVar[3] == 0)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void IOSecureBSDRoot(const char * rootName)
+{
+}
+
+void *
+IOBSDRegistryEntryForDeviceTree(char * path)
+{
+ return (IORegistryEntry::fromPath(path, gIODTPlane));
+}
+
+void
+IOBSDRegistryEntryRelease(void * entry)
+{
+ IORegistryEntry * regEntry = (IORegistryEntry *)entry;
+
+ if (regEntry)
+ regEntry->release();
+ return;
+}
+
+const void *
+IOBSDRegistryEntryGetData(void * entry, char * property_name,
+ int * packet_length)
+{
+ OSData * data;
+ IORegistryEntry * regEntry = (IORegistryEntry *)entry;
+
+ data = (OSData *) regEntry->getProperty(property_name);
+ if (data) {
+ *packet_length = data->getLength();
+ return (data->getBytesNoCopy());
+ }
+ return (NULL);
+}
+
+kern_return_t IOBSDGetPlatformUUID( uuid_t uuid, mach_timespec_t timeout )
+{
+ IOService * resources;
+ OSString * string;
+
+ resources = IOService::waitForService( IOService::resourceMatching( kIOPlatformUUIDKey ), ( timeout.tv_sec || timeout.tv_nsec ) ? &timeout : 0 );
+ if ( resources == 0 ) return KERN_OPERATION_TIMED_OUT;
+
+ string = ( OSString * ) IOService::getPlatform( )->getProvider( )->getProperty( kIOPlatformUUIDKey );
+ if ( string == 0 ) return KERN_NOT_SUPPORTED;
+
+ uuid_parse( string->getCStringNoCopy( ), uuid );
+
+ return KERN_SUCCESS;
+}
+
+kern_return_t IOBSDGetPlatformSerialNumber( char *serial_number_str, u_int32_t len )
+{
+ OSDictionary * platform_dict;
+ IOService *platform;
+ OSString * string;
+
+ if (len < 1) {
+ return 0;
+ }
+ serial_number_str[0] = '\0';
+
+ platform_dict = IOService::serviceMatching( "IOPlatformExpertDevice" );
+ if (platform_dict == NULL) {
+ return KERN_NOT_SUPPORTED;
+ }
+
+ platform = IOService::waitForService( platform_dict );
+ if (platform) {
+ string = ( OSString * ) platform->getProperty( kIOPlatformSerialNumberKey );
+ if ( string == 0 ) {
+ return KERN_NOT_SUPPORTED;
+ } else {
+ strlcpy( serial_number_str, string->getCStringNoCopy( ), len );
+ }
+ }
+
+ return KERN_SUCCESS;
+}
+
+void IOBSDIterateMediaWithContent(const char *content_uuid_cstring, int (*func)(const char *bsd_dev_name, const char *uuid_str, void *arg), void *arg)
+{
+ OSDictionary *dictionary;
+ OSString *content_uuid_string;
+
+ dictionary = IOService::serviceMatching( "IOMedia" );
+ if( dictionary ) {
+ content_uuid_string = OSString::withCString( content_uuid_cstring );
+ if( content_uuid_string ) {
+ IOService *service;
+ OSIterator *iter;
+
+ dictionary->setObject( "Content", content_uuid_string );
+ dictionary->retain();
+
+ iter = IOService::getMatchingServices(dictionary);
+ while (iter && (service = (IOService *)iter->getNextObject())) {
+ if( service ) {
+ OSString *iostr = (OSString *) service->getProperty( kIOBSDNameKey );
+ OSString *uuidstr = (OSString *) service->getProperty( "UUID" );
+ const char *uuid;
+
+ if( iostr) {
+ if (uuidstr) {
+ uuid = uuidstr->getCStringNoCopy();
+ } else {
+ uuid = "00000000-0000-0000-0000-000000000000";
+ }
+
+ // call the callback
+ if (func && func(iostr->getCStringNoCopy(), uuid, arg) == 0) {
+ break;
+ }
+ }
+ }
+ }
+ if (iter)
+ iter->release();
+
+ content_uuid_string->release();
+ }
+ dictionary->release();
+ }
+}
+
+
+int IOBSDIsMediaEjectable( const char *cdev_name )
+{
+ int ret = 0;
+ OSDictionary *dictionary;
+ OSString *dev_name;
+
+ if (strncmp(cdev_name, "/dev/", 5) == 0) {
+ cdev_name += 5;
+ }
+
+ dictionary = IOService::serviceMatching( "IOMedia" );
+ if( dictionary ) {
+ dev_name = OSString::withCString( cdev_name );
+ if( dev_name ) {
+ IOService *service;
+ mach_timespec_t tv = { 5, 0 }; // wait up to "timeout" seconds for the device
+
+ dictionary->setObject( kIOBSDNameKey, dev_name );
+ dictionary->retain();
+ service = IOService::waitForService( dictionary, &tv );
+ if( service ) {
+ OSBoolean *ejectable = (OSBoolean *) service->getProperty( "Ejectable" );
+
+ if( ejectable ) {
+ ret = (int)ejectable->getValue();
+ }
+
+ }
+ dev_name->release();
+ }
+ dictionary->release();
+ }
+
+ return ret;
+}
+