2003-09-13 06:25:36 +00:00
|
|
|
|
/*
|
2004-06-16 04:51:29 +00:00
|
|
|
|
$Id: _cdio_osx.c,v 1.35 2004/06/16 04:51:29 thesin Exp $
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
2004-03-09 02:55:37 +00:00
|
|
|
|
Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
|
|
|
|
|
|
from vcdimager code:
|
2003-09-13 06:25:36 +00:00
|
|
|
|
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
|
|
|
|
|
|
and VideoLAN code Copyright (C) 1998-2001 VideoLAN
|
|
|
|
|
|
Authors: Johan Bilien <jobi@via.ecp.fr>
|
|
|
|
|
|
Gildas Bazin <gbazin@netcourrier.com>
|
|
|
|
|
|
Jon Lech Johansen <jon-vl@nanocrew.net>
|
2003-10-08 01:06:19 +00:00
|
|
|
|
Derk-Jan Hartman <hartman at videolan.org>
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2003-09-14 01:21:41 +00:00
|
|
|
|
/* This file contains OSX-specific code and implements low-level
|
2003-09-13 06:25:36 +00:00
|
|
|
|
control of the CD drive.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2004-06-02 07:40:13 +00:00
|
|
|
|
#include "config.h"
|
2003-09-13 06:25:36 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2004-06-16 04:51:29 +00:00
|
|
|
|
static const char _rcsid[] = "$Id: _cdio_osx.c,v 1.35 2004/06/16 04:51:29 thesin Exp $";
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
|
|
|
|
|
#include <cdio/sector.h>
|
|
|
|
|
|
#include <cdio/util.h>
|
|
|
|
|
|
#include "cdio_assert.h"
|
|
|
|
|
|
#include "cdio_private.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
2003-10-04 20:11:27 +00:00
|
|
|
|
#ifdef HAVE_DARWIN_CDROM
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
2003-10-08 01:06:19 +00:00
|
|
|
|
#include <paths.h>
|
2003-09-13 06:25:36 +00:00
|
|
|
|
#include <CoreFoundation/CFBase.h>
|
2003-10-08 01:06:19 +00:00
|
|
|
|
#include <CoreFoundation/CFString.h>
|
|
|
|
|
|
#include <CoreFoundation/CFNumber.h>
|
2003-09-13 06:25:36 +00:00
|
|
|
|
#include <IOKit/IOKitLib.h>
|
2003-10-08 01:06:19 +00:00
|
|
|
|
#include <IOKit/IOBSD.h>
|
2003-09-13 06:25:36 +00:00
|
|
|
|
#include <IOKit/storage/IOCDTypes.h>
|
2004-06-01 03:44:55 +00:00
|
|
|
|
#include <IOKit/storage/IODVDTypes.h>
|
2003-10-08 01:06:19 +00:00
|
|
|
|
#include <IOKit/storage/IOMedia.h>
|
2003-09-13 06:25:36 +00:00
|
|
|
|
#include <IOKit/storage/IOCDMedia.h>
|
|
|
|
|
|
#include <IOKit/storage/IOCDMediaBSDClient.h>
|
2004-06-01 03:44:55 +00:00
|
|
|
|
#include <IOKit/storage/IODVDMediaBSDClient.h>
|
|
|
|
|
|
|
2004-06-06 10:50:55 +00:00
|
|
|
|
#define TOTAL_TRACKS (env->i_last_track - env->i_first_track)
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
2004-06-01 16:02:46 +00:00
|
|
|
|
#define CDROM_CDI_TRACK 0x1
|
2004-06-06 10:50:55 +00:00
|
|
|
|
#define CDROM_XA_TRACK 0x2
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
2004-05-01 01:05:26 +00:00
|
|
|
|
typedef enum {
|
2004-04-30 06:54:15 +00:00
|
|
|
|
_AM_NONE,
|
|
|
|
|
|
_AM_OSX,
|
|
|
|
|
|
} access_mode_t;
|
|
|
|
|
|
|
2003-09-13 06:25:36 +00:00
|
|
|
|
typedef struct {
|
|
|
|
|
|
/* Things common to all drivers like this.
|
|
|
|
|
|
This must be first. */
|
|
|
|
|
|
generic_img_private_t gen;
|
|
|
|
|
|
|
2004-04-30 06:54:15 +00:00
|
|
|
|
access_mode_t access_mode;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
|
|
|
|
|
/* Track information */
|
2004-06-06 10:50:55 +00:00
|
|
|
|
bool toc_init; /* if true, info below is valid. */
|
2003-09-13 06:25:36 +00:00
|
|
|
|
CDTOC *pTOC;
|
|
|
|
|
|
int i_descriptors;
|
2004-06-06 11:25:13 +00:00
|
|
|
|
track_t i_last_track; /* highest track number */
|
2004-06-06 10:50:55 +00:00
|
|
|
|
track_t i_first_track; /* first track */
|
2003-09-15 01:37:32 +00:00
|
|
|
|
lsn_t *pp_lba;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
|
|
|
|
|
} _img_private_t;
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-06-02 04:52:55 +00:00
|
|
|
|
_free_osx (void *user_data) {
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
|
|
|
|
|
if (NULL == env) return;
|
|
|
|
|
|
cdio_generic_free(env);
|
|
|
|
|
|
if (NULL != env->pp_lba) free((void *) env->pp_lba);
|
|
|
|
|
|
if (NULL != env->pTOC) free((void *) env->pTOC);
|
2003-09-13 06:25:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
|
cdio_getNumberOfTracks: get number of tracks in TOC
|
|
|
|
|
|
This is an internal routine and is called once per CD open.
|
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
static track_t
|
2004-06-06 10:50:55 +00:00
|
|
|
|
getNumberOfTracks_osx( CDTOC *pTOC, int i_descriptors )
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
2004-06-06 10:50:55 +00:00
|
|
|
|
track_t i_track = CDIO_INVALID_TRACK;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
int i;
|
|
|
|
|
|
int i_tracks = 0;
|
|
|
|
|
|
CDTOCDescriptor *pTrackDescriptors;
|
|
|
|
|
|
|
|
|
|
|
|
pTrackDescriptors = pTOC->descriptors;
|
|
|
|
|
|
|
|
|
|
|
|
for( i = i_descriptors; i >= 0; i-- )
|
|
|
|
|
|
{
|
2004-06-06 10:50:55 +00:00
|
|
|
|
i_track = pTrackDescriptors[i].point;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
2004-06-16 04:51:29 +00:00
|
|
|
|
if( i_track > CDIO_CD_MAX_TRACKS || i_track < CDIO_CD_MIN_TRACK_NO || i_track == 0xA2 )
|
2003-09-13 06:25:36 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
i_tracks++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return( i_tracks );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-06-06 10:50:55 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Return the number of the first track.
|
|
|
|
|
|
CDIO_INVALID_TRACK is returned on error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static track_t
|
|
|
|
|
|
getFirstTrack_osx( CDTOC *pTOC, int i_descriptors )
|
|
|
|
|
|
{
|
|
|
|
|
|
track_t i_track = CDIO_INVALID_TRACK;
|
|
|
|
|
|
int i;
|
|
|
|
|
|
CDTOCDescriptor *pTrackDescriptors;
|
|
|
|
|
|
|
|
|
|
|
|
pTrackDescriptors = pTOC->descriptors;
|
|
|
|
|
|
|
2004-06-13 21:43:41 +00:00
|
|
|
|
for( i = 0; i <= i_descriptors; i++ )
|
2004-06-06 10:50:55 +00:00
|
|
|
|
{
|
|
|
|
|
|
i_track = pTrackDescriptors[i].point;
|
|
|
|
|
|
|
2004-06-16 04:51:29 +00:00
|
|
|
|
if( i_track > CDIO_CD_MAX_TRACKS || i_track < CDIO_CD_MIN_TRACK_NO || i_track == 0xA2 )
|
2004-06-06 10:50:55 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
return ( i_track );
|
|
|
|
|
|
}
|
|
|
|
|
|
return CDIO_INVALID_TRACK;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-09-13 06:25:36 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Reads nblocks of mode2 form2 sectors from cd device into data starting
|
|
|
|
|
|
from lsn.
|
|
|
|
|
|
Returns 0 if no error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_get_read_mode1_sectors_osx (void *user_data, void *data, lsn_t lsn,
|
2004-06-06 10:50:55 +00:00
|
|
|
|
bool b_form2, unsigned int nblocks)
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
dk_cd_read_t cd_read;
|
|
|
|
|
|
|
|
|
|
|
|
memset( &cd_read, 0, sizeof(cd_read) );
|
|
|
|
|
|
|
2004-03-09 02:55:37 +00:00
|
|
|
|
cd_read.sectorArea = kCDSectorAreaUser;
|
|
|
|
|
|
cd_read.buffer = data;
|
|
|
|
|
|
cd_read.sectorType = kCDSectorTypeMode1;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
2004-04-25 15:41:26 +00:00
|
|
|
|
if (b_form2) {
|
2004-03-09 02:55:37 +00:00
|
|
|
|
cd_read.offset = lsn * kCDSectorSizeMode2;
|
|
|
|
|
|
cd_read.bufferLength = kCDSectorSizeMode2 * nblocks;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
cd_read.offset = lsn * kCDSectorSizeMode1;
|
|
|
|
|
|
cd_read.bufferLength = kCDSectorSizeMode1 * nblocks;
|
|
|
|
|
|
}
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
if( ioctl( env->gen.fd, DKIOCCDREAD, &cd_read ) == -1 )
|
2003-10-08 01:06:19 +00:00
|
|
|
|
{
|
|
|
|
|
|
cdio_error( "could not read block %d, %s", lsn, strerror(errno) );
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2003-09-13 06:25:36 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2004-03-09 02:55:37 +00:00
|
|
|
|
Reads nblocks of mode2 form2 sectors from cd device into data starting
|
2003-09-13 06:25:36 +00:00
|
|
|
|
from lsn.
|
|
|
|
|
|
Returns 0 if no error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_get_read_mode2_sectors_osx (void *user_data, void *data, lsn_t lsn,
|
2004-06-06 10:50:55 +00:00
|
|
|
|
bool b_form2, unsigned int nblocks)
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-10-08 01:06:19 +00:00
|
|
|
|
dk_cd_read_t cd_read;
|
|
|
|
|
|
|
|
|
|
|
|
memset( &cd_read, 0, sizeof(cd_read) );
|
|
|
|
|
|
|
|
|
|
|
|
cd_read.sectorArea = kCDSectorAreaUser;
|
|
|
|
|
|
cd_read.buffer = data;
|
2004-03-09 02:55:37 +00:00
|
|
|
|
|
2004-04-25 15:41:26 +00:00
|
|
|
|
if (b_form2) {
|
2004-03-09 02:55:37 +00:00
|
|
|
|
cd_read.offset = lsn * kCDSectorSizeMode2Form2;
|
|
|
|
|
|
cd_read.sectorType = kCDSectorTypeMode2Form2;
|
|
|
|
|
|
cd_read.bufferLength = kCDSectorSizeMode2Form2 * nblocks;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
cd_read.offset = lsn * kCDSectorSizeMode2Form1;
|
|
|
|
|
|
cd_read.sectorType = kCDSectorTypeMode2Form1;
|
|
|
|
|
|
cd_read.bufferLength = kCDSectorSizeMode2Form1 * nblocks;
|
|
|
|
|
|
}
|
2003-10-08 01:06:19 +00:00
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
if( ioctl( env->gen.fd, DKIOCCDREAD, &cd_read ) == -1 )
|
2003-10-08 01:06:19 +00:00
|
|
|
|
{
|
|
|
|
|
|
cdio_error( "could not read block %d, %s", lsn, strerror(errno) );
|
|
|
|
|
|
return -1;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-03-09 02:55:37 +00:00
|
|
|
|
|
2003-09-13 06:25:36 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Reads a single audio sector from CD device into data starting from lsn.
|
|
|
|
|
|
Returns 0 if no error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_get_read_audio_sectors_osx (void *user_data, void *data, lsn_t lsn,
|
2004-06-06 10:50:55 +00:00
|
|
|
|
unsigned int nblocks)
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-10-08 01:06:19 +00:00
|
|
|
|
dk_cd_read_t cd_read;
|
|
|
|
|
|
|
|
|
|
|
|
memset( &cd_read, 0, sizeof(cd_read) );
|
|
|
|
|
|
|
|
|
|
|
|
cd_read.offset = lsn * kCDSectorSizeCDDA;
|
|
|
|
|
|
cd_read.sectorArea = kCDSectorAreaUser;
|
|
|
|
|
|
cd_read.sectorType = kCDSectorTypeCDDA;
|
|
|
|
|
|
|
|
|
|
|
|
cd_read.buffer = data;
|
|
|
|
|
|
cd_read.bufferLength = kCDSectorSizeCDDA * nblocks;
|
|
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
if( ioctl( env->gen.fd, DKIOCCDREAD, &cd_read ) == -1 )
|
2003-10-08 01:06:19 +00:00
|
|
|
|
{
|
|
|
|
|
|
cdio_error( "could not read block %d", lsn );
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-03-09 02:55:37 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Reads a single mode2 sector from cd device into data starting
|
|
|
|
|
|
from lsn. Returns 0 if no error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_get_read_mode1_sector_osx (void *user_data, void *data, lsn_t lsn,
|
|
|
|
|
|
bool b_form2)
|
2004-03-09 02:55:37 +00:00
|
|
|
|
{
|
2004-06-02 01:01:18 +00:00
|
|
|
|
return _get_read_mode1_sectors_osx(user_data, data, lsn, b_form2, 1);
|
2004-03-09 02:55:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-09-13 06:25:36 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Reads a single mode2 sector from cd device into data starting
|
|
|
|
|
|
from lsn. Returns 0 if no error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_get_read_mode2_sector_osx (void *user_data, void *data, lsn_t lsn,
|
|
|
|
|
|
bool b_form2)
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
2004-06-02 01:01:18 +00:00
|
|
|
|
return _get_read_mode2_sectors_osx(user_data, data, lsn, b_form2, 1);
|
2003-09-13 06:25:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Set the key "arg" to "value" in source device.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_set_arg_osx (void *user_data, const char key[], const char value[])
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
|
|
|
|
|
if (!strcmp (key, "source"))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!value)
|
|
|
|
|
|
return -2;
|
|
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
free (env->gen.source_name);
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
env->gen.source_name = strdup (value);
|
2003-09-13 06:25:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (!strcmp (key, "access-mode"))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!strcmp(value, "OSX"))
|
2004-06-02 00:43:53 +00:00
|
|
|
|
env->access_mode = _AM_OSX;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
else
|
|
|
|
|
|
cdio_error ("unknown access type: %s. ignored.", value);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Read and cache the CD's Track Table of Contents and track info.
|
|
|
|
|
|
Return false if successful or true if an error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static bool
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_cdio_read_toc (_img_private_t *env)
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
mach_port_t port;
|
|
|
|
|
|
char *psz_devname;
|
|
|
|
|
|
kern_return_t ret;
|
|
|
|
|
|
io_iterator_t iterator;
|
|
|
|
|
|
io_registry_entry_t service;
|
|
|
|
|
|
CFMutableDictionaryRef properties;
|
|
|
|
|
|
CFDataRef data;
|
|
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
env->gen.fd = open( env->gen.source_name, O_RDONLY | O_NONBLOCK );
|
|
|
|
|
|
if (-1 == env->gen.fd) {
|
|
|
|
|
|
cdio_error("Failed to open %s: %s", env->gen.source_name,
|
2003-09-13 06:25:36 +00:00
|
|
|
|
strerror(errno));
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* get the device name */
|
2004-06-02 00:43:53 +00:00
|
|
|
|
if( ( psz_devname = strrchr( env->gen.source_name, '/') ) != NULL )
|
2003-09-13 06:25:36 +00:00
|
|
|
|
++psz_devname;
|
|
|
|
|
|
else
|
2004-06-02 00:43:53 +00:00
|
|
|
|
psz_devname = env->gen.source_name;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
|
|
|
|
|
/* unraw the device name */
|
|
|
|
|
|
if( *psz_devname == 'r' )
|
|
|
|
|
|
++psz_devname;
|
|
|
|
|
|
|
|
|
|
|
|
/* get port for IOKit communication */
|
|
|
|
|
|
if( ( ret = IOMasterPort( MACH_PORT_NULL, &port ) ) != KERN_SUCCESS )
|
|
|
|
|
|
{
|
|
|
|
|
|
cdio_error( "IOMasterPort: 0x%08x", ret );
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* get service iterator for the device */
|
|
|
|
|
|
if( ( ret = IOServiceGetMatchingServices(
|
|
|
|
|
|
port, IOBSDNameMatching( port, 0, psz_devname ),
|
|
|
|
|
|
&iterator ) ) != KERN_SUCCESS )
|
|
|
|
|
|
{
|
|
|
|
|
|
cdio_error( "IOServiceGetMatchingServices: 0x%08x", ret );
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* first service */
|
|
|
|
|
|
service = IOIteratorNext( iterator );
|
|
|
|
|
|
IOObjectRelease( iterator );
|
|
|
|
|
|
|
|
|
|
|
|
/* search for kIOCDMediaClass */
|
|
|
|
|
|
while( service && !IOObjectConformsTo( service, kIOCDMediaClass ) )
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
ret = IORegistryEntryGetParentIterator( service, kIOServicePlane,
|
|
|
|
|
|
&iterator );
|
|
|
|
|
|
if( ret != KERN_SUCCESS )
|
|
|
|
|
|
{
|
|
|
|
|
|
cdio_error( "IORegistryEntryGetParentIterator: 0x%08x", ret );
|
|
|
|
|
|
IOObjectRelease( service );
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IOObjectRelease( service );
|
|
|
|
|
|
service = IOIteratorNext( iterator );
|
|
|
|
|
|
IOObjectRelease( iterator );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-09-14 17:04:48 +00:00
|
|
|
|
if( service == 0 )
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
cdio_error( "search for kIOCDMediaClass came up empty" );
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* create a CF dictionary containing the TOC */
|
|
|
|
|
|
ret = IORegistryEntryCreateCFProperties( service, &properties,
|
|
|
|
|
|
kCFAllocatorDefault, kNilOptions );
|
|
|
|
|
|
|
|
|
|
|
|
if( ret != KERN_SUCCESS )
|
|
|
|
|
|
{
|
|
|
|
|
|
cdio_error( "IORegistryEntryCreateCFProperties: 0x%08x", ret );
|
|
|
|
|
|
IOObjectRelease( service );
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* get the TOC from the dictionary */
|
|
|
|
|
|
data = (CFDataRef) CFDictionaryGetValue( properties,
|
|
|
|
|
|
CFSTR(kIOCDMediaTOCKey) );
|
|
|
|
|
|
if( data != NULL )
|
|
|
|
|
|
{
|
|
|
|
|
|
CFRange range;
|
|
|
|
|
|
CFIndex buf_len;
|
|
|
|
|
|
|
|
|
|
|
|
buf_len = CFDataGetLength( data ) + 1;
|
|
|
|
|
|
range = CFRangeMake( 0, buf_len );
|
|
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
if( ( env->pTOC = (CDTOC *)malloc( buf_len ) ) != NULL ) {
|
|
|
|
|
|
CFDataGetBytes( data, range, (u_char *) env->pTOC );
|
2003-09-13 06:25:36 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
cdio_error( "Trouble allocating CDROM TOC" );
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
cdio_error( "CFDictionaryGetValue failed" );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CFRelease( properties );
|
|
|
|
|
|
IOObjectRelease( service );
|
|
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
env->i_descriptors = CDTOCGetDescriptorCount ( env->pTOC );
|
2004-06-06 10:50:55 +00:00
|
|
|
|
env->i_first_track = getFirstTrack_osx(env->pTOC, env->i_descriptors);
|
2004-06-16 04:51:29 +00:00
|
|
|
|
env->i_last_track = getNumberOfTracks_osx(env->pTOC, env->i_descriptors);
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
|
|
|
|
|
/* Read in starting sectors */
|
|
|
|
|
|
{
|
|
|
|
|
|
int i, i_leadout = -1;
|
|
|
|
|
|
CDTOCDescriptor *pTrackDescriptors;
|
2004-06-06 10:50:55 +00:00
|
|
|
|
track_t i_track;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
int i_tracks;
|
|
|
|
|
|
|
2004-06-06 10:50:55 +00:00
|
|
|
|
env->pp_lba = malloc( TOTAL_TRACKS * sizeof(int) );
|
2004-06-02 00:43:53 +00:00
|
|
|
|
if( env->pp_lba == NULL )
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
cdio_error("Out of memory in allocating track starting LSNs" );
|
2004-06-02 00:43:53 +00:00
|
|
|
|
free( env->pTOC );
|
2003-09-13 06:25:36 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
pTrackDescriptors = env->pTOC->descriptors;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
for( i_tracks = 0, i = 0; i <= env->i_descriptors; i++ )
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
2004-06-06 10:50:55 +00:00
|
|
|
|
i_track = pTrackDescriptors[i].point;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
2004-06-06 10:50:55 +00:00
|
|
|
|
if( i_track == 0xA2 )
|
2003-09-14 14:44:26 +00:00
|
|
|
|
/* Note leadout should be 0xAA, But OSX seems to use 0xA2. */
|
2003-09-13 06:25:36 +00:00
|
|
|
|
i_leadout = i;
|
|
|
|
|
|
|
2004-06-06 10:50:55 +00:00
|
|
|
|
if( i_track > CDIO_CD_MAX_TRACKS || i_track < CDIO_CD_MIN_TRACK_NO )
|
2003-09-13 06:25:36 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
|
2004-06-16 04:51:29 +00:00
|
|
|
|
env->pp_lba[i_tracks--] =
|
2003-09-15 01:37:32 +00:00
|
|
|
|
cdio_lsn_to_lba(CDConvertMSFToLBA( pTrackDescriptors[i].p ));
|
2003-09-13 06:25:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( i_leadout == -1 )
|
|
|
|
|
|
{
|
|
|
|
|
|
cdio_error( "CD leadout not found" );
|
2004-06-02 00:43:53 +00:00
|
|
|
|
free( env->pp_lba );
|
|
|
|
|
|
free( (void *) env->pTOC );
|
2003-09-13 06:25:36 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* set leadout sector */
|
2004-06-16 04:51:29 +00:00
|
|
|
|
env->pp_lba[i_leadout] =
|
2003-09-15 01:37:32 +00:00
|
|
|
|
cdio_lsn_to_lba(CDConvertMSFToLBA( pTrackDescriptors[i_leadout].p ));
|
2003-09-13 06:25:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
env->toc_init = true;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
|
|
|
|
|
return( true );
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2003-09-14 01:21:41 +00:00
|
|
|
|
Return the starting LSN track number
|
2004-06-02 00:43:53 +00:00
|
|
|
|
i_track in obj. Track numbers start at 1.
|
2003-09-13 06:25:36 +00:00
|
|
|
|
The "leadout" track is specified either by
|
2004-06-02 00:43:53 +00:00
|
|
|
|
using i_track LEADOUT_TRACK or the total tracks+1.
|
2003-09-13 06:25:36 +00:00
|
|
|
|
False is returned if there is no track entry.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static lsn_t
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_get_track_lba_osx(void *user_data, track_t i_track)
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
2004-06-06 11:25:13 +00:00
|
|
|
|
if (!env->toc_init) _cdio_read_toc (env) ;
|
|
|
|
|
|
|
2004-06-06 10:50:55 +00:00
|
|
|
|
if (i_track == CDIO_CDROM_LEADOUT_TRACK) i_track = env->i_last_track+1;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
2004-06-06 10:50:55 +00:00
|
|
|
|
if (i_track > env->i_last_track + 1 || i_track < env->i_first_track) {
|
2003-09-13 06:25:36 +00:00
|
|
|
|
return CDIO_INVALID_LSN;
|
|
|
|
|
|
} else {
|
2004-06-06 10:50:55 +00:00
|
|
|
|
return env->pp_lba[i_track - env->i_first_track];
|
2003-09-13 06:25:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Eject media . Return 1 if successful, 0 otherwise.
|
|
|
|
|
|
|
|
|
|
|
|
The only way to cleanly unmount the disc under MacOS X is to use the
|
|
|
|
|
|
'disktool' command line utility. It uses the non-public Disk
|
|
|
|
|
|
Arbitration API, which can not be used by Cocoa or Carbon
|
|
|
|
|
|
applications.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_eject_media_osx (void *user_data) {
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
|
|
|
|
|
FILE *p_eject;
|
|
|
|
|
|
char *psz_disk;
|
|
|
|
|
|
char sz_cmd[32];
|
|
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
if( ( psz_disk = (char *)strstr( env->gen.source_name, "disk" ) ) != NULL &&
|
2003-09-13 06:25:36 +00:00
|
|
|
|
strlen( psz_disk ) > 4 )
|
|
|
|
|
|
{
|
2004-06-01 03:44:55 +00:00
|
|
|
|
#define EJECT_CMD "/usr/sbin/hdiutil eject %s"
|
2003-09-13 06:25:36 +00:00
|
|
|
|
snprintf( sz_cmd, sizeof(sz_cmd), EJECT_CMD, psz_disk );
|
|
|
|
|
|
#undef EJECT_CMD
|
|
|
|
|
|
|
|
|
|
|
|
if( ( p_eject = popen( sz_cmd, "r" ) ) != NULL )
|
|
|
|
|
|
{
|
|
|
|
|
|
char psz_result[0x200];
|
|
|
|
|
|
int i_ret = fread( psz_result, 1, sizeof(psz_result) - 1, p_eject );
|
|
|
|
|
|
|
|
|
|
|
|
if( i_ret == 0 && ferror( p_eject ) != 0 )
|
|
|
|
|
|
{
|
|
|
|
|
|
pclose( p_eject );
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pclose( p_eject );
|
|
|
|
|
|
|
|
|
|
|
|
psz_result[ i_ret ] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if( strstr( psz_result, "Disk Ejected" ) != NULL )
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the size of the CD in logical block address (LBA) units.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static uint32_t
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_stat_size_osx (void *user_data)
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
2004-06-02 01:01:18 +00:00
|
|
|
|
return _get_track_lba_osx(user_data, CDIO_CDROM_LEADOUT_TRACK);
|
2003-09-13 06:25:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the value associated with the key "arg".
|
|
|
|
|
|
*/
|
|
|
|
|
|
static const char *
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_get_arg_osx (void *user_data, const char key[])
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
|
|
|
|
|
if (!strcmp (key, "source")) {
|
2004-06-02 00:43:53 +00:00
|
|
|
|
return env->gen.source_name;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
} else if (!strcmp (key, "access-mode")) {
|
2004-06-02 00:43:53 +00:00
|
|
|
|
switch (env->access_mode) {
|
2003-09-13 06:25:36 +00:00
|
|
|
|
case _AM_OSX:
|
|
|
|
|
|
return "OS X";
|
|
|
|
|
|
case _AM_NONE:
|
|
|
|
|
|
return "no access method";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2003-09-14 14:44:26 +00:00
|
|
|
|
Return the number of the first track.
|
2003-09-13 06:25:36 +00:00
|
|
|
|
CDIO_INVALID_TRACK is returned on error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static track_t
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_get_first_track_num_osx(void *user_data)
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
2004-06-16 04:51:29 +00:00
|
|
|
|
if (!env->toc_init) _cdio_read_toc (env) ;
|
|
|
|
|
|
|
2004-06-06 10:50:55 +00:00
|
|
|
|
return env->i_first_track;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-10-05 14:55:34 +00:00
|
|
|
|
/*!
|
2003-10-08 01:06:19 +00:00
|
|
|
|
Return the media catalog number MCN.
|
|
|
|
|
|
*/
|
2003-10-05 14:55:34 +00:00
|
|
|
|
static char *
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_get_mcn_osx (const void *user_data) {
|
|
|
|
|
|
const _img_private_t *env = user_data;
|
2003-10-08 01:06:19 +00:00
|
|
|
|
dk_cd_read_mcn_t cd_read;
|
2003-10-05 14:55:34 +00:00
|
|
|
|
|
2003-10-08 01:06:19 +00:00
|
|
|
|
memset( &cd_read, 0, sizeof(cd_read) );
|
2003-10-05 14:55:34 +00:00
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
if( ioctl( env->gen.fd, DKIOCCDREADMCN, &cd_read ) < 0 )
|
2003-10-08 01:06:19 +00:00
|
|
|
|
{
|
2004-05-27 10:47:07 +00:00
|
|
|
|
cdio_warn( "could not read MCN, %s", strerror(errno) );
|
2003-10-13 23:41:42 +00:00
|
|
|
|
return NULL;
|
2003-10-08 01:06:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
return strdup((char*)cd_read.mcn);
|
2003-10-05 14:55:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-10-08 01:06:19 +00:00
|
|
|
|
|
2003-09-13 06:25:36 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Return the number of tracks in the current medium.
|
|
|
|
|
|
CDIO_INVALID_TRACK is returned on error.
|
|
|
|
|
|
This is the externally called interface.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static track_t
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_get_num_tracks_osx(void *user_data)
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
2004-06-16 04:51:29 +00:00
|
|
|
|
if (!env->toc_init) _cdio_read_toc (env) ;
|
|
|
|
|
|
|
2004-06-06 10:50:55 +00:00
|
|
|
|
return( TOTAL_TRACKS );
|
2003-09-13 06:25:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Get format of track.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static track_format_t
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_get_track_format_osx(void *user_data, track_t i_track)
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
|
|
|
|
|
dk_cd_read_track_info_t cd_read;
|
2003-10-08 01:06:19 +00:00
|
|
|
|
CDTrackInfo a_track;
|
2004-06-16 04:51:29 +00:00
|
|
|
|
|
2004-06-06 10:50:55 +00:00
|
|
|
|
if (i_track > env->i_last_track || i_track < env->i_first_track)
|
2003-09-13 06:25:36 +00:00
|
|
|
|
return TRACK_FORMAT_ERROR;
|
2003-10-08 01:06:19 +00:00
|
|
|
|
|
|
|
|
|
|
memset( &cd_read, 0, sizeof(cd_read) );
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
cd_read.address = i_track;
|
2003-10-08 01:06:19 +00:00
|
|
|
|
cd_read.addressType = kCDTrackInfoAddressTypeTrackNumber;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
2003-10-08 01:06:19 +00:00
|
|
|
|
cd_read.buffer = &a_track;
|
|
|
|
|
|
cd_read.bufferLength = sizeof(CDTrackInfo);
|
|
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
if( ioctl( env->gen.fd, DKIOCCDREADTRACKINFO, &cd_read ) == -1 )
|
2003-10-08 01:06:19 +00:00
|
|
|
|
{
|
2004-06-02 00:43:53 +00:00
|
|
|
|
cdio_error( "could not read trackinfo for track %d", i_track );
|
2004-06-06 10:50:55 +00:00
|
|
|
|
return TRACK_FORMAT_ERROR;
|
2003-10-08 01:06:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-06-01 16:02:46 +00:00
|
|
|
|
/*cdio_warn( "trackinfo trackMode: %x dataMode: %x", a_track.trackMode, a_track.dataMode );*/
|
2003-10-08 01:06:19 +00:00
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
if (a_track.trackMode == CDIO_CDROM_DATA_TRACK) {
|
2004-06-01 03:44:55 +00:00
|
|
|
|
if (a_track.dataMode == CDROM_CDI_TRACK) {
|
|
|
|
|
|
return TRACK_FORMAT_CDI;
|
|
|
|
|
|
} else if (a_track.dataMode == CDROM_XA_TRACK) {
|
|
|
|
|
|
return TRACK_FORMAT_XA;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return TRACK_FORMAT_DATA;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return TRACK_FORMAT_AUDIO;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-09-13 06:25:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return true if we have XA data (green, mode2 form1) or
|
|
|
|
|
|
XA data (green, mode2 form2). That is track begins:
|
|
|
|
|
|
sync - header - subheader
|
|
|
|
|
|
12 4 - 8
|
|
|
|
|
|
|
|
|
|
|
|
FIXME: there's gotta be a better design for this and get_track_format?
|
|
|
|
|
|
*/
|
|
|
|
|
|
static bool
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_get_track_green_osx(void *user_data, track_t i_track)
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2004-06-01 16:02:46 +00:00
|
|
|
|
CDTrackInfo a_track;
|
2004-06-16 04:51:29 +00:00
|
|
|
|
|
2004-06-06 11:25:13 +00:00
|
|
|
|
if (!env->toc_init) _cdio_read_toc (env) ;
|
|
|
|
|
|
|
2004-06-06 10:50:55 +00:00
|
|
|
|
if ( i_track > env->i_last_track || i_track < env->i_first_track )
|
2003-09-13 06:25:36 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
2004-06-06 10:50:55 +00:00
|
|
|
|
else {
|
2004-06-01 16:02:46 +00:00
|
|
|
|
|
2004-06-06 10:50:55 +00:00
|
|
|
|
dk_cd_read_track_info_t cd_read;
|
|
|
|
|
|
|
|
|
|
|
|
memset( &cd_read, 0, sizeof(cd_read) );
|
|
|
|
|
|
|
|
|
|
|
|
cd_read.address = i_track;
|
|
|
|
|
|
cd_read.addressType = kCDTrackInfoAddressTypeTrackNumber;
|
|
|
|
|
|
|
|
|
|
|
|
cd_read.buffer = &a_track;
|
|
|
|
|
|
cd_read.bufferLength = sizeof(CDTrackInfo);
|
|
|
|
|
|
|
|
|
|
|
|
if( ioctl( env->gen.fd, DKIOCCDREADTRACKINFO, &cd_read ) == -1 ) {
|
|
|
|
|
|
cdio_error( "could not read trackinfo for track %d", i_track );
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2004-06-16 04:51:29 +00:00
|
|
|
|
return ((a_track.trackMode & CDIO_CDROM_DATA_TRACK) != 0);
|
2004-06-01 16:02:46 +00:00
|
|
|
|
}
|
2003-09-13 06:25:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-10-04 20:11:27 +00:00
|
|
|
|
#endif /* HAVE_DARWIN_CDROM */
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
2003-10-05 14:47:45 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Return a string containing the default CD device if none is specified.
|
|
|
|
|
|
*/
|
|
|
|
|
|
char **
|
|
|
|
|
|
cdio_get_devices_osx(void)
|
|
|
|
|
|
{
|
|
|
|
|
|
#ifndef HAVE_DARWIN_CDROM
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
#else
|
2004-06-02 04:52:55 +00:00
|
|
|
|
io_object_t next_media;
|
2003-10-05 14:47:45 +00:00
|
|
|
|
mach_port_t master_port;
|
|
|
|
|
|
kern_return_t kern_result;
|
|
|
|
|
|
io_iterator_t media_iterator;
|
|
|
|
|
|
CFMutableDictionaryRef classes_to_match;
|
|
|
|
|
|
char **drives = NULL;
|
|
|
|
|
|
unsigned int num_drives=0;
|
|
|
|
|
|
|
|
|
|
|
|
kern_result = IOMasterPort( MACH_PORT_NULL, &master_port );
|
|
|
|
|
|
if( kern_result != KERN_SUCCESS )
|
|
|
|
|
|
{
|
2004-06-06 10:50:55 +00:00
|
|
|
|
return( NULL );
|
2003-10-05 14:47:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
classes_to_match = IOServiceMatching( kIOCDMediaClass );
|
|
|
|
|
|
if( classes_to_match == NULL )
|
|
|
|
|
|
{
|
2004-06-06 10:50:55 +00:00
|
|
|
|
return( NULL );
|
2003-10-05 14:47:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-05-31 15:21:48 +00:00
|
|
|
|
CFDictionarySetValue( classes_to_match, CFSTR(kIOMediaEjectableKey),
|
2003-10-05 14:47:45 +00:00
|
|
|
|
kCFBooleanTrue );
|
|
|
|
|
|
|
|
|
|
|
|
kern_result = IOServiceGetMatchingServices( master_port,
|
|
|
|
|
|
classes_to_match,
|
|
|
|
|
|
&media_iterator );
|
|
|
|
|
|
if( kern_result != KERN_SUCCESS )
|
|
|
|
|
|
{
|
2004-06-06 10:50:55 +00:00
|
|
|
|
return( NULL );
|
2003-10-05 14:47:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
next_media = IOIteratorNext( media_iterator );
|
|
|
|
|
|
if( next_media != 0 )
|
|
|
|
|
|
{
|
|
|
|
|
|
char psz_buf[0x32];
|
|
|
|
|
|
size_t dev_path_length;
|
|
|
|
|
|
CFTypeRef str_bsd_path;
|
|
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
str_bsd_path = IORegistryEntryCreateCFProperty( next_media,
|
2004-05-31 15:21:48 +00:00
|
|
|
|
CFSTR( kIOBSDNameKey ),
|
2003-10-05 14:47:45 +00:00
|
|
|
|
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 ) )
|
|
|
|
|
|
{
|
|
|
|
|
|
CFRelease( str_bsd_path );
|
|
|
|
|
|
IOObjectRelease( next_media );
|
|
|
|
|
|
IOObjectRelease( media_iterator );
|
|
|
|
|
|
cdio_add_device_list(&drives, psz_buf, &num_drives);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CFRelease( str_bsd_path );
|
|
|
|
|
|
IOObjectRelease( next_media );
|
|
|
|
|
|
|
|
|
|
|
|
} while( ( next_media = IOIteratorNext( media_iterator ) ) != 0 );
|
|
|
|
|
|
}
|
|
|
|
|
|
IOObjectRelease( media_iterator );
|
|
|
|
|
|
cdio_add_device_list(&drives, NULL, &num_drives);
|
|
|
|
|
|
return drives;
|
|
|
|
|
|
#endif /* HAVE_DARWIN_CDROM */
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-09-13 06:25:36 +00:00
|
|
|
|
/*!
|
2003-09-14 01:21:41 +00:00
|
|
|
|
Return a string containing the default CD device if none is specified.
|
2003-09-13 06:25:36 +00:00
|
|
|
|
*/
|
|
|
|
|
|
char *
|
2003-10-05 14:47:45 +00:00
|
|
|
|
cdio_get_default_device_osx(void)
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
2003-10-05 14:47:45 +00:00
|
|
|
|
#ifndef HAVE_DARWIN_CDROM
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
#else
|
|
|
|
|
|
io_object_t next_media;
|
|
|
|
|
|
mach_port_t master_port;
|
|
|
|
|
|
kern_return_t kern_result;
|
|
|
|
|
|
io_iterator_t media_iterator;
|
|
|
|
|
|
CFMutableDictionaryRef classes_to_match;
|
|
|
|
|
|
|
|
|
|
|
|
kern_result = IOMasterPort( MACH_PORT_NULL, &master_port );
|
|
|
|
|
|
if( kern_result != KERN_SUCCESS )
|
|
|
|
|
|
{
|
2004-06-06 10:50:55 +00:00
|
|
|
|
return( NULL );
|
2003-10-05 14:47:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
classes_to_match = IOServiceMatching( kIOCDMediaClass );
|
|
|
|
|
|
if( classes_to_match == NULL )
|
|
|
|
|
|
{
|
2004-06-06 10:50:55 +00:00
|
|
|
|
return( NULL );
|
2003-10-05 14:47:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-05-31 15:21:48 +00:00
|
|
|
|
CFDictionarySetValue( classes_to_match, CFSTR(kIOMediaEjectableKey),
|
2003-10-05 14:47:45 +00:00
|
|
|
|
kCFBooleanTrue );
|
|
|
|
|
|
|
|
|
|
|
|
kern_result = IOServiceGetMatchingServices( master_port,
|
|
|
|
|
|
classes_to_match,
|
|
|
|
|
|
&media_iterator );
|
|
|
|
|
|
if( kern_result != KERN_SUCCESS )
|
|
|
|
|
|
{
|
2004-06-06 10:50:55 +00:00
|
|
|
|
return( NULL );
|
2003-10-05 14:47:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
next_media = IOIteratorNext( media_iterator );
|
|
|
|
|
|
if( next_media != 0 )
|
|
|
|
|
|
{
|
|
|
|
|
|
char psz_buf[0x32];
|
|
|
|
|
|
size_t dev_path_length;
|
|
|
|
|
|
CFTypeRef str_bsd_path;
|
|
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
str_bsd_path = IORegistryEntryCreateCFProperty( next_media,
|
2004-05-31 15:21:48 +00:00
|
|
|
|
CFSTR( kIOBSDNameKey ),
|
2003-10-05 14:47:45 +00:00
|
|
|
|
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 ) )
|
|
|
|
|
|
{
|
|
|
|
|
|
CFRelease( str_bsd_path );
|
|
|
|
|
|
IOObjectRelease( next_media );
|
|
|
|
|
|
IOObjectRelease( media_iterator );
|
|
|
|
|
|
return strdup( psz_buf );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CFRelease( str_bsd_path );
|
|
|
|
|
|
IOObjectRelease( next_media );
|
|
|
|
|
|
|
|
|
|
|
|
} while( ( next_media = IOIteratorNext( media_iterator ) ) != 0 );
|
|
|
|
|
|
}
|
|
|
|
|
|
IOObjectRelease( media_iterator );
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
#endif /* HAVE_DARWIN_CDROM */
|
2003-09-13 06:25:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-04-30 06:54:15 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Initialization routine. This is the only thing that doesn't
|
|
|
|
|
|
get called via a function pointer. In fact *we* are the
|
|
|
|
|
|
ones to set that up.
|
|
|
|
|
|
*/
|
|
|
|
|
|
CdIo *
|
|
|
|
|
|
cdio_open_am_osx (const char *psz_source_name, const char *psz_access_mode)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (psz_access_mode != NULL)
|
|
|
|
|
|
cdio_warn ("there is only one access mode for OS X. Arg %s ignored",
|
|
|
|
|
|
psz_access_mode);
|
|
|
|
|
|
return cdio_open_osx(psz_source_name);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-09-13 06:25:36 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Initialization routine. This is the only thing that doesn't
|
|
|
|
|
|
get called via a function pointer. In fact *we* are the
|
|
|
|
|
|
ones to set that up.
|
|
|
|
|
|
*/
|
|
|
|
|
|
CdIo *
|
2004-05-07 09:55:54 +00:00
|
|
|
|
cdio_open_osx (const char *psz_orig_source)
|
2003-09-13 06:25:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
2003-10-04 20:11:27 +00:00
|
|
|
|
#ifdef HAVE_DARWIN_CDROM
|
2003-09-13 06:25:36 +00:00
|
|
|
|
CdIo *ret;
|
|
|
|
|
|
_img_private_t *_data;
|
2004-05-07 09:55:54 +00:00
|
|
|
|
char *psz_source;
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
|
|
|
|
|
cdio_funcs _funcs = {
|
2004-04-25 15:41:26 +00:00
|
|
|
|
.eject_media = _eject_media_osx,
|
|
|
|
|
|
.free = _free_osx,
|
|
|
|
|
|
.get_arg = _get_arg_osx,
|
2003-09-13 06:25:36 +00:00
|
|
|
|
.get_default_device = cdio_get_default_device_osx,
|
2003-10-05 14:47:45 +00:00
|
|
|
|
.get_devices = cdio_get_devices_osx,
|
2004-04-25 17:05:07 +00:00
|
|
|
|
.get_drive_cap = NULL,
|
2004-04-25 15:41:26 +00:00
|
|
|
|
.get_first_track_num= _get_first_track_num_osx,
|
|
|
|
|
|
.get_mcn = _get_mcn_osx,
|
|
|
|
|
|
.get_num_tracks = _get_num_tracks_osx,
|
|
|
|
|
|
.get_track_format = _get_track_format_osx,
|
|
|
|
|
|
.get_track_green = _get_track_green_osx,
|
|
|
|
|
|
.get_track_lba = _get_track_lba_osx,
|
2003-09-13 06:25:36 +00:00
|
|
|
|
.get_track_msf = NULL,
|
|
|
|
|
|
.lseek = cdio_generic_lseek,
|
|
|
|
|
|
.read = cdio_generic_read,
|
2004-04-25 15:41:26 +00:00
|
|
|
|
.read_audio_sectors = _get_read_audio_sectors_osx,
|
|
|
|
|
|
.read_mode1_sector = _get_read_mode1_sector_osx,
|
|
|
|
|
|
.read_mode1_sectors = _get_read_mode1_sectors_osx,
|
|
|
|
|
|
.read_mode2_sector = _get_read_mode2_sector_osx,
|
|
|
|
|
|
.read_mode2_sectors = _get_read_mode2_sectors_osx,
|
|
|
|
|
|
.set_arg = _set_arg_osx,
|
|
|
|
|
|
.stat_size = _stat_size_osx
|
2003-09-13 06:25:36 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_data = _cdio_malloc (sizeof (_img_private_t));
|
|
|
|
|
|
_data->access_mode = _AM_OSX;
|
|
|
|
|
|
_data->gen.init = false;
|
|
|
|
|
|
_data->gen.fd = -1;
|
|
|
|
|
|
|
2004-05-07 09:55:54 +00:00
|
|
|
|
if (NULL == psz_orig_source) {
|
|
|
|
|
|
psz_source=cdio_get_default_device_osx();
|
|
|
|
|
|
if (NULL == psz_source) return NULL;
|
|
|
|
|
|
_set_arg_osx(_data, "source", psz_source);
|
|
|
|
|
|
free(psz_source);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (cdio_is_device_generic(psz_orig_source))
|
|
|
|
|
|
_set_arg_osx(_data, "source", psz_orig_source);
|
|
|
|
|
|
else {
|
|
|
|
|
|
/* The below would be okay if all device drivers worked this way. */
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
cdio_info ("source %s is a not a device", psz_orig_source);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
|
|
|
|
|
ret = cdio_new (_data, &_funcs);
|
|
|
|
|
|
if (ret == NULL) return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (cdio_generic_init(_data))
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
else {
|
|
|
|
|
|
cdio_generic_free (_data);
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
return NULL;
|
2003-10-04 20:11:27 +00:00
|
|
|
|
#endif /* HAVE_DARWIN_CDROM */
|
2003-09-13 06:25:36 +00:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
cdio_have_osx (void)
|
|
|
|
|
|
{
|
2003-10-04 20:11:27 +00:00
|
|
|
|
#ifdef HAVE_DARWIN_CDROM
|
2003-09-13 06:25:36 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
#else
|
|
|
|
|
|
return false;
|
2003-10-04 20:11:27 +00:00
|
|
|
|
#endif /* HAVE_DARWIN_CDROM */
|
2003-09-13 06:25:36 +00:00
|
|
|
|
}
|