2004-04-30 09:59:54 +00:00
|
|
|
|
/*
|
2004-06-25 20:49:56 +00:00
|
|
|
|
$Id: freebsd.c,v 1.23 2004/06/25 20:49:56 rocky Exp $
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
|
|
|
|
|
Copyright (C) 2003, 2004 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 FreeBSD-specific code and implements low-level
|
|
|
|
|
|
control of the CD drive. Culled initially I think from xine's or
|
|
|
|
|
|
mplayer's FreeBSD code with lots of modifications.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
|
# include "config.h"
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2004-06-25 20:49:56 +00:00
|
|
|
|
static const char _rcsid[] = "$Id: freebsd.c,v 1.23 2004/06/25 20:49:56 rocky Exp $";
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
|
|
|
|
|
#include "freebsd.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_FREEBSD_CDROM
|
|
|
|
|
|
|
2004-05-13 04:32:12 +00:00
|
|
|
|
#include <cdio/sector.h>
|
|
|
|
|
|
|
2004-04-30 09:59:54 +00:00
|
|
|
|
static access_mode_t
|
|
|
|
|
|
str_to_access_mode_freebsd(const char *psz_access_mode)
|
|
|
|
|
|
{
|
2004-05-13 01:50:10 +00:00
|
|
|
|
const access_mode_t default_access_mode = DEFAULT_FREEBSD_AM;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
|
|
|
|
|
if (NULL==psz_access_mode) return default_access_mode;
|
|
|
|
|
|
|
2004-05-16 13:33:26 +00:00
|
|
|
|
if (!strcmp(psz_access_mode, "ioctl"))
|
2004-04-30 09:59:54 +00:00
|
|
|
|
return _AM_IOCTL;
|
|
|
|
|
|
else if (!strcmp(psz_access_mode, "CAM"))
|
|
|
|
|
|
return _AM_CAM;
|
|
|
|
|
|
else {
|
2004-06-12 17:40:07 +00:00
|
|
|
|
cdio_warn ("unknown access type: %s. Default ioctl used.",
|
2004-04-30 09:59:54 +00:00
|
|
|
|
psz_access_mode);
|
|
|
|
|
|
return default_access_mode;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
_free_freebsd (void *obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
_img_private_t *env = obj;
|
|
|
|
|
|
|
|
|
|
|
|
if (NULL == env) return;
|
|
|
|
|
|
|
2004-05-04 04:42:17 +00:00
|
|
|
|
if (NULL != env->device) free(env->device);
|
|
|
|
|
|
|
2004-04-30 09:59:54 +00:00
|
|
|
|
if (_AM_CAM == env->access_mode)
|
|
|
|
|
|
return free_freebsd_cam(env);
|
|
|
|
|
|
else
|
|
|
|
|
|
return cdio_generic_free(obj);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 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 .
|
|
|
|
|
|
*/
|
|
|
|
|
|
static bool
|
|
|
|
|
|
cdio_is_cdrom(char *drive, char *mnttype)
|
|
|
|
|
|
{
|
|
|
|
|
|
return cdio_is_cdrom_freebsd_ioctl(drive, mnttype);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2004-06-05 02:47:49 +00:00
|
|
|
|
Reads nblocks of audio sectors from cd device into data starting from lsn.
|
2004-04-30 09:59:54 +00:00
|
|
|
|
Returns 0 if no error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_read_audio_sectors_freebsd (void *user_data, void *data, lsn_t lsn,
|
2004-04-30 09:59:54 +00:00
|
|
|
|
unsigned int nblocks)
|
|
|
|
|
|
{
|
2004-05-31 14:53:07 +00:00
|
|
|
|
return read_audio_sectors_freebsd_ioctl(user_data, data, lsn, nblocks);
|
2004-04-30 09:59:54 +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 14:53:07 +00:00
|
|
|
|
_read_mode2_sector_freebsd (void *user_data, void *data, lsn_t lsn,
|
2004-04-30 09:59:54 +00:00
|
|
|
|
bool b_form2)
|
|
|
|
|
|
{
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2004-06-05 02:47:49 +00:00
|
|
|
|
|
2004-05-31 14:53:07 +00:00
|
|
|
|
if ( env->access_mode == _AM_CAM )
|
2004-06-05 02:47:49 +00:00
|
|
|
|
return read_mode2_sector_freebsd_cam(env, data, lsn, b_form2);
|
2004-05-07 21:39:43 +00:00
|
|
|
|
else
|
2004-05-31 14:53:07 +00:00
|
|
|
|
return read_mode2_sector_freebsd_ioctl(env, data, lsn, b_form2);
|
2004-04-30 09:59:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Reads nblocks of mode2 sectors from cd device into data starting
|
|
|
|
|
|
from lsn.
|
|
|
|
|
|
Returns 0 if no error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_read_mode2_sectors_freebsd (void *user_data, void *data, lsn_t lsn,
|
2004-04-30 09:59:54 +00:00
|
|
|
|
bool b_form2, unsigned int nblocks)
|
|
|
|
|
|
{
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
2004-06-05 02:47:49 +00:00
|
|
|
|
if ( env->access_mode == _AM_CAM && b_form2) {
|
|
|
|
|
|
/* We have a routine that covers this case without looping. */
|
|
|
|
|
|
return read_mode2_sectors_freebsd_cam(env, data, lsn, nblocks);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
unsigned int i_blocksize = b_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE;
|
2004-04-30 21:36:53 +00:00
|
|
|
|
|
2004-06-05 02:47:49 +00:00
|
|
|
|
/* For each frame, pick out the data part we need */
|
|
|
|
|
|
for (i = 0; i < nblocks; i++) {
|
|
|
|
|
|
int retval = _read_mode2_sector_freebsd (env,
|
|
|
|
|
|
((char *)data) +
|
|
|
|
|
|
(i_blocksize * i),
|
|
|
|
|
|
lsn + i, b_form2);
|
|
|
|
|
|
if (retval) return retval;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the size of the CD in logical block address (LBA) units.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static uint32_t
|
2004-04-30 21:36:53 +00:00
|
|
|
|
_stat_size_freebsd (void *obj)
|
2004-04-30 09:59:54 +00:00
|
|
|
|
{
|
2004-04-30 21:36:53 +00:00
|
|
|
|
_img_private_t *env = obj;
|
|
|
|
|
|
|
|
|
|
|
|
if (NULL == env) return CDIO_INVALID_LBA;
|
|
|
|
|
|
|
|
|
|
|
|
if (_AM_CAM == env->access_mode)
|
|
|
|
|
|
return stat_size_freebsd_cam(env);
|
|
|
|
|
|
else
|
|
|
|
|
|
return stat_size_freebsd_ioctl(env);
|
2004-04-30 09:59:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Set the key "arg" to "value" in source device.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_set_arg_freebsd (void *user_data, const char key[], const char value[])
|
2004-04-30 09:59:54 +00:00
|
|
|
|
{
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
|
|
|
|
|
if (!strcmp (key, "source"))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!value)
|
|
|
|
|
|
return -2;
|
|
|
|
|
|
|
2004-05-31 14:53:07 +00:00
|
|
|
|
free (env->gen.source_name);
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
2004-05-31 14:53:07 +00:00
|
|
|
|
env->gen.source_name = strdup (value);
|
2004-04-30 09:59:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (!strcmp (key, "access-mode"))
|
|
|
|
|
|
{
|
2004-05-31 14:53:07 +00:00
|
|
|
|
env->access_mode = str_to_access_mode_freebsd(value);
|
|
|
|
|
|
if (env->access_mode == _AM_CAM && !env->b_cam_init)
|
|
|
|
|
|
return init_freebsd_cam(env) ? 1 : -3;
|
2004-04-30 21:36:53 +00:00
|
|
|
|
return 0;
|
2004-04-30 09:59:54 +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 14:53:07 +00:00
|
|
|
|
_cdio_read_toc (_img_private_t *env)
|
2004-04-30 09:59:54 +00:00
|
|
|
|
{
|
2004-05-13 04:32:12 +00:00
|
|
|
|
track_t i, j;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
|
|
|
|
|
/* read TOC header */
|
2004-05-31 14:53:07 +00:00
|
|
|
|
if ( ioctl(env->gen.fd, CDIOREADTOCHEADER, &env->tochdr) == -1 ) {
|
2004-06-25 20:49:56 +00:00
|
|
|
|
cdio_warn("error in ioctl(CDIOREADTOCHEADER): %s\n", strerror(errno));
|
2004-04-30 09:59:54 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-05-13 04:32:12 +00:00
|
|
|
|
j=0;
|
2004-05-31 14:53:07 +00:00
|
|
|
|
for ( i = env->tochdr.starting_track; i <= env->tochdr.ending_track;
|
2004-05-13 04:32:12 +00:00
|
|
|
|
i++, j++) {
|
2004-05-31 14:53:07 +00:00
|
|
|
|
env->tocent[j].track = i;
|
|
|
|
|
|
env->tocent[j].address_format = CD_LBA_FORMAT;
|
2004-05-13 04:32:12 +00:00
|
|
|
|
|
2004-05-31 14:53:07 +00:00
|
|
|
|
if ( ioctl(env->gen.fd, CDIOREADTOCENTRY, &(env->tocent[j]) ) ) {
|
2004-06-25 20:49:56 +00:00
|
|
|
|
cdio_warn("%s %d: %s\n",
|
2004-05-13 04:32:12 +00:00
|
|
|
|
"error in ioctl CDROMREADTOCENTRY for track",
|
|
|
|
|
|
i, strerror(errno));
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
2004-05-31 14:53:07 +00:00
|
|
|
|
env->tocent[j].track = CDIO_CDROM_LEADOUT_TRACK;
|
|
|
|
|
|
env->tocent[j].address_format = CD_LBA_FORMAT;
|
|
|
|
|
|
if ( ioctl(env->gen.fd, CDIOREADTOCENTRY, &(env->tocent[j]) ) ){
|
2004-06-25 20:49:56 +00:00
|
|
|
|
cdio_warn("%s: %s\n",
|
2004-05-13 04:32:12 +00:00
|
|
|
|
"error in ioctl CDROMREADTOCENTRY for leadout track",
|
2004-05-02 14:55:11 +00:00
|
|
|
|
strerror(errno));
|
2004-04-30 09:59:54 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Eject media. Return 1 if successful, 0 otherwise.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_eject_media_freebsd (void *user_data)
|
2004-04-30 09:59:54 +00:00
|
|
|
|
{
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
2004-05-31 14:53:07 +00:00
|
|
|
|
return (env->access_mode == _AM_IOCTL)
|
|
|
|
|
|
? eject_media_freebsd_ioctl(env)
|
|
|
|
|
|
: eject_media_freebsd_cam(env);
|
2004-04-30 09:59:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the value associated with the key "arg".
|
|
|
|
|
|
*/
|
|
|
|
|
|
static const char *
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_get_arg_freebsd (void *user_data, const char key[])
|
2004-04-30 09:59:54 +00:00
|
|
|
|
{
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
|
|
|
|
|
if (!strcmp (key, "source")) {
|
2004-05-31 14:53:07 +00:00
|
|
|
|
return env->gen.source_name;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
} else if (!strcmp (key, "access-mode")) {
|
2004-05-31 14:53:07 +00:00
|
|
|
|
switch (env->access_mode) {
|
2004-04-30 09:59:54 +00:00
|
|
|
|
case _AM_IOCTL:
|
|
|
|
|
|
return "ioctl";
|
|
|
|
|
|
case _AM_CAM:
|
|
|
|
|
|
return "CAM";
|
|
|
|
|
|
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 14:53:07 +00:00
|
|
|
|
_get_first_track_num_freebsd(void *user_data)
|
2004-04-30 09:59:54 +00:00
|
|
|
|
{
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
2004-05-31 14:53:07 +00:00
|
|
|
|
if (!env->toc_init) _cdio_read_toc (env) ;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
|
|
|
|
|
return FIRST_TRACK_NUM;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the media catalog number MCN.
|
|
|
|
|
|
|
|
|
|
|
|
Note: string is malloc'd so caller should free() then returned
|
|
|
|
|
|
string when done with it.
|
|
|
|
|
|
|
|
|
|
|
|
FIXME: This is just a guess.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
static char *
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_get_mcn_freebsd (const void *user_data) {
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
2004-05-19 03:00:03 +00:00
|
|
|
|
#if FIXED
|
2004-05-31 14:53:07 +00:00
|
|
|
|
const _img_private_t *env = user_data;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
struct ioc_read_subchannel subchannel;
|
|
|
|
|
|
struct cd_sub_channel_info subchannel_info;
|
|
|
|
|
|
|
|
|
|
|
|
subchannel.address_format = CD_LBA_FORMAT;
|
|
|
|
|
|
subchannel.data_format = CD_MEDIA_CATALOG;
|
|
|
|
|
|
subchannel.track = 0;
|
|
|
|
|
|
subchannel.data_len = 1;
|
|
|
|
|
|
subchannel.data = &subchannel_info;
|
|
|
|
|
|
|
2004-05-31 14:53:07 +00:00
|
|
|
|
if(ioctl(env->gen.fd, CDIOCREADSUBCHANNEL, &subchannel) < 0) {
|
2004-04-30 09:59:54 +00:00
|
|
|
|
perror("CDIOCREADSUBCHANNEL");
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Probably need a loop over tracks rather than give up if we
|
|
|
|
|
|
can't find in track 0.
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (subchannel_info.what.media_catalog.mc_valid)
|
|
|
|
|
|
return strdup(subchannel_info.what.media_catalog.mc_number);
|
|
|
|
|
|
else
|
|
|
|
|
|
return NULL;
|
2004-05-19 03:00:03 +00:00
|
|
|
|
#else
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2004-04-30 09:59:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the number of tracks in the current medium.
|
|
|
|
|
|
CDIO_INVALID_TRACK is returned on error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static track_t
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_get_num_tracks_freebsd(void *user_data)
|
2004-04-30 09:59:54 +00:00
|
|
|
|
{
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
2004-05-31 14:53:07 +00:00
|
|
|
|
if (!env->toc_init) _cdio_read_toc (env) ;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
|
|
|
|
|
return TOTAL_TRACKS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Get format of track.
|
|
|
|
|
|
|
|
|
|
|
|
FIXME: We're just guessing this from the GNU/Linux code.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
static track_format_t
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_get_track_format_freebsd(void *user_data, track_t i_track)
|
2004-04-30 09:59:54 +00:00
|
|
|
|
{
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
|
if (i_track > TOTAL_TRACKS || i_track == 0)
|
|
|
|
|
|
return TRACK_FORMAT_ERROR;
|
|
|
|
|
|
|
|
|
|
|
|
i_track -= FIRST_TRACK_NUM;
|
|
|
|
|
|
|
2004-05-13 04:32:12 +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].entry.control & CDIO_CDROM_DATA_TRACK) {
|
|
|
|
|
|
if (env->tocent[i_track].address_format == CDIO_CDROM_CDI_TRACK)
|
2004-04-30 09:59:54 +00:00
|
|
|
|
return TRACK_FORMAT_CDI;
|
2004-06-02 00:43:53 +00:00
|
|
|
|
else if (env->tocent[i_track].address_format == CDIO_CDROM_XA_TRACK)
|
2004-04-30 09:59:54 +00:00
|
|
|
|
return TRACK_FORMAT_XA;
|
|
|
|
|
|
else
|
|
|
|
|
|
return TRACK_FORMAT_DATA;
|
|
|
|
|
|
} else
|
|
|
|
|
|
return TRACK_FORMAT_AUDIO;
|
2004-05-13 04:32:12 +00:00
|
|
|
|
|
2004-04-30 09:59:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return true if we have XA data (green, mode2 form1) or
|
|
|
|
|
|
XA data (green, mode2 form2). That is track begins:
|
|
|
|
|
|
sync - header - subheader
|
|
|
|
|
|
12 4 - 8
|
|
|
|
|
|
|
|
|
|
|
|
FIXME: there's gotta be a better design for this and get_track_format?
|
|
|
|
|
|
*/
|
|
|
|
|
|
static bool
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_get_track_green_freebsd(void *user_data, track_t i_track)
|
2004-04-30 09:59:54 +00:00
|
|
|
|
{
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2004-05-13 04:32:12 +00:00
|
|
|
|
|
2004-05-27 12:10:21 +00:00
|
|
|
|
if (i_track == CDIO_CDROM_LEADOUT_TRACK) i_track = TOTAL_TRACKS+1;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
2004-05-27 12:10:21 +00:00
|
|
|
|
if (i_track > TOTAL_TRACKS+1 || i_track == 0)
|
2004-05-13 04:32:12 +00:00
|
|
|
|
return false;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
|
|
|
|
|
/* FIXME: Dunno if this is the right way, but it's what
|
|
|
|
|
|
I was using in cdinfo for a while.
|
|
|
|
|
|
*/
|
2004-05-31 14:53:07 +00:00
|
|
|
|
return ((env->tocent[i_track-FIRST_TRACK_NUM].entry.control & 2) != 0);
|
2004-04-30 09:59:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the starting LSN track number
|
2004-05-27 12:10:21 +00:00
|
|
|
|
i_track in obj. Track numbers start at 1.
|
2004-04-30 09:59:54 +00:00
|
|
|
|
The "leadout" track is specified either by
|
2004-05-27 12:10:21 +00:00
|
|
|
|
using i_track LEADOUT_TRACK or the total tracks+1.
|
2004-04-30 09:59:54 +00:00
|
|
|
|
False is returned if there is no track entry.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static lba_t
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_get_track_lba_freebsd(void *user_data, track_t i_track)
|
2004-04-30 09:59:54 +00:00
|
|
|
|
{
|
2004-05-31 14:53:07 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
2004-05-31 14:53:07 +00:00
|
|
|
|
if (!env->toc_init) _cdio_read_toc (env) ;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
2004-05-27 12:10:21 +00:00
|
|
|
|
if (i_track == CDIO_CDROM_LEADOUT_TRACK) i_track = TOTAL_TRACKS+1;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
2004-05-27 12:10:21 +00:00
|
|
|
|
if (i_track > TOTAL_TRACKS+1 || i_track == 0) {
|
2004-04-30 09:59:54 +00:00
|
|
|
|
return CDIO_INVALID_LBA;
|
|
|
|
|
|
} else {
|
2004-05-31 14:53:07 +00:00
|
|
|
|
return cdio_lsn_to_lba(ntohl(env->tocent[i_track-FIRST_TRACK_NUM].entry.addr.lba));
|
2004-04-30 09:59:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* HAVE_FREEBSD_CDROM */
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return an array of strings giving possible CD devices.
|
|
|
|
|
|
*/
|
|
|
|
|
|
char **
|
|
|
|
|
|
cdio_get_devices_freebsd (void)
|
|
|
|
|
|
{
|
|
|
|
|
|
#ifndef HAVE_FREEBSD_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.
|
|
|
|
|
|
*/
|
2004-06-19 16:34:45 +00:00
|
|
|
|
|
|
|
|
|
|
/* Scan SCSI and CAM devices */
|
2004-06-05 02:47:49 +00:00
|
|
|
|
for ( c='0'; exists && c <='9'; c++ ) {
|
2004-06-19 11:07:55 +00:00
|
|
|
|
sprintf(drive, "/dev/cd%c%s", c, DEVICE_POSTFIX);
|
2004-06-05 02:47:49 +00:00
|
|
|
|
exists = cdio_is_cdrom(drive, NULL);
|
|
|
|
|
|
if ( exists ) {
|
|
|
|
|
|
cdio_add_device_list(&drives, drive, &num_drives);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-06-19 16:34:45 +00:00
|
|
|
|
|
|
|
|
|
|
/* Scan are ATAPI devices */
|
2004-04-30 09:59:54 +00:00
|
|
|
|
for ( c='0'; exists && c <='9'; c++ ) {
|
2004-06-19 16:34:45 +00:00
|
|
|
|
sprintf(drive, "/dev/acd%c%s", c, DEVICE_POSTFIX);
|
2004-04-30 09:59:54 +00:00
|
|
|
|
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_FREEBSD_CDROM*/
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return a string containing the default CD device if none is specified.
|
|
|
|
|
|
*/
|
|
|
|
|
|
char *
|
|
|
|
|
|
cdio_get_default_device_freebsd()
|
|
|
|
|
|
{
|
2004-06-12 18:45:54 +00:00
|
|
|
|
#ifndef HAVE_FREEBSD_CDROM
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
#else
|
|
|
|
|
|
char drive[40];
|
|
|
|
|
|
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))
|
|
|
|
|
|
return strdup(fs->fs_spec);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* Scan the system for CD-ROM drives.
|
|
|
|
|
|
Not always 100% reliable, so use the USE_MNTENT code above first.
|
|
|
|
|
|
*/
|
2004-06-19 16:34:45 +00:00
|
|
|
|
|
|
|
|
|
|
/* Scan SCSI and CAM devices */
|
2004-06-12 18:45:54 +00:00
|
|
|
|
for ( c='0'; exists && c <='9'; c++ ) {
|
2004-06-19 11:07:55 +00:00
|
|
|
|
sprintf(drive, "/dev/cd%c%s", c, DEVICE_POSTFIX);
|
2004-06-12 18:45:54 +00:00
|
|
|
|
exists = cdio_is_cdrom(drive, NULL);
|
|
|
|
|
|
if ( exists ) {
|
|
|
|
|
|
return strdup(drive);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-06-19 16:34:45 +00:00
|
|
|
|
|
|
|
|
|
|
/* Scan are ATAPI devices */
|
2004-06-12 18:45:54 +00:00
|
|
|
|
for ( c='0'; exists && c <='9'; c++ ) {
|
2004-06-19 16:34:45 +00:00
|
|
|
|
sprintf(drive, "/dev/acd%c%s", c, DEVICE_POSTFIX);
|
2004-06-12 18:45:54 +00:00
|
|
|
|
exists = cdio_is_cdrom(drive, NULL);
|
|
|
|
|
|
if ( exists ) {
|
|
|
|
|
|
return strdup(drive);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
#endif /*HAVE_FREEBSD_CDROM*/
|
2004-04-30 09:59:54 +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 *psz_source_name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return cdio_open_am_freebsd(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 00:51:33 +00:00
|
|
|
|
cdio_open_am_freebsd (const char *psz_orig_source_name,
|
|
|
|
|
|
const char *psz_access_mode)
|
2004-04-30 09:59:54 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_FREEBSD_CDROM
|
|
|
|
|
|
CdIo *ret;
|
|
|
|
|
|
_img_private_t *_data;
|
2004-05-06 00:51:33 +00:00
|
|
|
|
char *psz_source_name;
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
|
|
|
|
|
cdio_funcs _funcs = {
|
|
|
|
|
|
.eject_media = _eject_media_freebsd,
|
|
|
|
|
|
.free = _free_freebsd,
|
|
|
|
|
|
.get_arg = _get_arg_freebsd,
|
|
|
|
|
|
.get_default_device = cdio_get_default_device_freebsd,
|
|
|
|
|
|
.get_devices = cdio_get_devices_freebsd,
|
|
|
|
|
|
.get_drive_cap = NULL,
|
|
|
|
|
|
.get_first_track_num= _get_first_track_num_freebsd,
|
|
|
|
|
|
.get_mcn = _get_mcn_freebsd,
|
|
|
|
|
|
.get_num_tracks = _get_num_tracks_freebsd,
|
|
|
|
|
|
.get_track_format = _get_track_format_freebsd,
|
|
|
|
|
|
.get_track_green = _get_track_green_freebsd,
|
|
|
|
|
|
.get_track_lba = _get_track_lba_freebsd,
|
|
|
|
|
|
.get_track_msf = NULL,
|
|
|
|
|
|
.lseek = cdio_generic_lseek,
|
|
|
|
|
|
.read = cdio_generic_read,
|
|
|
|
|
|
.read_audio_sectors = _read_audio_sectors_freebsd,
|
|
|
|
|
|
.read_mode2_sector = _read_mode2_sector_freebsd,
|
|
|
|
|
|
.read_mode2_sectors = _read_mode2_sectors_freebsd,
|
|
|
|
|
|
.set_arg = _set_arg_freebsd,
|
|
|
|
|
|
.stat_size = _stat_size_freebsd
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_data = _cdio_malloc (sizeof (_img_private_t));
|
|
|
|
|
|
_data->access_mode = str_to_access_mode_freebsd(psz_access_mode);
|
|
|
|
|
|
_data->gen.init = false;
|
|
|
|
|
|
_data->gen.fd = -1;
|
|
|
|
|
|
|
2004-05-06 00:51:33 +00:00
|
|
|
|
if (NULL == psz_orig_source_name) {
|
|
|
|
|
|
psz_source_name=cdio_get_default_device_freebsd();
|
2004-06-19 11:07:55 +00:00
|
|
|
|
if (NULL == psz_source_name) return NULL;
|
2004-05-19 03:00:03 +00:00
|
|
|
|
_data->device = psz_source_name;
|
2004-05-06 00:51:33 +00:00
|
|
|
|
_set_arg_freebsd(_data, "source", psz_source_name);
|
2004-04-30 09:59:54 +00:00
|
|
|
|
} else {
|
2004-05-19 03:00:03 +00:00
|
|
|
|
if (cdio_is_device_generic(psz_orig_source_name)) {
|
2004-05-06 00:51:33 +00:00
|
|
|
|
_set_arg_freebsd(_data, "source", psz_orig_source_name);
|
2004-05-19 03:00:03 +00:00
|
|
|
|
_data->device = strdup(psz_orig_source_name);
|
|
|
|
|
|
} else {
|
2004-05-06 00:51:33 +00:00
|
|
|
|
/* The below would be okay if all device drivers worked this way. */
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
cdio_info ("source %s is a not a device", psz_orig_source_name);
|
|
|
|
|
|
#endif
|
2004-04-30 09:59:54 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-05-06 00:51:33 +00:00
|
|
|
|
ret = cdio_new (_data, &_funcs);
|
|
|
|
|
|
if (ret == NULL) return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (cdio_generic_init(_data))
|
2004-05-07 02:16:57 +00:00
|
|
|
|
if ( _data->access_mode == _AM_IOCTL ) {
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (init_freebsd_cam(_data))
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
else {
|
|
|
|
|
|
cdio_generic_free (_data);
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-05-06 00:51:33 +00:00
|
|
|
|
else {
|
|
|
|
|
|
cdio_generic_free (_data);
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
2004-04-30 09:59:54 +00:00
|
|
|
|
|
|
|
|
|
|
#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 */
|
|
|
|
|
|
}
|