+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;
+}
+