-
-/*****************************************************************************
- * GetEjectableMediaOfClass
- *****************************************************************************/
-NSArray *GetEjectableMediaOfClass( const char *psz_class )
-{
- io_object_t next_media;
- mach_port_t master_port;
- kern_return_t kern_result;
- NSArray *o_devices = nil;
- NSMutableArray *p_list = nil;
- io_iterator_t media_iterator;
- CFMutableDictionaryRef classes_to_match;
-
- kern_result = IOMasterPort( MACH_PORT_NULL, &master_port );
- if( kern_result != KERN_SUCCESS )
- {
- return( nil );
- }
-
- classes_to_match = IOServiceMatching( psz_class );
- if( classes_to_match == NULL )
- {
- return( nil );
- }
-
- CFDictionarySetValue( classes_to_match, CFSTR( kIOMediaEjectableKey ),
- kCFBooleanTrue );
-
- kern_result = IOServiceGetMatchingServices( master_port, classes_to_match,
- &media_iterator );
- if( kern_result != KERN_SUCCESS )
- {
- return( nil );
- }
-
- p_list = [NSMutableArray arrayWithCapacity: 1];
-
- next_media = IOIteratorNext( media_iterator );
- if( next_media )
- {
- char psz_buf[0x32];
- size_t dev_path_length;
- CFTypeRef str_bsd_path;
-
- do
- {
- str_bsd_path = IORegistryEntryCreateCFProperty( next_media,
- CFSTR( kIOBSDNameKey ),
- kCFAllocatorDefault,
- 0 );
- if( str_bsd_path == NULL )
- {
- IOObjectRelease( next_media );
- continue;
- }
-
- snprintf( psz_buf, sizeof(psz_buf), "%s%c", _PATH_DEV, 'r' );
- dev_path_length = strlen( psz_buf );
-
- if( CFStringGetCString( str_bsd_path,
- (char*)&psz_buf + dev_path_length,
- sizeof(psz_buf) - dev_path_length,
- kCFStringEncodingASCII ) )
- {
- [p_list addObject: [NSString stringWithUTF8String: psz_buf]];
- }
-
- CFRelease( str_bsd_path );
-
- IOObjectRelease( next_media );
-
- } while( ( next_media = IOIteratorNext( media_iterator ) ) );
- }
-
- IOObjectRelease( media_iterator );
-
- o_devices = [NSArray arrayWithArray: p_list];
-
- return( o_devices );
-}