2003-03-25 00:00:36 +00:00
|
|
|
|
/*
|
2003-04-19 20:49:53 +00:00
|
|
|
|
$Id: _cdio_freebsd.c,v 1.7 2003/04/19 20:49:53 rocky Exp $
|
2003-03-25 00:00:36 +00:00
|
|
|
|
|
|
|
|
|
|
Copyright (C) 2003 Rocky Bernstein <rocky@panix.com>
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
2003-04-19 20:49:53 +00:00
|
|
|
|
static const char _rcsid[] = "$Id: _cdio_freebsd.c,v 1.7 2003/04/19 20:49:53 rocky Exp $";
|
2003-03-25 00:00:36 +00:00
|
|
|
|
|
|
|
|
|
|
#include "cdio_assert.h"
|
|
|
|
|
|
#include "cdio_private.h"
|
|
|
|
|
|
#include "sector.h"
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
2003-04-10 04:13:41 +00:00
|
|
|
|
/* Is this the right default? */
|
|
|
|
|
|
#define DEFAULT_CDIO_DEVICE "/dev/acd0c"
|
|
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
2003-03-25 00:00:36 +00:00
|
|
|
|
#ifdef HAVE_FREEBSD_CDROM
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_CDIO_H
|
|
|
|
|
|
# include <sys/cdio.h>
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#include <sys/cdrio.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
|
|
|
|
#define TOTAL_TRACKS (_obj->tochdr.ending_track \
|
|
|
|
|
|
- obj->tochdr.starting_track + 1)
|
|
|
|
|
|
#define FIRST_TRACK_NUM (_obj->tochdr.starting_track)
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2003-03-29 20:28:05 +00:00
|
|
|
|
/* Things common to all drivers like this.
|
|
|
|
|
|
This must be first. */
|
|
|
|
|
|
generic_img_private_t gen;
|
2003-03-25 00:00:36 +00:00
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
|
_AM_NONE,
|
|
|
|
|
|
_AM_IOCTL,
|
|
|
|
|
|
} access_mode;
|
|
|
|
|
|
|
|
|
|
|
|
/* Track information */
|
|
|
|
|
|
bool toc_init; /* if true, info below is valid. */
|
|
|
|
|
|
struct ioc_toc_header tochdr;
|
2003-03-30 00:38:11 +00:00
|
|
|
|
struct ioc_read_toc_single_entry tocent[100]; /* entry info for each track */
|
2003-03-25 00:00:36 +00:00
|
|
|
|
|
|
|
|
|
|
} _img_private_t;
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Initialize CD device.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static bool
|
|
|
|
|
|
_cdio_init (_img_private_t *_obj)
|
|
|
|
|
|
{
|
2003-03-29 20:28:05 +00:00
|
|
|
|
if (_obj->gen.init) {
|
2003-03-25 00:00:36 +00:00
|
|
|
|
cdio_error ("init called more than once");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-29 20:28:05 +00:00
|
|
|
|
_obj->gen.fd = open (_obj->gen.source_name, O_RDONLY, 0);
|
2003-03-25 00:00:36 +00:00
|
|
|
|
|
2003-03-29 20:28:05 +00:00
|
|
|
|
if (_obj->gen.fd < 0)
|
2003-03-25 00:00:36 +00:00
|
|
|
|
{
|
2003-03-29 20:28:05 +00:00
|
|
|
|
cdio_error ("open (%s): %s", _obj->gen.source_name, strerror (errno));
|
2003-03-25 00:00:36 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-29 20:28:05 +00:00
|
|
|
|
_obj->gen.init = true;
|
2003-03-25 00:00:36 +00:00
|
|
|
|
_obj->toc_init = false;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
|
_set_bsize (int fd, unsigned int bsize)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct cdrom_generic_command cgc;
|
|
|
|
|
|
|
|
|
|
|
|
if (ioctl (fd, CDRIOCSETBLOCKSIZE, &bsize) == -1) {
|
|
|
|
|
|
cdio_error("error in ioctl(CDRIOCSETBLOCKSIZE): %s\n", strerror(errno));
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
|
_read_mode2 (int fd, void *buf, lba_t lba, unsigned nblocks,
|
|
|
|
|
|
bool _workaround)
|
|
|
|
|
|
{
|
|
|
|
|
|
unsigned l = 0;
|
|
|
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
|
|
|
|
while (nblocks > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
const unsigned nblocks2 = (nblocks > 25) ? 25 : nblocks;
|
2003-03-30 00:38:11 +00:00
|
|
|
|
void *buf2 = ((char *)buf ) + (l * M2RAW_SECTOR_SIZE);
|
2003-03-25 00:00:36 +00:00
|
|
|
|
|
|
|
|
|
|
retval |= __read_mode2 (fd, buf2, lba + l, nblocks2, _workaround);
|
|
|
|
|
|
|
|
|
|
|
|
if (retval)
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
nblocks -= nblocks2;
|
|
|
|
|
|
l += nblocks2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-04-19 20:49:53 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Reads a single mode2 sector from cd device into data starting from lsn.
|
|
|
|
|
|
Returns 0 if no error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
|
|
|
|
|
_cdio_read_audio_sector (void *user_data, void *data, lsn_t lsn)
|
|
|
|
|
|
{
|
|
|
|
|
|
unsigned char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
|
|
|
|
|
|
|
|
|
|
|
|
struct cdrom_cdda cdda;
|
|
|
|
|
|
|
|
|
|
|
|
cdda.cdda_addr = frame;
|
|
|
|
|
|
cdda.cdda_length = 1;
|
|
|
|
|
|
cdda.cdda_data = buf;
|
|
|
|
|
|
cdda.cdda_subcode = CDROM_DA_NO_SUBCODE;
|
|
|
|
|
|
|
|
|
|
|
|
/* read a frame */
|
|
|
|
|
|
if(ioctl(fd, CDROMCDDA, &cdda) < 0) {
|
|
|
|
|
|
perror("CDROMCDDA");
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
memcpy (data, buf, CDIO_CD_FRAMESIZE_RAW);
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-25 00:00:36 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Reads a single mode2 sector from cd device into data starting
|
|
|
|
|
|
from lsn. Returns 0 if no error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2003-04-19 20:49:53 +00:00
|
|
|
|
_cdio_read_mode2_sector (void *user_data, void *data, lsn_t lsn,
|
2003-03-25 00:00:36 +00:00
|
|
|
|
bool mode2_form2)
|
|
|
|
|
|
{
|
|
|
|
|
|
char buf[M2RAW_SECTOR_SIZE] = { 0, };
|
|
|
|
|
|
struct cdrom_msf *msf = (struct cdrom_msf *) &buf;
|
|
|
|
|
|
msf_t _msf;
|
|
|
|
|
|
|
|
|
|
|
|
_img_private_t *_obj = user_data;
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
2003-04-19 20:49:53 +00:00
|
|
|
|
if (_obj->gen.ioctls_debugged == 75)
|
2003-03-25 00:00:36 +00:00
|
|
|
|
cdio_debug ("only displaying every 75th ioctl from now on");
|
|
|
|
|
|
|
2003-04-19 20:49:53 +00:00
|
|
|
|
if (_obj->get.ioctls_debugged == 30 * 75)
|
2003-03-25 00:00:36 +00:00
|
|
|
|
cdio_debug ("only displaying every 30*75th ioctl from now on");
|
|
|
|
|
|
|
2003-04-19 20:49:53 +00:00
|
|
|
|
if (_obj->gen.ioctls_debugged < 75
|
|
|
|
|
|
|| (_obj->get.ioctls_debugged < (30 * 75)
|
|
|
|
|
|
&& _obj->gen.ioctls_debugged % 75 == 0)
|
2003-03-25 00:00:36 +00:00
|
|
|
|
|| _obj->ioctls_debugged % (30 * 75) == 0)
|
|
|
|
|
|
cdio_debug ("reading %2.2d:%2.2d:%2.2d",
|
|
|
|
|
|
msf->cdmsf_min0, msf->cdmsf_sec0, msf->cdmsf_frame0);
|
|
|
|
|
|
|
2003-04-19 20:49:53 +00:00
|
|
|
|
_obj->gen.ioctls_debugged++;
|
2003-03-25 00:00:36 +00:00
|
|
|
|
|
|
|
|
|
|
retry:
|
|
|
|
|
|
switch (_obj->access_mode)
|
|
|
|
|
|
{
|
|
|
|
|
|
case _AM_NONE:
|
|
|
|
|
|
cdio_error ("no way to read mode2");
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case _AM_IOCTL:
|
2003-03-29 20:28:05 +00:00
|
|
|
|
if (ioctl (_obj->gen.fd, CDROMREADMODE2, &buf) == -1)
|
2003-03-25 00:00:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
perror ("ioctl()");
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
/* exit (EXIT_FAILURE); */
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mode2_form2)
|
|
|
|
|
|
memcpy (data, buf, M2RAW_SECTOR_SIZE);
|
|
|
|
|
|
else
|
2003-03-29 17:32:00 +00:00
|
|
|
|
memcpy (((char *)data), buf + 8, FORM1_DATA_SIZE);
|
2003-03-25 00:00:36 +00:00
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Reads nblocks of mode2 sectors from cd device into data starting
|
|
|
|
|
|
from lsn.
|
|
|
|
|
|
Returns 0 if no error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2003-04-19 20:49:53 +00:00
|
|
|
|
_cdio_read_mode2_sectors (void *user_data, void *data, lsn_t lsn,
|
2003-03-25 00:00:36 +00:00
|
|
|
|
bool mode2_form2, unsigned nblocks)
|
|
|
|
|
|
{
|
|
|
|
|
|
_img_private_t *_obj = user_data;
|
|
|
|
|
|
int i;
|
|
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nblocks; i++) {
|
|
|
|
|
|
if (mode2_form2) {
|
2003-04-19 20:49:53 +00:00
|
|
|
|
if ( (retval = _cdio_read_mode2_sector (_obj,
|
2003-03-25 00:00:36 +00:00
|
|
|
|
((char *)data) + (M2RAW_SECTOR_SIZE * i),
|
|
|
|
|
|
lsn + i, true)) )
|
|
|
|
|
|
return retval;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
char buf[M2RAW_SECTOR_SIZE] = { 0, };
|
2003-04-19 20:49:53 +00:00
|
|
|
|
if ( (retval = _cdio_read_mode2_sector (_obj, buf, lsn + i, true)) )
|
2003-03-25 00:00:36 +00:00
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
|
|
|
|
memcpy (((char *)data) + (M2F1_SECTOR_SIZE * i), buf + 8,
|
|
|
|
|
|
M2F1_SECTOR_SIZE);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the size of the CD in logical block address (LBA) units.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static uint32_t
|
|
|
|
|
|
_cdio_stat_size (void *user_data)
|
|
|
|
|
|
{
|
|
|
|
|
|
_img_private_t *_obj = user_data;
|
|
|
|
|
|
|
|
|
|
|
|
struct cdrom_tocentry tocent;
|
|
|
|
|
|
uint32_t size;
|
|
|
|
|
|
|
|
|
|
|
|
tocent.cdte_track = CDROM_LEADOUT;
|
|
|
|
|
|
tocent.cdte_format = CDROM_LBA;
|
2003-03-29 20:28:05 +00:00
|
|
|
|
if (ioctl (_obj->gen.fd, CDROMREADTOCENTRY, &tocent) == -1)
|
2003-03-25 00:00:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
perror ("ioctl(CDROMREADTOCENTRY)");
|
|
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size = tocent.cdte_addr.lba;
|
|
|
|
|
|
|
|
|
|
|
|
return size;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Set the key "arg" to "value" in source device.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
|
|
|
|
|
_cdio_set_arg (void *user_data, const char key[], const char value[])
|
|
|
|
|
|
{
|
|
|
|
|
|
_img_private_t *_obj = user_data;
|
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp (key, "source"))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!value)
|
|
|
|
|
|
return -2;
|
|
|
|
|
|
|
2003-03-29 20:28:05 +00:00
|
|
|
|
free (_obj->gen.source_name);
|
2003-03-25 00:00:36 +00:00
|
|
|
|
|
2003-03-29 20:28:05 +00:00
|
|
|
|
_obj->gen.source_name = strdup (value);
|
2003-03-25 00:00:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (!strcmp (key, "access-mode"))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!strcmp(value, "IOCTL"))
|
|
|
|
|
|
_obj->access_mode = _AM_IOCTL;
|
|
|
|
|
|
else
|
|
|
|
|
|
cdio_error ("unknown access type: %s. ignored.", value);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Read and cache the CD's Track Table of Contents and track info.
|
|
|
|
|
|
Return false if successful or true if an error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static bool
|
|
|
|
|
|
_cdio_read_toc (_img_private_t *_obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
int i;
|
|
|
|
|
|
struct ioc_read_toc_entry te;
|
|
|
|
|
|
|
|
|
|
|
|
/* read TOC header */
|
2003-03-29 20:28:05 +00:00
|
|
|
|
if ( ioctl(_obj->gen.fd, CDROMREADTOCHDR, &_obj->tochdr) == -1 ) {
|
2003-03-25 00:00:36 +00:00
|
|
|
|
cdio_error("error in ioctl(CDROMREADTOCHDR): %s\n", strerror(errno));
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
te.address_format = CD_MSF_FORMAT;
|
|
|
|
|
|
te.starting_track = 0;
|
|
|
|
|
|
te.data_len = (TOTAL_TRACKS+1) * sizeof(struct cd_toc_entry);
|
|
|
|
|
|
|
|
|
|
|
|
te.data = _obj->tocent;
|
|
|
|
|
|
|
2003-03-29 20:28:05 +00:00
|
|
|
|
if ( ioctl(_obj->gen.fd, CDIOREADTOCENTRYS, &te) == -1 ) {
|
2003-03-25 00:00:36 +00:00
|
|
|
|
cdio_error("%s %d: %s\n",
|
|
|
|
|
|
"error in ioctl CDROMREADTOCENTRY for track",
|
|
|
|
|
|
i, strerror(errno));
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Eject media in CD drive. If successful, as a side effect we
|
|
|
|
|
|
also free obj.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
|
|
|
|
|
_cdio_eject_media (void *user_data) {
|
|
|
|
|
|
|
|
|
|
|
|
_img_private_t *_obj = user_data;
|
|
|
|
|
|
int ret=2;
|
|
|
|
|
|
int status;
|
|
|
|
|
|
int fd;
|
|
|
|
|
|
|
2003-03-29 20:28:05 +00:00
|
|
|
|
if ((fd = open(_obj->gen.source_name, O_RDONLY|O_NONBLOCK)) > -1) {
|
2003-03-25 00:00:36 +00:00
|
|
|
|
ret = 1;
|
|
|
|
|
|
if (ioctl(fd, CDIOCALLOW) == -1) {
|
|
|
|
|
|
cdio_error("ioctl(fd, CDIOCALLOW) failed: %s\n", strerror(errno));
|
|
|
|
|
|
} else if (ioctl(fd, CDIOCEJECT) == -1) {
|
|
|
|
|
|
cdio_error("ioctl(CDIOCEJECT) failed: %s\n" strerror(errno));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
close(fd);
|
2003-03-29 20:28:05 +00:00
|
|
|
|
_cdio_generic_free((void *) _obj);
|
2003-03-25 00:00:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the value associated with the key "arg".
|
|
|
|
|
|
*/
|
|
|
|
|
|
static const char *
|
|
|
|
|
|
_cdio_get_arg (void *user_data, const char key[])
|
|
|
|
|
|
{
|
|
|
|
|
|
_img_private_t *_obj = user_data;
|
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp (key, "source")) {
|
2003-03-29 20:28:05 +00:00
|
|
|
|
return _obj->gen.source_name;
|
2003-03-25 00:00:36 +00:00
|
|
|
|
} else if (!strcmp (key, "access-mode")) {
|
|
|
|
|
|
switch (_obj->access_mode) {
|
|
|
|
|
|
case _AM_IOCTL:
|
|
|
|
|
|
return "ioctl";
|
|
|
|
|
|
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
|
|
|
|
|
|
_cdio_get_first_track_num(void *user_data)
|
|
|
|
|
|
{
|
|
|
|
|
|
_img_private_t *_obj = user_data;
|
|
|
|
|
|
|
|
|
|
|
|
if (!_obj->toc_init) _cdio_read_toc (_obj) ;
|
|
|
|
|
|
|
|
|
|
|
|
return FIRST_TRACK_NUM;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the number of tracks in the current medium.
|
|
|
|
|
|
CDIO_INVALID_TRACK is returned on error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static track_t
|
|
|
|
|
|
_cdio_get_num_tracks(void *user_data)
|
|
|
|
|
|
{
|
|
|
|
|
|
_img_private_t *_obj = user_data;
|
|
|
|
|
|
|
|
|
|
|
|
if (!_obj->toc_init) _cdio_read_toc (_obj) ;
|
|
|
|
|
|
|
|
|
|
|
|
return TOTAL_TRACKS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Get format of track.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static track_format_t
|
|
|
|
|
|
_cdio_get_track_format(void *user_data, track_t track_num)
|
|
|
|
|
|
{
|
|
|
|
|
|
_img_private_t *_obj = user_data;
|
|
|
|
|
|
|
|
|
|
|
|
if (!_obj->toc_init) _cdio_read_toc (_obj) ;
|
|
|
|
|
|
|
|
|
|
|
|
if (track_num > TOTAL_TRACKS || track_num == 0)
|
|
|
|
|
|
return TRACK_FORMAT_ERROR;
|
|
|
|
|
|
|
|
|
|
|
|
/* This is pretty much copied from the "badly broken" cdrom_count_tracks
|
|
|
|
|
|
in linux/cdrom.c.
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (_obj->tocent[track_num-1].cdte_ctrl & CDROM_DATA_TRACK) {
|
|
|
|
|
|
if (_obj->tocent[track_num-1].cdte_format == 0x10)
|
|
|
|
|
|
return TRACK_FORMAT_CDI;
|
|
|
|
|
|
else if (_obj->tocent[track_num-1].cdte_format == 0x20)
|
|
|
|
|
|
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
|
|
|
|
|
|
_cdio_get_track_green(void *user_data, track_t track_num)
|
|
|
|
|
|
{
|
|
|
|
|
|
_img_private_t *_obj = user_data;
|
|
|
|
|
|
|
|
|
|
|
|
if (!_obj->toc_init) _cdio_read_toc (_obj) ;
|
|
|
|
|
|
|
|
|
|
|
|
if (track_num == CDIO_LEADOUT_TRACK) track_num = TOTAL_TRACKS+1;
|
|
|
|
|
|
|
|
|
|
|
|
if (track_num > TOTAL_TRACKS+1 || track_num == 0)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
/* FIXME: Dunno if this is the right way, but it's what
|
|
|
|
|
|
I was using in cdinfo for a while.
|
|
|
|
|
|
*/
|
|
|
|
|
|
return ((_obj->tocent[track_num-1].cdte_ctrl & 2) != 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the starting MSF (minutes/secs/frames) for track number
|
|
|
|
|
|
track_num in obj. Track numbers start at 1.
|
|
|
|
|
|
The "leadout" track is specified either by
|
|
|
|
|
|
using track_num LEADOUT_TRACK or the total tracks+1.
|
|
|
|
|
|
False is returned if there is no track entry.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static bool
|
|
|
|
|
|
_cdio_get_track_msf(void *user_data, track_t track_num, msf_t *msf)
|
|
|
|
|
|
{
|
|
|
|
|
|
_img_private_t *_obj = user_data;
|
|
|
|
|
|
|
|
|
|
|
|
if (NULL == msf) return false;
|
|
|
|
|
|
|
|
|
|
|
|
if (!_obj->toc_init) _cdio_read_toc (_obj) ;
|
|
|
|
|
|
|
|
|
|
|
|
if (track_num == CDIO_LEADOUT_TRACK) track_num = TOTAL_TRACKS+1;
|
|
|
|
|
|
|
|
|
|
|
|
if (track_num > TOTAL_TRACKS+1 || track_num == 0) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
struct cdrom_msf0 *msf0= &_obj->tocent[track_num-1].cdte_addr.msf;
|
|
|
|
|
|
msf->m = to_bcd8(msf0->minute);
|
|
|
|
|
|
msf->s = to_bcd8(msf0->second);
|
|
|
|
|
|
msf->f = to_bcd8(msf0->frame);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* HAVE_FREEBSD_CDROM */
|
|
|
|
|
|
|
2003-04-10 04:13:41 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Return a string containing the default VCD device if none is specified.
|
|
|
|
|
|
*/
|
|
|
|
|
|
char *
|
|
|
|
|
|
cdio_get_default_device_freebsd()
|
|
|
|
|
|
{
|
|
|
|
|
|
return strdup(DEFAULT_CDIO_DEVICE);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-25 00:00:36 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Initialization routine. This is the only thing that doesn't
|
|
|
|
|
|
get called via a function pointer. In fact *we* are the
|
|
|
|
|
|
ones to set that up.
|
|
|
|
|
|
*/
|
|
|
|
|
|
CdIo *
|
|
|
|
|
|
cdio_open_freebsd (const char *source_name)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_FREEBSD_CDROM
|
|
|
|
|
|
CdIo *ret;
|
|
|
|
|
|
_img_private_t *_data;
|
|
|
|
|
|
|
|
|
|
|
|
cdio_funcs _funcs = {
|
|
|
|
|
|
.eject_media = _cdio_eject_media,
|
2003-03-29 20:28:05 +00:00
|
|
|
|
.free = _cdio_generic_free,
|
2003-03-25 00:00:36 +00:00
|
|
|
|
.get_arg = _cdio_get_arg,
|
2003-04-19 20:49:53 +00:00
|
|
|
|
.get_default_device = _cdio_get_default_device_freebsd,
|
2003-03-25 00:00:36 +00:00
|
|
|
|
.get_first_track_num= _cdio_get_first_track_num,
|
|
|
|
|
|
.get_num_tracks = _cdio_get_num_tracks,
|
|
|
|
|
|
.get_track_format = _cdio_get_track_format,
|
|
|
|
|
|
.get_track_green = _cdio_get_track_green,
|
|
|
|
|
|
.get_track_lba = NULL, /* This could be implemented if need be. */
|
|
|
|
|
|
.get_track_msf = _cdio_get_track_msf,
|
2003-03-29 20:28:05 +00:00
|
|
|
|
.lseek = cdio_generic_lseek,
|
|
|
|
|
|
.read = cdio_generic_read,
|
2003-04-19 20:49:53 +00:00
|
|
|
|
.read_audio_sector = _cdio_read_audio_sector,
|
|
|
|
|
|
.read_mode2_sector = _cdio_read_mode2_sector,
|
|
|
|
|
|
.read_mode2_sectors = _cdio_read_mode2_sectors,
|
2003-03-25 00:00:36 +00:00
|
|
|
|
.set_arg = _cdio_set_arg,
|
|
|
|
|
|
.stat_size = _cdio_stat_size
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_data = _cdio_malloc (sizeof (_img_private_t));
|
|
|
|
|
|
_data->access_mode = _AM_READ_CD;
|
2003-03-30 00:40:29 +00:00
|
|
|
|
_data->gen.init = false;
|
2003-03-29 20:28:05 +00:00
|
|
|
|
_data->gen.fd = -1;
|
2003-03-25 00:00:36 +00:00
|
|
|
|
|
|
|
|
|
|
_cdio_set_arg(_data, "source", (NULL == source_name)
|
|
|
|
|
|
? DEFAULT_CDIO_DEVICE: source_name);
|
|
|
|
|
|
|
|
|
|
|
|
ret = cdio_new (_data, &_funcs);
|
|
|
|
|
|
if (ret == NULL) return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (_cdio_init(_data))
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
else {
|
2003-03-29 20:28:05 +00:00
|
|
|
|
_cdio_generic_free (_data);
|
2003-03-25 00:00:36 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
#endif /* HAVE_FREEBSD_CDROM */
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
cdio_have_freebsd (void)
|
|
|
|
|
|
{
|
|
|
|
|
|
#ifdef HAVE_FREEBSD_CDROM
|
|
|
|
|
|
return true;
|
|
|
|
|
|
#else
|
|
|
|
|
|
return false;
|
|
|
|
|
|
#endif /* HAVE_FREEBSD_CDROM */
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-04-10 04:13:41 +00:00
|
|
|
|
|