2003-03-24 19:01:09 +00:00
|
|
|
|
/*
|
2004-07-11 14:25:07 +00:00
|
|
|
|
$Id: bincue.c,v 1.33 2004/07/11 14:25:07 rocky Exp $
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-01-09 02:42:39 +00:00
|
|
|
|
Copyright (C) 2002, 2003, 2004 Rocky Bernstein <rocky@panix.com>
|
2004-06-01 11:15:58 +00:00
|
|
|
|
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
|
2004-07-09 02:46:42 +00:00
|
|
|
|
cue parsing routine adapted from cuetools
|
2004-07-09 01:23:46 +00:00
|
|
|
|
Copyright (C) 2003 Svend Sanjay Sorensen <ssorensen@fastmail.fm>
|
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 code implements low-level access functions for a CD images
|
|
|
|
|
|
residing inside a disk file (*.bin) and its associated cue sheet.
|
|
|
|
|
|
(*.cue).
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2004-07-11 14:25:07 +00:00
|
|
|
|
static const char _rcsid[] = "$Id: bincue.c,v 1.33 2004/07/11 14:25:07 rocky Exp $";
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-07-10 02:17:57 +00:00
|
|
|
|
#include "image.h"
|
2003-09-18 13:42:01 +00:00
|
|
|
|
#include "cdio_assert.h"
|
|
|
|
|
|
#include "cdio_private.h"
|
|
|
|
|
|
#include "_cdio_stdio.h"
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-04-22 12:09:08 +00:00
|
|
|
|
#include <cdio/logging.h>
|
|
|
|
|
|
#include <cdio/util.h>
|
2003-09-18 13:42:01 +00:00
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_STDIO_H
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
#endif
|
2003-10-03 02:36:52 +00:00
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
|
|
#include <strings.h>
|
|
|
|
|
|
#endif
|
2004-07-09 10:12:15 +00:00
|
|
|
|
#ifdef HAVE_ERRNO_H
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
#endif
|
2003-09-30 03:26:11 +00:00
|
|
|
|
#ifdef HAVE_GLOB_H
|
|
|
|
|
|
#include <glob.h>
|
|
|
|
|
|
#endif
|
2003-09-18 13:42:01 +00:00
|
|
|
|
#include <ctype.h>
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-09-18 13:49:59 +00:00
|
|
|
|
/* FIXME: should put in a common definition somewhere. */
|
2004-03-10 11:53:10 +00:00
|
|
|
|
#ifdef HAVE_MEMSET
|
2003-09-18 13:49:59 +00:00
|
|
|
|
#define BZERO(ptr, size) memset(ptr, 0, size)
|
2004-03-10 11:53:10 +00:00
|
|
|
|
#elif HAVE_BZERO
|
|
|
|
|
|
#define BZERO(ptr, size) bzero(ptr, size)
|
2003-09-18 13:49:59 +00:00
|
|
|
|
#else
|
|
|
|
|
|
Error -- you need either memset or bzero
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
/* reader */
|
|
|
|
|
|
|
|
|
|
|
|
#define DEFAULT_CDIO_DEVICE "videocd.bin"
|
|
|
|
|
|
#define DEFAULT_CDIO_CUE "videocd.cue"
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2003-03-30 13:01:22 +00:00
|
|
|
|
/* Things common to all drivers like this.
|
|
|
|
|
|
This must be first. */
|
|
|
|
|
|
generic_img_private_t gen;
|
2003-04-04 05:15:33 +00:00
|
|
|
|
internal_position_t pos;
|
2003-03-30 13:01:22 +00:00
|
|
|
|
|
2004-07-09 02:46:42 +00:00
|
|
|
|
char *psz_cue_name;
|
2004-07-10 11:06:00 +00:00
|
|
|
|
char *psz_mcn; /* Media Catalog Number (5.22.3)
|
|
|
|
|
|
exactly 13 bytes */
|
2004-06-27 15:29:20 +00:00
|
|
|
|
track_info_t tocent[CDIO_CD_MAX_TRACKS+1]; /* entry info for each track
|
|
|
|
|
|
add 1 for leadout. */
|
2004-07-11 14:25:07 +00:00
|
|
|
|
track_t i_tracks; /* number of tracks in image */
|
2004-06-01 11:15:58 +00:00
|
|
|
|
track_t i_first_track; /* track number of first track */
|
2004-07-11 14:25:07 +00:00
|
|
|
|
cdtext_t cdtext; /* CD-TEXT */
|
2004-07-10 11:06:00 +00:00
|
|
|
|
track_format_t mode;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
} _img_private_t;
|
|
|
|
|
|
|
2004-06-01 11:15:58 +00:00
|
|
|
|
static uint32_t _stat_size_bincue (void *user_data);
|
2004-07-09 10:12:15 +00:00
|
|
|
|
static bool parse_cuefile (_img_private_t *cd, const char *toc_name);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-07-11 14:25:07 +00:00
|
|
|
|
#define NEED_MEDIA_EJECT_IMAGE
|
2004-04-23 02:18:07 +00:00
|
|
|
|
#include "image_common.h"
|
2004-04-23 01:01:35 +00:00
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Initialize image structures.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static bool
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_bincue_init (_img_private_t *env)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2003-03-29 17:32:00 +00:00
|
|
|
|
lsn_t lead_lsn;
|
|
|
|
|
|
|
2004-06-01 11:15:58 +00:00
|
|
|
|
if (env->gen.init)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
2004-06-01 11:15:58 +00:00
|
|
|
|
if (!(env->gen.data_source = cdio_stdio_new (env->gen.source_name))) {
|
2004-02-26 03:57:42 +00:00
|
|
|
|
cdio_warn ("init failed");
|
2003-03-29 17:32:00 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-04-25 14:48:17 +00:00
|
|
|
|
/* Have to set init before calling _stat_size_bincue() or we will
|
2003-03-29 17:32:00 +00:00
|
|
|
|
get into infinite recursion calling passing right here.
|
|
|
|
|
|
*/
|
2004-07-09 10:12:15 +00:00
|
|
|
|
env->gen.init = true;
|
|
|
|
|
|
env->i_first_track = 1;
|
|
|
|
|
|
env->psz_mcn = NULL;
|
2004-07-11 14:25:07 +00:00
|
|
|
|
|
|
|
|
|
|
cdtext_init (&(env->cdtext));
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
2004-06-01 11:15:58 +00:00
|
|
|
|
lead_lsn = _stat_size_bincue( (_img_private_t *) env);
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
2004-07-09 10:12:15 +00:00
|
|
|
|
if (-1 == lead_lsn) return false;
|
|
|
|
|
|
|
|
|
|
|
|
if ((env->psz_cue_name == NULL)) return false;
|
2003-04-07 02:58:49 +00:00
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
/* Read in CUE sheet. */
|
2004-07-10 11:06:00 +00:00
|
|
|
|
if ( !parse_cuefile(env, env->psz_cue_name) ) return false;
|
2004-07-09 10:12:15 +00:00
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
/* Fake out leadout track and sector count for last track*/
|
2004-06-01 11:15:58 +00:00
|
|
|
|
cdio_lsn_to_msf (lead_lsn, &env->tocent[env->i_tracks].start_msf);
|
|
|
|
|
|
env->tocent[env->i_tracks].start_lba = cdio_lsn_to_lba(lead_lsn);
|
|
|
|
|
|
env->tocent[env->i_tracks - env->i_first_track].sec_count =
|
|
|
|
|
|
cdio_lsn_to_lba(lead_lsn - env->tocent[env->i_tracks - env->i_first_track].start_lba);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Reads into buf the next size bytes.
|
|
|
|
|
|
Returns -1 on error.
|
|
|
|
|
|
Would be libc's seek() but we have to adjust for the extra track header
|
|
|
|
|
|
information in each sector.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static off_t
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_lseek_bincue (void *user_data, off_t offset, int whence)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
{
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
/* real_offset is the real byte offset inside the disk image
|
|
|
|
|
|
The number below was determined empirically. I'm guessing
|
|
|
|
|
|
the 1st 24 bytes of a bin file are used for something.
|
|
|
|
|
|
*/
|
2003-04-06 06:44:25 +00:00
|
|
|
|
off_t real_offset=0;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
2004-06-01 11:15:58 +00:00
|
|
|
|
env->pos.lba = 0;
|
|
|
|
|
|
for (i=0; i<env->i_tracks; i++) {
|
|
|
|
|
|
track_info_t *this_track=&(env->tocent[i]);
|
|
|
|
|
|
env->pos.index = i;
|
2003-04-06 06:44:25 +00:00
|
|
|
|
if ( (this_track->sec_count*this_track->datasize) >= offset) {
|
|
|
|
|
|
int blocks = offset / this_track->datasize;
|
|
|
|
|
|
int rem = offset % this_track->datasize;
|
|
|
|
|
|
int block_offset = blocks * this_track->blocksize;
|
2003-04-04 05:15:33 +00:00
|
|
|
|
real_offset += block_offset + rem;
|
2004-06-01 11:15:58 +00:00
|
|
|
|
env->pos.buff_offset = rem;
|
|
|
|
|
|
env->pos.lba += blocks;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2003-04-06 06:44:25 +00:00
|
|
|
|
real_offset += this_track->sec_count*this_track->blocksize;
|
|
|
|
|
|
offset -= this_track->sec_count*this_track->datasize;
|
2004-06-01 11:15:58 +00:00
|
|
|
|
env->pos.lba += this_track->sec_count;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-06-01 11:15:58 +00:00
|
|
|
|
if (i==env->i_tracks) {
|
2003-03-29 17:32:00 +00:00
|
|
|
|
cdio_warn ("seeking outside range of disk image");
|
|
|
|
|
|
return -1;
|
2003-04-06 06:44:25 +00:00
|
|
|
|
} else {
|
2004-06-01 11:15:58 +00:00
|
|
|
|
real_offset += env->tocent[i].datastart;
|
|
|
|
|
|
return cdio_stream_seek(env->gen.data_source, real_offset, whence);
|
2003-04-06 06:44:25 +00:00
|
|
|
|
}
|
2003-03-29 17:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Reads into buf the next size bytes.
|
|
|
|
|
|
Returns -1 on error.
|
|
|
|
|
|
FIXME:
|
|
|
|
|
|
At present we assume a read doesn't cross sector or track
|
|
|
|
|
|
boundaries.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static ssize_t
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_read_bincue (void *user_data, void *data, size_t size)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
{
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-04-06 17:57:20 +00:00
|
|
|
|
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
|
2003-04-04 05:15:33 +00:00
|
|
|
|
char *p = data;
|
|
|
|
|
|
ssize_t final_size=0;
|
|
|
|
|
|
ssize_t this_size;
|
2004-06-01 11:15:58 +00:00
|
|
|
|
track_info_t *this_track=&(env->tocent[env->pos.index]);
|
2003-04-06 06:44:25 +00:00
|
|
|
|
ssize_t skip_size = this_track->datastart + this_track->endsize;
|
2003-04-04 05:15:33 +00:00
|
|
|
|
|
|
|
|
|
|
while (size > 0) {
|
2004-06-19 19:15:15 +00:00
|
|
|
|
long int rem = this_track->datasize - env->pos.buff_offset;
|
|
|
|
|
|
if ((long int) size <= rem) {
|
2004-06-01 11:15:58 +00:00
|
|
|
|
this_size = cdio_stream_read(env->gen.data_source, buf, size, 1);
|
2003-04-04 05:15:33 +00:00
|
|
|
|
final_size += this_size;
|
|
|
|
|
|
memcpy (p, buf, this_size);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Finish off reading this sector. */
|
2003-04-06 06:44:25 +00:00
|
|
|
|
cdio_warn ("Reading across block boundaries not finished");
|
|
|
|
|
|
|
2003-04-04 05:15:33 +00:00
|
|
|
|
size -= rem;
|
2004-06-01 11:15:58 +00:00
|
|
|
|
this_size = cdio_stream_read(env->gen.data_source, buf, rem, 1);
|
2003-04-04 05:15:33 +00:00
|
|
|
|
final_size += this_size;
|
|
|
|
|
|
memcpy (p, buf, this_size);
|
|
|
|
|
|
p += this_size;
|
2004-06-01 11:15:58 +00:00
|
|
|
|
this_size = cdio_stream_read(env->gen.data_source, buf, rem, 1);
|
2003-04-06 06:44:25 +00:00
|
|
|
|
|
|
|
|
|
|
/* Skip over stuff at end of this sector and the beginning of the next.
|
2003-04-04 05:15:33 +00:00
|
|
|
|
*/
|
2004-06-01 11:15:58 +00:00
|
|
|
|
cdio_stream_read(env->gen.data_source, buf, skip_size, 1);
|
2003-04-06 06:44:25 +00:00
|
|
|
|
|
|
|
|
|
|
/* Get ready to read another sector. */
|
2004-06-01 11:15:58 +00:00
|
|
|
|
env->pos.buff_offset=0;
|
|
|
|
|
|
env->pos.lba++;
|
2003-04-06 06:44:25 +00:00
|
|
|
|
|
|
|
|
|
|
/* Have gone into next track. */
|
2004-06-01 11:15:58 +00:00
|
|
|
|
if (env->pos.lba >= env->tocent[env->pos.index+1].start_lba) {
|
|
|
|
|
|
env->pos.index++;
|
|
|
|
|
|
this_track=&(env->tocent[env->pos.index]);
|
2003-04-06 06:44:25 +00:00
|
|
|
|
skip_size = this_track->datastart + this_track->endsize;
|
|
|
|
|
|
}
|
2003-04-04 05:15:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
return final_size;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the size of the CD in logical block address (LBA) units.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static uint32_t
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_stat_size_bincue (void *user_data)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
long size;
|
|
|
|
|
|
|
2004-06-01 11:15:58 +00:00
|
|
|
|
size = cdio_stream_stat (env->gen.data_source);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-07-09 10:12:15 +00:00
|
|
|
|
if (size % CDIO_CD_FRAMESIZE_RAW)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2003-04-06 17:57:20 +00:00
|
|
|
|
cdio_warn ("image %s size (%ld) not multiple of blocksize (%d)",
|
2004-07-09 10:12:15 +00:00
|
|
|
|
env->gen.source_name, size, CDIO_CD_FRAMESIZE_RAW);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
if (size % M2RAW_SECTOR_SIZE == 0)
|
|
|
|
|
|
cdio_warn ("this may be a 2336-type disc image");
|
2003-04-06 17:57:20 +00:00
|
|
|
|
else if (size % CDIO_CD_FRAMESIZE_RAW == 0)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
cdio_warn ("this may be a 2352-type disc image");
|
|
|
|
|
|
/* exit (EXIT_FAILURE); */
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-07-09 10:12:15 +00:00
|
|
|
|
size /= CDIO_CD_FRAMESIZE_RAW;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
return size;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-07-09 01:05:31 +00:00
|
|
|
|
#define MAXLINE 4096 /* maximum line length + 1 */
|
|
|
|
|
|
|
2004-07-09 10:12:15 +00:00
|
|
|
|
static bool
|
|
|
|
|
|
parse_cuefile (_img_private_t *cd, const char *psz_cue_name)
|
2004-07-09 01:05:31 +00:00
|
|
|
|
{
|
2004-07-11 14:25:07 +00:00
|
|
|
|
/* The below declarations may be common in other image-parse routines. */
|
2004-07-09 10:12:15 +00:00
|
|
|
|
FILE *fp;
|
2004-07-11 14:25:07 +00:00
|
|
|
|
char psz_line[MAXLINE]; /* text of current line read in file fp. */
|
|
|
|
|
|
unsigned int i_line=0; /* line number in file of psz_line. */
|
|
|
|
|
|
int i = -1; /* Position in tocent. Same as
|
|
|
|
|
|
cd->i_tracks - 1 */
|
2004-07-09 10:12:15 +00:00
|
|
|
|
char *psz_keyword, *psz_field;
|
|
|
|
|
|
cdio_log_level_t log_level = (NULL == cd) ? CDIO_LOG_INFO : CDIO_LOG_WARN;
|
2004-07-11 14:25:07 +00:00
|
|
|
|
cdtext_field_t cdtext_key;
|
|
|
|
|
|
|
|
|
|
|
|
/* The below declarations may be unique to this image-parse routine. */
|
|
|
|
|
|
int start_index;
|
2004-07-09 10:12:15 +00:00
|
|
|
|
bool b_first_index_for_track=false;
|
|
|
|
|
|
|
|
|
|
|
|
if (NULL == psz_cue_name)
|
|
|
|
|
|
return false;
|
2004-07-09 01:05:31 +00:00
|
|
|
|
|
2004-07-09 10:12:15 +00:00
|
|
|
|
fp = fopen (psz_cue_name, "r");
|
|
|
|
|
|
if (fp == NULL) {
|
|
|
|
|
|
cdio_log(log_level, "error opening %s for reading: %s",
|
|
|
|
|
|
psz_cue_name, strerror(errno));
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (cd) {
|
|
|
|
|
|
cd->i_tracks=0;
|
|
|
|
|
|
cd->i_first_track=1;
|
|
|
|
|
|
cd->psz_mcn=NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while ((fgets(psz_line, MAXLINE, fp)) != NULL) {
|
|
|
|
|
|
|
|
|
|
|
|
i_line++;
|
|
|
|
|
|
|
|
|
|
|
|
if (NULL != (psz_keyword = strtok (psz_line, " \t\n\r"))) {
|
|
|
|
|
|
/* REM remarks ... */
|
|
|
|
|
|
if (0 == strcmp ("REM", psz_keyword)) {
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
/* global section */
|
|
|
|
|
|
/* CATALOG ddddddddddddd */
|
|
|
|
|
|
} else if (0 == strcmp ("CATALOG", psz_keyword)) {
|
|
|
|
|
|
if (-1 == i) {
|
2004-07-09 20:48:05 +00:00
|
|
|
|
if (NULL == (psz_field = strtok (NULL, " \t\n\r"))) {
|
|
|
|
|
|
cdio_log(log_level,
|
|
|
|
|
|
"%s line %d after word CATALOG: ",
|
|
|
|
|
|
psz_cue_name, i_line);
|
|
|
|
|
|
cdio_log(log_level,
|
|
|
|
|
|
"expecting 13-digit media catalog number, got nothing.");
|
|
|
|
|
|
goto err_exit;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (strlen(psz_field) != 13) {
|
|
|
|
|
|
cdio_log(log_level,
|
|
|
|
|
|
"%s line %d after word CATALOG: ",
|
|
|
|
|
|
psz_cue_name, i_line);
|
|
|
|
|
|
cdio_log(log_level,
|
|
|
|
|
|
"Token %s has length %ld. Should be 13 digits.",
|
|
|
|
|
|
psz_field, (long int) strlen(psz_field));
|
|
|
|
|
|
goto err_exit;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
/* Check that we have all digits*/
|
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
for (i=0; i<13; i++) {
|
|
|
|
|
|
if (!isdigit(psz_field[i])) {
|
|
|
|
|
|
cdio_log(log_level,
|
|
|
|
|
|
"%s line %d after word CATALOG:",
|
|
|
|
|
|
psz_cue_name, i_line);
|
|
|
|
|
|
cdio_log(log_level,
|
|
|
|
|
|
"Character \"%c\" at postition %i of token \"%s\" "
|
|
|
|
|
|
"is not all digits.",
|
|
|
|
|
|
psz_field[i], i+1, psz_field);
|
|
|
|
|
|
goto err_exit;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (cd) cd->psz_mcn = strdup (psz_field);
|
2004-07-09 10:12:15 +00:00
|
|
|
|
if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) {
|
|
|
|
|
|
goto format_error;
|
|
|
|
|
|
}
|
2004-07-09 02:46:42 +00:00
|
|
|
|
} else {
|
2004-07-09 10:12:15 +00:00
|
|
|
|
goto not_in_global_section;
|
2004-07-09 02:46:42 +00:00
|
|
|
|
}
|
2004-07-09 10:12:15 +00:00
|
|
|
|
|
|
|
|
|
|
/* FILE "<filename>" <BINARY|WAVE|other?> */
|
|
|
|
|
|
} else if (0 == strcmp ("FILE", psz_keyword)) {
|
|
|
|
|
|
if (NULL != (psz_field = strtok (NULL, "\"\t\n\r"))) {
|
|
|
|
|
|
if (cd) cd->tocent[i + 1].filename = strdup (psz_field);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
goto format_error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* TRACK N <mode> */
|
|
|
|
|
|
} else if (0 == strcmp ("TRACK", psz_keyword)) {
|
|
|
|
|
|
int i_track;
|
2004-07-11 14:25:07 +00:00
|
|
|
|
|
2004-07-09 10:12:15 +00:00
|
|
|
|
if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) {
|
|
|
|
|
|
if (1!=sscanf(psz_field, "%d", &i_track)) {
|
|
|
|
|
|
cdio_log(log_level,
|
2004-07-10 01:21:19 +00:00
|
|
|
|
"%s line %d after word TRACK:",
|
2004-07-09 10:12:15 +00:00
|
|
|
|
psz_cue_name, i_line);
|
2004-07-10 01:21:19 +00:00
|
|
|
|
cdio_log(log_level,
|
|
|
|
|
|
"Expecting a track number, got %s", psz_field);
|
2004-07-09 10:12:15 +00:00
|
|
|
|
goto err_exit;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) {
|
|
|
|
|
|
track_info_t *this_track=NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (cd) {
|
|
|
|
|
|
this_track = &(cd->tocent[cd->i_tracks]);
|
|
|
|
|
|
this_track->track_num = cd->i_tracks;
|
|
|
|
|
|
this_track->num_indices = 0;
|
|
|
|
|
|
b_first_index_for_track = false;
|
2004-07-11 14:25:07 +00:00
|
|
|
|
cdtext_init (&(cd->tocent[cd->i_tracks].cdtext));
|
2004-07-09 10:12:15 +00:00
|
|
|
|
cd->i_tracks++;
|
|
|
|
|
|
}
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
|
|
|
|
if (0 == strcmp ("AUDIO", psz_field)) {
|
|
|
|
|
|
if (cd) {
|
|
|
|
|
|
this_track->mode = AUDIO;
|
|
|
|
|
|
this_track->blocksize = CDIO_CD_FRAMESIZE_RAW;
|
|
|
|
|
|
this_track->datasize = CDIO_CD_FRAMESIZE_RAW;
|
|
|
|
|
|
this_track->datastart = 0;
|
|
|
|
|
|
this_track->endsize = 0;
|
|
|
|
|
|
this_track->track_format = TRACK_FORMAT_AUDIO;
|
|
|
|
|
|
this_track->track_green = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (0 == strcmp ("MODE1/2048", psz_field)) {
|
|
|
|
|
|
if (cd) {
|
|
|
|
|
|
this_track->mode = MODE1;
|
|
|
|
|
|
this_track->blocksize = 2048;
|
|
|
|
|
|
this_track->track_format= TRACK_FORMAT_DATA;
|
|
|
|
|
|
this_track->track_green = false;
|
|
|
|
|
|
/* Is the below correct? */
|
|
|
|
|
|
this_track->datastart = 0;
|
|
|
|
|
|
this_track->datasize = CDIO_CD_FRAMESIZE;
|
|
|
|
|
|
this_track->endsize = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (0 == strcmp ("MODE1/2352", psz_field)) {
|
|
|
|
|
|
if (cd) {
|
|
|
|
|
|
this_track->blocksize = 2352;
|
|
|
|
|
|
this_track->track_format= TRACK_FORMAT_DATA;
|
|
|
|
|
|
this_track->track_green = false;
|
|
|
|
|
|
this_track->datastart = CDIO_CD_SYNC_SIZE
|
|
|
|
|
|
+ CDIO_CD_HEADER_SIZE;
|
|
|
|
|
|
this_track->datasize = CDIO_CD_FRAMESIZE;
|
|
|
|
|
|
this_track->endsize = CDIO_CD_EDC_SIZE
|
|
|
|
|
|
+ CDIO_CD_M1F1_ZERO_SIZE + CDIO_CD_ECC_SIZE;
|
|
|
|
|
|
this_track->mode = MODE1_RAW;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (0 == strcmp ("MODE2/2336", psz_field)) {
|
|
|
|
|
|
if (cd) {
|
|
|
|
|
|
this_track->blocksize = 2336;
|
|
|
|
|
|
this_track->track_format= TRACK_FORMAT_XA;
|
|
|
|
|
|
this_track->track_green = true;
|
|
|
|
|
|
this_track->mode = MODE2;
|
|
|
|
|
|
this_track->datastart = CDIO_CD_SYNC_SIZE
|
|
|
|
|
|
+ CDIO_CD_HEADER_SIZE;
|
|
|
|
|
|
this_track->datasize = M2RAW_SECTOR_SIZE;
|
|
|
|
|
|
this_track->endsize = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (0 == strcmp ("MODE2/2048", psz_field)) {
|
|
|
|
|
|
if (cd) {
|
|
|
|
|
|
this_track->blocksize = 2048;
|
|
|
|
|
|
this_track->track_format= TRACK_FORMAT_XA;
|
|
|
|
|
|
this_track->track_green = true;
|
|
|
|
|
|
this_track->mode = MODE2_FORM1;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (0 == strcmp ("MODE2/2324", psz_field)) {
|
|
|
|
|
|
if (cd) {
|
|
|
|
|
|
this_track->blocksize = 2324;
|
|
|
|
|
|
this_track->track_format= TRACK_FORMAT_XA;
|
|
|
|
|
|
this_track->track_green = true;
|
|
|
|
|
|
this_track->mode = MODE2_FORM2;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (0 == strcmp ("MODE2/2336", psz_field)) {
|
|
|
|
|
|
if (cd) {
|
|
|
|
|
|
this_track->blocksize = 2336;
|
|
|
|
|
|
this_track->track_format= TRACK_FORMAT_XA;
|
|
|
|
|
|
this_track->track_green = true;
|
|
|
|
|
|
this_track->mode = MODE2_FORM_MIX;
|
|
|
|
|
|
this_track->datastart = CDIO_CD_SYNC_SIZE
|
|
|
|
|
|
+ CDIO_CD_HEADER_SIZE;
|
|
|
|
|
|
this_track->datasize = M2RAW_SECTOR_SIZE;
|
|
|
|
|
|
this_track->endsize = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (0 == strcmp ("MODE2/2352", psz_field)) {
|
|
|
|
|
|
if (cd) {
|
|
|
|
|
|
this_track->blocksize = 2352;
|
|
|
|
|
|
this_track->track_format= TRACK_FORMAT_XA;
|
|
|
|
|
|
this_track->track_green = true;
|
|
|
|
|
|
this_track->mode = MODE2_RAW;
|
|
|
|
|
|
this_track->datastart = CDIO_CD_SYNC_SIZE
|
|
|
|
|
|
+ CDIO_CD_HEADER_SIZE + CDIO_CD_SUBHEADER_SIZE;
|
|
|
|
|
|
this_track->datasize = CDIO_CD_FRAMESIZE;
|
|
|
|
|
|
this_track->endsize = CDIO_CD_SYNC_SIZE + CDIO_CD_ECC_SIZE;
|
|
|
|
|
|
}
|
2004-07-09 01:05:31 +00:00
|
|
|
|
} else {
|
2004-07-10 01:21:19 +00:00
|
|
|
|
cdio_log(log_level,
|
|
|
|
|
|
"%s line %d after word TRACK:",
|
|
|
|
|
|
psz_cue_name, i_line);
|
|
|
|
|
|
cdio_log(log_level,
|
|
|
|
|
|
"Unknown track mode %s", psz_field);
|
|
|
|
|
|
goto err_exit;
|
2004-07-09 01:05:31 +00:00
|
|
|
|
}
|
2004-07-09 10:12:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
goto format_error;
|
2004-07-09 01:05:31 +00:00
|
|
|
|
}
|
2004-07-09 10:12:15 +00:00
|
|
|
|
|
|
|
|
|
|
/* FLAGS flag1 flag2 ... */
|
|
|
|
|
|
} else if (0 == strcmp ("FLAGS", psz_keyword)) {
|
|
|
|
|
|
if (0 <= i) {
|
|
|
|
|
|
while (NULL != (psz_field = strtok (NULL, " \t\n\r"))) {
|
|
|
|
|
|
if (0 == strcmp ("PRE", psz_field)) {
|
|
|
|
|
|
if (cd) cd->tocent[i].flags |= PRE_EMPHASIS;
|
|
|
|
|
|
} else if (0 == strcmp ("DCP", psz_field)) {
|
|
|
|
|
|
if (cd) cd->tocent[i].flags |= COPY_PERMITTED;
|
|
|
|
|
|
} else if (0 == strcmp ("4CH", psz_field)) {
|
|
|
|
|
|
if (cd) cd->tocent[i].flags |= FOUR_CHANNEL_AUDIO;
|
|
|
|
|
|
} else if (0 == strcmp ("SCMS", psz_field)) {
|
|
|
|
|
|
if (cd) cd->tocent[i].flags |= SCMS;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
goto format_error;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
goto format_error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ISRC CCOOOYYSSSSS */
|
|
|
|
|
|
} else if (0 == strcmp ("ISRC", psz_keyword)) {
|
|
|
|
|
|
if (0 <= i) {
|
|
|
|
|
|
if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) {
|
|
|
|
|
|
if (cd) cd->tocent[i].isrc = strdup (psz_field);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
goto format_error;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
goto in_global_section;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* PREGAP MM:SS:FF */
|
|
|
|
|
|
} else if (0 == strcmp ("PREGAP", psz_keyword)) {
|
|
|
|
|
|
if (0 <= i) {
|
|
|
|
|
|
if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) {
|
2004-07-10 01:21:19 +00:00
|
|
|
|
lba_t lba = cdio_lsn_to_lba(cdio_mmssff_to_lba (psz_field));
|
|
|
|
|
|
if (CDIO_INVALID_LBA == lba) {
|
|
|
|
|
|
cdio_log(log_level, "%s line %d: after word PREGAP:",
|
|
|
|
|
|
psz_cue_name, i_line);
|
|
|
|
|
|
cdio_log(log_level, "Invalid MSF string %s",
|
|
|
|
|
|
psz_field);
|
|
|
|
|
|
goto err_exit;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (cd) {
|
|
|
|
|
|
cd->tocent[i].pregap = lba;
|
|
|
|
|
|
}
|
2004-07-09 10:12:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
goto format_error;
|
|
|
|
|
|
} if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) {
|
|
|
|
|
|
goto format_error;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
goto in_global_section;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* INDEX [##] MM:SS:FF */
|
|
|
|
|
|
} else if (0 == strcmp ("INDEX", psz_keyword)) {
|
|
|
|
|
|
if (0 <= i) {
|
|
|
|
|
|
if (NULL != (psz_field = strtok (NULL, " \t\n\r")))
|
|
|
|
|
|
if (1!=sscanf(psz_field, "%d", &start_index)) {
|
|
|
|
|
|
cdio_log(log_level,
|
2004-07-10 01:21:19 +00:00
|
|
|
|
"%s line %d after word INDEX:",
|
2004-07-09 10:12:15 +00:00
|
|
|
|
psz_cue_name, i_line);
|
2004-07-10 01:21:19 +00:00
|
|
|
|
cdio_log(log_level,
|
|
|
|
|
|
"expecting an index number, got %s",
|
|
|
|
|
|
psz_field);
|
2004-07-09 10:12:15 +00:00
|
|
|
|
goto err_exit;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (NULL != (psz_field = strtok (NULL, " \t\n\r"))) {
|
2004-07-10 01:21:19 +00:00
|
|
|
|
lba_t lba = cdio_mmssff_to_lba (psz_field);
|
|
|
|
|
|
if (CDIO_INVALID_LBA == lba) {
|
|
|
|
|
|
cdio_log(log_level, "%s line %d: after word INDEX:",
|
|
|
|
|
|
psz_cue_name, i_line);
|
|
|
|
|
|
cdio_log(log_level, "Invalid MSF string %s",
|
|
|
|
|
|
psz_field);
|
|
|
|
|
|
goto err_exit;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (cd) {
|
2004-07-09 10:12:15 +00:00
|
|
|
|
#if FIXED_ME
|
2004-07-10 01:21:19 +00:00
|
|
|
|
cd->tocent[i].indexes[cd->tocent[i].nindex++] = lba;
|
2004-07-09 01:05:31 +00:00
|
|
|
|
#else
|
2004-07-10 01:21:19 +00:00
|
|
|
|
track_info_t *this_track=
|
|
|
|
|
|
&(cd->tocent[cd->i_tracks - cd->i_first_track]);
|
|
|
|
|
|
|
|
|
|
|
|
if (start_index != 0) {
|
|
|
|
|
|
if (!b_first_index_for_track) {
|
|
|
|
|
|
lba += CDIO_PREGAP_SECTORS;
|
|
|
|
|
|
cdio_lba_to_msf(lba, &(this_track->start_msf));
|
|
|
|
|
|
b_first_index_for_track = true;
|
|
|
|
|
|
this_track->start_lba = lba;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (cd->i_tracks > 1) {
|
|
|
|
|
|
/* Figure out number of sectors for previous track */
|
|
|
|
|
|
track_info_t *prev_track=&(cd->tocent[cd->i_tracks-2]);
|
|
|
|
|
|
if ( this_track->start_lba < prev_track->start_lba ) {
|
|
|
|
|
|
cdio_log (log_level,
|
|
|
|
|
|
"track %d at LBA %lu starts before track %d at LBA %lu",
|
|
|
|
|
|
cd->i_tracks,
|
|
|
|
|
|
(unsigned long int) this_track->start_lba,
|
|
|
|
|
|
cd->i_tracks,
|
|
|
|
|
|
(unsigned long int) prev_track->start_lba);
|
|
|
|
|
|
prev_track->sec_count = 0;
|
|
|
|
|
|
} else if ( this_track->start_lba >= prev_track->start_lba
|
|
|
|
|
|
+ CDIO_PREGAP_SECTORS ) {
|
|
|
|
|
|
prev_track->sec_count = this_track->start_lba -
|
|
|
|
|
|
prev_track->start_lba - CDIO_PREGAP_SECTORS ;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
cdio_log (log_level,
|
|
|
|
|
|
"%lu fewer than pregap (%d) sectors in track %d",
|
|
|
|
|
|
(long unsigned int)
|
|
|
|
|
|
this_track->start_lba - prev_track->start_lba,
|
|
|
|
|
|
CDIO_PREGAP_SECTORS,
|
|
|
|
|
|
cd->i_tracks);
|
|
|
|
|
|
/* Include pregap portion in sec_count. Maybe the pregap
|
|
|
|
|
|
was omitted. */
|
|
|
|
|
|
prev_track->sec_count = this_track->start_lba -
|
|
|
|
|
|
prev_track->start_lba;
|
2004-07-09 10:12:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-07-10 01:21:19 +00:00
|
|
|
|
this_track->num_indices++;
|
2004-07-09 10:12:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-07-09 01:05:31 +00:00
|
|
|
|
#endif
|
2004-07-09 10:12:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
goto format_error;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
goto in_global_section;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* CD-TEXT */
|
2004-07-11 14:25:07 +00:00
|
|
|
|
} else if ( CDTEXT_INVALID !=
|
|
|
|
|
|
(cdtext_key = cdtext_is_keyword (psz_keyword)) ) {
|
2004-07-09 10:12:15 +00:00
|
|
|
|
if (-1 == i) {
|
2004-07-11 14:25:07 +00:00
|
|
|
|
if (cd) {
|
|
|
|
|
|
cdtext_set (cdtext_key, strtok (NULL, "\"\t\n\r"), &(cd->cdtext));
|
|
|
|
|
|
}
|
2004-07-09 10:12:15 +00:00
|
|
|
|
} else {
|
2004-07-11 14:25:07 +00:00
|
|
|
|
if (cd) {
|
|
|
|
|
|
cdtext_set (cdtext_key, strtok (NULL, "\"\t\n\r"),
|
|
|
|
|
|
&(cd->tocent[i].cdtext));
|
|
|
|
|
|
}
|
2004-07-09 10:12:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* unrecognized line */
|
2004-07-09 01:05:31 +00:00
|
|
|
|
} else {
|
2004-07-09 10:12:15 +00:00
|
|
|
|
cdio_log(log_level, "%s line %d: warning: unrecognized keyword: %s",
|
|
|
|
|
|
psz_cue_name, i_line, psz_keyword);
|
|
|
|
|
|
goto err_exit;
|
2004-07-09 01:05:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-07-09 10:12:15 +00:00
|
|
|
|
|
|
|
|
|
|
fclose (fp);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
format_error:
|
2004-07-10 01:21:19 +00:00
|
|
|
|
cdio_log(log_level, "%s line %d after word %s",
|
2004-07-09 10:12:15 +00:00
|
|
|
|
psz_cue_name, i_line, psz_keyword);
|
|
|
|
|
|
goto err_exit;
|
|
|
|
|
|
|
|
|
|
|
|
in_global_section:
|
2004-07-10 01:21:19 +00:00
|
|
|
|
cdio_log(log_level, "%s line %d: word %s not allowed in global section",
|
2004-07-09 10:12:15 +00:00
|
|
|
|
psz_cue_name, i_line, psz_keyword);
|
|
|
|
|
|
goto err_exit;
|
|
|
|
|
|
|
|
|
|
|
|
not_in_global_section:
|
2004-07-10 01:21:19 +00:00
|
|
|
|
cdio_log(log_level, "%s line %d: word %s only allowed in global section",
|
2004-07-09 10:12:15 +00:00
|
|
|
|
psz_cue_name, i_line, psz_keyword);
|
|
|
|
|
|
|
|
|
|
|
|
err_exit:
|
|
|
|
|
|
fclose (fp);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
2004-07-09 01:05:31 +00:00
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-07-27 22:52:22 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Reads a single audio sector from CD device into data starting
|
|
|
|
|
|
from lsn. Returns 0 if no error.
|
|
|
|
|
|
*/
|
2003-03-24 19:01:09 +00:00
|
|
|
|
static int
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_read_audio_sectors_bincue (void *user_data, void *data, lsn_t lsn,
|
2003-09-20 12:34:02 +00:00
|
|
|
|
unsigned int nblocks)
|
2003-04-10 07:22:56 +00:00
|
|
|
|
{
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-04-10 07:22:56 +00:00
|
|
|
|
int ret;
|
|
|
|
|
|
|
2003-09-18 13:32:19 +00:00
|
|
|
|
/* Why the adjustment of 272, I don't know. It seems to work though */
|
|
|
|
|
|
if (lsn != 0) {
|
2004-06-01 11:15:58 +00:00
|
|
|
|
ret = cdio_stream_seek (env->gen.data_source,
|
2003-09-18 13:32:19 +00:00
|
|
|
|
(lsn * CDIO_CD_FRAMESIZE_RAW) - 272, SEEK_SET);
|
|
|
|
|
|
if (ret!=0) return ret;
|
2003-04-10 07:22:56 +00:00
|
|
|
|
|
2004-06-01 11:15:58 +00:00
|
|
|
|
ret = cdio_stream_read (env->gen.data_source, data,
|
2003-09-20 12:34:02 +00:00
|
|
|
|
CDIO_CD_FRAMESIZE_RAW, nblocks);
|
2003-09-18 13:32:19 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
/* We need to pad out the first 272 bytes with 0's */
|
2003-09-18 13:49:59 +00:00
|
|
|
|
BZERO(data, 272);
|
2003-09-18 13:32:19 +00:00
|
|
|
|
|
2004-06-01 11:15:58 +00:00
|
|
|
|
ret = cdio_stream_seek (env->gen.data_source, 0, SEEK_SET);
|
2003-09-18 13:32:19 +00:00
|
|
|
|
|
|
|
|
|
|
if (ret!=0) return ret;
|
|
|
|
|
|
|
2004-06-01 11:15:58 +00:00
|
|
|
|
ret = cdio_stream_read (env->gen.data_source, (uint8_t *) data+272,
|
2003-09-20 12:34:02 +00:00
|
|
|
|
CDIO_CD_FRAMESIZE_RAW - 272, nblocks);
|
2003-09-18 13:32:19 +00:00
|
|
|
|
}
|
2003-04-10 07:22:56 +00:00
|
|
|
|
|
2003-11-04 04:44:43 +00:00
|
|
|
|
/* ret is number of bytes if okay, but we need to return 0 okay. */
|
|
|
|
|
|
return ret == 0;
|
2003-04-10 07:22:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-07-27 22:52:22 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Reads a single mode2 sector from cd device into data starting
|
|
|
|
|
|
from lsn. Returns 0 if no error.
|
|
|
|
|
|
*/
|
2003-04-10 07:22:56 +00:00
|
|
|
|
static int
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_read_mode1_sector_bincue (void *user_data, void *data, lsn_t lsn,
|
2004-03-06 18:22:07 +00:00
|
|
|
|
bool b_form2)
|
2004-03-05 04:23:52 +00:00
|
|
|
|
{
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2004-03-05 04:23:52 +00:00
|
|
|
|
int ret;
|
|
|
|
|
|
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
|
2004-07-09 10:12:15 +00:00
|
|
|
|
int blocksize = CDIO_CD_FRAMESIZE_RAW;
|
2004-03-05 04:23:52 +00:00
|
|
|
|
|
2004-06-01 11:15:58 +00:00
|
|
|
|
ret = cdio_stream_seek (env->gen.data_source, lsn * blocksize, SEEK_SET);
|
2004-03-05 04:23:52 +00:00
|
|
|
|
if (ret!=0) return ret;
|
|
|
|
|
|
|
2004-03-06 03:21:59 +00:00
|
|
|
|
/* FIXME: Not completely sure the below is correct. */
|
2004-07-09 10:12:15 +00:00
|
|
|
|
ret = cdio_stream_read (env->gen.data_source, buf, CDIO_CD_FRAMESIZE_RAW, 1);
|
2004-03-05 04:23:52 +00:00
|
|
|
|
if (ret==0) return ret;
|
|
|
|
|
|
|
|
|
|
|
|
memcpy (data, buf + CDIO_CD_SYNC_SIZE + CDIO_CD_HEADER_SIZE,
|
2004-03-06 18:22:07 +00:00
|
|
|
|
b_form2 ? M2RAW_SECTOR_SIZE: CDIO_CD_FRAMESIZE);
|
2004-03-05 04:23:52 +00:00
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Reads nblocks of mode1 sectors from cd device into data starting
|
|
|
|
|
|
from lsn.
|
|
|
|
|
|
Returns 0 if no error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_read_mode1_sectors_bincue (void *user_data, void *data, lsn_t lsn,
|
2004-05-11 02:15:42 +00:00
|
|
|
|
bool b_form2, unsigned int nblocks)
|
2004-03-05 04:23:52 +00:00
|
|
|
|
{
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2004-03-05 04:23:52 +00:00
|
|
|
|
int i;
|
|
|
|
|
|
int retval;
|
2004-03-06 18:22:07 +00:00
|
|
|
|
unsigned int blocksize = b_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE;
|
2004-03-05 04:23:52 +00:00
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nblocks; i++) {
|
2004-06-01 11:15:58 +00:00
|
|
|
|
if ( (retval = _read_mode1_sector_bincue (env,
|
2004-03-05 12:32:45 +00:00
|
|
|
|
((char *)data) + (blocksize * i),
|
2004-03-06 18:22:07 +00:00
|
|
|
|
lsn + i, b_form2)) )
|
2004-03-05 12:32:45 +00:00
|
|
|
|
return retval;
|
2004-03-05 04:23:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Reads a single mode1 sector from cd device into data starting
|
|
|
|
|
|
from lsn. Returns 0 if no error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_read_mode2_sector_bincue (void *user_data, void *data, lsn_t lsn,
|
2004-03-06 18:22:07 +00:00
|
|
|
|
bool b_form2)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-04-07 02:41:40 +00:00
|
|
|
|
int ret;
|
2003-04-06 17:57:20 +00:00
|
|
|
|
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
|
2004-03-06 01:26:35 +00:00
|
|
|
|
|
|
|
|
|
|
/* NOTE: The logic below seems a bit wrong and convoluted
|
|
|
|
|
|
to me, but passes the regression tests. (Perhaps it is why we get
|
|
|
|
|
|
valgrind errors in vcdxrip). Leave it the way it was for now.
|
|
|
|
|
|
Review this sector 2336 stuff later.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2004-07-09 10:12:15 +00:00
|
|
|
|
int blocksize = CDIO_CD_FRAMESIZE_RAW;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-06-01 11:15:58 +00:00
|
|
|
|
ret = cdio_stream_seek (env->gen.data_source, lsn * blocksize, SEEK_SET);
|
2003-04-07 02:41:40 +00:00
|
|
|
|
if (ret!=0) return ret;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-07-09 10:12:15 +00:00
|
|
|
|
ret = cdio_stream_read (env->gen.data_source, buf, CDIO_CD_FRAMESIZE_RAW, 1);
|
2003-04-07 02:41:40 +00:00
|
|
|
|
if (ret==0) return ret;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-03-06 01:26:35 +00:00
|
|
|
|
|
|
|
|
|
|
/* See NOTE above. */
|
2004-03-06 18:22:07 +00:00
|
|
|
|
if (b_form2)
|
2004-03-06 01:24:29 +00:00
|
|
|
|
memcpy (data, buf + CDIO_CD_SYNC_SIZE + CDIO_CD_HEADER_SIZE,
|
|
|
|
|
|
M2RAW_SECTOR_SIZE);
|
|
|
|
|
|
else
|
|
|
|
|
|
memcpy (data, buf + CDIO_CD_XA_SYNC_HEADER, 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-06-01 11:15:58 +00:00
|
|
|
|
_read_mode2_sectors_bincue (void *user_data, void *data, lsn_t lsn,
|
2004-05-11 02:15:42 +00:00
|
|
|
|
bool b_form2, unsigned int nblocks)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
int i;
|
|
|
|
|
|
int retval;
|
2004-03-06 18:22:07 +00:00
|
|
|
|
unsigned int blocksize = b_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nblocks; i++) {
|
2004-06-01 11:15:58 +00:00
|
|
|
|
if ( (retval = _read_mode2_sector_bincue (env,
|
2004-03-05 12:32:45 +00:00
|
|
|
|
((char *)data) + (blocksize * i),
|
2004-03-06 18:22:07 +00:00
|
|
|
|
lsn + i, b_form2)) )
|
2004-03-05 12:32:45 +00:00
|
|
|
|
return retval;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2004-04-25 14:48:17 +00:00
|
|
|
|
Return an array of strings giving possible BIN/CUE disk images.
|
2003-09-30 03:26:11 +00:00
|
|
|
|
*/
|
|
|
|
|
|
char **
|
|
|
|
|
|
cdio_get_devices_bincue (void)
|
|
|
|
|
|
{
|
|
|
|
|
|
char **drives = NULL;
|
|
|
|
|
|
unsigned int num_files=0;
|
|
|
|
|
|
#ifdef HAVE_GLOB_H
|
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
glob_t globbuf;
|
|
|
|
|
|
globbuf.gl_offs = 0;
|
|
|
|
|
|
glob("*.cue", GLOB_DOOFFS, NULL, &globbuf);
|
|
|
|
|
|
for (i=0; i<globbuf.gl_pathc; i++) {
|
|
|
|
|
|
cdio_add_device_list(&drives, globbuf.gl_pathv[i], &num_files);
|
|
|
|
|
|
}
|
|
|
|
|
|
globfree(&globbuf);
|
|
|
|
|
|
#else
|
|
|
|
|
|
cdio_add_device_list(&drives, DEFAULT_CDIO_DEVICE, &num_files);
|
|
|
|
|
|
#endif /*HAVE_GLOB_H*/
|
|
|
|
|
|
cdio_add_device_list(&drives, NULL, &num_files);
|
|
|
|
|
|
return drives;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return a string containing the default CD device.
|
2003-03-24 19:01:09 +00:00
|
|
|
|
*/
|
2003-04-10 04:13:41 +00:00
|
|
|
|
char *
|
|
|
|
|
|
cdio_get_default_device_bincue(void)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2003-09-30 03:26:11 +00:00
|
|
|
|
char **drives = cdio_get_devices_nrg();
|
|
|
|
|
|
char *drive = (drives[0] == NULL) ? NULL : strdup(drives[0]);
|
2004-03-20 22:46:56 +00:00
|
|
|
|
cdio_free_device_list(drives);
|
2003-09-30 03:26:11 +00:00
|
|
|
|
return drive;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-04-25 00:46:34 +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.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
static cdio_drive_cap_t
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_get_drive_cap_bincue (const void *user_data) {
|
2004-04-25 00:46:34 +00:00
|
|
|
|
|
|
|
|
|
|
/* There may be more in the future but these we can handle now.
|
|
|
|
|
|
Also, we know we can't handle
|
|
|
|
|
|
LOCK, OPEN_TRAY, CLOSE_TRAY, SELECT_SPEED, SELECT_DISC
|
|
|
|
|
|
*/
|
2004-04-25 14:07:23 +00:00
|
|
|
|
return CDIO_DRIVE_CAP_FILE | CDIO_DRIVE_CAP_MCN | CDIO_DRIVE_CAP_CD_AUDIO ;
|
2004-04-25 00:46:34 +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_format_t
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_get_track_format_bincue(void *user_data, track_t i_track)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-06-01 11:15:58 +00:00
|
|
|
|
if (i_track > env->i_tracks || i_track == 0)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return TRACK_FORMAT_ERROR;
|
|
|
|
|
|
|
2004-06-01 11:15:58 +00:00
|
|
|
|
return env->tocent[i_track-env->i_first_track].track_format;
|
2003-03-24 19:01:09 +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-06-01 11:15:58 +00:00
|
|
|
|
_get_track_green_bincue(void *user_data, track_t i_track)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-06-01 11:15:58 +00:00
|
|
|
|
if (i_track > env->i_tracks || i_track == 0)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
2004-06-01 11:15:58 +00:00
|
|
|
|
return env->tocent[i_track-env->i_first_track].track_green;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
/*!
|
2003-10-03 07:54:58 +00:00
|
|
|
|
Return the starting LSN track number
|
2004-06-01 11:15:58 +00:00
|
|
|
|
i_track in obj. Track numbers start at 1.
|
2003-03-29 17:32:00 +00:00
|
|
|
|
The "leadout" track is specified either by
|
2004-06-01 11:15:58 +00:00
|
|
|
|
using i_track LEADOUT_TRACK or the total tracks+1.
|
2003-10-03 07:54:58 +00:00
|
|
|
|
False is returned if there is no track entry.
|
2003-03-29 17:32:00 +00:00
|
|
|
|
*/
|
|
|
|
|
|
static lba_t
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_get_lba_track_bincue(void *user_data, track_t i_track)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
{
|
2004-06-01 11:15:58 +00:00
|
|
|
|
_img_private_t *env = user_data;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
2004-06-01 11:15:58 +00:00
|
|
|
|
if (i_track == CDIO_CDROM_LEADOUT_TRACK) i_track = env->i_tracks+1;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
2004-06-01 11:45:35 +00:00
|
|
|
|
if (i_track <= env->i_tracks + env->i_first_track && i_track != 0) {
|
2004-06-01 11:15:58 +00:00
|
|
|
|
return env->tocent[i_track-env->i_first_track].start_lba;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
} else
|
|
|
|
|
|
return CDIO_INVALID_LBA;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-04-12 03:38:00 +00:00
|
|
|
|
/*!
|
2004-07-09 02:46:42 +00:00
|
|
|
|
Return corresponding BIN file if psz_cue_name is a cue file or NULL
|
2003-04-12 03:38:00 +00:00
|
|
|
|
if not a CUE file.
|
|
|
|
|
|
*/
|
|
|
|
|
|
char *
|
2004-07-09 02:46:42 +00:00
|
|
|
|
cdio_is_cuefile(const char *psz_cue_name)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2003-04-12 03:38:00 +00:00
|
|
|
|
int i;
|
2004-07-09 10:12:15 +00:00
|
|
|
|
char *psz_bin_name;
|
2003-04-12 03:38:00 +00:00
|
|
|
|
|
2004-07-09 02:46:42 +00:00
|
|
|
|
if (psz_cue_name == NULL) return NULL;
|
2003-04-12 03:38:00 +00:00
|
|
|
|
|
2004-07-09 10:12:15 +00:00
|
|
|
|
/* FIXME? Now that we have cue parsing, should we really force
|
|
|
|
|
|
the filename extension requirement or is it enough just to
|
|
|
|
|
|
parse the cuefile?
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
psz_bin_name=strdup(psz_cue_name);
|
|
|
|
|
|
i=strlen(psz_bin_name)-strlen("cue");
|
2003-04-12 03:38:00 +00:00
|
|
|
|
|
|
|
|
|
|
if (i>0) {
|
2004-07-09 02:46:42 +00:00
|
|
|
|
if (psz_cue_name[i]=='c' && psz_cue_name[i+1]=='u' && psz_cue_name[i+2]=='e') {
|
2004-07-09 10:12:15 +00:00
|
|
|
|
psz_bin_name[i++]='b'; psz_bin_name[i++]='i'; psz_bin_name[i++]='n';
|
|
|
|
|
|
if (parse_cuefile(NULL, psz_cue_name))
|
|
|
|
|
|
return psz_bin_name;
|
|
|
|
|
|
else
|
|
|
|
|
|
return NULL;
|
2003-04-12 03:38:00 +00:00
|
|
|
|
}
|
2004-07-09 02:46:42 +00:00
|
|
|
|
else if (psz_cue_name[i]=='C' && psz_cue_name[i+1]=='U' && psz_cue_name[i+2]=='E') {
|
2004-07-09 10:12:15 +00:00
|
|
|
|
psz_bin_name[i++]='B'; psz_bin_name[i++]='I'; psz_bin_name[i++]='N';
|
|
|
|
|
|
if (parse_cuefile(NULL, psz_cue_name))
|
|
|
|
|
|
return psz_bin_name;
|
|
|
|
|
|
else
|
|
|
|
|
|
return NULL;
|
2003-04-12 03:38:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-07-09 10:12:15 +00:00
|
|
|
|
free(psz_bin_name);
|
2003-05-18 01:50:51 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2004-07-09 10:12:15 +00:00
|
|
|
|
Return corresponding CUE file if psz_bin_name is a bin file or NULL
|
2003-05-18 01:50:51 +00:00
|
|
|
|
if not a BIN file.
|
|
|
|
|
|
*/
|
|
|
|
|
|
char *
|
2004-07-09 10:12:15 +00:00
|
|
|
|
cdio_is_binfile(const char *psz_bin_name)
|
2003-05-18 01:50:51 +00:00
|
|
|
|
{
|
|
|
|
|
|
int i;
|
2004-07-09 02:46:42 +00:00
|
|
|
|
char *psz_cue_name;
|
2003-05-18 01:50:51 +00:00
|
|
|
|
|
2004-07-09 10:12:15 +00:00
|
|
|
|
if (psz_bin_name == NULL) return NULL;
|
2003-05-18 01:50:51 +00:00
|
|
|
|
|
2004-07-09 10:12:15 +00:00
|
|
|
|
psz_cue_name=strdup(psz_bin_name);
|
|
|
|
|
|
i=strlen(psz_bin_name)-strlen("bin");
|
2003-05-18 01:50:51 +00:00
|
|
|
|
|
|
|
|
|
|
if (i>0) {
|
2004-07-09 10:12:15 +00:00
|
|
|
|
if (psz_bin_name[i]=='b' && psz_bin_name[i+1]=='i' && psz_bin_name[i+2]=='n') {
|
2004-07-09 02:46:42 +00:00
|
|
|
|
psz_cue_name[i++]='c'; psz_cue_name[i++]='u'; psz_cue_name[i++]='e';
|
|
|
|
|
|
return psz_cue_name;
|
2003-05-18 01:50:51 +00:00
|
|
|
|
}
|
2004-07-09 10:12:15 +00:00
|
|
|
|
else if (psz_bin_name[i]=='B' && psz_bin_name[i+1]=='I' && psz_bin_name[i+2]=='N') {
|
2004-07-09 02:46:42 +00:00
|
|
|
|
psz_cue_name[i++]='C'; psz_cue_name[i++]='U'; psz_cue_name[i++]='E';
|
|
|
|
|
|
return psz_cue_name;
|
2003-05-18 01:50:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-07-09 02:46:42 +00:00
|
|
|
|
free(psz_cue_name);
|
2003-04-12 03:38:00 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-04-30 06:54:15 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Initialization routine. This is the only thing that doesn't
|
|
|
|
|
|
get called via a function pointer. In fact *we* are the
|
|
|
|
|
|
ones to set that up.
|
|
|
|
|
|
*/
|
|
|
|
|
|
CdIo *
|
|
|
|
|
|
cdio_open_am_bincue (const char *psz_source_name, const char *psz_access_mode)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (psz_access_mode != NULL)
|
|
|
|
|
|
cdio_warn ("there is only one access mode for bincue. Arg %s ignored",
|
|
|
|
|
|
psz_access_mode);
|
|
|
|
|
|
return cdio_open_bincue(psz_source_name);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
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.
|
|
|
|
|
|
*/
|
2004-03-20 21:54:38 +00:00
|
|
|
|
CdIo *
|
|
|
|
|
|
cdio_open_bincue (const char *source_name)
|
2003-04-12 03:38:00 +00:00
|
|
|
|
{
|
2004-07-09 10:12:15 +00:00
|
|
|
|
char *psz_bin_name = cdio_is_cuefile(source_name);
|
2004-03-20 21:54:38 +00:00
|
|
|
|
|
2004-07-09 10:12:15 +00:00
|
|
|
|
if (NULL != psz_bin_name) {
|
|
|
|
|
|
free(psz_bin_name);
|
2004-03-20 21:54:38 +00:00
|
|
|
|
return cdio_open_cue(source_name);
|
|
|
|
|
|
} else {
|
2004-07-09 02:46:42 +00:00
|
|
|
|
char *psz_cue_name = cdio_is_binfile(source_name);
|
|
|
|
|
|
CdIo *cdio = cdio_open_cue(psz_cue_name);
|
|
|
|
|
|
free(psz_cue_name);
|
2004-03-20 21:54:38 +00:00
|
|
|
|
return cdio;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CdIo *
|
2004-07-09 02:46:42 +00:00
|
|
|
|
cdio_open_cue (const char *psz_cue_name)
|
2004-03-20 21:54:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
CdIo *ret;
|
|
|
|
|
|
_img_private_t *_data;
|
2004-07-09 10:12:15 +00:00
|
|
|
|
char *psz_bin_name;
|
2004-03-20 21:54:38 +00:00
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
cdio_funcs _funcs = {
|
2004-07-10 11:06:00 +00:00
|
|
|
|
.eject_media = _eject_media_image,
|
|
|
|
|
|
.free = _free_image,
|
|
|
|
|
|
.get_arg = _get_arg_image,
|
2004-07-11 14:25:07 +00:00
|
|
|
|
.get_cdtext = _get_cdtext_image,
|
2004-04-25 14:48:17 +00:00
|
|
|
|
.get_devices = cdio_get_devices_bincue,
|
2003-04-10 04:13:41 +00:00
|
|
|
|
.get_default_device = cdio_get_default_device_bincue,
|
2004-04-25 14:48:17 +00:00
|
|
|
|
.get_drive_cap = _get_drive_cap_bincue,
|
|
|
|
|
|
.get_first_track_num= _get_first_track_num_image,
|
|
|
|
|
|
.get_mcn = _get_mcn_image,
|
|
|
|
|
|
.get_num_tracks = _get_num_tracks_image,
|
|
|
|
|
|
.get_track_format = _get_track_format_bincue,
|
|
|
|
|
|
.get_track_green = _get_track_green_bincue,
|
|
|
|
|
|
.get_track_lba = _get_lba_track_bincue,
|
|
|
|
|
|
.get_track_msf = _get_track_msf_image,
|
|
|
|
|
|
.lseek = _lseek_bincue,
|
|
|
|
|
|
.read = _read_bincue,
|
|
|
|
|
|
.read_audio_sectors = _read_audio_sectors_bincue,
|
|
|
|
|
|
.read_mode1_sector = _read_mode1_sector_bincue,
|
|
|
|
|
|
.read_mode1_sectors = _read_mode1_sectors_bincue,
|
|
|
|
|
|
.read_mode2_sector = _read_mode2_sector_bincue,
|
|
|
|
|
|
.read_mode2_sectors = _read_mode2_sectors_bincue,
|
2004-07-10 11:06:00 +00:00
|
|
|
|
.set_arg = _set_arg_image,
|
2004-04-25 14:48:17 +00:00
|
|
|
|
.stat_size = _stat_size_bincue
|
2003-03-24 19:01:09 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2004-07-09 02:46:42 +00:00
|
|
|
|
if (NULL == psz_cue_name) return NULL;
|
2004-03-22 01:01:50 +00:00
|
|
|
|
|
2004-03-20 21:54:38 +00:00
|
|
|
|
_data = _cdio_malloc (sizeof (_img_private_t));
|
2004-07-10 11:06:00 +00:00
|
|
|
|
_data->gen.init = false;
|
|
|
|
|
|
_data->psz_cue_name = NULL;
|
2003-04-12 03:38:00 +00:00
|
|
|
|
|
2004-03-20 21:54:38 +00:00
|
|
|
|
ret = cdio_new (_data, &_funcs);
|
2003-04-12 03:38:00 +00:00
|
|
|
|
|
2004-07-10 11:06:00 +00:00
|
|
|
|
if (ret == NULL) {
|
|
|
|
|
|
free(_data);
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-07-09 10:12:15 +00:00
|
|
|
|
psz_bin_name = cdio_is_cuefile(psz_cue_name);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-07-09 10:12:15 +00:00
|
|
|
|
if (NULL == psz_bin_name) {
|
2004-07-09 02:46:42 +00:00
|
|
|
|
cdio_error ("source name %s is not recognized as a CUE file",
|
|
|
|
|
|
psz_cue_name);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
2003-04-14 04:27:11 +00:00
|
|
|
|
|
2004-07-10 11:06:00 +00:00
|
|
|
|
_set_arg_image (_data, "cue", psz_cue_name);
|
|
|
|
|
|
_set_arg_image (_data, "source", psz_bin_name);
|
2004-07-09 10:12:15 +00:00
|
|
|
|
free(psz_bin_name);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-04-25 14:48:17 +00:00
|
|
|
|
if (_bincue_init(_data)) {
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return ret;
|
2003-04-12 03:38:00 +00:00
|
|
|
|
} else {
|
2004-07-10 11:06:00 +00:00
|
|
|
|
_free_image(_data);
|
2004-03-20 21:54:38 +00:00
|
|
|
|
free(ret);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
cdio_have_bincue (void)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|