First commit after CVS conversion. Should be just administrative changes.

This commit is contained in:
R. Bernstein
2008-11-29 00:56:26 -05:00
parent 4ea407f746
commit 95f087cdc3
413 changed files with 86786 additions and 86 deletions

View File

@@ -0,0 +1,22 @@
# $Id: Makefile,v 1.2 2008/04/21 18:30:19 karl Exp $
#
# Copyright (C) 2004, 2008 Rocky Bernstein
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
#
# The make is done above. This boilerplate Makefile just transfers the call
all install check clean:
cd .. && $(MAKE) $@

View File

@@ -0,0 +1,893 @@
/*
$Id: freebsd.c,v 1.38 2008/04/21 18:30:20 karl Exp $
Copyright (C) 2003, 2004, 2005, 2008 Rocky Bernstein <rocky@gnu.org>
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 3 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, see <http://www.gnu.org/licenses/>.
*/
/* 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
static const char _rcsid[] = "$Id: freebsd.c,v 1.38 2008/04/21 18:30:20 karl Exp $";
#include "freebsd.h"
#ifdef HAVE_FREEBSD_CDROM
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include <netinet/in.h>
#include <cdio/sector.h>
static lba_t get_track_lba_freebsd(void *p_user_data, track_t i_track);
static access_mode_t
str_to_access_mode_freebsd(const char *psz_access_mode)
{
const access_mode_t default_access_mode = DEFAULT_FREEBSD_AM;
if (NULL==psz_access_mode) return default_access_mode;
if (!strcmp(psz_access_mode, "ioctl"))
return _AM_IOCTL;
else if (!strcmp(psz_access_mode, "CAM"))
return _AM_CAM;
else {
cdio_warn ("unknown access type: %s. Default ioctl used.",
psz_access_mode);
return default_access_mode;
}
}
static void
free_freebsd (void *p_obj)
{
_img_private_t *p_env = p_obj;
if (NULL == p_env) return;
if (NULL != p_env->device) free(p_env->device);
if (_AM_CAM == p_env->access_mode)
return free_freebsd_cam(p_env);
else
return cdio_generic_free(p_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);
}
/*!
Reads i_blocks of audio sectors from cd device into data starting from lsn.
Returns 0 if no error.
*/
static driver_return_code_t
read_audio_sectors_freebsd (void *p_user_data, void *p_buf, lsn_t i_lsn,
unsigned int i_blocks)
{
_img_private_t *p_env = p_user_data;
if ( p_env->access_mode == _AM_CAM ) {
return mmc_read_sectors( p_env->gen.cdio, p_buf, i_lsn,
CDIO_MMC_READ_TYPE_CDDA, i_blocks);
} else
return read_audio_sectors_freebsd_ioctl(p_user_data, p_buf, i_lsn,
i_blocks);
}
/*!
Reads a single mode2 sector from cd device into data starting
from i_lsn. Returns 0 if no error.
*/
static driver_return_code_t
read_mode2_sector_freebsd (void *p_user_data, void *data, lsn_t i_lsn,
bool b_form2)
{
_img_private_t *p_env = p_user_data;
if ( p_env->access_mode == _AM_CAM )
return read_mode2_sector_freebsd_cam(p_env, data, i_lsn, b_form2);
else
return read_mode2_sector_freebsd_ioctl(p_env, data, i_lsn, b_form2);
}
/*!
Reads i_blocks of mode2 sectors from cd device into data starting
from lsn.
*/
static driver_return_code_t
read_mode2_sectors_freebsd (void *p_user_data, void *p_data, lsn_t i_lsn,
bool b_form2, unsigned int i_blocks)
{
_img_private_t *p_env = p_user_data;
if ( p_env->access_mode == _AM_CAM && b_form2 ) {
/* We have a routine that covers this case without looping. */
return read_mode2_sectors_freebsd_cam(p_env, p_data, i_lsn, i_blocks);
} else {
unsigned int i;
uint16_t i_blocksize = b_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE;
/* For each frame, pick out the data part we need */
for (i = 0; i < i_blocks; i++) {
int retval = read_mode2_sector_freebsd (p_env,
((char *)p_data) +
(i_blocksize * i),
i_lsn + i, b_form2);
if (retval) return retval;
}
}
return DRIVER_OP_SUCCESS;
}
/*!
Return the size of the CD in logical block address (LBA) units.
@return the lsn. On error return CDIO_INVALID_LSN.
*/
static lsn_t
get_disc_last_lsn_freebsd (void *p_obj)
{
_img_private_t *p_env = p_obj;
if (!p_env) return CDIO_INVALID_LSN;
if (_AM_CAM == p_env->access_mode)
return get_disc_last_lsn_mmc(p_env);
else
return get_disc_last_lsn_freebsd_ioctl(p_env);
}
/*!
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
DRIVER_OP_SUCCESS is returned if no error was found,
and nonzero if there as an error.
*/
static driver_return_code_t
set_arg_freebsd (void *p_user_data, const char key[], const char value[])
{
_img_private_t *p_env = p_user_data;
if (!strcmp (key, "source"))
{
if (!value) return DRIVER_OP_ERROR;
free (p_env->gen.source_name);
p_env->gen.source_name = strdup (value);
}
else if (!strcmp (key, "access-mode"))
{
p_env->access_mode = str_to_access_mode_freebsd(value);
if (p_env->access_mode == _AM_CAM && !p_env->b_cam_init)
return init_freebsd_cam(p_env)
? DRIVER_OP_SUCCESS : DRIVER_OP_ERROR;
}
else return DRIVER_OP_ERROR;
return DRIVER_OP_SUCCESS;
}
/* Set CD-ROM drive speed */
static int
set_speed_freebsd (void *p_user_data, int i_speed)
{
const _img_private_t *p_env = p_user_data;
if (!p_env) return -1;
#ifdef CDRIOCREADSPEED
i_speed *= 177;
return ioctl(p_env->gen.fd, CDRIOCREADSPEED, &i_speed);
#else
return -2;
#endif
}
/*!
Read and cache the CD's Track Table of Contents and track info.
Return false if unsuccessful;
*/
static bool
read_toc_freebsd (void *p_user_data)
{
_img_private_t *p_env = p_user_data;
track_t i, j;
/* read TOC header */
if ( ioctl(p_env->gen.fd, CDIOREADTOCHEADER, &p_env->tochdr) == -1 ) {
cdio_warn("error in ioctl(CDIOREADTOCHEADER): %s\n", strerror(errno));
return false;
}
p_env->gen.i_first_track = p_env->tochdr.starting_track;
p_env->gen.i_tracks = p_env->tochdr.ending_track -
p_env->gen.i_first_track + 1;
j=0;
for (i=p_env->gen.i_first_track; i<=p_env->gen.i_tracks; i++, j++) {
struct ioc_read_toc_single_entry *p_toc =
&(p_env->tocent[i-p_env->gen.i_first_track]);
p_toc->track = i;
p_toc->address_format = CD_LBA_FORMAT;
if ( ioctl(p_env->gen.fd, CDIOREADTOCENTRY, p_toc) ) {
cdio_warn("%s %d: %s\n",
"error in ioctl CDROMREADTOCENTRY for track",
i, strerror(errno));
return false;
}
set_track_flags(&(p_env->gen.track_flags[i]), p_toc->entry.control);
}
p_env->tocent[j].track = CDIO_CDROM_LEADOUT_TRACK;
p_env->tocent[j].address_format = CD_LBA_FORMAT;
if ( ioctl(p_env->gen.fd, CDIOREADTOCENTRY, &(p_env->tocent[j]) ) ){
cdio_warn("%s: %s\n",
"error in ioctl CDROMREADTOCENTRY for leadout track",
strerror(errno));
return false;
}
p_env->gen.toc_init = true;
return true;
}
/*!
Get the volume of an audio CD.
@param p_cdio the CD object to be acted upon.
*/
static driver_return_code_t
audio_get_volume_freebsd (void *p_user_data,
/*out*/ cdio_audio_volume_t *p_volume)
{
const _img_private_t *p_env = p_user_data;
return ioctl(p_env->gen.fd, CDIOCGETVOL, p_volume);
}
/*!
Pause playing CD through analog output
@param p_cdio the CD object to be acted upon.
*/
static driver_return_code_t
audio_pause_freebsd (void *p_user_data)
{
const _img_private_t *p_env = p_user_data;
return ioctl(p_env->gen.fd, CDIOCPAUSE);
}
/*!
Playing starting at given MSF through analog output
@param p_cdio the CD object to be acted upon.
*/
static driver_return_code_t
audio_play_msf_freebsd (void *p_user_data, msf_t *p_start_msf,
msf_t *p_end_msf)
{
const _img_private_t *p_env = p_user_data;
struct ioc_play_msf freebsd_play_msf;
freebsd_play_msf.start_m = cdio_from_bcd8(p_start_msf->m);
freebsd_play_msf.start_s = cdio_from_bcd8(p_start_msf->s);
freebsd_play_msf.start_f = cdio_from_bcd8(p_start_msf->f);
freebsd_play_msf.end_m = cdio_from_bcd8(p_end_msf->m);
freebsd_play_msf.end_s = cdio_from_bcd8(p_end_msf->s);
freebsd_play_msf.end_f = cdio_from_bcd8(p_end_msf->f);
return ioctl(p_env->gen.fd, CDIOCPLAYMSF, &freebsd_play_msf);
}
/*!
Playing CD through analog output at the desired track and index
@param p_user_data the CD object to be acted upon.
@param p_track_index location to start/end.
*/
static driver_return_code_t
audio_play_track_index_freebsd (void *p_user_data,
cdio_track_index_t *p_track_index)
{
const _img_private_t *p_env = p_user_data;
msf_t start_msf;
msf_t end_msf;
struct ioc_play_msf freebsd_play_msf;
lsn_t i_lsn = get_track_lba_freebsd(p_user_data,
p_track_index->i_start_track);
cdio_lsn_to_msf(i_lsn, &start_msf);
i_lsn = get_track_lba_freebsd(p_user_data, p_track_index->i_end_track);
cdio_lsn_to_msf(i_lsn, &end_msf);
freebsd_play_msf.start_m = start_msf.m;
freebsd_play_msf.start_s = start_msf.s;
freebsd_play_msf.start_f = start_msf.f;
freebsd_play_msf.end_m = end_msf.m;
freebsd_play_msf.end_s = end_msf.s;
freebsd_play_msf.end_f = end_msf.f;
return ioctl(p_env->gen.fd, CDIOCPLAYMSF, &freebsd_play_msf);
}
/*!
Read Audio Subchannel information
@param p_user_data the CD object to be acted upon.
@param p_subchannel returned information
*/
#if 1
static driver_return_code_t
audio_read_subchannel_freebsd (void *p_user_data,
/*out*/ cdio_subchannel_t *p_subchannel)
{
const _img_private_t *p_env = p_user_data;
int i_rc;
struct cd_sub_channel_info bsdinfo;
struct ioc_read_subchannel read_subchannel;
memset(& bsdinfo, 0, sizeof(struct cd_sub_channel_info));
read_subchannel.address_format = CD_MSF_FORMAT;
read_subchannel.data_format = CD_CURRENT_POSITION;
read_subchannel.track = 0;
read_subchannel.data_len = sizeof(struct cd_sub_channel_info);
read_subchannel.data = & bsdinfo;
i_rc = ioctl(p_env->gen.fd, CDIOCREADSUBCHANNEL, &read_subchannel);
if (0 == i_rc) {
p_subchannel->audio_status = bsdinfo.header.audio_status;
p_subchannel->address = bsdinfo.what.position.addr_type;
p_subchannel->control = bsdinfo.what.position.control;
p_subchannel->track = bsdinfo.what.position.track_number;
p_subchannel->index = bsdinfo.what.position.index_number;
p_subchannel->abs_addr.m = cdio_to_bcd8 (bsdinfo.what.position.absaddr.msf.minute);
p_subchannel->abs_addr.s = cdio_to_bcd8 (bsdinfo.what.position.absaddr.msf.second);
p_subchannel->abs_addr.f = cdio_to_bcd8 (bsdinfo.what.position.absaddr.msf.frame);
p_subchannel->rel_addr.m = cdio_to_bcd8 (bsdinfo.what.position.reladdr.msf.minute);
p_subchannel->rel_addr.s = cdio_to_bcd8 (bsdinfo.what.position.reladdr.msf.second);
p_subchannel->rel_addr.f = cdio_to_bcd8 (bsdinfo.what.position.reladdr.msf.frame);
}
return i_rc;
}
#endif
/*!
Resume playing an audio CD.
@param p_cdio the CD object to be acted upon.
*/
static driver_return_code_t
audio_resume_freebsd (void *p_user_data)
{
const _img_private_t *p_env = p_user_data;
return ioctl(p_env->gen.fd, CDIOCRESUME, 0);
}
/*!
Set the volume of an audio CD.
@param p_cdio the CD object to be acted upon.
*/
static driver_return_code_t
audio_set_volume_freebsd (void *p_user_data,
cdio_audio_volume_t *p_volume)
{
const _img_private_t *p_env = p_user_data;
return ioctl(p_env->gen.fd, CDIOCSETVOL, p_volume);
}
/*!
Eject media. Return 1 if successful, 0 otherwise.
*/
static int
eject_media_freebsd (void *p_user_data)
{
_img_private_t *p_env = p_user_data;
return (p_env->access_mode == _AM_IOCTL)
? eject_media_freebsd_ioctl(p_env)
: eject_media_freebsd_cam(p_env);
}
/*!
Stop playing an audio CD.
@param p_user_data the CD object to be acted upon.
*/
static driver_return_code_t
audio_stop_freebsd (void *p_user_data)
{
const _img_private_t *p_env = p_user_data;
return ioctl(p_env->gen.fd, CDIOCSTOP);
}
/*!
Return the value associated with the key "arg".
*/
static const char *
get_arg_freebsd (void *user_data, const char key[])
{
_img_private_t *env = user_data;
if (!strcmp (key, "source")) {
return env->gen.source_name;
} else if (!strcmp (key, "access-mode")) {
switch (env->access_mode) {
case _AM_IOCTL:
return "ioctl";
case _AM_CAM:
return "CAM";
case _AM_NONE:
return "no access method";
}
}
return NULL;
}
/*!
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 *
get_mcn_freebsd (const void *p_user_data) {
const _img_private_t *p_env = p_user_data;
return (p_env->access_mode == _AM_IOCTL)
? get_mcn_freebsd_ioctl(p_env)
: mmc_get_mcn(p_env->gen.cdio);
}
static void
get_drive_cap_freebsd (const void *p_user_data,
cdio_drive_read_cap_t *p_read_cap,
cdio_drive_write_cap_t *p_write_cap,
cdio_drive_misc_cap_t *p_misc_cap)
{
const _img_private_t *p_env = p_user_data;
if (p_env->access_mode == _AM_CAM)
get_drive_cap_mmc (p_user_data, p_read_cap, p_write_cap, p_misc_cap);
}
/*!
Run a SCSI MMC command.
p_user_data internal CD structure.
i_timeout_ms time in milliseconds we will wait for the command
to complete. If this value is -1, use the default
time-out value.
i_cdb Size of p_cdb
p_cdb CDB bytes.
e_direction direction the transfer is to go.
i_buf Size of buffer
p_buf Buffer for data, both sending and receiving
*/
static driver_return_code_t
run_mmc_cmd_freebsd( void *p_user_data, unsigned int i_timeout_ms,
unsigned int i_cdb, const mmc_cdb_t *p_cdb,
cdio_mmc_direction_t e_direction,
unsigned int i_buf, /*in/out*/ void *p_buf )
{
const _img_private_t *p_env = p_user_data;
if (p_env->access_mode == _AM_CAM)
return run_mmc_cmd_freebsd_cam( p_user_data, i_timeout_ms, i_cdb, p_cdb,
e_direction, i_buf, p_buf );
else
return DRIVER_OP_UNSUPPORTED;
}
/*!
Get format of track.
FIXME: We're just guessing this from the GNU/Linux code.
*/
static track_format_t
get_track_format_freebsd(void *p_user_data, track_t i_track)
{
_img_private_t *p_env = p_user_data;
if (!p_env->gen.toc_init) read_toc_freebsd (p_user_data) ;
if (i_track > TOTAL_TRACKS || i_track == 0)
return TRACK_FORMAT_ERROR;
i_track -= FIRST_TRACK_NUM;
/* This is pretty much copied from the "badly broken" cdrom_count_tracks
in linux/cdrom.c.
*/
if (p_env->tocent[i_track].entry.control & CDIO_CDROM_DATA_TRACK) {
if (p_env->tocent[i_track].address_format == CDIO_CDROM_CDI_TRACK)
return TRACK_FORMAT_CDI;
else if (p_env->tocent[i_track].address_format == CDIO_CDROM_XA_TRACK)
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
get_track_green_freebsd(void *user_data, track_t i_track)
{
_img_private_t *p_env = user_data;
if (i_track == CDIO_CDROM_LEADOUT_TRACK) i_track = TOTAL_TRACKS+1;
if (i_track > TOTAL_TRACKS+1 || i_track == 0)
return false;
/* FIXME: Dunno if this is the right way, but it's what
I was using in cdinfo for a while.
*/
return ((p_env->tocent[i_track-FIRST_TRACK_NUM].entry.control & 2) != 0);
}
/*!
Return the starting LSN track number
i_track in obj. Track numbers start at 1.
The "leadout" track is specified either by
using i_track LEADOUT_TRACK or the total tracks+1.
CDIO_INVALID_LBA is returned if there is no track entry.
*/
static lba_t
get_track_lba_freebsd(void *user_data, track_t i_track)
{
_img_private_t *p_env = user_data;
if (!p_env->gen.toc_init) read_toc_freebsd (p_env) ;
if (i_track == CDIO_CDROM_LEADOUT_TRACK) i_track = TOTAL_TRACKS+1;
if (i_track > TOTAL_TRACKS+1 || i_track == 0 || !p_env->gen.toc_init) {
return CDIO_INVALID_LBA;
} else {
return cdio_lsn_to_lba(ntohl(p_env->tocent[i_track-FIRST_TRACK_NUM].entry.addr.lba));
}
}
#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.
*/
/* Scan SCSI and CAM devices */
for ( c='0'; exists && c <='9'; c++ ) {
sprintf(drive, "/dev/cd%c%s", c, DEVICE_POSTFIX);
exists = cdio_is_cdrom(drive, NULL);
if ( exists ) {
cdio_add_device_list(&drives, drive, &num_drives);
}
}
/* Scan are ATAPI devices */
for ( c='0'; exists && c <='9'; c++ ) {
sprintf(drive, "/dev/acd%c%s", c, DEVICE_POSTFIX);
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()
{
#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.
*/
/* Scan SCSI and CAM devices */
for ( c='0'; exists && c <='9'; c++ ) {
sprintf(drive, "/dev/cd%c%s", c, DEVICE_POSTFIX);
exists = cdio_is_cdrom(drive, NULL);
if ( exists ) {
return strdup(drive);
}
}
/* Scan are ATAPI devices */
for ( c='0'; exists && c <='9'; c++ ) {
sprintf(drive, "/dev/acd%c%s", c, DEVICE_POSTFIX);
exists = cdio_is_cdrom(drive, NULL);
if ( exists ) {
return strdup(drive);
}
}
return NULL;
#endif /*HAVE_FREEBSD_CDROM*/
}
/*!
Close tray on CD-ROM.
@param psz_device the CD-ROM drive to be closed.
*/
driver_return_code_t
close_tray_freebsd (const char *psz_device)
{
#ifdef HAVE_FREEBSD_CDROM
int fd = open (psz_device, O_RDONLY|O_NONBLOCK, 0);
int i_rc;
if((i_rc = ioctl(fd, CDIOCCLOSE)) != 0) {
cdio_warn ("ioctl CDIOCCLOSE failed: %s\n", strerror(errno));
return DRIVER_OP_ERROR;
}
close(fd);
return DRIVER_OP_SUCCESS;
#else
return DRIVER_OP_NO_DRIVER;
#endif /*HAVE_FREEBSD_CDROM*/
}
#ifdef HAVE_FREEBSD_CDROM
/*! Find out if media has changed since the last call. @param
p_user_data the environment of the CD object to be acted upon.
@return 1 if media has changed since last call, 0 if not. Error
return codes are the same as driver_return_code_t
*/
static int
get_media_changed_freebsd (const void *p_user_data)
{
const _img_private_t *p_env = p_user_data;
if ( p_env->access_mode == _AM_CAM ) {
return mmc_get_media_changed( p_env->gen.cdio );
}
else
return DRIVER_OP_UNSUPPORTED;
}
#endif /*HAVE_FREEBSD_CDROM*/
/*!
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 *
cdio_open_am_freebsd (const char *psz_orig_source_name,
const char *psz_access_mode)
{
#ifdef HAVE_FREEBSD_CDROM
CdIo *ret;
_img_private_t *_data;
char *psz_source_name;
cdio_funcs_t _funcs = {
.audio_get_volume = audio_get_volume_freebsd,
.audio_pause = audio_pause_freebsd,
.audio_play_msf = audio_play_msf_freebsd,
.audio_play_track_index = audio_play_track_index_freebsd,
.audio_read_subchannel = audio_read_subchannel_freebsd,
.audio_resume = audio_resume_freebsd,
.audio_set_volume = audio_set_volume_freebsd,
.audio_stop = audio_stop_freebsd,
.eject_media = eject_media_freebsd,
.free = free_freebsd,
.get_arg = get_arg_freebsd,
.get_blocksize = get_blocksize_mmc,
.get_cdtext = get_cdtext_generic,
.get_default_device = cdio_get_default_device_freebsd,
.get_devices = cdio_get_devices_freebsd,
.get_disc_last_lsn = get_disc_last_lsn_freebsd,
.get_discmode = get_discmode_generic,
.get_drive_cap = get_drive_cap_freebsd,
.get_first_track_num = get_first_track_num_generic,
.get_media_changed = get_media_changed_freebsd,
.get_mcn = get_mcn_freebsd,
.get_num_tracks = get_num_tracks_generic,
.get_track_channels = get_track_channels_generic,
.get_track_copy_permit = get_track_copy_permit_generic,
.get_track_format = get_track_format_freebsd,
.get_track_green = get_track_green_freebsd,
.get_track_lba = get_track_lba_freebsd,
.get_track_preemphasis = get_track_preemphasis_generic,
.get_track_msf = NULL,
.lseek = cdio_generic_lseek,
.read = cdio_generic_read,
.read_audio_sectors = read_audio_sectors_freebsd,
.read_data_sectors = read_data_sectors_mmc,
.read_mode2_sector = read_mode2_sector_freebsd,
.read_mode2_sectors = read_mode2_sectors_freebsd,
.read_toc = read_toc_freebsd,
.run_mmc_cmd = run_mmc_cmd_freebsd,
.set_arg = set_arg_freebsd,
.set_blocksize = set_blocksize_mmc,
.set_speed = set_speed_freebsd,
};
_data = calloc(1, sizeof (_img_private_t));
_data->access_mode = str_to_access_mode_freebsd(psz_access_mode);
_data->gen.init = false;
_data->gen.fd = -1;
_data->gen.toc_init = false;
_data->gen.b_cdtext_init = false;
_data->gen.b_cdtext_error = false;
if (NULL == psz_orig_source_name) {
psz_source_name=cdio_get_default_device_freebsd();
if (NULL == psz_source_name) return NULL;
_data->device = psz_source_name;
set_arg_freebsd(_data, "source", psz_source_name);
} else {
if (cdio_is_device_generic(psz_orig_source_name)) {
set_arg_freebsd(_data, "source", psz_orig_source_name);
_data->device = strdup(psz_orig_source_name);
} else {
/* The below would be okay if all device drivers worked this way. */
#if 0
cdio_info ("source %s is a not a device", psz_orig_source_name);
#endif
free(_data);
return NULL;
}
}
ret = cdio_new ((void *)_data, &_funcs);
if (ret == NULL) return NULL;
if (cdio_generic_init(_data, O_RDONLY))
if ( _data->access_mode == _AM_IOCTL ) {
return ret;
} else {
if (init_freebsd_cam(_data))
return ret;
else {
cdio_generic_free (_data);
return NULL;
}
}
else {
cdio_generic_free (_data);
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 */
}

View File

@@ -0,0 +1,232 @@
/*
$Id: freebsd.h,v 1.10 2008/05/11 09:50:54 rocky Exp $
Copyright (C) 2003, 2004, 2008 Rocky Bernstein <rocky@gnu.org>
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 3 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, see <http://www.gnu.org/licenses/>.
*/
/* 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
#include <cdio/sector.h>
#include "cdio_assert.h"
#include "cdio_private.h"
/*!
For ioctl access /dev/acd0c is preferred over /dev/cd0c.
For cam access /dev/cd0c is preferred. DEFAULT_CDIO_DEVICE and
DEFAULT_FREEBSD_AM should be consistent.
*/
#ifndef DEFAULT_CDIO_DEVICE
#define DEFAULT_CDIO_DEVICE "/dev/cd0c"
#endif
#ifndef DEFAULT_FREEBSD_AM
#define DEFAULT_FREEBSD_AM _AM_CAM
#endif
#include <string.h>
#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
#ifndef CDIOCREADAUDIO
struct ioc_read_audio
{
u_char address_format;
union msf_lba address;
int nframes;
u_char* buffer;
};
#define CDIOCREADAUDIO _IOWR('c',31,struct ioc_read_audio)
#endif
#include <sys/cdrio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/param.h> /* for __FreeBSD_version */
#if (__FreeBSD_version < 500000) && (__FreeBSD_kernel_version < 500000)
#define DEVICE_POSTFIX "c"
#else
#define DEVICE_POSTFIX ""
#endif
#define HAVE_FREEBSD_CAM
#ifdef HAVE_FREEBSD_CAM
#include <camlib.h>
#include <cam/scsi/scsi_message.h>
#include <cam/scsi/scsi_pass.h>
#include <errno.h>
#define ERRCODE(s) ((((s)[2]&0x0F)<<16)|((s)[12]<<8)|((s)[13]))
#define EMEDIUMTYPE EINVAL
#define ENOMEDIUM ENODEV
#define CREAM_ON_ERRNO(s) do { \
switch ((s)[12]) \
{ case 0x04: errno=EAGAIN; break; \
case 0x20: errno=ENODEV; break; \
case 0x21: if ((s)[13]==0) errno=ENOSPC; \
else errno=EINVAL; \
break; \
case 0x30: errno=EMEDIUMTYPE; break; \
case 0x3A: errno=ENOMEDIUM; break; \
} \
} while(0)
#endif /*HAVE_FREEBSD_CAM*/
#include <cdio/util.h>
#define TOTAL_TRACKS ( p_env->tochdr.ending_track \
- p_env->tochdr.starting_track + 1)
#define FIRST_TRACK_NUM (p_env->tochdr.starting_track)
typedef enum {
_AM_NONE,
_AM_IOCTL,
_AM_CAM
} access_mode_t;
typedef struct {
/* Things common to all drivers like this.
This must be first. */
generic_img_private_t gen;
#ifdef HAVE_FREEBSD_CAM
char *device;
struct cam_device *cam;
union ccb ccb;
#endif
access_mode_t access_mode;
bool b_ioctl_init;
bool b_cam_init;
/* Track information */
struct ioc_toc_header tochdr;
/* Entry info for each track. Add 1 for leadout. */
struct ioc_read_toc_single_entry tocent[CDIO_CD_MAX_TRACKS+1];
} _img_private_t;
bool cdio_is_cdrom_freebsd_ioctl(char *drive, char *mnttype);
track_format_t get_track_format_freebsd_ioctl(const _img_private_t *env,
track_t i_track);
bool get_track_green_freebsd_ioctl(const _img_private_t *env,
track_t i_track);
driver_return_code_t eject_media_freebsd_ioctl (_img_private_t *p_env);
driver_return_code_t eject_media_freebsd_cam (_img_private_t *p_env);
void get_drive_cap_freebsd_cam (const _img_private_t *p_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);
static int get_media_changed_freebsd (const void *p_user_data);
char *get_mcn_freebsd_ioctl (const _img_private_t *p_env);
void free_freebsd_cam (void *obj);
/*!
Using the ioctl method, r nblocks of audio sectors from cd device
into data starting from lsn. Returns 0 if no error.
*/
int read_audio_sectors_freebsd_ioctl (_img_private_t *env, void *data,
lsn_t lsn, unsigned int nblocks);
/*!
Using the CAM method, reads nblocks of mode2 sectors from
cd device using into data starting from lsn. Returns 0 if no
error.
*/
int read_mode2_sector_freebsd_cam (_img_private_t *env, void *data,
lsn_t lsn, bool b_form2);
/*!
Using the ioctl method, reads nblocks of mode2 sectors from
cd device using into data starting from lsn. Returns 0 if no
error.
*/
int read_mode2_sector_freebsd_ioctl (_img_private_t *env, void *data,
lsn_t lsn, bool b_form2);
/*!
Using the CAM method, reads nblocks of mode2 form2 sectors from
cd device using into data starting from lsn. Returns 0 if no
error.
Note: if you want form1 sectors, the caller has to pick out the
appropriate piece.
*/
int read_mode2_sectors_freebsd_cam (_img_private_t *env, void *buf,
lsn_t lsn, unsigned int nblocks);
bool read_toc_freebsd_ioctl (_img_private_t *env);
/*!
Run a SCSI MMC command.
p_user_data internal CD structure.
i_timeout time in milliseconds we will wait for the command
to complete. If this value is -1, use the default
time-out value.
i_cdb Size of p_cdb
p_cdb CDB bytes.
e_direction direction the transfer is to go.
i_buf Size of buffer
p_buf Buffer for data, both sending and receiving
Return 0 if no error.
*/
int run_mmc_cmd_freebsd_cam( const void *p_user_data,
unsigned int i_timeout_ms,
unsigned int i_cdb,
const mmc_cdb_t *p_cdb,
cdio_mmc_direction_t e_direction,
unsigned int i_buf,
/*in/out*/ void *p_buf );
/*!
Return the size of the CD in logical block address (LBA) units.
*/
lsn_t get_disc_last_lsn_freebsd_ioctl (_img_private_t *_obj);
bool init_freebsd_cam (_img_private_t *env);
void free_freebsd_cam (void *user_data);
#endif /*HAVE_FREEBSD_CDROM*/

View File

@@ -0,0 +1,257 @@
/*
$Id: freebsd_cam.c,v 1.12 2008/04/21 18:30:20 karl Exp $
Copyright (C) 2004, 2005, 2008 Rocky Bernstein <rocky@gnu.org>
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 3 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, see <http://www.gnu.org/licenses/>.
*/
/* This file contains FreeBSD-specific code and implements low-level
control of the CD drive via SCSI emulation.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
static const char _rcsid[] = "$Id: freebsd_cam.c,v 1.12 2008/04/21 18:30:20 karl Exp $";
#ifdef HAVE_FREEBSD_CDROM
#include "freebsd.h"
#include <cdio/mmc.h>
/* Default value in seconds we will wait for a command to
complete. */
#define DEFAULT_TIMEOUT_MSECS 10000
/*!
Run a SCSI MMC command.
p_user_data internal CD structure.
i_timeout_ms time in milliseconds we will wait for the command
to complete. If this value is -1, use the default
time-out value.
i_cdb Size of p_cdb
p_cdb CDB bytes.
e_direction direction the transfer is to go.
i_buf Size of buffer
p_buf Buffer for data, both sending and receiving
Return 0 if no error.
*/
int
run_mmc_cmd_freebsd_cam( const void *p_user_data, unsigned int i_timeout_ms,
unsigned int i_cdb, const mmc_cdb_t *p_cdb,
cdio_mmc_direction_t e_direction,
unsigned int i_buf, /*in/out*/ void *p_buf )
{
const _img_private_t *p_env = p_user_data;
int i_status;
int direction = CAM_DEV_QFRZDIS;
union ccb ccb;
if (!p_env || !p_env->cam) return -2;
memset(&ccb, 0, sizeof(ccb));
ccb.ccb_h.path_id = p_env->cam->path_id;
ccb.ccb_h.target_id = p_env->cam->target_id;
ccb.ccb_h.target_lun = p_env->cam->target_lun;
ccb.ccb_h.timeout = i_timeout_ms;
if (!i_buf)
direction |= CAM_DIR_NONE;
else
direction |= (e_direction == SCSI_MMC_DATA_READ)?CAM_DIR_IN : CAM_DIR_OUT;
memcpy(ccb.csio.cdb_io.cdb_bytes, p_cdb->field, i_cdb);
ccb.csio.cdb_len =
mmc_get_cmd_len(ccb.csio.cdb_io.cdb_bytes[0]);
cam_fill_csio (&(ccb.csio), 1, NULL,
direction | CAM_DEV_QFRZDIS, MSG_SIMPLE_Q_TAG, p_buf, i_buf,
sizeof(ccb.csio.sense_data), ccb.csio.cdb_len, 30*1000);
if (cam_send_ccb(p_env->cam, &ccb) < 0)
{
cdio_warn ("transport failed: %s", strerror(errno));
return -1;
}
if ((ccb.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP)
{
return 0;
}
errno = EIO;
i_status = ERRCODE(((unsigned char *)&ccb.csio.sense_data));
if (i_status == 0)
i_status = -1;
else
CREAM_ON_ERRNO(((unsigned char *)&ccb.csio.sense_data));
cdio_warn ("transport failed: %d", i_status);
return i_status;
}
bool
init_freebsd_cam (_img_private_t *p_env)
{
char pass[100];
p_env->cam=NULL;
memset (&p_env->ccb, 0, sizeof(p_env->ccb));
p_env->ccb.ccb_h.func_code = XPT_GDEVLIST;
if (-1 == p_env->gen.fd)
p_env->gen.fd = open (p_env->device, O_RDONLY, 0);
if (p_env->gen.fd < 0)
{
cdio_warn ("open (%s): %s", p_env->device, strerror (errno));
return false;
}
if (ioctl (p_env->gen.fd, CAMGETPASSTHRU, &p_env->ccb) < 0)
{
cdio_warn ("open: %s", strerror (errno));
return false;
}
sprintf (pass,"/dev/%.15s%u",
p_env->ccb.cgdl.periph_name,
p_env->ccb.cgdl.unit_number);
p_env->cam = cam_open_pass (pass,O_RDWR,NULL);
if (!p_env->cam) return false;
p_env->gen.init = true;
p_env->b_cam_init = true;
return true;
}
void
free_freebsd_cam (void *user_data)
{
_img_private_t *p_env = user_data;
if (NULL == p_env) return;
if (p_env->gen.fd > 0)
close (p_env->gen.fd);
p_env->gen.fd = -1;
if(p_env->cam)
cam_close_device(p_env->cam);
free (p_env);
}
driver_return_code_t
read_mode2_sector_freebsd_cam (_img_private_t *p_env, void *data, lsn_t lsn,
bool b_form2)
{
if ( b_form2 )
return read_mode2_sectors_freebsd_cam(p_env, data, lsn, 1);
else {
/* Need to pick out the data portion from a mode2 form2 frame */
char buf[M2RAW_SECTOR_SIZE] = { 0, };
int retval = read_mode2_sectors_freebsd_cam(p_env, buf, lsn, 1);
if ( retval ) return retval;
memcpy (((char *)data), buf + CDIO_CD_SUBHEADER_SIZE, CDIO_CD_FRAMESIZE);
return DRIVER_OP_SUCCESS;
}
}
/*!
Reads nblocks of mode2 sectors from cd device into data starting
from lsn.
Returns 0 if no error.
*/
int
read_mode2_sectors_freebsd_cam (_img_private_t *p_env, void *p_buf,
lsn_t lsn, unsigned int nblocks)
{
mmc_cdb_t cdb = {{0, }};
bool b_read_10 = false;
CDIO_MMC_SET_READ_LBA(cdb.field, lsn);
if (b_read_10) {
int retval;
CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_READ_10);
CDIO_MMC_SET_READ_LENGTH16(cdb.field, nblocks);
if ((retval = mmc_set_blocksize (p_env->gen.cdio, M2RAW_SECTOR_SIZE)))
return retval;
if ((retval = run_mmc_cmd_freebsd_cam (p_env, 0,
mmc_get_cmd_len(cdb.field[0]),
&cdb,
SCSI_MMC_DATA_READ,
M2RAW_SECTOR_SIZE * nblocks,
p_buf)))
{
mmc_set_blocksize (p_env->gen.cdio, CDIO_CD_FRAMESIZE);
return retval;
}
return mmc_set_blocksize (p_env->gen.cdio, CDIO_CD_FRAMESIZE);
} else {
CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_READ_CD);
CDIO_MMC_SET_READ_LENGTH24(cdb.field, nblocks);
cdb.field[1] = 0; /* sector size mode2 */
cdb.field[9] = 0x58; /* 2336 mode2 */
return run_mmc_cmd_freebsd_cam (p_env, 0,
mmc_get_cmd_len(cdb.field[0]),
&cdb,
SCSI_MMC_DATA_READ,
M2RAW_SECTOR_SIZE * nblocks, p_buf);
}
}
/*!
Eject media in CD-ROM drive. Return DRIVER_OP_SUCCESS if successful,
DRIVER_OP_ERROR on error.
*/
driver_return_code_t
eject_media_freebsd_cam (_img_private_t *p_env)
{
int i_status;
mmc_cdb_t cdb = {{0, }};
uint8_t buf[1];
CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_ALLOW_MEDIUM_REMOVAL);
i_status = run_mmc_cmd_freebsd_cam (p_env, DEFAULT_TIMEOUT_MSECS,
mmc_get_cmd_len(cdb.field[0]),
&cdb, SCSI_MMC_DATA_WRITE, 0, &buf);
if (i_status) return i_status;
CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_START_STOP);
cdb.field[4] = 1;
i_status = run_mmc_cmd_freebsd_cam (p_env, DEFAULT_TIMEOUT_MSECS,
mmc_get_cmd_len(cdb.field[0]), &cdb,
SCSI_MMC_DATA_WRITE, 0, &buf);
if (i_status) return i_status;
CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_START_STOP);
cdb.field[4] = 2; /* eject */
return run_mmc_cmd_freebsd_cam (p_env, DEFAULT_TIMEOUT_MSECS,
mmc_get_cmd_len(cdb.field[0]),
&cdb,
SCSI_MMC_DATA_WRITE, 0, &buf);
}
#endif /* HAVE_FREEBSD_CDROM */

View File

@@ -0,0 +1,262 @@
/*
$Id: freebsd_ioctl.c,v 1.7 2008/04/21 18:30:20 karl Exp $
Copyright (C) 2003, 2004, 2005, 2008 Rocky Bernstein <rocky@gnu.org>
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 3 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, see <http://www.gnu.org/licenses/>.
*/
/* 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
static const char _rcsid[] = "$Id: freebsd_ioctl.c,v 1.7 2008/04/21 18:30:20 karl Exp $";
#ifdef HAVE_FREEBSD_CDROM
#include "freebsd.h"
/* 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 .
*/
bool
cdio_is_cdrom_freebsd_ioctl(char *drive, char *mnttype)
{
bool is_cd=false;
int cdfd;
struct ioc_toc_header tochdr;
/* If it doesn't exist, return -1 */
if ( !cdio_is_device_quiet_generic(drive) ) {
return(false);
}
/* If it does exist, verify that it's an available CD-ROM */
cdfd = open(drive, (O_RDONLY|O_EXCL|O_NONBLOCK), 0);
/* Should we want to test the condition in more detail:
ENOENT is the error for /dev/xxxxx does not exist;
ENODEV means there's no drive present. */
if ( cdfd >= 0 ) {
if ( ioctl(cdfd, CDIOREADTOCHEADER, &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);
}
/*!
Reads a single mode2 sector from cd device into data starting from lsn.
Returns 0 if no error.
*/
int
read_audio_sectors_freebsd_ioctl (_img_private_t *_obj, void *data, lsn_t lsn,
unsigned int nblocks)
{
unsigned char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
struct ioc_read_audio cdda;
cdda.address.lba = lsn;
cdda.buffer = buf;
cdda.nframes = nblocks;
cdda.address_format = CDIO_CDROM_LBA;
/* read a frame */
if(ioctl(_obj->gen.fd, CDIOCREADAUDIO, &cdda) < 0) {
perror("CDIOCREADAUDIO");
return 1;
}
memcpy (data, buf, CDIO_CD_FRAMESIZE_RAW);
return 0;
}
/*!
Reads a single mode2 sector from cd device into data starting
from lsn. Returns 0 if no error.
*/
int
read_mode2_sector_freebsd_ioctl (_img_private_t *p_env, void *data, lsn_t lsn,
bool b_form2)
{
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
int retval;
if ( !b_form2 )
return cdio_generic_read_form1_sector (p_env, buf, lsn);
if ( (retval = read_audio_sectors_freebsd_ioctl (p_env, buf, lsn, 1)) )
return retval;
memcpy (data, buf + CDIO_CD_XA_SYNC_HEADER, M2RAW_SECTOR_SIZE);
return 0;
}
/*!
Return the size of the CD in logical block address (LBA) units.
*/
lsn_t
get_disc_last_lsn_freebsd_ioctl (_img_private_t *p_obj)
{
struct ioc_read_toc_single_entry tocent;
uint32_t size;
tocent.track = CDIO_CDROM_LEADOUT_TRACK;
tocent.address_format = CDIO_CDROM_LBA;
if (ioctl (p_obj->gen.fd, CDIOREADTOCENTRY, &tocent) == -1)
{
perror ("ioctl(CDROMREADTOCENTRY)");
exit (EXIT_FAILURE);
}
size = tocent.entry.addr.lba;
return size;
}
/*!
Eject media in CD-ROM drive. Return DRIVER_OP_SUCCESS if successful,
DRIVER_OP_ERROR on error.
*/
driver_return_code_t
eject_media_freebsd_ioctl (_img_private_t *p_env)
{
_img_private_t *p_obj = p_env;
int ret=DRIVER_OP_ERROR;
if (ioctl(p_obj->gen.fd, CDIOCALLOW) == -1) {
cdio_warn("ioctl(fd, CDIOCALLOW) failed: %s\n", strerror(errno));
} else if (ioctl(p_obj->gen.fd, CDIOCEJECT) == -1) {
cdio_warn("ioctl(CDIOCEJECT) failed: %s\n", strerror(errno));
} else {
ret=DRIVER_OP_SUCCESS;;
}
return ret;
}
/*!
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.
*/
char *
get_mcn_freebsd_ioctl (const _img_private_t *p_env) {
struct ioc_read_subchannel subchannel;
struct cd_sub_channel_info subchannel_info;
subchannel.address_format = CDIO_CDROM_MSF;
subchannel.data_format = CDIO_SUBCHANNEL_MEDIA_CATALOG;
subchannel.track = 0;
subchannel.data_len = sizeof(subchannel_info);
subchannel.data = &subchannel_info;
if(ioctl(p_env->gen.fd, CDIOCREADSUBCHANNEL, &subchannel) < 0) {
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;
}
/*!
Get format of track.
FIXME: We're just guessing this from the GNU/Linux code.
*/
track_format_t
get_track_format_freebsd_ioctl(const _img_private_t *p_env, track_t i_track)
{
struct ioc_read_subchannel subchannel;
struct cd_sub_channel_info subchannel_info;
subchannel.address_format = CDIO_CDROM_LBA;
subchannel.data_format = CDIO_SUBCHANNEL_CURRENT_POSITION;
subchannel.track = i_track;
subchannel.data_len = 1;
subchannel.data = &subchannel_info;
if(ioctl(p_env->gen.fd, CDIOCREADSUBCHANNEL, &subchannel) < 0) {
perror("CDIOCREADSUBCHANNEL");
return 1;
}
if (subchannel_info.what.position.control == 0x04) {
if (subchannel_info.what.position.data_format == 0x10)
return TRACK_FORMAT_CDI;
else if (subchannel_info.what.position.data_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?
*/
bool
get_track_green_freebsd_ioctl(const _img_private_t *p_env, track_t i_track)
{
struct ioc_read_subchannel subchannel;
struct cd_sub_channel_info subchannel_info;
subchannel.address_format = CDIO_CDROM_LBA;
subchannel.data_format = CDIO_SUBCHANNEL_CURRENT_POSITION;
subchannel.track = i_track;
subchannel.data_len = 1;
subchannel.data = &subchannel_info;
if(ioctl(p_env->gen.fd, CDIOCREADSUBCHANNEL, &subchannel) < 0) {
perror("CDIOCREADSUBCHANNEL");
return 1;
}
/* FIXME: Dunno if this is the right way, but it's what
I was using in cdinfo for a while.
*/
return (subchannel_info.what.position.control & 2) != 0;
}
#endif /* HAVE_FREEBSD_CDROM */