1/* 2 * Copyright (c) 2014 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 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. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24#include "device.h" 25 26#include "storage/storage.h" 27#include "usb/usb.h" 28 29#include <IOKit/storage/IOMedia.h> 30#include <IOKit/usb/IOUSBLib.h> 31 32CFDictionaryRef _DeviceCopyIdentifier( io_service_t service ) 33{ 34 CFDictionaryRef identifier = 0; 35 36 if ( IOObjectConformsTo( service, kIOMediaClass ) ) 37 { 38 identifier = _IOMediaCopyIdentifier( service ); 39 } 40 else if ( IOObjectConformsTo( service, kIOUSBDeviceClassName ) ) 41 { 42 identifier = _IOUSBDeviceCopyIdentifier( service ); 43 } 44 45 return identifier; 46} 47 48CFStringRef _DeviceCopyName( CFDictionaryRef identifier ) 49{ 50 CFStringRef class; 51 CFStringRef name = 0; 52 53 class = CFDictionaryGetValue( identifier, CFSTR( kIOProviderClassKey ) ); 54 55 if ( CFEqual( class, CFSTR( kIOMediaClass ) ) ) 56 { 57 name = _IOMediaCopyName( identifier ); 58 } 59 else if ( CFEqual( class, CFSTR( kIOUSBDeviceClassName ) ) ) 60 { 61 name = _IOUSBDeviceCopyName( identifier ); 62 } 63 64 return name; 65} 66 67Boolean _DeviceIsEqual( CFDictionaryRef identifier1, CFDictionaryRef identifier2 ) 68{ 69 CFStringRef class; 70 Boolean equal = FALSE; 71 72 class = CFDictionaryGetValue( identifier1, CFSTR( kIOProviderClassKey ) ); 73 74 if ( CFEqual( class, CFDictionaryGetValue( identifier2, CFSTR( kIOProviderClassKey ) ) ) ) 75 { 76 if ( CFEqual( class, CFSTR( kIOMediaClass ) ) ) 77 { 78 equal = _IOMediaIsEqual( identifier1, identifier2 ); 79 } 80 else if ( CFEqual( class, CFSTR( kIOUSBDeviceClassName ) ) ) 81 { 82 equal = _IOUSBDeviceIsEqual( identifier1, identifier2 ); 83 } 84 } 85 86 return equal; 87} 88 89Boolean _DeviceIsValid( io_service_t service ) 90{ 91 Boolean valid = FALSE; 92 93 if ( IOObjectConformsTo( service, kIOMediaClass ) ) 94 { 95 valid = _IOMediaIsValid( service ); 96 } 97 else if ( IOObjectConformsTo( service, kIOUSBDeviceClassName ) ) 98 { 99 valid = _IOUSBDeviceIsValid( service ); 100 } 101 102 return valid; 103} 104