Some cleanups, possibly bug fixes. Hack in optimistic guess for drive properties.

This commit is contained in:
rocky
2004-08-28 16:06:25 +00:00
parent 1949a54ec9
commit 1db61171af

View File

@@ -1,5 +1,5 @@
/* /*
$Id: _cdio_osx.c,v 1.61 2004/08/28 09:15:41 rocky Exp $ $Id: _cdio_osx.c,v 1.62 2004/08/28 16:06:25 rocky Exp $
Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
from vcdimager code: from vcdimager code:
@@ -34,7 +34,7 @@
#include "config.h" #include "config.h"
#endif #endif
static const char _rcsid[] = "$Id: _cdio_osx.c,v 1.61 2004/08/28 09:15:41 rocky Exp $"; static const char _rcsid[] = "$Id: _cdio_osx.c,v 1.62 2004/08/28 16:06:25 rocky Exp $";
#include <cdio/sector.h> #include <cdio/sector.h>
#include <cdio/util.h> #include <cdio/util.h>
@@ -114,7 +114,6 @@ typedef struct {
track_t i_last_session; /* highest session number */ track_t i_last_session; /* highest session number */
track_t i_first_session; /* first session number */ track_t i_first_session; /* first session number */
lsn_t *pp_lba; lsn_t *pp_lba;
CFMutableDictionaryRef dict;
io_service_t MediaClass_service; io_service_t MediaClass_service;
char psz_MediaClass_service[MAX_SERVICE_NAME]; char psz_MediaClass_service[MAX_SERVICE_NAME];
SCSITaskDeviceInterface **pp_scsiTaskDeviceInterface; SCSITaskDeviceInterface **pp_scsiTaskDeviceInterface;
@@ -131,17 +130,14 @@ static bool read_toc_osx (void *p_user_data);
static CFMutableDictionaryRef static CFMutableDictionaryRef
GetRegistryEntryProperties ( io_service_t service ) GetRegistryEntryProperties ( io_service_t service )
{ {
IOReturn err = kIOReturnSuccess; IOReturn err = kIOReturnSuccess;
CFMutableDictionaryRef dict = 0; CFMutableDictionaryRef dict = 0;
err = IORegistryEntryCreateCFProperties ( service, err = IORegistryEntryCreateCFProperties (service, &dict, kCFAllocatorDefault, 0);
&dict, if ( err != kIOReturnSuccess )
kCFAllocatorDefault, cdio_warn( "IORegistryEntryCreateCFProperties: 0x%08x", err );
0 );
check ( err == kIOReturnSuccess );
return dict;
return dict;
} }
@@ -215,25 +211,15 @@ init_osx(_img_private_t *p_env) {
IOObjectRelease( iterator ); IOObjectRelease( iterator );
} }
if( p_env->MediaClass_service == 0 ) if ( 0 == p_env->MediaClass_service ) {
{ cdio_warn( "search for kIOCDMediaClass/kIODVDMediaClass came up empty" );
cdio_warn( "search for kIOCDMediaClass came up empty" );
return false;
}
/* create a CF dictionary containing the TOC */
ret = IORegistryEntryCreateCFProperties( p_env->MediaClass_service,
&(p_env->dict),
kCFAllocatorDefault,
kNilOptions );
if( ret != KERN_SUCCESS )
{
cdio_warn( "IORegistryEntryCreateCFProperties: 0x%08x", ret );
IOObjectRelease( p_env->MediaClass_service );
return false; return false;
} }
/* Save the name so we can compare against this in case we have to do
another scan. FIXME: this is hoaky and there's got to be a better
variable to test or way to do.
*/
IORegistryEntryGetPath(p_env->MediaClass_service, kIOServicePlane, IORegistryEntryGetPath(p_env->MediaClass_service, kIOServicePlane,
p_env->psz_MediaClass_service); p_env->psz_MediaClass_service);
return true; return true;
@@ -433,7 +419,7 @@ get_discmode_osx (void *p_user_data)
i_discmode = CDIO_DISC_MODE_CD_DATA; i_discmode = CDIO_DISC_MODE_CD_DATA;
else if (0 == strncmp(str, "CDRW", sizeof(str)) ) else if (0 == strncmp(str, "CDRW", sizeof(str)) )
i_discmode = CDIO_DISC_MODE_CD_DATA; i_discmode = CDIO_DISC_MODE_CD_DATA;
CFRelease( data ); //?? Handled by below? CFRelease( data );
} }
CFRelease( propertiesDict ); CFRelease( propertiesDict );
if (CDIO_DISC_MODE_CD_DATA == i_discmode) { if (CDIO_DISC_MODE_CD_DATA == i_discmode) {
@@ -541,8 +527,18 @@ get_drive_cap_osx(const void *p_user_data,
*p_write_cap |= CDIO_DRIVE_CAP_WRITE_DVD_PRW; *p_write_cap |= CDIO_DRIVE_CAP_WRITE_DVD_PRW;
***/ ***/
/* FIXME: fill out */ /* FIXME: fill out. For now assume CD-ROM is relatively modern. */
*p_misc_cap = 0; *p_misc_cap = (
CDIO_DRIVE_CAP_MISC_CLOSE_TRAY
| CDIO_DRIVE_CAP_MISC_EJECT
| CDIO_DRIVE_CAP_MISC_LOCK
| CDIO_DRIVE_CAP_MISC_SELECT_SPEED
| CDIO_DRIVE_CAP_MISC_MULTI_SESSION
| CDIO_DRIVE_CAP_MISC_MEDIA_CHANGED
| CDIO_DRIVE_CAP_MISC_RESET
| CDIO_DRIVE_CAP_MCN
| CDIO_DRIVE_CAP_ISRC
);
IOObjectRelease( service ); IOObjectRelease( service );
} }
@@ -584,8 +580,8 @@ get_hwinfo_osx ( const CdIo *p_cdio, /*out*/ cdio_hwinfo_t *hw_info)
CFDictionaryGetValue ( deviceDict, CFSTR ( kIOPropertyVendorNameKey ) ); CFDictionaryGetValue ( deviceDict, CFSTR ( kIOPropertyVendorNameKey ) );
if ( CFStringGetCString( vendor, if ( CFStringGetCString( vendor,
(char *) &(hw_info->vendor), (char *) &(hw_info->psz_vendor),
sizeof(hw_info->vendor), sizeof(hw_info->psz_vendor),
kCFStringEncodingASCII ) ) kCFStringEncodingASCII ) )
CFRelease( vendor ); CFRelease( vendor );
@@ -593,8 +589,8 @@ get_hwinfo_osx ( const CdIo *p_cdio, /*out*/ cdio_hwinfo_t *hw_info)
CFDictionaryGetValue ( deviceDict, CFSTR ( kIOPropertyProductNameKey ) ); CFDictionaryGetValue ( deviceDict, CFSTR ( kIOPropertyProductNameKey ) );
if ( CFStringGetCString( product, if ( CFStringGetCString( product,
(char *) &(hw_info->model), (char *) &(hw_info->psz_model),
sizeof(hw_info->model), sizeof(hw_info->psz_model),
kCFStringEncodingASCII ) ) kCFStringEncodingASCII ) )
CFRelease( product ); CFRelease( product );
@@ -603,8 +599,8 @@ get_hwinfo_osx ( const CdIo *p_cdio, /*out*/ cdio_hwinfo_t *hw_info)
CFSTR ( kIOPropertyProductRevisionLevelKey ) ); CFSTR ( kIOPropertyProductRevisionLevelKey ) );
if ( CFStringGetCString( product, if ( CFStringGetCString( product,
(char *) &(hw_info->revision), (char *) &(hw_info->psz_revision),
sizeof(hw_info->revision), sizeof(hw_info->psz_revision),
kCFStringEncodingASCII ) ) kCFStringEncodingASCII ) )
CFRelease( revision ); CFRelease( revision );
} }
@@ -633,7 +629,6 @@ _free_osx (void *p_user_data) {
cdio_generic_free(p_env); cdio_generic_free(p_env);
if (NULL != p_env->pp_lba) free((void *) p_env->pp_lba); if (NULL != p_env->pp_lba) free((void *) p_env->pp_lba);
if (NULL != p_env->pTOC) free((void *) p_env->pTOC); if (NULL != p_env->pTOC) free((void *) p_env->pTOC);
if (NULL != p_env->dict) CFRelease( p_env->dict );
IOObjectRelease( p_env->MediaClass_service ); IOObjectRelease( p_env->MediaClass_service );
if (NULL != p_env->pp_scsiTaskDeviceInterface) if (NULL != p_env->pp_scsiTaskDeviceInterface)
@@ -846,13 +841,20 @@ static bool
read_toc_osx (void *p_user_data) read_toc_osx (void *p_user_data)
{ {
_img_private_t *p_env = p_user_data; _img_private_t *p_env = p_user_data;
CFDictionaryRef propertiesDict = 0;
CFDataRef data; CFDataRef data;
/* create a CF dictionary containing the TOC */
propertiesDict = GetRegistryEntryProperties( p_env->MediaClass_service );
if ( 0 == propertiesDict ) {
return false;
}
/* get the TOC from the dictionary */ /* get the TOC from the dictionary */
data = (CFDataRef) CFDictionaryGetValue( p_env->dict, data = (CFDataRef) CFDictionaryGetValue( propertiesDict,
CFSTR(kIOCDMediaTOCKey) ); CFSTR(kIOCDMediaTOCKey) );
if( data != NULL ) if ( data != NULL ) {
{
CFRange range; CFRange range;
CFIndex buf_len; CFIndex buf_len;
@@ -865,15 +867,13 @@ read_toc_osx (void *p_user_data)
cdio_warn( "Trouble allocating CDROM TOC" ); cdio_warn( "Trouble allocating CDROM TOC" );
return false; return false;
} }
} } else {
else
{
cdio_warn( "CFDictionaryGetValue failed" ); cdio_warn( "CFDictionaryGetValue failed" );
return false; return false;
} }
/* TestDevice(p_env, service); */ /* TestDevice(p_env, service); */
IOObjectRelease( p_env->MediaClass_service ); CFRelease( propertiesDict );
p_env->i_descriptors = CDTOCGetDescriptorCount ( p_env->pTOC ); p_env->i_descriptors = CDTOCGetDescriptorCount ( p_env->pTOC );