2003-03-24 19:01:09 +00:00
|
|
|
|
/*
|
2004-11-20 12:50:26 +00:00
|
|
|
|
$Id: _cdio_bsdi.c,v 1.44 2004/11/20 12:50:26 rocky Exp $
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
|
2004-03-20 03:34:12 +00:00
|
|
|
|
Copyright (C) 2002, 2003, 2004 Rocky Bernstein <rocky@panix.com>
|
2003-03-24 19:01:09 +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-03-29 17:32:00 +00:00
|
|
|
|
|
2003-10-02 02:59:57 +00:00
|
|
|
|
/* This file contains BSDI-specific code and implements low-level
|
2003-03-29 17:32:00 +00:00
|
|
|
|
control of the CD drive.
|
|
|
|
|
|
*/
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
|
# include "config.h"
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2004-11-20 12:50:26 +00:00
|
|
|
|
static const char _rcsid[] = "$Id: _cdio_bsdi.c,v 1.44 2004/11/20 12:50:26 rocky Exp $";
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
2004-09-03 23:20:11 +00:00
|
|
|
|
#include <cdio/logging.h>
|
2003-04-22 12:09:08 +00:00
|
|
|
|
#include <cdio/sector.h>
|
|
|
|
|
|
#include <cdio/util.h>
|
2003-03-24 19:01:09 +00:00
|
|
|
|
#include "cdio_assert.h"
|
|
|
|
|
|
#include "cdio_private.h"
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
2003-04-10 04:13:41 +00:00
|
|
|
|
#define DEFAULT_CDIO_DEVICE "/dev/rsr0c"
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
#ifdef HAVE_BSDI_CDROM
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#include <stdlib.h>
|
2003-03-29 17:32:00 +00:00
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
#include <fcntl.h>
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-10-03 17:29:59 +00:00
|
|
|
|
/*#define USE_ETC_FSTAB*/
|
2003-10-03 01:43:45 +00:00
|
|
|
|
#ifdef USE_ETC_FSTAB
|
|
|
|
|
|
#include <fstab.h>
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
#include <dvd.h>
|
2003-03-24 19:01:09 +00:00
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
#include <sys/types.h>
|
2003-03-29 17:32:00 +00:00
|
|
|
|
#include <sys/ioctl.h>
|
2004-07-27 15:02:01 +00:00
|
|
|
|
#include </sys/dev/scsi/scsi.h>
|
|
|
|
|
|
#include </sys/dev/scsi/scsi_ioctl.h>
|
2004-07-27 16:51:14 +00:00
|
|
|
|
#include "cdtext_private.h"
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-04-30 06:54:15 +00:00
|
|
|
|
typedef enum {
|
|
|
|
|
|
_AM_NONE,
|
|
|
|
|
|
_AM_IOCTL,
|
|
|
|
|
|
} access_mode_t;
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
typedef struct {
|
2003-03-30 01:11:35 +00:00
|
|
|
|
/* Things common to all drivers like this.
|
|
|
|
|
|
This must be first. */
|
|
|
|
|
|
generic_img_private_t gen;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-04-30 06:54:15 +00:00
|
|
|
|
access_mode_t access_mode;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-08-10 03:03:27 +00:00
|
|
|
|
/* Some of the more OS specific things. */
|
2003-03-29 17:32:00 +00:00
|
|
|
|
/* Track information */
|
|
|
|
|
|
struct cdrom_tochdr tochdr;
|
2004-07-27 16:51:14 +00:00
|
|
|
|
struct cdrom_tocentry tocent[CDIO_CD_MAX_TRACKS+1];
|
|
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
} _img_private_t;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-07-27 15:02:01 +00:00
|
|
|
|
/* Define the Cdrom Generic Command structure */
|
|
|
|
|
|
typedef struct cgc
|
|
|
|
|
|
{
|
2004-07-28 01:09:59 +00:00
|
|
|
|
scsi_mmc_cdb_t cdb;
|
2004-07-27 15:02:01 +00:00
|
|
|
|
u_char *buf;
|
|
|
|
|
|
int buflen;
|
|
|
|
|
|
int rw;
|
2004-07-28 01:09:59 +00:00
|
|
|
|
unsigned int timeout;
|
2004-07-27 15:02:01 +00:00
|
|
|
|
scsi_user_sense_t *sus;
|
|
|
|
|
|
} cgc_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
This code adapted from Steven M. Schultz's libdvd
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-07-29 02:48:55 +00:00
|
|
|
|
run_scsi_cmd_bsdi(const void *p_user_data, unsigned int i_timeout_ms,
|
2004-07-28 01:09:59 +00:00
|
|
|
|
unsigned int i_cdb, const scsi_mmc_cdb_t *p_cdb,
|
|
|
|
|
|
scsi_mmc_direction_t e_direction,
|
|
|
|
|
|
unsigned int i_buf, /*in/out*/ void *p_buf )
|
2004-07-27 15:02:01 +00:00
|
|
|
|
{
|
|
|
|
|
|
const _img_private_t *p_env = p_user_data;
|
|
|
|
|
|
int i_status, i_asc;
|
|
|
|
|
|
struct scsi_user_cdb suc;
|
|
|
|
|
|
struct scsi_sense *sp;
|
|
|
|
|
|
|
|
|
|
|
|
again:
|
|
|
|
|
|
suc.suc_flags = SCSI_MMC_DATA_READ == e_direction ?
|
|
|
|
|
|
SUC_READ : SUC_WRITE;
|
|
|
|
|
|
suc.suc_cdblen = i_cdb;
|
|
|
|
|
|
memcpy(suc.suc_cdb, p_cdb, i_cdb);
|
|
|
|
|
|
suc.suc_data = p_buf;
|
|
|
|
|
|
suc.suc_datalen = i_buf;
|
2004-07-28 01:09:59 +00:00
|
|
|
|
suc.suc_timeout = msecs2secs(i_timeout_ms);
|
2004-07-27 15:02:01 +00:00
|
|
|
|
if (ioctl(p_env->gen.fd, SCSIRAWCDB, &suc) == -1)
|
|
|
|
|
|
return(errno);
|
|
|
|
|
|
i_status = suc.suc_sus.sus_status;
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
/*
|
|
|
|
|
|
* If the device returns a scsi sense error and debugging is enabled print
|
|
|
|
|
|
* some hopefully useful information on stderr.
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (i_status && debug)
|
|
|
|
|
|
{
|
|
|
|
|
|
unsigned char *cp;
|
|
|
|
|
|
int i;
|
|
|
|
|
|
cp = suc.suc_sus.sus_sense;
|
|
|
|
|
|
fprintf(stderr,"i_status = %x cdb =",
|
|
|
|
|
|
i_status);
|
|
|
|
|
|
for (i = 0; i < cdblen; i++)
|
|
|
|
|
|
fprintf(stderr, " %x", cgc->cdb[i]);
|
|
|
|
|
|
fprintf(stderr, "\nsense =");
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
|
|
fprintf(stderr, " %x", cp[i]);
|
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* HACK! Some drives return a silly "medium changed" on the first
|
|
|
|
|
|
* command AND a non-zero i_status which gets turned into a fatal
|
|
|
|
|
|
* (EIO) error even though the operation was a success. Retrying
|
|
|
|
|
|
* the operation clears the media changed status and gets the
|
|
|
|
|
|
* answer. */
|
|
|
|
|
|
|
|
|
|
|
|
sp = (struct scsi_sense *)&suc.suc_sus.sus_sense;
|
|
|
|
|
|
i_asc = XSENSE_ASC(sp);
|
|
|
|
|
|
if (i_status == STS_CHECKCOND && i_asc == 0x28)
|
|
|
|
|
|
goto again;
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
if (cgc->sus)
|
|
|
|
|
|
memcpy(cgc->sus, &suc.suc_sus, sizeof (struct scsi_user_sense));
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
return(i_status);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-10-02 02:59:57 +00:00
|
|
|
|
/* Check a drive to see if it is a CD-ROM
|
|
|
|
|
|
Return 1 if a CD-ROM. 0 if it exists but isn't a CD-ROM drive
|
|
|
|
|
|
and -1 if no device exists .
|
|
|
|
|
|
*/
|
2003-10-03 01:43:45 +00:00
|
|
|
|
static bool
|
2003-10-02 02:59:57 +00:00
|
|
|
|
cdio_is_cdrom(char *drive, char *mnttype)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool is_cd=false;
|
|
|
|
|
|
int cdfd;
|
|
|
|
|
|
struct cdrom_tochdr tochdr;
|
|
|
|
|
|
|
|
|
|
|
|
/* If it doesn't exist, return -1 */
|
|
|
|
|
|
if ( !cdio_is_device_quiet_generic(drive) ) {
|
|
|
|
|
|
return(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* If it does exist, verify that it's an available CD-ROM */
|
|
|
|
|
|
cdfd = open(drive, (O_RDONLY|O_EXCL|O_NONBLOCK), 0);
|
2003-10-03 01:43:45 +00:00
|
|
|
|
|
|
|
|
|
|
/* Should we want to test the condition in more detail:
|
|
|
|
|
|
ENOENT is the error for /dev/xxxxx does not exist;
|
|
|
|
|
|
ENODEV means there's no drive present. */
|
|
|
|
|
|
|
2003-10-02 02:59:57 +00:00
|
|
|
|
if ( cdfd >= 0 ) {
|
|
|
|
|
|
if ( ioctl(cdfd, CDROMREADTOCHDR, &tochdr) != -1 ) {
|
|
|
|
|
|
is_cd = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
close(cdfd);
|
|
|
|
|
|
}
|
|
|
|
|
|
/* Even if we can't read it, it might be mounted */
|
2003-10-03 17:29:59 +00:00
|
|
|
|
else if ( mnttype && (strcmp(mnttype, "cd9660") == 0) ) {
|
2003-10-02 02:59:57 +00:00
|
|
|
|
is_cd = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return(is_cd);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Initialize CD device.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static bool
|
2004-08-10 03:37:16 +00:00
|
|
|
|
_cdio_init (_img_private_t *p_env)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-08-10 03:37:16 +00:00
|
|
|
|
if (p_env->gen.init) {
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn ("init called more than once");
|
2003-03-29 17:32:00 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
p_env->gen.fd = open (p_env->gen.source_name, O_RDONLY, 0);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
if (p_env->gen.fd < 0)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-08-10 03:37:16 +00:00
|
|
|
|
cdio_warn ("open (%s): %s", p_env->gen.source_name, strerror (errno));
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
p_env->gen.init = true;
|
|
|
|
|
|
p_env->gen.toc_init = false;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-10-02 02:59:57 +00:00
|
|
|
|
/* Read audio sectors
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_read_audio_sectors_bsdi (void *user_data, void *data, lsn_t lsn,
|
2004-06-03 09:22:10 +00:00
|
|
|
|
unsigned int nblocks)
|
2003-10-02 02:59:57 +00:00
|
|
|
|
{
|
|
|
|
|
|
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
|
|
|
|
|
|
struct cdrom_msf *msf = (struct cdrom_msf *) &buf;
|
|
|
|
|
|
msf_t _msf;
|
|
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2003-10-02 02:59:57 +00:00
|
|
|
|
|
|
|
|
|
|
cdio_lba_to_msf (cdio_lsn_to_lba(lsn), &_msf);
|
2004-11-19 13:04:25 +00:00
|
|
|
|
msf->cdmsf_min0 = cdio_from_bcd8(_msf.m);
|
|
|
|
|
|
msf->cdmsf_sec0 = cdio_from_bcd8(_msf.s);
|
|
|
|
|
|
msf->cdmsf_frame0 = cdio_from_bcd8(_msf.f);
|
2003-10-02 02:59:57 +00:00
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
if (p_env->gen.ioctls_debugged == 75)
|
2003-10-02 02:59:57 +00:00
|
|
|
|
cdio_debug ("only displaying every 75th ioctl from now on");
|
|
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
if (p_env->gen.ioctls_debugged == 30 * 75)
|
2003-10-02 02:59:57 +00:00
|
|
|
|
cdio_debug ("only displaying every 30*75th ioctl from now on");
|
|
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
if (p_env->gen.ioctls_debugged < 75
|
|
|
|
|
|
|| (p_env->gen.ioctls_debugged < (30 * 75)
|
|
|
|
|
|
&& p_env->gen.ioctls_debugged % 75 == 0)
|
|
|
|
|
|
|| p_env->gen.ioctls_debugged % (30 * 75) == 0)
|
2003-10-02 02:59:57 +00:00
|
|
|
|
cdio_debug ("reading %2.2d:%2.2d:%2.2d",
|
|
|
|
|
|
msf->cdmsf_min0, msf->cdmsf_sec0, msf->cdmsf_frame0);
|
|
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
p_env->gen.ioctls_debugged++;
|
2003-10-02 02:59:57 +00:00
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
switch (p_env->access_mode) {
|
2003-10-02 02:59:57 +00:00
|
|
|
|
case _AM_NONE:
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn ("no way to read audio");
|
2003-10-02 02:59:57 +00:00
|
|
|
|
return 1;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case _AM_IOCTL: {
|
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
for (i=0; i < nblocks; i++) {
|
2004-08-10 03:37:16 +00:00
|
|
|
|
if (ioctl (p_env->gen.fd, CDROMREADRAW, &buf) == -1) {
|
2003-10-02 02:59:57 +00:00
|
|
|
|
perror ("ioctl()");
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
/* exit (EXIT_FAILURE); */
|
|
|
|
|
|
}
|
|
|
|
|
|
memcpy (((char *)data) + (CDIO_CD_FRAMESIZE_RAW * i), buf,
|
|
|
|
|
|
CDIO_CD_FRAMESIZE_RAW);
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-03-20 03:34:12 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Reads a single mode1 sector from cd device into data starting
|
|
|
|
|
|
from lsn. Returns 0 if no error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_read_mode1_sector_bsdi (void *user_data, void *data, lsn_t lsn,
|
2004-03-20 03:34:12 +00:00
|
|
|
|
bool b_form2)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
#if FIXED
|
2004-06-26 00:39:00 +00:00
|
|
|
|
char buf[M2RAW_SECTOR_SIZE] = { 0, };
|
2004-03-20 03:34:12 +00:00
|
|
|
|
do something here.
|
|
|
|
|
|
#else
|
2004-06-26 00:39:00 +00:00
|
|
|
|
return cdio_generic_read_form1_sector(user_data, data, lsn);
|
2004-03-20 03:34:12 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Reads nblocks of mode2 sectors from cd device into data starting
|
|
|
|
|
|
from lsn.
|
|
|
|
|
|
Returns 0 if no error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_read_mode1_sectors_bsdi (void *user_data, void *data, lsn_t lsn,
|
2004-03-20 03:34:12 +00:00
|
|
|
|
bool b_form2, unsigned int nblocks)
|
|
|
|
|
|
{
|
2004-08-10 03:37:16 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2004-03-20 03:34:12 +00:00
|
|
|
|
unsigned int i;
|
|
|
|
|
|
int retval;
|
|
|
|
|
|
unsigned int blocksize = b_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE;
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nblocks; i++) {
|
2004-08-10 03:37:16 +00:00
|
|
|
|
if ( (retval = _read_mode1_sector_bsdi (p_env,
|
2004-03-20 03:34:12 +00:00
|
|
|
|
((char *)data) + (blocksize * i),
|
|
|
|
|
|
lsn + i, b_form2)) )
|
|
|
|
|
|
return retval;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-29 17:32:00 +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
|
|
|
|
_read_mode2_sector_bsdi (void *user_data, void *data, lsn_t lsn,
|
2004-03-20 03:34:12 +00:00
|
|
|
|
bool b_form2)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2003-03-29 17:32:00 +00:00
|
|
|
|
char buf[M2RAW_SECTOR_SIZE] = { 0, };
|
|
|
|
|
|
struct cdrom_msf *msf = (struct cdrom_msf *) &buf;
|
|
|
|
|
|
msf_t _msf;
|
|
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
cdio_lba_to_msf (cdio_lsn_to_lba(lsn), &_msf);
|
2004-11-19 13:04:25 +00:00
|
|
|
|
msf->cdmsf_min0 = cdio_from_bcd8(_msf.m);
|
|
|
|
|
|
msf->cdmsf_sec0 = cdio_from_bcd8(_msf.s);
|
|
|
|
|
|
msf->cdmsf_frame0 = cdio_from_bcd8(_msf.f);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
if (p_env->gen.ioctls_debugged == 75)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
cdio_debug ("only displaying every 75th ioctl from now on");
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
if (p_env->gen.ioctls_debugged == 30 * 75)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
cdio_debug ("only displaying every 30*75th ioctl from now on");
|
|
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
if (p_env->gen.ioctls_debugged < 75
|
|
|
|
|
|
|| (p_env->gen.ioctls_debugged < (30 * 75)
|
|
|
|
|
|
&& p_env->gen.ioctls_debugged % 75 == 0)
|
|
|
|
|
|
|| p_env->gen.ioctls_debugged % (30 * 75) == 0)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
cdio_debug ("reading %2.2d:%2.2d:%2.2d",
|
|
|
|
|
|
msf->cdmsf_min0, msf->cdmsf_sec0, msf->cdmsf_frame0);
|
|
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
p_env->gen.ioctls_debugged++;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
switch (p_env->access_mode)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
|
case _AM_NONE:
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn ("no way to read mode2");
|
2003-03-29 17:32:00 +00:00
|
|
|
|
return 1;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case _AM_IOCTL:
|
2004-08-10 03:37:16 +00:00
|
|
|
|
if (ioctl (p_env->gen.fd, CDROMREADMODE2, &buf) == -1)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
|
perror ("ioctl()");
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
/* exit (EXIT_FAILURE); */
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-03-20 03:34:12 +00:00
|
|
|
|
if (b_form2)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
memcpy (data, buf, M2RAW_SECTOR_SIZE);
|
|
|
|
|
|
else
|
2003-04-08 10:35:09 +00:00
|
|
|
|
memcpy (((char *)data), buf + CDIO_CD_SUBHEADER_SIZE, CDIO_CD_FRAMESIZE);
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
|
|
|
|
|
return 0;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Reads nblocks of mode2 sectors from cd device into data starting
|
|
|
|
|
|
from lsn.
|
|
|
|
|
|
Returns 0 if no error.
|
|
|
|
|
|
*/
|
2003-03-24 19:01:09 +00:00
|
|
|
|
static int
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_read_mode2_sectors_bsdi (void *user_data, void *data, lsn_t lsn,
|
2004-03-20 03:34:12 +00:00
|
|
|
|
bool b_form2, unsigned int nblocks)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-08-10 03:37:16 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2004-06-03 09:22:10 +00:00
|
|
|
|
unsigned int i;
|
|
|
|
|
|
unsigned int i_blocksize = b_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
2004-06-03 09:22:10 +00:00
|
|
|
|
/* For each frame, pick out the data part we need */
|
2003-03-29 17:32:00 +00:00
|
|
|
|
for (i = 0; i < nblocks; i++) {
|
2004-08-10 03:37:16 +00:00
|
|
|
|
int retval = _read_mode2_sector_bsdi(p_env,
|
2004-06-03 12:37:54 +00:00
|
|
|
|
((char *)data) +
|
|
|
|
|
|
(i_blocksize * i),
|
|
|
|
|
|
lsn + i, b_form2);
|
2004-06-03 09:22:10 +00:00
|
|
|
|
if (retval) return retval;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
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_bsdi (void *user_data)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
{
|
2004-08-10 03:37:16 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
struct cdrom_tocentry tocent;
|
|
|
|
|
|
uint32_t size;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-04-06 17:57:20 +00:00
|
|
|
|
tocent.cdte_track = CDIO_CDROM_LEADOUT_TRACK;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
tocent.cdte_format = CDROM_LBA;
|
2004-08-10 03:37:16 +00:00
|
|
|
|
if (ioctl (p_env->gen.fd, CDROMREADTOCENTRY, &tocent) == -1)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2003-03-29 17:32:00 +00:00
|
|
|
|
perror ("ioctl(CDROMREADTOCENTRY)");
|
|
|
|
|
|
exit (EXIT_FAILURE);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
size = tocent.cdte_addr.lba;
|
|
|
|
|
|
|
|
|
|
|
|
return size;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Set the key "arg" to "value" in source device.
|
|
|
|
|
|
*/
|
2003-03-24 19:01:09 +00:00
|
|
|
|
static int
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_set_arg_bsdi (void *user_data, const char key[], const char value[])
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-08-10 03:37:16 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
if (!strcmp (key, "source"))
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2003-03-29 17:32:00 +00:00
|
|
|
|
if (!value)
|
|
|
|
|
|
return -2;
|
|
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
free (p_env->gen.source_name);
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
p_env->gen.source_name = strdup (value);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
2003-03-29 17:32:00 +00:00
|
|
|
|
else if (!strcmp (key, "access-mode"))
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2003-03-29 17:32:00 +00:00
|
|
|
|
if (!strcmp(value, "IOCTL"))
|
2004-08-10 03:37:16 +00:00
|
|
|
|
p_env->access_mode = _AM_IOCTL;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
else
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn ("unknown access type: %s. ignored.", value);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
2003-03-29 17:32:00 +00:00
|
|
|
|
else
|
|
|
|
|
|
return -1;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
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-07-29 02:48:55 +00:00
|
|
|
|
read_toc_bsdi (void *p_user_data)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-07-29 02:48:55 +00:00
|
|
|
|
_img_private_t *p_env = p_user_data;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
int i;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
/* read TOC header */
|
2004-07-27 01:06:01 +00:00
|
|
|
|
if ( ioctl(p_env->gen.fd, CDROMREADTOCHDR, &p_env->tochdr) == -1 ) {
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn("%s: %s\n",
|
2003-03-29 17:32:00 +00:00
|
|
|
|
"error in ioctl CDROMREADTOCHDR", strerror(errno));
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-07-27 16:36:59 +00:00
|
|
|
|
p_env->gen.i_first_track = p_env->tochdr.cdth_trk0;
|
2004-07-29 02:48:55 +00:00
|
|
|
|
p_env->gen.i_tracks = p_env->tochdr.cdth_trk1;
|
2004-07-27 16:36:59 +00:00
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
/* read individual tracks */
|
2004-07-29 02:48:55 +00:00
|
|
|
|
for (i= p_env->gen.i_first_track; i<=p_env->gen.i_tracks; i++) {
|
2004-07-27 01:06:01 +00:00
|
|
|
|
p_env->tocent[i-1].cdte_track = i;
|
|
|
|
|
|
p_env->tocent[i-1].cdte_format = CDROM_MSF;
|
|
|
|
|
|
if (ioctl(p_env->gen.fd, CDROMREADTOCENTRY, &p_env->tocent[i-1]) == -1) {
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn("%s %d: %s\n",
|
2003-03-29 17:32:00 +00:00
|
|
|
|
"error in ioctl CDROMREADTOCENTRY for track",
|
|
|
|
|
|
i, strerror(errno));
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
/****
|
2004-07-27 01:06:01 +00:00
|
|
|
|
struct cdrom_msf0 *msf= &p_env->tocent[i-1].cdte_addr.msf;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
|
|
|
|
|
fprintf (stdout, "--- track# %d (msf %2.2x:%2.2x:%2.2x)\n",
|
|
|
|
|
|
i, msf->minute, msf->second, msf->frame);
|
|
|
|
|
|
****/
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
/* read the lead-out track */
|
2004-07-29 02:48:55 +00:00
|
|
|
|
p_env->tocent[p_env->gen.i_tracks].cdte_track = CDIO_CDROM_LEADOUT_TRACK;
|
|
|
|
|
|
p_env->tocent[p_env->gen.i_tracks].cdte_format = CDROM_MSF;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-07-27 01:06:01 +00:00
|
|
|
|
if (ioctl(p_env->gen.fd, CDROMREADTOCENTRY,
|
2004-07-29 02:48:55 +00:00
|
|
|
|
&p_env->tocent[p_env->gen.i_tracks]) == -1 ) {
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn("%s: %s\n",
|
2003-03-29 17:32:00 +00:00
|
|
|
|
"error in ioctl CDROMREADTOCENTRY for lead-out",
|
|
|
|
|
|
strerror(errno));
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
/*
|
2004-07-29 02:48:55 +00:00
|
|
|
|
struct cdrom_msf0 *msf= &p_env->tocent[p_env->gen.i_tracks].cdte_addr.msf;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
fprintf (stdout, "--- track# %d (msf %2.2x:%2.2x:%2.2x)\n",
|
|
|
|
|
|
i, msf->minute, msf->second, msf->frame);
|
|
|
|
|
|
*/
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-07-27 16:36:59 +00:00
|
|
|
|
p_env->gen.toc_init = true;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Eject media in CD drive. If successful, as a side effect we
|
|
|
|
|
|
also free obj.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_eject_media_bsdi (void *user_data) {
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-07-27 01:06:01 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
int ret=2;
|
|
|
|
|
|
int status;
|
|
|
|
|
|
int fd;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-07-27 01:06:01 +00:00
|
|
|
|
close(p_env->gen.fd);
|
|
|
|
|
|
p_env->gen.fd = -1;
|
2004-08-10 03:37:16 +00:00
|
|
|
|
if ((fd = open (p_env->gen.source_name, O_RDONLY|O_NONBLOCK)) > -1) {
|
2003-03-29 17:32:00 +00:00
|
|
|
|
if((status = ioctl(fd, CDROM_DRIVE_STATUS, (void *) CDSL_CURRENT)) > 0) {
|
|
|
|
|
|
switch(status) {
|
|
|
|
|
|
case CDS_TRAY_OPEN:
|
|
|
|
|
|
if((ret = ioctl(fd, CDROMCLOSETRAY, 0)) != 0) {
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn ("ioctl CDROMCLOSETRAY failed: %s\n", strerror(errno));
|
2003-03-29 17:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case CDS_DISC_OK:
|
|
|
|
|
|
if((ret = ioctl(fd, CDROMEJECT, 0)) != 0) {
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn("ioctl CDROMEJECT failed: %s\n", strerror(errno));
|
2003-03-29 17:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
2003-03-29 17:32:00 +00:00
|
|
|
|
ret=0;
|
|
|
|
|
|
} else {
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn ("CDROM_DRIVE_STATUS failed: %s\n", strerror(errno));
|
2003-03-29 17:32:00 +00:00
|
|
|
|
ret=1;
|
|
|
|
|
|
}
|
|
|
|
|
|
close(fd);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
2003-03-29 17:32:00 +00:00
|
|
|
|
return 2;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the value associated with the key "arg".
|
|
|
|
|
|
*/
|
|
|
|
|
|
static const char *
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_get_arg_bsdi (void *user_data, const char key[])
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-07-27 01:06:01 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
if (!strcmp (key, "source")) {
|
2004-08-10 03:37:16 +00:00
|
|
|
|
return p_env->gen.source_name;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
} else if (!strcmp (key, "access-mode")) {
|
2004-07-27 01:06:01 +00:00
|
|
|
|
switch (p_env->access_mode) {
|
2003-03-29 17:32:00 +00:00
|
|
|
|
case _AM_IOCTL:
|
|
|
|
|
|
return "ioctl";
|
2003-03-24 19:01:09 +00:00
|
|
|
|
case _AM_NONE:
|
|
|
|
|
|
return "no access method";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-10-03 04:04:24 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Return the media catalog number MCN.
|
|
|
|
|
|
Note: string is malloc'd so caller should free() then returned
|
|
|
|
|
|
string when done with it.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static char *
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_get_mcn_bsdi (const void *user_data) {
|
2003-10-03 04:04:24 +00:00
|
|
|
|
|
|
|
|
|
|
struct cdrom_mcn mcn;
|
2004-07-27 01:06:01 +00:00
|
|
|
|
const _img_private_t *p_env = user_data;
|
|
|
|
|
|
if (ioctl(p_env->gen.fd, CDROM_GET_MCN, &mcn) != 0)
|
2003-10-03 04:04:24 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
return strdup(mcn.medium_catalog_number);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Get format of track.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static track_format_t
|
2004-07-27 16:36:59 +00:00
|
|
|
|
get_track_format_bsdi(void *user_data, track_t i_track)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
{
|
2004-07-27 01:06:01 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
if (!p_env->gen.toc_init) read_toc_bsdi (p_env) ;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
2004-07-29 02:48:55 +00:00
|
|
|
|
if (i_track > p_env->gen.i_tracks || i_track == 0)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
return TRACK_FORMAT_ERROR;
|
|
|
|
|
|
|
2004-07-27 13:10:20 +00:00
|
|
|
|
i_track -= p_env->gen.i_first_track;
|
2004-06-02 00:43:53 +00:00
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
/* This is pretty much copied from the "badly broken" cdrom_count_tracks
|
|
|
|
|
|
in linux/cdrom.c.
|
|
|
|
|
|
*/
|
2004-07-27 01:06:01 +00:00
|
|
|
|
if (p_env->tocent[i_track].cdte_ctrl & CDROM_DATA_TRACK) {
|
|
|
|
|
|
if (p_env->tocent[i_track].cdte_format == CDIO_CDROM_CDI_TRACK)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
return TRACK_FORMAT_CDI;
|
2004-07-27 01:06:01 +00:00
|
|
|
|
else if (p_env->tocent[i_track].cdte_format == CDIO_CDROM_XA_TRACK)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
return TRACK_FORMAT_XA;
|
|
|
|
|
|
else
|
|
|
|
|
|
return TRACK_FORMAT_DATA;
|
|
|
|
|
|
} else
|
|
|
|
|
|
return TRACK_FORMAT_AUDIO;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
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_bsdi(void *user_data, track_t i_track)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
{
|
2004-07-27 01:06:01 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
if (!p_env->gen.toc_init) read_toc_bsdi (p_env) ;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
2004-07-29 02:48:55 +00:00
|
|
|
|
if (i_track == CDIO_CDROM_LEADOUT_TRACK) i_track = p_env->gen.i_tracks+1;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
2004-07-29 02:48:55 +00:00
|
|
|
|
if (i_track > p_env->gen.i_tracks+1 || i_track == 0)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
/* FIXME: Dunno if this is the right way, but it's what
|
|
|
|
|
|
I was using in cdinfo for a while.
|
|
|
|
|
|
*/
|
2004-07-27 01:06:01 +00:00
|
|
|
|
return ((p_env->tocent[i_track-1].cdte_ctrl & 2) != 0);
|
2003-03-29 17:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the starting MSF (minutes/secs/frames) for track number
|
2004-06-02 00:43:53 +00:00
|
|
|
|
i_track in obj. Track numbers start at 1.
|
2003-03-29 17:32:00 +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-03-29 17:32:00 +00:00
|
|
|
|
False is returned if there is no track entry.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static bool
|
2004-06-02 00:43:53 +00:00
|
|
|
|
_get_track_msf_bsdi(void *user_data, track_t i_track, msf_t *msf)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
{
|
2004-07-27 01:06:01 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
|
|
|
|
|
if (NULL == msf) return false;
|
|
|
|
|
|
|
2004-08-10 03:37:16 +00:00
|
|
|
|
if (!p_env->gen.toc_init) read_toc_bsdi (p_env) ;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
2004-07-29 02:48:55 +00:00
|
|
|
|
if (i_track == CDIO_CDROM_LEADOUT_TRACK) i_track = p_env->gen.i_tracks+1;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
2004-07-29 02:48:55 +00:00
|
|
|
|
if (i_track > p_env->gen.i_tracks+1 || i_track == 0) {
|
2003-03-29 17:32:00 +00:00
|
|
|
|
return false;
|
2004-06-02 00:43:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-07-27 13:10:20 +00:00
|
|
|
|
i_track -= p_env->gen.i_first_track;
|
2004-06-02 00:43:53 +00:00
|
|
|
|
|
|
|
|
|
|
{
|
2004-07-27 01:06:01 +00:00
|
|
|
|
struct cdrom_msf0 *msf0= &p_env->tocent[i_track].cdte_addr.msf;
|
2004-11-19 13:04:25 +00:00
|
|
|
|
msf->m = cdio_to_bcd8(msf0->minute);
|
|
|
|
|
|
msf->s = cdio_to_bcd8(msf0->second);
|
|
|
|
|
|
msf->f = cdio_to_bcd8(msf0->frame);
|
2003-03-29 17:32:00 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-07-28 01:09:59 +00:00
|
|
|
|
#endif /* HAVE_BSDI_CDROM */
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return an array of strings giving possible CD devices.
|
|
|
|
|
|
*/
|
|
|
|
|
|
char **
|
|
|
|
|
|
cdio_get_devices_bsdi (void)
|
|
|
|
|
|
{
|
|
|
|
|
|
#ifndef HAVE_BSDI_CDROM
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
#else
|
|
|
|
|
|
char drive[40];
|
|
|
|
|
|
char **drives = NULL;
|
|
|
|
|
|
unsigned int num_drives=0;
|
|
|
|
|
|
bool exists=true;
|
|
|
|
|
|
char c;
|
|
|
|
|
|
|
|
|
|
|
|
/* Scan the system for CD-ROM drives.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_ETC_FSTAB
|
|
|
|
|
|
|
|
|
|
|
|
struct fstab *fs;
|
|
|
|
|
|
setfsent();
|
|
|
|
|
|
|
|
|
|
|
|
/* Check what's in /etc/fstab... */
|
|
|
|
|
|
while ( (fs = getfsent()) )
|
|
|
|
|
|
{
|
|
|
|
|
|
if (strncmp(fs->fs_spec, "/dev/sr", 7))
|
|
|
|
|
|
cdio_add_device_list(&drives, fs->fs_spec, &num_drives);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* Scan the system for CD-ROM drives.
|
|
|
|
|
|
Not always 100% reliable, so use the USE_MNTENT code above first.
|
|
|
|
|
|
*/
|
|
|
|
|
|
for ( c='0'; exists && c <='9'; c++ ) {
|
|
|
|
|
|
sprintf(drive, "/dev/rsr%cc", c);
|
|
|
|
|
|
exists = cdio_is_cdrom(drive, NULL);
|
|
|
|
|
|
if ( exists ) {
|
|
|
|
|
|
cdio_add_device_list(&drives, drive, &num_drives);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
cdio_add_device_list(&drives, NULL, &num_drives);
|
|
|
|
|
|
return drives;
|
|
|
|
|
|
#endif /*HAVE_BSDI_CDROM*/
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return a string containing the default CD device if none is specified.
|
|
|
|
|
|
*/
|
|
|
|
|
|
char *
|
|
|
|
|
|
cdio_get_default_device_bsdi(void)
|
|
|
|
|
|
{
|
|
|
|
|
|
return strdup(DEFAULT_CDIO_DEVICE);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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_bsdi (const char *psz_source_name, const char *psz_access_mode)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (psz_access_mode != NULL)
|
|
|
|
|
|
cdio_warn ("there is only one access mode for bsdi. Arg %s ignored",
|
|
|
|
|
|
psz_access_mode);
|
|
|
|
|
|
return cdio_open_bsdi(psz_source_name);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-03-29 17:32:00 +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.
|
|
|
|
|
|
*/
|
2003-03-24 19:01:09 +00:00
|
|
|
|
CdIo *
|
2004-05-06 01:37:43 +00:00
|
|
|
|
cdio_open_bsdi (const char *psz_orig_source)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_BSDI_CDROM
|
2003-03-29 17:32:00 +00:00
|
|
|
|
CdIo *ret;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
_img_private_t *_data;
|
2004-05-06 01:37:43 +00:00
|
|
|
|
char *psz_source;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
cdio_funcs _funcs = {
|
2004-04-25 17:05:07 +00:00
|
|
|
|
.eject_media = _eject_media_bsdi,
|
2003-03-30 01:11:35 +00:00
|
|
|
|
.free = cdio_generic_free,
|
2004-04-25 17:05:07 +00:00
|
|
|
|
.get_arg = _get_arg_bsdi,
|
2004-08-10 11:58:14 +00:00
|
|
|
|
.get_cdtext = get_cdtext_generic,
|
2003-04-10 04:13:41 +00:00
|
|
|
|
.get_default_device = cdio_get_default_device_bsdi,
|
2003-10-02 02:59:57 +00:00
|
|
|
|
.get_devices = cdio_get_devices_bsdi,
|
2004-07-27 15:02:01 +00:00
|
|
|
|
.get_drive_cap = scsi_mmc_get_drive_cap_generic,
|
2004-07-29 02:48:55 +00:00
|
|
|
|
.get_discmode = get_discmode_generic,
|
|
|
|
|
|
.get_first_track_num= get_first_track_num_generic,
|
2004-11-20 12:50:26 +00:00
|
|
|
|
.get_hwinfo = NULL,
|
2004-04-25 17:05:07 +00:00
|
|
|
|
.get_mcn = _get_mcn_bsdi,
|
2004-07-29 02:48:55 +00:00
|
|
|
|
.get_num_tracks = get_num_tracks_generic,
|
2004-07-27 16:36:59 +00:00
|
|
|
|
.get_track_format = get_track_format_bsdi,
|
2004-04-25 17:05:07 +00:00
|
|
|
|
.get_track_green = _get_track_green_bsdi,
|
2003-03-29 17:32:00 +00:00
|
|
|
|
.get_track_lba = NULL, /* This could be implemented if need be. */
|
2004-04-25 17:05:07 +00:00
|
|
|
|
.get_track_msf = _get_track_msf_bsdi,
|
2003-03-30 01:11:35 +00:00
|
|
|
|
.lseek = cdio_generic_lseek,
|
|
|
|
|
|
.read = cdio_generic_read,
|
2004-04-25 17:05:07 +00:00
|
|
|
|
.read_audio_sectors = _read_audio_sectors_bsdi,
|
|
|
|
|
|
.read_mode1_sector = _read_mode1_sector_bsdi,
|
|
|
|
|
|
.read_mode1_sectors = _read_mode1_sectors_bsdi,
|
|
|
|
|
|
.read_mode2_sector = _read_mode2_sector_bsdi,
|
|
|
|
|
|
.read_mode2_sectors = _read_mode2_sectors_bsdi,
|
2004-07-29 02:48:55 +00:00
|
|
|
|
.read_toc = &read_toc_bsdi,
|
2004-07-28 01:09:59 +00:00
|
|
|
|
.run_scsi_mmc_cmd = &run_scsi_cmd_bsdi,
|
2004-04-25 17:05:07 +00:00
|
|
|
|
.set_arg = _set_arg_bsdi,
|
|
|
|
|
|
.stat_size = _stat_size_bsdi
|
2003-03-24 19:01:09 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_data = _cdio_malloc (sizeof (_img_private_t));
|
2003-03-29 17:32:00 +00:00
|
|
|
|
_data->access_mode = _AM_IOCTL;
|
2003-03-30 01:11:35 +00:00
|
|
|
|
_data->gen.init = false;
|
|
|
|
|
|
_data->gen.fd = -1;
|
2004-08-16 01:47:49 +00:00
|
|
|
|
_data->gen.toc_init = false;
|
2004-08-07 22:58:51 +00:00
|
|
|
|
_data->gen.b_cdtext_init = false;
|
|
|
|
|
|
_data->gen.b_cdtext_error = false;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-05-06 01:37:43 +00:00
|
|
|
|
if (NULL == psz_orig_source) {
|
|
|
|
|
|
psz_source=cdio_get_default_device_linux();
|
|
|
|
|
|
if (NULL == psz_source) return NULL;
|
|
|
|
|
|
_set_arg_bsdi(_data, "source", psz_source);
|
|
|
|
|
|
free(psz_source);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (cdio_is_device_generic(psz_orig_source))
|
|
|
|
|
|
_set_arg_bsdi(_data, "source", psz_orig_source);
|
|
|
|
|
|
else {
|
|
|
|
|
|
/* The below would be okay if all device drivers worked this way. */
|
|
|
|
|
|
#if 0
|
2004-09-03 23:20:11 +00:00
|
|
|
|
cdio_info ("source %s is not a device", psz_orig_source);
|
2004-05-06 01:37:43 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-07-27 15:02:01 +00:00
|
|
|
|
ret = cdio_new ( (void *) _data, &_funcs);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
if (ret == NULL) return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (_cdio_init(_data))
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
else {
|
2003-03-30 01:11:35 +00:00
|
|
|
|
cdio_generic_free (_data);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
#endif /* HAVE_BSDI_CDROM */
|
|
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
cdio_have_bsdi (void)
|
|
|
|
|
|
{
|
|
|
|
|
|
#ifdef HAVE_BSDI_CDROM
|
|
|
|
|
|
return true;
|
|
|
|
|
|
#else
|
|
|
|
|
|
return false;
|
|
|
|
|
|
#endif /* HAVE_BSDI_CDROM */
|
|
|
|
|
|
}
|