2003-03-24 19:01:09 +00:00
|
|
|
|
/*
|
2004-07-21 10:19:20 +00:00
|
|
|
|
$Id: _cdio_linux.c,v 1.71 2004/07/21 10:19:21 rocky Exp $
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
|
2004-02-07 02:40:20 +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
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* This file contains Linux-specific code and implements low-level
|
|
|
|
|
|
control of the CD drive.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
|
# include "config.h"
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2004-07-21 10:19:20 +00:00
|
|
|
|
static const char _rcsid[] = "$Id: _cdio_linux.c,v 1.71 2004/07/21 10:19:21 rocky Exp $";
|
2003-04-15 05:19:00 +00:00
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-04-22 12:09:08 +00:00
|
|
|
|
#include <cdio/sector.h>
|
|
|
|
|
|
#include <cdio/util.h>
|
2004-05-10 03:28:51 +00:00
|
|
|
|
#include <cdio/scsi_mmc.h>
|
2004-07-08 01:27:57 +00:00
|
|
|
|
#include <cdio/cdtext.h>
|
2004-07-09 01:05:31 +00:00
|
|
|
|
#include "cdtext_private.h"
|
2003-03-24 19:01:09 +00:00
|
|
|
|
#include "cdio_assert.h"
|
|
|
|
|
|
#include "cdio_private.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LINUX_CDROM
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(HAVE_LINUX_VERSION_H)
|
|
|
|
|
|
# include <linux/version.h>
|
|
|
|
|
|
# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,16)
|
|
|
|
|
|
# define __CDIO_LINUXCD_BUILD
|
|
|
|
|
|
# else
|
|
|
|
|
|
# error "You need a kernel greater than 2.2.16 to have CDROM support"
|
|
|
|
|
|
# endif
|
|
|
|
|
|
#else
|
|
|
|
|
|
# error "You need <linux/version.h> to have CDROM support"
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
#include <fcntl.h>
|
2003-06-12 04:46:27 +00:00
|
|
|
|
#include <mntent.h>
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
#include <linux/cdrom.h>
|
2003-05-16 07:18:27 +00:00
|
|
|
|
#include <scsi/scsi.h>
|
|
|
|
|
|
#include <scsi/sg.h>
|
|
|
|
|
|
#include <scsi/scsi_ioctl.h>
|
|
|
|
|
|
#include <sys/mount.h>
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
2004-07-08 01:27:57 +00:00
|
|
|
|
typedef struct cdrom_generic_command cgc_t;
|
|
|
|
|
|
|
2004-05-31 12:29:09 +00:00
|
|
|
|
#define TOTAL_TRACKS (env->tochdr.cdth_trk1)
|
|
|
|
|
|
#define FIRST_TRACK_NUM (env->tochdr.cdth_trk0)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-04-30 06:54:15 +00:00
|
|
|
|
typedef enum {
|
|
|
|
|
|
_AM_NONE,
|
|
|
|
|
|
_AM_IOCTL,
|
|
|
|
|
|
_AM_READ_CD,
|
|
|
|
|
|
_AM_READ_10
|
|
|
|
|
|
} access_mode_t;
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
typedef struct {
|
2003-03-29 17:32:00 +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-07-15 02:24:29 +00:00
|
|
|
|
/* Entry info for each track, add 1 for leadout. */
|
|
|
|
|
|
struct cdrom_tocentry tocent[CDIO_CD_MAX_TRACKS+1];
|
|
|
|
|
|
|
|
|
|
|
|
cdtext_t cdtext; /* CD-TEXT */
|
|
|
|
|
|
|
2004-04-30 06:54:15 +00:00
|
|
|
|
access_mode_t access_mode;
|
2004-07-15 02:24:29 +00:00
|
|
|
|
bool b_cdtext_init;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-07-15 02:24:29 +00:00
|
|
|
|
/* Some of the more OS specific things. */
|
|
|
|
|
|
cdtext_t cdtext_track[CDIO_CD_MAX_TRACKS+1]; /*CD-TEXT for each track*/
|
2003-03-24 19:01:09 +00:00
|
|
|
|
struct cdrom_tochdr tochdr;
|
|
|
|
|
|
|
|
|
|
|
|
} _img_private_t;
|
|
|
|
|
|
|
2003-06-12 04:46:27 +00:00
|
|
|
|
/* Some ioctl() errno values which occur when the tray is empty */
|
|
|
|
|
|
#define ERRNO_TRAYEMPTY(errno) \
|
|
|
|
|
|
((errno == EIO) || (errno == ENOENT) || (errno == EINVAL))
|
|
|
|
|
|
|
2004-04-30 06:54:15 +00:00
|
|
|
|
static access_mode_t
|
|
|
|
|
|
str_to_access_mode_linux(const char *psz_access_mode)
|
|
|
|
|
|
{
|
|
|
|
|
|
const access_mode_t default_access_mode = _AM_IOCTL;
|
|
|
|
|
|
|
|
|
|
|
|
if (NULL==psz_access_mode) return default_access_mode;
|
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(psz_access_mode, "IOCTL"))
|
|
|
|
|
|
return _AM_IOCTL;
|
|
|
|
|
|
else if (!strcmp(psz_access_mode, "READ_CD"))
|
|
|
|
|
|
return _AM_READ_CD;
|
|
|
|
|
|
else if (!strcmp(psz_access_mode, "READ_10"))
|
|
|
|
|
|
return _AM_READ_10;
|
|
|
|
|
|
else {
|
|
|
|
|
|
cdio_warn ("unknown access type: %s. Default IOCTL used.",
|
|
|
|
|
|
psz_access_mode);
|
|
|
|
|
|
return default_access_mode;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2003-06-12 04:46:27 +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:26:52 +00:00
|
|
|
|
static bool
|
2003-06-12 04:46:27 +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 */
|
2004-03-07 01:40:00 +00:00
|
|
|
|
cdfd = open(drive, (O_RDONLY|O_NONBLOCK), 0);
|
2003-06-12 04:46:27 +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 */
|
|
|
|
|
|
else if ( mnttype && (strcmp(mnttype, "iso9660") == 0) ) {
|
|
|
|
|
|
is_cd = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return(is_cd);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-07-21 10:19:20 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Get disc tyhpe associated with cd_obj.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static discmode_t
|
|
|
|
|
|
_get_discmode_linux (void *user_data)
|
|
|
|
|
|
{
|
|
|
|
|
|
_img_private_t *env = user_data;
|
|
|
|
|
|
|
|
|
|
|
|
int32_t i_discmode;
|
|
|
|
|
|
i_discmode = ioctl (env->gen.fd, CDROM_DISC_STATUS);
|
|
|
|
|
|
|
|
|
|
|
|
if (i_discmode < 0) return CDIO_DISC_MODE_ERROR;
|
|
|
|
|
|
|
|
|
|
|
|
/* FIXME Need to add getting DVD types. */
|
|
|
|
|
|
switch(i_discmode) {
|
|
|
|
|
|
case CDS_AUDIO:
|
|
|
|
|
|
return CDIO_DISC_MODE_CD_DA;
|
|
|
|
|
|
case CDS_DATA_1:
|
|
|
|
|
|
return CDIO_DISC_MODE_CD_DATA_1;
|
|
|
|
|
|
case CDS_DATA_2:
|
|
|
|
|
|
return CDIO_DISC_MODE_CD_DATA_2;
|
|
|
|
|
|
case CDS_MIXED:
|
|
|
|
|
|
return CDIO_DISC_MODE_CD_MIXED;
|
|
|
|
|
|
case CDS_XA_2_1:
|
|
|
|
|
|
return CDIO_DISC_MODE_CD_XA_2_1;
|
|
|
|
|
|
case CDS_XA_2_2:
|
|
|
|
|
|
return CDIO_DISC_MODE_CD_XA_2_2;
|
|
|
|
|
|
case CDS_NO_INFO:
|
|
|
|
|
|
return CDIO_DISC_MODE_NO_INFO;
|
|
|
|
|
|
default:
|
|
|
|
|
|
return CDIO_DISC_MODE_ERROR;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-06-12 04:46:27 +00:00
|
|
|
|
static char *
|
|
|
|
|
|
cdio_check_mounts(const char *mtab)
|
|
|
|
|
|
{
|
|
|
|
|
|
FILE *mntfp;
|
|
|
|
|
|
struct mntent *mntent;
|
|
|
|
|
|
|
|
|
|
|
|
mntfp = setmntent(mtab, "r");
|
|
|
|
|
|
if ( mntfp != NULL ) {
|
|
|
|
|
|
char *tmp;
|
|
|
|
|
|
char *mnt_type;
|
|
|
|
|
|
char *mnt_dev;
|
|
|
|
|
|
|
|
|
|
|
|
while ( (mntent=getmntent(mntfp)) != NULL ) {
|
|
|
|
|
|
mnt_type = malloc(strlen(mntent->mnt_type) + 1);
|
|
|
|
|
|
if (mnt_type == NULL)
|
|
|
|
|
|
continue; /* maybe you'll get lucky next time. */
|
|
|
|
|
|
|
|
|
|
|
|
mnt_dev = malloc(strlen(mntent->mnt_fsname) + 1);
|
|
|
|
|
|
if (mnt_dev == NULL) {
|
|
|
|
|
|
free(mnt_type);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
strcpy(mnt_type, mntent->mnt_type);
|
|
|
|
|
|
strcpy(mnt_dev, mntent->mnt_fsname);
|
|
|
|
|
|
|
|
|
|
|
|
/* Handle "supermount" filesystem mounts */
|
|
|
|
|
|
if ( strcmp(mnt_type, "supermount") == 0 ) {
|
|
|
|
|
|
tmp = strstr(mntent->mnt_opts, "fs=");
|
|
|
|
|
|
if ( tmp ) {
|
|
|
|
|
|
free(mnt_type);
|
|
|
|
|
|
mnt_type = strdup(tmp + strlen("fs="));
|
|
|
|
|
|
if ( mnt_type ) {
|
|
|
|
|
|
tmp = strchr(mnt_type, ',');
|
|
|
|
|
|
if ( tmp ) {
|
|
|
|
|
|
*tmp = '\0';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
tmp = strstr(mntent->mnt_opts, "dev=");
|
|
|
|
|
|
if ( tmp ) {
|
|
|
|
|
|
free(mnt_dev);
|
|
|
|
|
|
mnt_dev = strdup(tmp + strlen("dev="));
|
|
|
|
|
|
if ( mnt_dev ) {
|
|
|
|
|
|
tmp = strchr(mnt_dev, ',');
|
|
|
|
|
|
if ( tmp ) {
|
|
|
|
|
|
*tmp = '\0';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( strcmp(mnt_type, "iso9660") == 0 ) {
|
|
|
|
|
|
if (cdio_is_cdrom(mnt_dev, mnt_type) > 0) {
|
|
|
|
|
|
free(mnt_type);
|
|
|
|
|
|
endmntent(mntfp);
|
2004-02-21 17:18:04 +00:00
|
|
|
|
return mnt_dev;
|
2003-06-12 04:46:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
free(mnt_dev);
|
|
|
|
|
|
free(mnt_type);
|
|
|
|
|
|
}
|
|
|
|
|
|
endmntent(mntfp);
|
|
|
|
|
|
}
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
static int
|
2003-03-24 23:59:22 +00:00
|
|
|
|
_set_bsize (int fd, unsigned int bsize)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
struct cdrom_generic_command cgc;
|
|
|
|
|
|
|
|
|
|
|
|
struct
|
|
|
|
|
|
{
|
|
|
|
|
|
uint8_t reserved1;
|
|
|
|
|
|
uint8_t medium;
|
|
|
|
|
|
uint8_t reserved2;
|
|
|
|
|
|
uint8_t block_desc_length;
|
|
|
|
|
|
uint8_t density;
|
|
|
|
|
|
uint8_t number_of_blocks_hi;
|
|
|
|
|
|
uint8_t number_of_blocks_med;
|
|
|
|
|
|
uint8_t number_of_blocks_lo;
|
|
|
|
|
|
uint8_t reserved3;
|
|
|
|
|
|
uint8_t block_length_hi;
|
|
|
|
|
|
uint8_t block_length_med;
|
|
|
|
|
|
uint8_t block_length_lo;
|
|
|
|
|
|
} mh;
|
|
|
|
|
|
|
|
|
|
|
|
memset (&mh, 0, sizeof (mh));
|
|
|
|
|
|
memset (&cgc, 0, sizeof (struct cdrom_generic_command));
|
|
|
|
|
|
|
2004-07-15 11:36:12 +00:00
|
|
|
|
CDIO_MMC_SET_COMMAND(cgc.cmd, CDIO_MMC_GPCMD_MODE_SELECT_6);
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
cgc.cmd[1] = 1 << 4;
|
|
|
|
|
|
cgc.cmd[4] = 12;
|
|
|
|
|
|
|
|
|
|
|
|
cgc.buflen = sizeof (mh);
|
|
|
|
|
|
cgc.buffer = (void *) &mh;
|
|
|
|
|
|
|
|
|
|
|
|
cgc.data_direction = CGC_DATA_WRITE;
|
|
|
|
|
|
|
|
|
|
|
|
mh.block_desc_length = 0x08;
|
2003-04-08 21:12:45 +00:00
|
|
|
|
mh.block_length_hi = (bsize >> 16) & 0xff;
|
|
|
|
|
|
mh.block_length_med = (bsize >> 8) & 0xff;
|
|
|
|
|
|
mh.block_length_lo = (bsize >> 0) & 0xff;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
return ioctl (fd, CDROM_SEND_PACKET, &cgc);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-04-10 04:11:45 +00:00
|
|
|
|
/* Packet driver to read mode2 sectors.
|
|
|
|
|
|
Can read only up to 25 blocks.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-07-13 04:33:05 +00:00
|
|
|
|
_read_sectors_mmc (int fd, void *buf, lba_t lba, int sector_type,
|
2003-09-20 12:34:02 +00:00
|
|
|
|
unsigned int nblocks)
|
2003-04-10 04:11:45 +00:00
|
|
|
|
{
|
2003-09-20 12:34:02 +00:00
|
|
|
|
cgc_t cgc;
|
2003-04-10 04:11:45 +00:00
|
|
|
|
|
2003-09-20 12:34:02 +00:00
|
|
|
|
memset (&cgc, 0, sizeof (cgc_t));
|
2003-04-10 04:11:45 +00:00
|
|
|
|
|
2003-09-18 13:31:07 +00:00
|
|
|
|
cgc.cmd[0] = CDIO_MMC_GPCMD_READ_CD;
|
2003-09-19 04:37:31 +00:00
|
|
|
|
CDIO_MMC_SET_READ_TYPE (cgc.cmd, sector_type);
|
|
|
|
|
|
CDIO_MMC_SET_READ_LBA (cgc.cmd, lba);
|
2003-09-18 13:31:07 +00:00
|
|
|
|
CDIO_MMC_SET_READ_LENGTH(cgc.cmd, nblocks);
|
2003-09-20 12:34:02 +00:00
|
|
|
|
CDIO_MMC_SET_MAIN_CHANNEL_SELECTION_BITS(cgc.cmd, CDIO_MMC_MCSB_ALL_HEADERS);
|
2003-04-10 04:11:45 +00:00
|
|
|
|
|
|
|
|
|
|
cgc.buflen = CDIO_CD_FRAMESIZE_RAW * nblocks;
|
|
|
|
|
|
cgc.buffer = buf;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LINUX_CDROM_TIMEOUT
|
|
|
|
|
|
cgc.timeout = 500;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
cgc.data_direction = CGC_DATA_READ;
|
|
|
|
|
|
|
|
|
|
|
|
return ioctl (fd, CDROM_SEND_PACKET, &cgc);
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-09-20 12:34:02 +00:00
|
|
|
|
/* MMC driver to read audio sectors.
|
2003-09-18 13:31:07 +00:00
|
|
|
|
Can read only up to 25 blocks.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_read_audio_sectors_linux (void *user_data, void *buf, lsn_t lsn,
|
2004-04-25 15:41:26 +00:00
|
|
|
|
unsigned int nblocks)
|
2003-09-18 13:31:07 +00:00
|
|
|
|
{
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2004-07-13 04:33:05 +00:00
|
|
|
|
return _read_sectors_mmc( env->gen.fd, buf, lsn,
|
|
|
|
|
|
CDIO_MMC_READ_TYPE_CDDA, nblocks);
|
2003-09-18 13:31:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-04-08 21:12:45 +00:00
|
|
|
|
/* Packet driver to read mode2 sectors.
|
|
|
|
|
|
Can read only up to 25 blocks.
|
|
|
|
|
|
*/
|
2003-03-24 19:01:09 +00:00
|
|
|
|
static int
|
2004-07-13 04:33:05 +00:00
|
|
|
|
_read_mode2_sectors_mmc (int fd, void *buf, lba_t lba,
|
|
|
|
|
|
unsigned int nblocks, bool b_read_10)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
struct cdrom_generic_command cgc;
|
|
|
|
|
|
|
|
|
|
|
|
memset (&cgc, 0, sizeof (struct cdrom_generic_command));
|
|
|
|
|
|
|
2004-05-05 02:47:18 +00:00
|
|
|
|
CDIO_MMC_SET_COMMAND(cgc.cmd, b_read_10
|
|
|
|
|
|
? CDIO_MMC_GPCMD_READ_10 : CDIO_MMC_GPCMD_READ_CD);
|
2003-09-14 09:34:17 +00:00
|
|
|
|
|
2003-09-18 13:31:07 +00:00
|
|
|
|
CDIO_MMC_SET_READ_LBA(cgc.cmd, lba);
|
|
|
|
|
|
CDIO_MMC_SET_READ_LENGTH(cgc.cmd, nblocks);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-05-05 02:47:18 +00:00
|
|
|
|
if (!b_read_10) {
|
|
|
|
|
|
cgc.cmd[1] = 0; /* sector size mode2 */
|
|
|
|
|
|
cgc.cmd[9] = 0x58; /* 2336 mode2 */
|
|
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-04-26 07:54:47 +00:00
|
|
|
|
cgc.buflen = M2RAW_SECTOR_SIZE * nblocks;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
cgc.buffer = buf;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LINUX_CDROM_TIMEOUT
|
|
|
|
|
|
cgc.timeout = 500;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
cgc.data_direction = CGC_DATA_READ;
|
|
|
|
|
|
|
2004-05-05 02:47:18 +00:00
|
|
|
|
if (b_read_10)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
int retval;
|
|
|
|
|
|
|
2004-04-26 07:54:47 +00:00
|
|
|
|
if ((retval = _set_bsize (fd, M2RAW_SECTOR_SIZE)))
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
|
|
|
|
if ((retval = ioctl (fd, CDROM_SEND_PACKET, &cgc)))
|
|
|
|
|
|
{
|
2004-04-26 07:54:47 +00:00
|
|
|
|
_set_bsize (fd, CDIO_CD_FRAMESIZE);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return retval;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-04-26 07:54:47 +00:00
|
|
|
|
if ((retval = _set_bsize (fd, CDIO_CD_FRAMESIZE)))
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return retval;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
return ioctl (fd, CDROM_SEND_PACKET, &cgc);
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2004-07-13 04:33:05 +00:00
|
|
|
|
_read_mode2_sectors (int fd, void *buf, lba_t lba,
|
2004-07-15 11:36:12 +00:00
|
|
|
|
unsigned int nblocks, bool b_read_10)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2003-09-01 15:11:36 +00:00
|
|
|
|
unsigned int l = 0;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
|
|
|
|
while (nblocks > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
const unsigned nblocks2 = (nblocks > 25) ? 25 : nblocks;
|
2004-04-26 07:54:47 +00:00
|
|
|
|
void *buf2 = ((char *)buf ) + (l * M2RAW_SECTOR_SIZE);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-07-13 04:33:05 +00:00
|
|
|
|
retval |= _read_mode2_sectors_mmc (fd, buf2, lba + l, nblocks2,
|
|
|
|
|
|
b_read_10);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
if (retval)
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
nblocks -= nblocks2;
|
|
|
|
|
|
l += nblocks2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-03-06 04:49:26 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Reads a single mode1 sector from cd device into data starting
|
|
|
|
|
|
from lsn. Returns 0 if no error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-04-25 15:41:26 +00:00
|
|
|
|
_read_mode1_sector_linux (void *env, void *data, lsn_t lsn,
|
2004-03-07 02:42:22 +00:00
|
|
|
|
bool b_form2)
|
2004-03-06 04:49:26 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
#if FIXED
|
2004-06-26 00:39:00 +00:00
|
|
|
|
char buf[M2RAW_SECTOR_SIZE] = { 0, };
|
2004-03-06 04:49:26 +00:00
|
|
|
|
struct cdrom_msf *msf = (struct cdrom_msf *) &buf;
|
|
|
|
|
|
msf_t _msf;
|
|
|
|
|
|
|
|
|
|
|
|
_img_private_t *_obj = env;
|
|
|
|
|
|
|
|
|
|
|
|
cdio_lba_to_msf (cdio_lsn_to_lba(lsn), &_msf);
|
|
|
|
|
|
msf->cdmsf_min0 = from_bcd8(_msf.m);
|
|
|
|
|
|
msf->cdmsf_sec0 = from_bcd8(_msf.s);
|
|
|
|
|
|
msf->cdmsf_frame0 = from_bcd8(_msf.f);
|
|
|
|
|
|
|
|
|
|
|
|
retry:
|
|
|
|
|
|
switch (_obj->access_mode)
|
|
|
|
|
|
{
|
|
|
|
|
|
case _AM_NONE:
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn ("no way to read mode1");
|
2004-03-06 04:49:26 +00:00
|
|
|
|
return 1;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case _AM_IOCTL:
|
|
|
|
|
|
if (ioctl (_obj->gen.fd, CDROMREADMODE1, &buf) == -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
perror ("ioctl()");
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
/* exit (EXIT_FAILURE); */
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case _AM_READ_CD:
|
|
|
|
|
|
case _AM_READ_10:
|
2004-07-13 04:33:05 +00:00
|
|
|
|
if (_read_mode2_sectors (_obj->gen.fd, buf, lsn, 1,
|
2004-03-06 04:49:26 +00:00
|
|
|
|
(_obj->access_mode == _AM_READ_10)))
|
|
|
|
|
|
{
|
|
|
|
|
|
perror ("ioctl()");
|
|
|
|
|
|
if (_obj->access_mode == _AM_READ_CD)
|
|
|
|
|
|
{
|
|
|
|
|
|
cdio_info ("READ_CD failed; switching to READ_10 mode...");
|
|
|
|
|
|
_obj->access_mode = _AM_READ_10;
|
|
|
|
|
|
goto retry;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
cdio_info ("READ_10 failed; switching to ioctl(CDROMREADMODE2) mode...");
|
|
|
|
|
|
_obj->access_mode = _AM_IOCTL;
|
|
|
|
|
|
goto retry;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
memcpy (data, buf + CDIO_CD_SYNC_SIZE + CDIO_CD_HEADER_SIZE,
|
2004-03-07 02:42:22 +00:00
|
|
|
|
b_form2 ? M2RAW_SECTOR_SIZE: CDIO_CD_FRAMESIZE);
|
2004-03-06 04:49:26 +00:00
|
|
|
|
|
|
|
|
|
|
#else
|
2004-06-26 00:39:00 +00:00
|
|
|
|
return cdio_generic_read_form1_sector(env, data, lsn);
|
2004-03-06 04:49:26 +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-05-31 12:29:09 +00:00
|
|
|
|
_read_mode1_sectors_linux (void *user_data, void *data, lsn_t lsn,
|
2004-03-07 02:42:22 +00:00
|
|
|
|
bool b_form2, unsigned int nblocks)
|
2004-03-06 04:49:26 +00:00
|
|
|
|
{
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2004-03-06 04:49:26 +00:00
|
|
|
|
unsigned int i;
|
|
|
|
|
|
int retval;
|
2004-03-07 02:42:22 +00:00
|
|
|
|
unsigned int blocksize = b_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE;
|
2004-03-06 04:49:26 +00:00
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nblocks; i++) {
|
2004-05-31 12:29:09 +00:00
|
|
|
|
if ( (retval = _read_mode1_sector_linux (env,
|
2004-03-06 04:49:26 +00:00
|
|
|
|
((char *)data) + (blocksize * i),
|
2004-03-07 02:42:22 +00:00
|
|
|
|
lsn + i, b_form2)) )
|
2004-03-06 04:49:26 +00:00
|
|
|
|
return retval;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Reads a single mode2 sector from cd device into data starting
|
|
|
|
|
|
from lsn. Returns 0 if no error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_read_mode2_sector_linux (void *user_data, void *data, lsn_t lsn,
|
2004-06-03 08:50:30 +00:00
|
|
|
|
bool b_form2)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
char buf[M2RAW_SECTOR_SIZE] = { 0, };
|
|
|
|
|
|
struct cdrom_msf *msf = (struct cdrom_msf *) &buf;
|
|
|
|
|
|
msf_t _msf;
|
|
|
|
|
|
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
cdio_lba_to_msf (cdio_lsn_to_lba(lsn), &_msf);
|
|
|
|
|
|
msf->cdmsf_min0 = from_bcd8(_msf.m);
|
|
|
|
|
|
msf->cdmsf_sec0 = from_bcd8(_msf.s);
|
|
|
|
|
|
msf->cdmsf_frame0 = from_bcd8(_msf.f);
|
|
|
|
|
|
|
|
|
|
|
|
retry:
|
2004-05-31 12:29:09 +00:00
|
|
|
|
switch (env->access_mode)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
case _AM_NONE:
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn ("no way to read mode2");
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return 1;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case _AM_IOCTL:
|
2004-05-31 12:29:09 +00:00
|
|
|
|
if (ioctl (env->gen.fd, CDROMREADMODE2, &buf) == -1)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
perror ("ioctl()");
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
/* exit (EXIT_FAILURE); */
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case _AM_READ_CD:
|
|
|
|
|
|
case _AM_READ_10:
|
2004-07-13 04:33:05 +00:00
|
|
|
|
if (_read_mode2_sectors (env->gen.fd, buf, lsn, 1,
|
2004-05-31 12:29:09 +00:00
|
|
|
|
(env->access_mode == _AM_READ_10)))
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
perror ("ioctl()");
|
2004-05-31 12:29:09 +00:00
|
|
|
|
if (env->access_mode == _AM_READ_CD)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
cdio_info ("READ_CD failed; switching to READ_10 mode...");
|
2004-05-31 12:29:09 +00:00
|
|
|
|
env->access_mode = _AM_READ_10;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
goto retry;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
cdio_info ("READ_10 failed; switching to ioctl(CDROMREADMODE2) mode...");
|
2004-05-31 12:29:09 +00:00
|
|
|
|
env->access_mode = _AM_IOCTL;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
goto retry;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-03-07 02:42:22 +00:00
|
|
|
|
if (b_form2)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
memcpy (data, buf, M2RAW_SECTOR_SIZE);
|
|
|
|
|
|
else
|
2003-04-06 18:12:37 +00:00
|
|
|
|
memcpy (((char *)data), buf + CDIO_CD_SUBHEADER_SIZE, CDIO_CD_FRAMESIZE);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Reads nblocks of mode2 sectors from cd device into data starting
|
|
|
|
|
|
from lsn.
|
|
|
|
|
|
Returns 0 if no error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_read_mode2_sectors_linux (void *user_data, void *data, lsn_t lsn,
|
2004-03-07 02:42:22 +00:00
|
|
|
|
bool b_form2, unsigned int nblocks)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-09-27 23:29:29 +00:00
|
|
|
|
unsigned int i;
|
2004-06-03 08:50:30 +00:00
|
|
|
|
unsigned int i_blocksize = b_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-06-03 08:50:30 +00:00
|
|
|
|
/* For each frame, pick out the data part we need */
|
2003-03-24 19:01:09 +00:00
|
|
|
|
for (i = 0; i < nblocks; i++) {
|
2004-06-03 08:50:30 +00:00
|
|
|
|
int retval;
|
2004-05-31 12:29:09 +00:00
|
|
|
|
if ( (retval = _read_mode2_sector_linux (env,
|
2004-06-03 08:50:30 +00:00
|
|
|
|
((char *)data) + (i_blocksize * i),
|
2004-03-07 02:42:22 +00:00
|
|
|
|
lsn + i, b_form2)) )
|
2004-03-06 04:49:26 +00:00
|
|
|
|
return retval;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the size of the CD in logical block address (LBA) units.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static uint32_t
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_stat_size_linux (void *user_data)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
struct cdrom_tocentry tocent;
|
|
|
|
|
|
uint32_t size;
|
|
|
|
|
|
|
2003-04-06 17:57:20 +00:00
|
|
|
|
tocent.cdte_track = CDIO_CDROM_LEADOUT_TRACK;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
tocent.cdte_format = CDROM_LBA;
|
2004-05-31 12:29:09 +00:00
|
|
|
|
if (ioctl (env->gen.fd, CDROMREADTOCENTRY, &tocent) == -1)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
perror ("ioctl(CDROMREADTOCENTRY)");
|
|
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size = tocent.cdte_addr.lba;
|
|
|
|
|
|
|
|
|
|
|
|
return size;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2003-09-27 23:29:29 +00:00
|
|
|
|
Set the arg "key" with "value" in the source device.
|
|
|
|
|
|
Currently "source" and "access-mode" are valid keys.
|
|
|
|
|
|
"source" sets the source device in I/O operations
|
|
|
|
|
|
"access-mode" sets the the method of CD access
|
|
|
|
|
|
|
|
|
|
|
|
0 is returned if no error was found, and nonzero if there as an error.
|
2003-03-24 19:01:09 +00:00
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_set_arg_linux (void *user_data, const char key[], const char value[])
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
if (!strcmp (key, "source"))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!value)
|
|
|
|
|
|
return -2;
|
|
|
|
|
|
|
2004-05-31 12:29:09 +00:00
|
|
|
|
free (env->gen.source_name);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-05-31 12:29:09 +00:00
|
|
|
|
env->gen.source_name = strdup (value);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (!strcmp (key, "access-mode"))
|
|
|
|
|
|
{
|
2004-04-30 06:54:15 +00:00
|
|
|
|
return str_to_access_mode_linux(value);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
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-05-31 12:29:09 +00:00
|
|
|
|
_cdio_read_toc (_img_private_t *env)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
|
|
/* read TOC header */
|
2004-05-31 12:29:09 +00:00
|
|
|
|
if ( ioctl(env->gen.fd, CDROMREADTOCHDR, &env->tochdr) == -1 ) {
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn("%s: %s\n",
|
2003-03-24 19:01:09 +00:00
|
|
|
|
"error in ioctl CDROMREADTOCHDR", strerror(errno));
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* read individual tracks */
|
|
|
|
|
|
for (i= FIRST_TRACK_NUM; i<=TOTAL_TRACKS; i++) {
|
2004-05-31 12:29:09 +00:00
|
|
|
|
env->tocent[i-FIRST_TRACK_NUM].cdte_track = i;
|
|
|
|
|
|
env->tocent[i-FIRST_TRACK_NUM].cdte_format = CDROM_MSF;
|
|
|
|
|
|
if ( ioctl(env->gen.fd, CDROMREADTOCENTRY,
|
|
|
|
|
|
&env->tocent[i-FIRST_TRACK_NUM]) == -1 ) {
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn("%s %d: %s\n",
|
2003-03-24 19:01:09 +00:00
|
|
|
|
"error in ioctl CDROMREADTOCENTRY for track",
|
|
|
|
|
|
i, strerror(errno));
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
/****
|
2004-05-31 12:29:09 +00:00
|
|
|
|
struct cdrom_msf0 *msf= &env->tocent[i-1].cdte_addr.msf;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
fprintf (stdout, "--- track# %d (msf %2.2x:%2.2x:%2.2x)\n",
|
|
|
|
|
|
i, msf->minute, msf->second, msf->frame);
|
|
|
|
|
|
****/
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* read the lead-out track */
|
2004-05-31 12:29:09 +00:00
|
|
|
|
env->tocent[TOTAL_TRACKS].cdte_track = CDIO_CDROM_LEADOUT_TRACK;
|
|
|
|
|
|
env->tocent[TOTAL_TRACKS].cdte_format = CDROM_MSF;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-05-31 12:29:09 +00:00
|
|
|
|
if (ioctl(env->gen.fd, CDROMREADTOCENTRY,
|
|
|
|
|
|
&env->tocent[TOTAL_TRACKS]) == -1 ) {
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn("%s: %s\n",
|
2003-03-24 19:01:09 +00:00
|
|
|
|
"error in ioctl CDROMREADTOCENTRY for lead-out",
|
|
|
|
|
|
strerror(errno));
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-05-31 12:29:09 +00:00
|
|
|
|
struct cdrom_msf0 *msf= &env->tocent[TOTAL_TRACKS].cdte_addr.msf;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
fprintf (stdout, "--- track# %d (msf %2.2x:%2.2x:%2.2x)\n",
|
|
|
|
|
|
i, msf->minute, msf->second, msf->frame);
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2004-05-31 12:29:09 +00:00
|
|
|
|
env->gen.toc_init = true;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-07-17 08:59:44 +00:00
|
|
|
|
static void
|
|
|
|
|
|
set_cdtext_field_linux(void *user_data, track_t i_track,
|
|
|
|
|
|
track_t i_first_track,
|
|
|
|
|
|
cdtext_field_t e_field, const char *psz_value)
|
|
|
|
|
|
{
|
|
|
|
|
|
char **pp_field;
|
|
|
|
|
|
_img_private_t *env = user_data;
|
|
|
|
|
|
|
|
|
|
|
|
if( i_track == 0 )
|
|
|
|
|
|
pp_field = &(env->cdtext.field[e_field]);
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
pp_field = &(env->cdtext_track[i_track-i_first_track].field[e_field]);
|
2004-07-15 02:24:29 +00:00
|
|
|
|
|
2004-07-17 08:59:44 +00:00
|
|
|
|
*pp_field = strdup(psz_value);
|
|
|
|
|
|
}
|
2004-07-15 02:24:29 +00:00
|
|
|
|
|
2004-07-17 02:43:41 +00:00
|
|
|
|
/*
|
|
|
|
|
|
Read cdtext information for a CdIo object .
|
2004-07-15 02:24:29 +00:00
|
|
|
|
|
2004-07-17 02:43:41 +00:00
|
|
|
|
return true on success, false on error or CD-TEXT information does
|
|
|
|
|
|
not exist.
|
2004-07-15 02:24:29 +00:00
|
|
|
|
*/
|
2004-07-17 02:18:26 +00:00
|
|
|
|
static bool
|
|
|
|
|
|
_init_cdtext_linux (_img_private_t *env)
|
2004-07-08 01:27:57 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
2004-07-21 10:19:20 +00:00
|
|
|
|
struct cdrom_generic_command cdc;
|
|
|
|
|
|
struct request_sense sense;
|
|
|
|
|
|
unsigned char wdata[2000]= {0, }; /* Data read from device starts here */
|
2004-07-15 02:24:29 +00:00
|
|
|
|
int status;
|
2004-07-08 01:27:57 +00:00
|
|
|
|
|
2004-07-21 10:19:20 +00:00
|
|
|
|
memset(&cdc, 0, sizeof(struct cdrom_generic_command));
|
|
|
|
|
|
memset(&sense, 0, sizeof(struct request_sense));
|
2004-07-19 01:13:31 +00:00
|
|
|
|
|
|
|
|
|
|
/* Operation code */
|
2004-07-21 10:19:20 +00:00
|
|
|
|
CDIO_MMC_SET_COMMAND(cdc.cmd, CDIO_MMC_GPCMD_READ_TOC);
|
2004-07-19 01:13:31 +00:00
|
|
|
|
|
|
|
|
|
|
/* Format */
|
2004-07-21 10:19:20 +00:00
|
|
|
|
cdc.cmd[2] = CDIO_MMC_READTOC_FMT_CDTEXT;
|
2004-07-19 01:13:31 +00:00
|
|
|
|
|
2004-07-21 10:19:20 +00:00
|
|
|
|
cdc.buffer = wdata;
|
|
|
|
|
|
cdc.buflen = sizeof(wdata);
|
|
|
|
|
|
cdc.stat = 0;
|
|
|
|
|
|
cdc.sense = &sense;
|
|
|
|
|
|
cdc.data_direction = CGC_DATA_READ;
|
2004-07-08 01:27:57 +00:00
|
|
|
|
|
2004-07-21 10:19:20 +00:00
|
|
|
|
status = ioctl(env->gen.fd, CDROM_SEND_PACKET, (void *)&cdc);
|
|
|
|
|
|
if (status < 0) {
|
|
|
|
|
|
cdio_info ("CDTEXT reading failed\n");
|
2004-07-17 02:18:26 +00:00
|
|
|
|
return false;
|
2004-07-15 02:24:29 +00:00
|
|
|
|
} else {
|
2004-07-21 10:19:20 +00:00
|
|
|
|
return cdtext_data_init(env, FIRST_TRACK_NUM, wdata,
|
2004-07-17 08:59:44 +00:00
|
|
|
|
set_cdtext_field_linux);
|
2004-07-08 01:27:57 +00:00
|
|
|
|
}
|
2004-07-17 02:18:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Get cdtext information for a CdIo object .
|
|
|
|
|
|
|
|
|
|
|
|
@param obj the CD object that may contain CD-TEXT information.
|
|
|
|
|
|
@return the CD-TEXT object or NULL if obj is NULL
|
|
|
|
|
|
or CD-TEXT information does not exist.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static const cdtext_t *
|
|
|
|
|
|
_get_cdtext_linux (void *user_data, track_t i_track)
|
|
|
|
|
|
{
|
|
|
|
|
|
_img_private_t *env = user_data;
|
|
|
|
|
|
|
|
|
|
|
|
if ( NULL == env ||
|
|
|
|
|
|
(0 != i_track
|
|
|
|
|
|
&& i_track >= TOTAL_TRACKS+FIRST_TRACK_NUM ) )
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
env->b_cdtext_init = _init_cdtext_linux(env);
|
|
|
|
|
|
if (!env->b_cdtext_init) return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (0 == i_track)
|
|
|
|
|
|
return &(env->cdtext);
|
|
|
|
|
|
else
|
|
|
|
|
|
return &(env->cdtext_track[i_track-FIRST_TRACK_NUM]);
|
|
|
|
|
|
|
2004-07-08 01:27:57 +00:00
|
|
|
|
}
|
2004-07-15 02:24:29 +00:00
|
|
|
|
|
2003-05-16 07:18:27 +00:00
|
|
|
|
/*
|
|
|
|
|
|
* Eject using SCSI commands. Return 1 if successful, 0 otherwise.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-04-26 07:54:47 +00:00
|
|
|
|
_eject_media_mmc(int fd)
|
2003-05-16 07:18:27 +00:00
|
|
|
|
{
|
|
|
|
|
|
int status;
|
|
|
|
|
|
struct sdata {
|
2004-07-15 11:36:12 +00:00
|
|
|
|
unsigned int inlen; /* Length of data written to device */
|
|
|
|
|
|
unsigned int outlen; /* Length of data read from device */
|
|
|
|
|
|
char cdb[10]; /* SCSI command bytes (6 <= x <= 16) */
|
2003-05-16 07:18:27 +00:00
|
|
|
|
} scsi_cmd;
|
|
|
|
|
|
|
2004-07-15 11:36:12 +00:00
|
|
|
|
CDIO_MMC_SET_COMMAND(scsi_cmd.cdb, CDIO_MMC_GPCMD_ALLOW_MEDIUM_REMOVAL);
|
2004-07-08 01:27:57 +00:00
|
|
|
|
|
|
|
|
|
|
scsi_cmd.inlen = 0;
|
2003-05-16 07:18:27 +00:00
|
|
|
|
scsi_cmd.outlen = 0;
|
2004-07-15 11:36:12 +00:00
|
|
|
|
scsi_cmd.cdb[1] = 0;
|
|
|
|
|
|
scsi_cmd.cdb[2] = 0;
|
|
|
|
|
|
scsi_cmd.cdb[3] = 0;
|
|
|
|
|
|
scsi_cmd.cdb[4] = 0;
|
|
|
|
|
|
scsi_cmd.cdb[5] = 0;
|
2003-05-16 07:18:27 +00:00
|
|
|
|
status = ioctl(fd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd);
|
|
|
|
|
|
if (status != 0)
|
2004-07-08 01:27:57 +00:00
|
|
|
|
return status;
|
2003-05-16 07:18:27 +00:00
|
|
|
|
|
|
|
|
|
|
scsi_cmd.inlen = 0;
|
|
|
|
|
|
scsi_cmd.outlen = 0;
|
2004-07-15 11:36:12 +00:00
|
|
|
|
CDIO_MMC_SET_COMMAND(scsi_cmd.cdb, CDIO_MMC_GPCMD_START_STOP);
|
|
|
|
|
|
scsi_cmd.cdb[1] = 0;
|
|
|
|
|
|
scsi_cmd.cdb[2] = 0;
|
|
|
|
|
|
scsi_cmd.cdb[3] = 0;
|
|
|
|
|
|
scsi_cmd.cdb[4] = 1;
|
|
|
|
|
|
scsi_cmd.cdb[5] = 0;
|
2003-05-16 07:18:27 +00:00
|
|
|
|
status = ioctl(fd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd);
|
|
|
|
|
|
if (status != 0)
|
2004-07-08 01:27:57 +00:00
|
|
|
|
return status;
|
2003-05-16 07:18:27 +00:00
|
|
|
|
|
|
|
|
|
|
scsi_cmd.inlen = 0;
|
|
|
|
|
|
scsi_cmd.outlen = 0;
|
2004-07-15 11:36:12 +00:00
|
|
|
|
CDIO_MMC_SET_COMMAND(scsi_cmd.cdb, CDIO_MMC_GPCMD_START_STOP);
|
|
|
|
|
|
scsi_cmd.cdb[1] = 0;
|
|
|
|
|
|
scsi_cmd.cdb[2] = 0;
|
|
|
|
|
|
scsi_cmd.cdb[3] = 0;
|
|
|
|
|
|
scsi_cmd.cdb[4] = 2; /* eject */
|
|
|
|
|
|
scsi_cmd.cdb[5] = 0;
|
2003-05-16 07:18:27 +00:00
|
|
|
|
status = ioctl(fd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd);
|
|
|
|
|
|
if (status != 0)
|
2004-07-08 01:27:57 +00:00
|
|
|
|
return status;
|
2003-05-16 07:18:27 +00:00
|
|
|
|
|
|
|
|
|
|
/* force kernel to reread partition table when new disc inserted */
|
|
|
|
|
|
status = ioctl(fd, BLKRRPART);
|
2004-07-08 01:27:57 +00:00
|
|
|
|
return (status);
|
|
|
|
|
|
|
2003-05-16 07:18:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
/*!
|
2003-05-16 07:18:27 +00:00
|
|
|
|
Eject media in CD drive.
|
|
|
|
|
|
Return 0 if success and 1 for failure, and 2 if no routine.
|
2003-03-24 19:01:09 +00:00
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_eject_media_linux (void *user_data) {
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-03-24 23:59:22 +00:00
|
|
|
|
int ret=2;
|
|
|
|
|
|
int status;
|
|
|
|
|
|
int fd;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-05-31 12:29:09 +00:00
|
|
|
|
close(env->gen.fd);
|
|
|
|
|
|
env->gen.fd = -1;
|
|
|
|
|
|
if ((fd = open (env->gen.source_name, O_RDONLY|O_NONBLOCK)) > -1) {
|
2003-03-24 23:59:22 +00:00
|
|
|
|
if((status = ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT)) > 0) {
|
2003-03-24 19:01:09 +00:00
|
|
|
|
switch(status) {
|
|
|
|
|
|
case CDS_TRAY_OPEN:
|
2003-03-24 23:59:22 +00:00
|
|
|
|
if((ret = ioctl(fd, CDROMCLOSETRAY)) != 0) {
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn ("ioctl CDROMCLOSETRAY failed: %s\n", strerror(errno));
|
2003-05-16 07:18:27 +00:00
|
|
|
|
ret = 1;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case CDS_DISC_OK:
|
2003-03-24 23:59:22 +00:00
|
|
|
|
if((ret = ioctl(fd, CDROMEJECT)) != 0) {
|
2003-05-16 07:18:27 +00:00
|
|
|
|
int eject_error = errno;
|
2004-04-26 07:54:47 +00:00
|
|
|
|
/* Try ejecting the MMC way... */
|
|
|
|
|
|
ret = _eject_media_mmc(fd);
|
2003-05-16 07:18:27 +00:00
|
|
|
|
if (0 != ret) {
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn("ioctl CDROMEJECT failed: %s\n", strerror(eject_error));
|
2003-05-16 07:18:27 +00:00
|
|
|
|
ret = 1;
|
|
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
2003-05-16 07:18:27 +00:00
|
|
|
|
default:
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn ("Unknown CD-ROM (%d)\n", status);
|
2003-05-16 07:18:27 +00:00
|
|
|
|
ret = 1;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2004-06-25 21:10:36 +00:00
|
|
|
|
cdio_warn ("CDROM_DRIVE_STATUS failed: %s\n", strerror(errno));
|
2003-03-24 23:59:22 +00:00
|
|
|
|
ret=1;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
2003-03-24 23:59:22 +00:00
|
|
|
|
close(fd);
|
2003-05-16 07:18:27 +00:00
|
|
|
|
return ret;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
return 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the value associated with the key "arg".
|
|
|
|
|
|
*/
|
|
|
|
|
|
static const char *
|
2004-04-25 15:41:26 +00:00
|
|
|
|
_get_arg_linux (void *env, const char key[])
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2003-09-25 09:38:15 +00:00
|
|
|
|
_img_private_t *_obj = env;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
if (!strcmp (key, "source")) {
|
2003-03-29 17:32:00 +00:00
|
|
|
|
return _obj->gen.source_name;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
} else if (!strcmp (key, "access-mode")) {
|
|
|
|
|
|
switch (_obj->access_mode) {
|
|
|
|
|
|
case _AM_IOCTL:
|
|
|
|
|
|
return "ioctl";
|
|
|
|
|
|
case _AM_READ_CD:
|
|
|
|
|
|
return "READ_CD";
|
|
|
|
|
|
case _AM_READ_10:
|
|
|
|
|
|
return "READ_10";
|
|
|
|
|
|
case _AM_NONE:
|
|
|
|
|
|
return "no access method";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the number of of the first track.
|
|
|
|
|
|
CDIO_INVALID_TRACK is returned on error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static track_t
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_get_first_track_num_linux(void *user_data)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-05-31 12:29:09 +00:00
|
|
|
|
if (!env->gen.toc_init) _cdio_read_toc (env) ;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
return FIRST_TRACK_NUM;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-09-25 09:38:15 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Return the media catalog number MCN.
|
|
|
|
|
|
|
|
|
|
|
|
Note: string is malloc'd so caller should free() then returned
|
|
|
|
|
|
string when done with it.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2004-06-27 16:36:38 +00:00
|
|
|
|
static char *
|
2004-04-25 15:41:26 +00:00
|
|
|
|
_get_mcn_linux (const void *env) {
|
2003-09-25 09:38:15 +00:00
|
|
|
|
|
|
|
|
|
|
struct cdrom_mcn mcn;
|
2004-04-22 03:24:38 +00:00
|
|
|
|
const _img_private_t *_obj = env;
|
2004-02-07 02:40:20 +00:00
|
|
|
|
memset(&mcn, 0, sizeof(mcn));
|
2003-09-25 09:38:15 +00:00
|
|
|
|
if (ioctl(_obj->gen.fd, CDROM_GET_MCN, &mcn) != 0)
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
return strdup(mcn.medium_catalog_number);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-04-22 03:24:38 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Return the the kind of drive capabilities of device.
|
|
|
|
|
|
|
|
|
|
|
|
Note: string is malloc'd so caller should free() then returned
|
|
|
|
|
|
string when done with it.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2004-07-17 22:16:46 +00:00
|
|
|
|
static void
|
|
|
|
|
|
_get_drive_cap_linux (const void *env,
|
|
|
|
|
|
cdio_drive_read_cap_t *p_read_cap,
|
|
|
|
|
|
cdio_drive_write_cap_t *p_write_cap,
|
|
|
|
|
|
cdio_drive_misc_cap_t *p_misc_cap)
|
|
|
|
|
|
{
|
2004-04-22 03:24:38 +00:00
|
|
|
|
const _img_private_t *_obj = env;
|
|
|
|
|
|
int32_t i_drivetype;
|
|
|
|
|
|
|
|
|
|
|
|
i_drivetype = ioctl (_obj->gen.fd, CDROM_GET_CAPABILITY, CDSL_CURRENT);
|
|
|
|
|
|
|
2004-07-17 22:16:46 +00:00
|
|
|
|
if (i_drivetype < 0) {
|
|
|
|
|
|
*p_read_cap = CDIO_DRIVE_CAP_ERROR;
|
|
|
|
|
|
*p_write_cap = CDIO_DRIVE_CAP_ERROR;
|
|
|
|
|
|
*p_misc_cap = CDIO_DRIVE_CAP_ERROR;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*p_read_cap = 0;
|
|
|
|
|
|
*p_write_cap = 0;
|
|
|
|
|
|
*p_misc_cap = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* Reader */
|
|
|
|
|
|
if (i_drivetype & CDC_PLAY_AUDIO)
|
|
|
|
|
|
*p_read_cap |= CDIO_DRIVE_CAP_READ_AUDIO;
|
|
|
|
|
|
if (i_drivetype & CDC_CD_R)
|
|
|
|
|
|
*p_read_cap |= CDIO_DRIVE_CAP_READ_CD_R;
|
|
|
|
|
|
if (i_drivetype & CDC_CD_RW)
|
|
|
|
|
|
*p_read_cap |= CDIO_DRIVE_CAP_READ_CD_RW;
|
|
|
|
|
|
if (i_drivetype & CDC_DVD)
|
|
|
|
|
|
*p_read_cap |= CDIO_DRIVE_CAP_READ_DVD_ROM;
|
|
|
|
|
|
|
|
|
|
|
|
/* Writer */
|
|
|
|
|
|
if (i_drivetype & CDC_CD_RW)
|
|
|
|
|
|
*p_read_cap |= CDIO_DRIVE_CAP_WRITE_CD_RW;
|
|
|
|
|
|
if (i_drivetype & CDC_DVD_R)
|
|
|
|
|
|
*p_read_cap |= CDIO_DRIVE_CAP_WRITE_DVD_R;
|
|
|
|
|
|
if (i_drivetype & CDC_DVD_RAM)
|
|
|
|
|
|
*p_read_cap |= CDIO_DRIVE_CAP_WRITE_DVD_RAM;
|
|
|
|
|
|
|
|
|
|
|
|
/* Misc */
|
|
|
|
|
|
if (i_drivetype & CDC_CLOSE_TRAY)
|
|
|
|
|
|
*p_misc_cap |= CDIO_DRIVE_CAP_MISC_CLOSE_TRAY;
|
|
|
|
|
|
if (i_drivetype & CDC_OPEN_TRAY)
|
2004-07-18 03:35:07 +00:00
|
|
|
|
*p_misc_cap |= CDIO_DRIVE_CAP_MISC_EJECT;
|
2004-07-17 22:16:46 +00:00
|
|
|
|
if (i_drivetype & CDC_LOCK)
|
|
|
|
|
|
*p_misc_cap |= CDIO_DRIVE_CAP_MISC_LOCK;
|
|
|
|
|
|
if (i_drivetype & CDC_SELECT_SPEED)
|
|
|
|
|
|
*p_misc_cap |= CDIO_DRIVE_CAP_MISC_SELECT_SPEED;
|
|
|
|
|
|
if (i_drivetype & CDC_SELECT_DISC)
|
|
|
|
|
|
*p_misc_cap |= CDIO_DRIVE_CAP_MISC_SELECT_DISC;
|
|
|
|
|
|
if (i_drivetype & CDC_MULTI_SESSION)
|
|
|
|
|
|
*p_misc_cap |= CDIO_DRIVE_CAP_MISC_MULTI_SESSION;
|
|
|
|
|
|
if (i_drivetype & CDC_MEDIA_CHANGED)
|
|
|
|
|
|
*p_misc_cap |= CDIO_DRIVE_CAP_MISC_MEDIA_CHANGED;
|
|
|
|
|
|
if (i_drivetype & CDC_RESET)
|
|
|
|
|
|
*p_misc_cap |= CDIO_DRIVE_CAP_MISC_RESET;
|
2004-04-22 03:24:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Return the number of tracks in the current medium.
|
|
|
|
|
|
CDIO_INVALID_TRACK is returned on error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static track_t
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_get_num_tracks_linux(void *user_data)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-05-31 12:29:09 +00:00
|
|
|
|
if (!env->gen.toc_init) _cdio_read_toc (env) ;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
return TOTAL_TRACKS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Get format of track.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static track_format_t
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_get_track_format_linux(void *user_data, track_t i_track)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-06-06 10:50:55 +00:00
|
|
|
|
if (i_track > (TOTAL_TRACKS+FIRST_TRACK_NUM) || i_track < FIRST_TRACK_NUM)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return TRACK_FORMAT_ERROR;
|
|
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
i_track -= FIRST_TRACK_NUM;
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
/* This is pretty much copied from the "badly broken" cdrom_count_tracks
|
|
|
|
|
|
in linux/cdrom.c.
|
|
|
|
|
|
*/
|
2004-06-02 00:43:53 +00:00
|
|
|
|
if (env->tocent[i_track].cdte_ctrl & CDIO_CDROM_DATA_TRACK) {
|
|
|
|
|
|
if (env->tocent[i_track].cdte_format == CDIO_CDROM_CDI_TRACK)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return TRACK_FORMAT_CDI;
|
2004-06-02 00:43:53 +00:00
|
|
|
|
else if (env->tocent[i_track].cdte_format == CDIO_CDROM_XA_TRACK)
|
2003-03-24 19:01:09 +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-05-31 12:29:09 +00:00
|
|
|
|
_get_track_green_linux(void *user_data, track_t i_track)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-06-06 11:25:13 +00:00
|
|
|
|
if (!env->gen.toc_init) _cdio_read_toc (env) ;
|
|
|
|
|
|
|
2004-07-17 02:43:41 +00:00
|
|
|
|
if (i_track >= (TOTAL_TRACKS+FIRST_TRACK_NUM) || i_track < FIRST_TRACK_NUM)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
2004-06-06 10:50:55 +00:00
|
|
|
|
i_track -= FIRST_TRACK_NUM;
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
/* FIXME: Dunno if this is the right way, but it's what
|
2004-06-06 10:50:55 +00:00
|
|
|
|
I was using in cd-info for a while.
|
2003-03-24 19:01:09 +00:00
|
|
|
|
*/
|
2004-06-06 10:50:55 +00:00
|
|
|
|
return ((env->tocent[i_track].cdte_ctrl & 2) != 0);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the starting MSF (minutes/secs/frames) for track number
|
2004-06-06 11:44:51 +00:00
|
|
|
|
track_num in obj. Track numbers usually start at something
|
2004-06-06 11:38:33 +00:00
|
|
|
|
greater than 0, usually 1.
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
The "leadout" track is specified either by
|
2004-05-27 10:58:11 +00:00
|
|
|
|
using i_track LEADOUT_TRACK or the total tracks+1.
|
2003-03-24 19:01:09 +00:00
|
|
|
|
False is returned if there is no track entry.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static bool
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_get_track_msf_linux(void *user_data, track_t i_track, msf_t *msf)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-05-31 12:29:09 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
if (NULL == msf) return false;
|
|
|
|
|
|
|
2004-05-31 12:29:09 +00:00
|
|
|
|
if (!env->gen.toc_init) _cdio_read_toc (env) ;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-06-06 11:30:48 +00:00
|
|
|
|
if (i_track == CDIO_CDROM_LEADOUT_TRACK)
|
|
|
|
|
|
i_track = TOTAL_TRACKS + FIRST_TRACK_NUM;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-06-06 10:50:55 +00:00
|
|
|
|
if (i_track > (TOTAL_TRACKS+FIRST_TRACK_NUM) || i_track < FIRST_TRACK_NUM) {
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
} else {
|
2004-05-31 12:29:09 +00:00
|
|
|
|
struct cdrom_msf0 *msf0= &env->tocent[i_track-FIRST_TRACK_NUM].cdte_addr.msf;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
msf->m = to_bcd8(msf0->minute);
|
|
|
|
|
|
msf->s = to_bcd8(msf0->second);
|
|
|
|
|
|
msf->f = to_bcd8(msf0->frame);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-09-28 17:14:20 +00:00
|
|
|
|
/* checklist: /dev/cdrom, /dev/dvd /dev/hd?, /dev/scd? /dev/sr? */
|
|
|
|
|
|
static char checklist1[][40] = {
|
|
|
|
|
|
{"cdrom"}, {"dvd"}, {""}
|
|
|
|
|
|
};
|
|
|
|
|
|
static char checklist2[][40] = {
|
|
|
|
|
|
{"?a hd?"}, {"?0 scd?"}, {"?0 sr?"}, {""}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2003-09-30 03:26:11 +00:00
|
|
|
|
#endif /* HAVE_LINUX_CDROM */
|
|
|
|
|
|
|
2003-09-28 17:14:20 +00:00
|
|
|
|
/*!
|
2003-09-30 03:26:11 +00:00
|
|
|
|
Return an array of strings giving possible CD devices.
|
2003-09-28 17:14:20 +00:00
|
|
|
|
*/
|
2003-09-30 03:26:11 +00:00
|
|
|
|
char **
|
|
|
|
|
|
cdio_get_devices_linux (void)
|
2003-09-28 17:14:20 +00:00
|
|
|
|
{
|
2003-09-30 03:26:11 +00:00
|
|
|
|
#ifndef HAVE_LINUX_CDROM
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
#else
|
2003-09-28 17:14:20 +00:00
|
|
|
|
unsigned int i;
|
|
|
|
|
|
char drive[40];
|
|
|
|
|
|
char *ret_drive;
|
2003-10-03 01:26:52 +00:00
|
|
|
|
bool exists;
|
2003-09-28 17:14:20 +00:00
|
|
|
|
char **drives = NULL;
|
|
|
|
|
|
unsigned int num_drives=0;
|
|
|
|
|
|
|
|
|
|
|
|
/* Scan the system for CD-ROM drives.
|
|
|
|
|
|
*/
|
|
|
|
|
|
for ( i=0; strlen(checklist1[i]) > 0; ++i ) {
|
|
|
|
|
|
sprintf(drive, "/dev/%s", checklist1[i]);
|
|
|
|
|
|
if ( (exists=cdio_is_cdrom(drive, NULL)) > 0 ) {
|
|
|
|
|
|
cdio_add_device_list(&drives, drive, &num_drives);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Now check the currently mounted CD drives */
|
|
|
|
|
|
if (NULL != (ret_drive = cdio_check_mounts("/etc/mtab"))) {
|
2004-02-21 17:18:04 +00:00
|
|
|
|
cdio_add_device_list(&drives, ret_drive, &num_drives);
|
|
|
|
|
|
free(ret_drive);
|
2003-09-28 17:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Finally check possible mountable drives in /etc/fstab */
|
|
|
|
|
|
if (NULL != (ret_drive = cdio_check_mounts("/etc/fstab"))) {
|
2004-02-21 17:18:04 +00:00
|
|
|
|
cdio_add_device_list(&drives, ret_drive, &num_drives);
|
|
|
|
|
|
free(ret_drive);
|
2003-09-28 17:14:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Scan the system for CD-ROM drives.
|
|
|
|
|
|
Not always 100% reliable, so use the USE_MNTENT code above first.
|
|
|
|
|
|
*/
|
|
|
|
|
|
for ( i=0; strlen(checklist2[i]) > 0; ++i ) {
|
|
|
|
|
|
unsigned int j;
|
|
|
|
|
|
char *insert;
|
2003-10-03 01:26:52 +00:00
|
|
|
|
exists = true;
|
2003-09-28 17:14:20 +00:00
|
|
|
|
for ( j=checklist2[i][1]; exists; ++j ) {
|
|
|
|
|
|
sprintf(drive, "/dev/%s", &checklist2[i][3]);
|
|
|
|
|
|
insert = strchr(drive, '?');
|
|
|
|
|
|
if ( insert != NULL ) {
|
|
|
|
|
|
*insert = j;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( (exists=cdio_is_cdrom(drive, NULL)) > 0 ) {
|
|
|
|
|
|
cdio_add_device_list(&drives, drive, &num_drives);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
cdio_add_device_list(&drives, NULL, &num_drives);
|
|
|
|
|
|
return drives;
|
2003-09-30 03:26:11 +00:00
|
|
|
|
#endif /*HAVE_LINUX_CDROM*/
|
2003-09-28 17:14:20 +00:00
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-04-10 04:11:45 +00:00
|
|
|
|
/*!
|
2003-09-29 02:56:22 +00:00
|
|
|
|
Return a string containing the default CD device.
|
2003-04-10 04:11:45 +00:00
|
|
|
|
*/
|
|
|
|
|
|
char *
|
|
|
|
|
|
cdio_get_default_device_linux(void)
|
|
|
|
|
|
{
|
2003-06-12 04:46:27 +00:00
|
|
|
|
#ifndef HAVE_LINUX_CDROM
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
char drive[40];
|
2003-10-03 01:26:52 +00:00
|
|
|
|
bool exists;
|
2003-06-12 04:46:27 +00:00
|
|
|
|
char *ret_drive;
|
|
|
|
|
|
|
|
|
|
|
|
/* Scan the system for CD-ROM drives.
|
|
|
|
|
|
*/
|
|
|
|
|
|
for ( i=0; strlen(checklist1[i]) > 0; ++i ) {
|
|
|
|
|
|
sprintf(drive, "/dev/%s", checklist1[i]);
|
|
|
|
|
|
if ( (exists=cdio_is_cdrom(drive, NULL)) > 0 ) {
|
|
|
|
|
|
return strdup(drive);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Now check the currently mounted CD drives */
|
|
|
|
|
|
if (NULL != (ret_drive = cdio_check_mounts("/etc/mtab")))
|
|
|
|
|
|
return ret_drive;
|
|
|
|
|
|
|
|
|
|
|
|
/* Finally check possible mountable drives in /etc/fstab */
|
|
|
|
|
|
if (NULL != (ret_drive = cdio_check_mounts("/etc/fstab")))
|
|
|
|
|
|
return ret_drive;
|
|
|
|
|
|
|
|
|
|
|
|
/* Scan the system for CD-ROM drives.
|
|
|
|
|
|
Not always 100% reliable, so use the USE_MNTENT code above first.
|
|
|
|
|
|
*/
|
|
|
|
|
|
for ( i=0; strlen(checklist2[i]) > 0; ++i ) {
|
|
|
|
|
|
unsigned int j;
|
|
|
|
|
|
char *insert;
|
2003-10-03 01:26:52 +00:00
|
|
|
|
exists = true;
|
2003-06-12 04:46:27 +00:00
|
|
|
|
for ( j=checklist2[i][1]; exists; ++j ) {
|
|
|
|
|
|
sprintf(drive, "/dev/%s", &checklist2[i][3]);
|
|
|
|
|
|
insert = strchr(drive, '?');
|
|
|
|
|
|
if ( insert != NULL ) {
|
|
|
|
|
|
*insert = j;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( (exists=cdio_is_cdrom(drive, NULL)) > 0 ) {
|
|
|
|
|
|
return(strdup(drive));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
#endif /*HAVE_LINUX_CDROM*/
|
2003-04-10 04:11:45 +00:00
|
|
|
|
}
|
2003-03-24 19:01:09 +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-04-30 06:54:15 +00:00
|
|
|
|
cdio_open_linux (const char *psz_source_name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return cdio_open_am_linux(psz_source_name, NULL);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
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-06 01:21:29 +00:00
|
|
|
|
cdio_open_am_linux (const char *psz_orig_source, const char *access_mode)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LINUX_CDROM
|
|
|
|
|
|
CdIo *ret;
|
|
|
|
|
|
_img_private_t *_data;
|
2004-05-06 01:21:29 +00:00
|
|
|
|
char *psz_source;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
cdio_funcs _funcs = {
|
2004-04-25 15:41:26 +00:00
|
|
|
|
.eject_media = _eject_media_linux,
|
2003-03-29 17:32:00 +00:00
|
|
|
|
.free = cdio_generic_free,
|
2004-04-25 15:41:26 +00:00
|
|
|
|
.get_arg = _get_arg_linux,
|
2004-07-15 02:24:29 +00:00
|
|
|
|
.get_cdtext = _get_cdtext_linux,
|
2003-09-30 03:26:11 +00:00
|
|
|
|
.get_devices = cdio_get_devices_linux,
|
2003-04-10 04:11:45 +00:00
|
|
|
|
.get_default_device = cdio_get_default_device_linux,
|
2004-07-21 10:19:20 +00:00
|
|
|
|
.get_discmode = _get_discmode_linux,
|
2004-04-25 15:41:26 +00:00
|
|
|
|
.get_drive_cap = _get_drive_cap_linux,
|
|
|
|
|
|
.get_first_track_num= _get_first_track_num_linux,
|
|
|
|
|
|
.get_mcn = _get_mcn_linux,
|
|
|
|
|
|
.get_num_tracks = _get_num_tracks_linux,
|
|
|
|
|
|
.get_track_format = _get_track_format_linux,
|
|
|
|
|
|
.get_track_green = _get_track_green_linux,
|
2003-03-24 19:01:09 +00:00
|
|
|
|
.get_track_lba = NULL, /* This could be implemented if need be. */
|
2004-04-25 15:41:26 +00:00
|
|
|
|
.get_track_msf = _get_track_msf_linux,
|
2003-03-29 17:32:00 +00:00
|
|
|
|
.lseek = cdio_generic_lseek,
|
|
|
|
|
|
.read = cdio_generic_read,
|
2004-04-25 15:41:26 +00:00
|
|
|
|
.read_audio_sectors = _read_audio_sectors_linux,
|
|
|
|
|
|
.read_mode1_sector = _read_mode1_sector_linux,
|
|
|
|
|
|
.read_mode1_sectors = _read_mode1_sectors_linux,
|
|
|
|
|
|
.read_mode2_sector = _read_mode2_sector_linux,
|
|
|
|
|
|
.read_mode2_sectors = _read_mode2_sectors_linux,
|
|
|
|
|
|
.set_arg = _set_arg_linux,
|
|
|
|
|
|
.stat_size = _stat_size_linux
|
2003-03-24 19:01:09 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_data = _cdio_malloc (sizeof (_img_private_t));
|
2004-04-30 06:54:15 +00:00
|
|
|
|
|
|
|
|
|
|
_data->access_mode = str_to_access_mode_linux(access_mode);
|
2003-03-29 17:32:00 +00:00
|
|
|
|
_data->gen.init = false;
|
|
|
|
|
|
_data->gen.fd = -1;
|
2004-07-15 02:24:29 +00:00
|
|
|
|
_data->b_cdtext_init = false;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-05-06 01:21:29 +00:00
|
|
|
|
if (NULL == psz_orig_source) {
|
|
|
|
|
|
psz_source=cdio_get_default_device_linux();
|
|
|
|
|
|
if (NULL == psz_source) return NULL;
|
|
|
|
|
|
_set_arg_linux(_data, "source", psz_source);
|
|
|
|
|
|
free(psz_source);
|
2004-04-23 01:01:35 +00:00
|
|
|
|
} else {
|
2004-05-06 01:21:29 +00:00
|
|
|
|
if (cdio_is_device_generic(psz_orig_source))
|
|
|
|
|
|
_set_arg_linux(_data, "source", psz_orig_source);
|
2004-04-23 01:01:35 +00:00
|
|
|
|
else {
|
2004-05-04 01:57:23 +00:00
|
|
|
|
/* The below would be okay if all device drivers worked this way. */
|
2004-05-06 01:21:29 +00:00
|
|
|
|
cdio_info ("source %s is a not a device", psz_orig_source);
|
2004-04-23 01:01:35 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
ret = cdio_new (_data, &_funcs);
|
|
|
|
|
|
if (ret == NULL) return NULL;
|
|
|
|
|
|
|
2003-03-30 13:01:22 +00:00
|
|
|
|
if (cdio_generic_init(_data))
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return ret;
|
|
|
|
|
|
else {
|
2003-03-29 17:32:00 +00:00
|
|
|
|
cdio_generic_free (_data);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
#endif /* HAVE_LINUX_CDROM */
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
cdio_have_linux (void)
|
|
|
|
|
|
{
|
|
|
|
|
|
#ifdef HAVE_LINUX_CDROM
|
|
|
|
|
|
return true;
|
|
|
|
|
|
#else
|
|
|
|
|
|
return false;
|
|
|
|
|
|
#endif /* HAVE_LINUX_CDROM */
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-04-10 04:11:45 +00:00
|
|
|
|
|