Some variable renaming.

Also less pervasive assumption that the first track is 1.
This commit is contained in:
rocky
2004-06-01 11:15:58 +00:00
parent 2c272e7e90
commit 33be1e3ebf
3 changed files with 258 additions and 279 deletions

View File

@@ -1,8 +1,8 @@
/* /*
$Id: bincue.c,v 1.18 2004/05/13 01:50:23 rocky Exp $ $Id: bincue.c,v 1.19 2004/06/01 11:15:58 rocky Exp $
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2002, 2003, 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2002, 2003, 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
(*.cue). (*.cue).
*/ */
static const char _rcsid[] = "$Id: bincue.c,v 1.18 2004/05/13 01:50:23 rocky Exp $"; static const char _rcsid[] = "$Id: bincue.c,v 1.19 2004/06/01 11:15:58 rocky Exp $";
#include "cdio_assert.h" #include "cdio_assert.h"
#include "cdio_private.h" #include "cdio_private.h"
@@ -96,13 +96,13 @@ typedef struct {
char *cue_name; char *cue_name;
char *mcn; /* Media catalog number. */ char *mcn; /* Media catalog number. */
track_info_t tocent[100]; /* entry info for each track */ track_info_t tocent[100]; /* entry info for each track */
track_t total_tracks; /* number of tracks in image */ track_t i_tracks; /* number of tracks in image */
track_t first_track_num; /* track number of first track */ track_t i_first_track; /* track number of first track */
bool have_cue; bool have_cue;
} _img_private_t; } _img_private_t;
static bool _bincue_image_read_cue (_img_private_t *_obj); static bool _bincue_image_read_cue (_img_private_t *env);
static uint32_t _stat_size_bincue (void *env); static uint32_t _stat_size_bincue (void *user_data);
#include "image_common.h" #include "image_common.h"
@@ -110,14 +110,14 @@ static uint32_t _stat_size_bincue (void *env);
Initialize image structures. Initialize image structures.
*/ */
static bool static bool
_bincue_init (_img_private_t *_obj) _bincue_init (_img_private_t *env)
{ {
lsn_t lead_lsn; lsn_t lead_lsn;
if (_obj->gen.init) if (env->gen.init)
return false; return false;
if (!(_obj->gen.data_source = cdio_stdio_new (_obj->gen.source_name))) { if (!(env->gen.data_source = cdio_stdio_new (env->gen.source_name))) {
cdio_warn ("init failed"); cdio_warn ("init failed");
return false; return false;
} }
@@ -125,30 +125,30 @@ _bincue_init (_img_private_t *_obj)
/* Have to set init before calling _stat_size_bincue() or we will /* Have to set init before calling _stat_size_bincue() or we will
get into infinite recursion calling passing right here. get into infinite recursion calling passing right here.
*/ */
_obj->gen.init = true; env->gen.init = true;
lead_lsn = _stat_size_bincue( (_img_private_t *) _obj); lead_lsn = _stat_size_bincue( (_img_private_t *) env);
if (-1 == lead_lsn) if (-1 == lead_lsn)
return false; return false;
/* Read in CUE sheet. */ /* Read in CUE sheet. */
if ((_obj->cue_name != NULL)) { if ((env->cue_name != NULL)) {
_obj->have_cue = _bincue_image_read_cue(_obj); env->have_cue = _bincue_image_read_cue(env);
} }
if (!_obj->have_cue ) { if (!env->have_cue ) {
/* Time to fake things... /* Time to fake things...
Make one big track, track 0 and 1 are the same. Make one big track, track 0 and 1 are the same.
We are guessing stuff starts at msf 00:04:00 - 2 for the 150 We are guessing stuff starts at msf 00:04:00 - 2 for the 150
sector pregap and 2 for the cue information. sector pregap and 2 for the cue information.
*/ */
track_info_t *this_track=&(_obj->tocent[0]); track_info_t *this_track=&(env->tocent[0]);
int blocksize = _obj->sector_2336 int blocksize = env->sector_2336
? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE_RAW; ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE_RAW;
_obj->total_tracks = 2; env->i_tracks = 2;
_obj->first_track_num = 1; env->i_first_track = 1;
this_track->start_msf.m = to_bcd8(0); this_track->start_msf.m = to_bcd8(0);
this_track->start_msf.s = to_bcd8(4); this_track->start_msf.s = to_bcd8(4);
this_track->start_msf.f = to_bcd8(0); this_track->start_msf.f = to_bcd8(0);
@@ -158,14 +158,14 @@ _bincue_init (_img_private_t *_obj)
this_track->track_green = true; this_track->track_green = true;
_obj->tocent[1] = _obj->tocent[0]; env->tocent[1] = env->tocent[0];
} }
/* Fake out leadout track and sector count for last track*/ /* Fake out leadout track and sector count for last track*/
cdio_lsn_to_msf (lead_lsn, &_obj->tocent[_obj->total_tracks].start_msf); cdio_lsn_to_msf (lead_lsn, &env->tocent[env->i_tracks].start_msf);
_obj->tocent[_obj->total_tracks].start_lba = cdio_lsn_to_lba(lead_lsn); env->tocent[env->i_tracks].start_lba = cdio_lsn_to_lba(lead_lsn);
_obj->tocent[_obj->total_tracks-1].sec_count = env->tocent[env->i_tracks - env->i_first_track].sec_count =
cdio_lsn_to_lba(lead_lsn - _obj->tocent[_obj->total_tracks-1].start_lba); cdio_lsn_to_lba(lead_lsn - env->tocent[env->i_tracks - env->i_first_track].start_lba);
return true; return true;
} }
@@ -177,9 +177,9 @@ _bincue_init (_img_private_t *_obj)
information in each sector. information in each sector.
*/ */
static off_t static off_t
_lseek_bincue (void *env, off_t offset, int whence) _lseek_bincue (void *user_data, off_t offset, int whence)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
/* real_offset is the real byte offset inside the disk image /* real_offset is the real byte offset inside the disk image
The number below was determined empirically. I'm guessing The number below was determined empirically. I'm guessing
@@ -189,30 +189,30 @@ _lseek_bincue (void *env, off_t offset, int whence)
unsigned int i; unsigned int i;
_obj->pos.lba = 0; env->pos.lba = 0;
for (i=0; i<_obj->total_tracks; i++) { for (i=0; i<env->i_tracks; i++) {
track_info_t *this_track=&(_obj->tocent[i]); track_info_t *this_track=&(env->tocent[i]);
_obj->pos.index = i; env->pos.index = i;
if ( (this_track->sec_count*this_track->datasize) >= offset) { if ( (this_track->sec_count*this_track->datasize) >= offset) {
int blocks = offset / this_track->datasize; int blocks = offset / this_track->datasize;
int rem = offset % this_track->datasize; int rem = offset % this_track->datasize;
int block_offset = blocks * this_track->blocksize; int block_offset = blocks * this_track->blocksize;
real_offset += block_offset + rem; real_offset += block_offset + rem;
_obj->pos.buff_offset = rem; env->pos.buff_offset = rem;
_obj->pos.lba += blocks; env->pos.lba += blocks;
break; break;
} }
real_offset += this_track->sec_count*this_track->blocksize; real_offset += this_track->sec_count*this_track->blocksize;
offset -= this_track->sec_count*this_track->datasize; offset -= this_track->sec_count*this_track->datasize;
_obj->pos.lba += this_track->sec_count; env->pos.lba += this_track->sec_count;
} }
if (i==_obj->total_tracks) { if (i==env->i_tracks) {
cdio_warn ("seeking outside range of disk image"); cdio_warn ("seeking outside range of disk image");
return -1; return -1;
} else { } else {
real_offset += _obj->tocent[i].datastart; real_offset += env->tocent[i].datastart;
return cdio_stream_seek(_obj->gen.data_source, real_offset, whence); return cdio_stream_seek(env->gen.data_source, real_offset, whence);
} }
} }
@@ -224,20 +224,20 @@ _lseek_bincue (void *env, off_t offset, int whence)
boundaries. boundaries.
*/ */
static ssize_t static ssize_t
_read_bincue (void *env, void *data, size_t size) _read_bincue (void *user_data, void *data, size_t size)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, }; char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
char *p = data; char *p = data;
ssize_t final_size=0; ssize_t final_size=0;
ssize_t this_size; ssize_t this_size;
track_info_t *this_track=&(_obj->tocent[_obj->pos.index]); track_info_t *this_track=&(env->tocent[env->pos.index]);
ssize_t skip_size = this_track->datastart + this_track->endsize; ssize_t skip_size = this_track->datastart + this_track->endsize;
while (size > 0) { while (size > 0) {
int rem = this_track->datasize - _obj->pos.buff_offset; int rem = this_track->datasize - env->pos.buff_offset;
if (size <= rem) { if (size <= rem) {
this_size = cdio_stream_read(_obj->gen.data_source, buf, size, 1); this_size = cdio_stream_read(env->gen.data_source, buf, size, 1);
final_size += this_size; final_size += this_size;
memcpy (p, buf, this_size); memcpy (p, buf, this_size);
break; break;
@@ -247,24 +247,24 @@ _read_bincue (void *env, void *data, size_t size)
cdio_warn ("Reading across block boundaries not finished"); cdio_warn ("Reading across block boundaries not finished");
size -= rem; size -= rem;
this_size = cdio_stream_read(_obj->gen.data_source, buf, rem, 1); this_size = cdio_stream_read(env->gen.data_source, buf, rem, 1);
final_size += this_size; final_size += this_size;
memcpy (p, buf, this_size); memcpy (p, buf, this_size);
p += this_size; p += this_size;
this_size = cdio_stream_read(_obj->gen.data_source, buf, rem, 1); this_size = cdio_stream_read(env->gen.data_source, buf, rem, 1);
/* Skip over stuff at end of this sector and the beginning of the next. /* Skip over stuff at end of this sector and the beginning of the next.
*/ */
cdio_stream_read(_obj->gen.data_source, buf, skip_size, 1); cdio_stream_read(env->gen.data_source, buf, skip_size, 1);
/* Get ready to read another sector. */ /* Get ready to read another sector. */
_obj->pos.buff_offset=0; env->pos.buff_offset=0;
_obj->pos.lba++; env->pos.lba++;
/* Have gone into next track. */ /* Have gone into next track. */
if (_obj->pos.lba >= _obj->tocent[_obj->pos.index+1].start_lba) { if (env->pos.lba >= env->tocent[env->pos.index+1].start_lba) {
_obj->pos.index++; env->pos.index++;
this_track=&(_obj->tocent[_obj->pos.index]); this_track=&(env->tocent[env->pos.index]);
skip_size = this_track->datastart + this_track->endsize; skip_size = this_track->datastart + this_track->endsize;
} }
} }
@@ -275,21 +275,19 @@ _read_bincue (void *env, void *data, size_t size)
Return the size of the CD in logical block address (LBA) units. Return the size of the CD in logical block address (LBA) units.
*/ */
static uint32_t static uint32_t
_stat_size_bincue (void *env) _stat_size_bincue (void *user_data)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
long size; long size;
int blocksize = _obj->sector_2336 int blocksize = env->sector_2336
? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE_RAW; ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE_RAW;
_bincue_init (_obj); size = cdio_stream_stat (env->gen.data_source);
size = cdio_stream_stat (_obj->gen.data_source);
if (size % blocksize) if (size % blocksize)
{ {
cdio_warn ("image %s size (%ld) not multiple of blocksize (%d)", cdio_warn ("image %s size (%ld) not multiple of blocksize (%d)",
_obj->gen.source_name, size, blocksize); env->gen.source_name, size, blocksize);
if (size % M2RAW_SECTOR_SIZE == 0) if (size % M2RAW_SECTOR_SIZE == 0)
cdio_warn ("this may be a 2336-type disc image"); cdio_warn ("this may be a 2336-type disc image");
else if (size % CDIO_CD_FRAMESIZE_RAW == 0) else if (size % CDIO_CD_FRAMESIZE_RAW == 0)
@@ -305,25 +303,25 @@ _stat_size_bincue (void *env)
#define MAXLINE 512 #define MAXLINE 512
static bool static bool
_bincue_image_read_cue (_img_private_t *_obj) _bincue_image_read_cue (_img_private_t *env)
{ {
FILE *fp; FILE *fp;
char line[MAXLINE]; char line[MAXLINE];
int track_num; int i_track;
int min,sec,frame; int min,sec,frame;
int blocksize; int blocksize;
int start_index; int start_index;
bool seen_first_index_for_track=false; bool seen_first_index_for_track=false;
if ( _obj == NULL || _obj->cue_name == NULL ) return false; if ( env == NULL || env->cue_name == NULL ) return false;
fp = fopen (_obj->cue_name, "r"); fp = fopen (env->cue_name, "r");
if (fp == NULL) return false; if (fp == NULL) return false;
_obj->total_tracks=0; env->i_tracks=0;
_obj->first_track_num=1; env->i_first_track=1;
_obj->mcn=NULL; env->mcn=NULL;
while ((fgets(line, MAXLINE, fp)) != NULL) { while ((fgets(line, MAXLINE, fp)) != NULL) {
char s[80]; char s[80];
@@ -333,21 +331,21 @@ _bincue_image_read_cue (_img_private_t *_obj)
for (p=line; isspace(*p); p++) ; for (p=line; isspace(*p); p++) ;
if (1==sscanf(p, "FILE \"%80s[^\"]", s)) { if (1==sscanf(p, "FILE \"%80s[^\"]", s)) {
/* Should expand file name based on cue file basename. /* Should expand file name based on cue file basename.
free(_obj->bin_file); free(env->bin_file);
_obj->bin_file = strdup(s); env->bin_file = strdup(s);
*/ */
/* printf("Found file name %s\n", s); */ /* printf("Found file name %s\n", s); */
} else if (1==sscanf(p, "CATALOG %80s", s)) { } else if (1==sscanf(p, "CATALOG %80s", s)) {
_obj->mcn = strdup(s); env->mcn = strdup(s);
} else if (2==sscanf(p, "TRACK %d MODE2/%d", &track_num, &blocksize)) { } else if (2==sscanf(p, "TRACK %d MODE2/%d", &i_track, &blocksize)) {
track_info_t *this_track=&(_obj->tocent[_obj->total_tracks]); track_info_t *this_track=&(env->tocent[env->i_tracks]);
this_track->track_num = track_num; this_track->track_num = i_track;
this_track->num_indices = 0; this_track->num_indices = 0;
this_track->track_format= TRACK_FORMAT_XA; this_track->track_format= TRACK_FORMAT_XA;
this_track->track_green = true; this_track->track_green = true;
_obj->total_tracks++; env->i_tracks++;
seen_first_index_for_track=false; seen_first_index_for_track=false;
/*printf("Added track %d with blocksize %d\n", track_num, blocksize);*/ /*printf("Added track %d with blocksize %d\n", i_track, blocksize);*/
this_track->blocksize = blocksize; this_track->blocksize = blocksize;
switch(blocksize) { switch(blocksize) {
@@ -359,7 +357,7 @@ _bincue_image_read_cue (_img_private_t *_obj)
default: default:
cdio_warn ("Unknown MODE2 size %d. Assuming 2352", blocksize); cdio_warn ("Unknown MODE2 size %d. Assuming 2352", blocksize);
case 2352: case 2352:
if (_obj->sector_2336) { if (env->sector_2336) {
this_track->datastart = 0; this_track->datastart = 0;
this_track->datasize = M2RAW_SECTOR_SIZE; this_track->datasize = M2RAW_SECTOR_SIZE;
this_track->endsize = blocksize - 2336; this_track->endsize = blocksize - 2336;
@@ -372,8 +370,8 @@ _bincue_image_read_cue (_img_private_t *_obj)
break; break;
} }
} else if (2==sscanf(p, "TRACK %d MODE1/%d", &track_num, &blocksize)) { } else if (2==sscanf(p, "TRACK %d MODE1/%d", &i_track, &blocksize)) {
track_info_t *this_track=&(_obj->tocent[_obj->total_tracks]); track_info_t *this_track=&(env->tocent[env->i_tracks]);
this_track->blocksize = blocksize; this_track->blocksize = blocksize;
switch(blocksize) { switch(blocksize) {
case 2048: case 2048:
@@ -391,30 +389,30 @@ _bincue_image_read_cue (_img_private_t *_obj)
+ CDIO_CD_ECC_SIZE; + CDIO_CD_ECC_SIZE;
} }
this_track->track_num = track_num; this_track->track_num = i_track;
this_track->num_indices = 0; this_track->num_indices = 0;
this_track->track_format = TRACK_FORMAT_DATA; this_track->track_format = TRACK_FORMAT_DATA;
this_track->track_green = false; this_track->track_green = false;
_obj->total_tracks++; env->i_tracks++;
seen_first_index_for_track=false; seen_first_index_for_track=false;
/*printf("Added track %d with blocksize %d\n", track_num, blocksize);*/ /*printf("Added track %d with blocksize %d\n", i_track, blocksize);*/
} else if (1==sscanf(p, "TRACK %d AUDIO", &track_num)) { } else if (1==sscanf(p, "TRACK %d AUDIO", &i_track)) {
track_info_t *this_track=&(_obj->tocent[_obj->total_tracks]); track_info_t *this_track=&(env->tocent[env->i_tracks]);
this_track->blocksize = CDIO_CD_FRAMESIZE_RAW; this_track->blocksize = CDIO_CD_FRAMESIZE_RAW;
this_track->datasize = CDIO_CD_FRAMESIZE_RAW; this_track->datasize = CDIO_CD_FRAMESIZE_RAW;
this_track->datastart = 0; this_track->datastart = 0;
this_track->endsize = 0; this_track->endsize = 0;
this_track->track_num = track_num; this_track->track_num = i_track;
this_track->num_indices = 0; this_track->num_indices = 0;
this_track->track_format = TRACK_FORMAT_AUDIO; this_track->track_format = TRACK_FORMAT_AUDIO;
this_track->track_green = false; this_track->track_green = false;
_obj->total_tracks++; env->i_tracks++;
seen_first_index_for_track=false; seen_first_index_for_track=false;
} else if (4==sscanf(p, "INDEX %d %d:%d:%d", } else if (4==sscanf(p, "INDEX %d %d:%d:%d",
&start_index, &min, &sec, &frame)) { &start_index, &min, &sec, &frame)) {
track_info_t *this_track=&(_obj->tocent[_obj->total_tracks-1]); track_info_t *this_track=&(env->tocent[env->i_tracks - env->i_first_track]);
/* FIXME! all of this is a big hack. /* FIXME! all of this is a big hack.
If start_index == 0, then this is the "last_cue" information. If start_index == 0, then this is the "last_cue" information.
The +2 below seconds is to adjust for the 150 pregap. The +2 below seconds is to adjust for the 150 pregap.
@@ -434,14 +432,14 @@ _bincue_image_read_cue (_img_private_t *_obj)
seen_first_index_for_track=true; seen_first_index_for_track=true;
} }
if (_obj->total_tracks > 1) { if (env->i_tracks > 1) {
/* Figure out number of sectors for previous track */ /* Figure out number of sectors for previous track */
track_info_t *prev_track=&(_obj->tocent[_obj->total_tracks-2]); track_info_t *prev_track=&(env->tocent[env->i_tracks-2]);
if ( this_track->start_lba < prev_track->start_lba ) { if ( this_track->start_lba < prev_track->start_lba ) {
cdio_warn("track %d at LBA %lu starts before track %d at LBA %lu", cdio_warn("track %d at LBA %lu starts before track %d at LBA %lu",
_obj->total_tracks, env->i_tracks,
(unsigned long int) this_track->start_lba, (unsigned long int) this_track->start_lba,
_obj->total_tracks-1, env->i_tracks,
(unsigned long int) prev_track->start_lba); (unsigned long int) prev_track->start_lba);
prev_track->sec_count = 0; prev_track->sec_count = 0;
} else if ( this_track->start_lba >= prev_track->start_lba } else if ( this_track->start_lba >= prev_track->start_lba
@@ -453,7 +451,7 @@ _bincue_image_read_cue (_img_private_t *_obj)
(long unsigned int) (long unsigned int)
this_track->start_lba - prev_track->start_lba, this_track->start_lba - prev_track->start_lba,
CDIO_PREGAP_SECTORS, CDIO_PREGAP_SECTORS,
_obj->total_tracks-1); env->i_tracks);
/* Include pregap portion in sec_count. Maybe the pregap /* Include pregap portion in sec_count. Maybe the pregap
was omitted. */ was omitted. */
prev_track->sec_count = this_track->start_lba - prev_track->sec_count = this_track->start_lba -
@@ -464,7 +462,7 @@ _bincue_image_read_cue (_img_private_t *_obj)
} }
} }
} }
_obj->have_cue = _obj->total_tracks != 0; env->have_cue = env->i_tracks != 0;
fclose (fp); fclose (fp);
return true; return true;
@@ -475,31 +473,29 @@ _bincue_image_read_cue (_img_private_t *_obj)
from lsn. Returns 0 if no error. from lsn. Returns 0 if no error.
*/ */
static int static int
_read_audio_sectors_bincue (void *env, void *data, lsn_t lsn, _read_audio_sectors_bincue (void *user_data, void *data, lsn_t lsn,
unsigned int nblocks) unsigned int nblocks)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
int ret; int ret;
_bincue_init (_obj);
/* Why the adjustment of 272, I don't know. It seems to work though */ /* Why the adjustment of 272, I don't know. It seems to work though */
if (lsn != 0) { if (lsn != 0) {
ret = cdio_stream_seek (_obj->gen.data_source, ret = cdio_stream_seek (env->gen.data_source,
(lsn * CDIO_CD_FRAMESIZE_RAW) - 272, SEEK_SET); (lsn * CDIO_CD_FRAMESIZE_RAW) - 272, SEEK_SET);
if (ret!=0) return ret; if (ret!=0) return ret;
ret = cdio_stream_read (_obj->gen.data_source, data, ret = cdio_stream_read (env->gen.data_source, data,
CDIO_CD_FRAMESIZE_RAW, nblocks); CDIO_CD_FRAMESIZE_RAW, nblocks);
} else { } else {
/* We need to pad out the first 272 bytes with 0's */ /* We need to pad out the first 272 bytes with 0's */
BZERO(data, 272); BZERO(data, 272);
ret = cdio_stream_seek (_obj->gen.data_source, 0, SEEK_SET); ret = cdio_stream_seek (env->gen.data_source, 0, SEEK_SET);
if (ret!=0) return ret; if (ret!=0) return ret;
ret = cdio_stream_read (_obj->gen.data_source, (uint8_t *) data+272, ret = cdio_stream_read (env->gen.data_source, (uint8_t *) data+272,
CDIO_CD_FRAMESIZE_RAW - 272, nblocks); CDIO_CD_FRAMESIZE_RAW - 272, nblocks);
} }
@@ -512,23 +508,21 @@ _read_audio_sectors_bincue (void *env, void *data, lsn_t lsn,
from lsn. Returns 0 if no error. from lsn. Returns 0 if no error.
*/ */
static int static int
_read_mode1_sector_bincue (void *env, void *data, lsn_t lsn, _read_mode1_sector_bincue (void *user_data, void *data, lsn_t lsn,
bool b_form2) bool b_form2)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
int ret; int ret;
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, }; char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
int blocksize = _obj->sector_2336 int blocksize = env->sector_2336
? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE_RAW; ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE_RAW;
_bincue_init (_obj); ret = cdio_stream_seek (env->gen.data_source, lsn * blocksize, SEEK_SET);
ret = cdio_stream_seek (_obj->gen.data_source, lsn * blocksize, SEEK_SET);
if (ret!=0) return ret; if (ret!=0) return ret;
/* FIXME: Not completely sure the below is correct. */ /* FIXME: Not completely sure the below is correct. */
ret = cdio_stream_read (_obj->gen.data_source, ret = cdio_stream_read (env->gen.data_source,
_obj->sector_2336 env->sector_2336
? (buf + CDIO_CD_SYNC_SIZE + CDIO_CD_HEADER_SIZE) ? (buf + CDIO_CD_SYNC_SIZE + CDIO_CD_HEADER_SIZE)
: buf, : buf,
blocksize, 1); blocksize, 1);
@@ -546,16 +540,16 @@ _read_mode1_sector_bincue (void *env, void *data, lsn_t lsn,
Returns 0 if no error. Returns 0 if no error.
*/ */
static int static int
_read_mode1_sectors_bincue (void *env, void *data, lsn_t lsn, _read_mode1_sectors_bincue (void *user_data, void *data, lsn_t lsn,
bool b_form2, unsigned int nblocks) bool b_form2, unsigned int nblocks)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
int i; int i;
int retval; int retval;
unsigned int blocksize = b_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE; unsigned int blocksize = b_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE;
for (i = 0; i < nblocks; i++) { for (i = 0; i < nblocks; i++) {
if ( (retval = _read_mode1_sector_bincue (_obj, if ( (retval = _read_mode1_sector_bincue (env,
((char *)data) + (blocksize * i), ((char *)data) + (blocksize * i),
lsn + i, b_form2)) ) lsn + i, b_form2)) )
return retval; return retval;
@@ -568,10 +562,10 @@ _read_mode1_sectors_bincue (void *env, void *data, lsn_t lsn,
from lsn. Returns 0 if no error. from lsn. Returns 0 if no error.
*/ */
static int static int
_read_mode2_sector_bincue (void *env, void *data, lsn_t lsn, _read_mode2_sector_bincue (void *user_data, void *data, lsn_t lsn,
bool b_form2) bool b_form2)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
int ret; int ret;
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, }; char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
@@ -581,16 +575,14 @@ _read_mode2_sector_bincue (void *env, void *data, lsn_t lsn,
Review this sector 2336 stuff later. Review this sector 2336 stuff later.
*/ */
int blocksize = _obj->sector_2336 int blocksize = env->sector_2336
? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE_RAW; ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE_RAW;
_bincue_init (_obj); ret = cdio_stream_seek (env->gen.data_source, lsn * blocksize, SEEK_SET);
ret = cdio_stream_seek (_obj->gen.data_source, lsn * blocksize, SEEK_SET);
if (ret!=0) return ret; if (ret!=0) return ret;
ret = cdio_stream_read (_obj->gen.data_source, ret = cdio_stream_read (env->gen.data_source,
_obj->sector_2336 env->sector_2336
? (buf + CDIO_CD_SYNC_SIZE + CDIO_CD_HEADER_SIZE) ? (buf + CDIO_CD_SYNC_SIZE + CDIO_CD_HEADER_SIZE)
: buf, : buf,
blocksize, 1); blocksize, 1);
@@ -613,16 +605,16 @@ _read_mode2_sector_bincue (void *env, void *data, lsn_t lsn,
Returns 0 if no error. Returns 0 if no error.
*/ */
static int static int
_read_mode2_sectors_bincue (void *env, void *data, lsn_t lsn, _read_mode2_sectors_bincue (void *user_data, void *data, lsn_t lsn,
bool b_form2, unsigned int nblocks) bool b_form2, unsigned int nblocks)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
int i; int i;
int retval; int retval;
unsigned int blocksize = b_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE; unsigned int blocksize = b_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE;
for (i = 0; i < nblocks; i++) { for (i = 0; i < nblocks; i++) {
if ( (retval = _read_mode2_sector_bincue (_obj, if ( (retval = _read_mode2_sector_bincue (env,
((char *)data) + (blocksize * i), ((char *)data) + (blocksize * i),
lsn + i, b_form2)) ) lsn + i, b_form2)) )
return retval; return retval;
@@ -664,36 +656,36 @@ _eject_media_bincue(void *obj)
0 is returned if no error was found, and nonzero if there as an error. 0 is returned if no error was found, and nonzero if there as an error.
*/ */
static int static int
_set_arg_bincue (void *env, const char key[], const char value[]) _set_arg_bincue (void *user_data, const char key[], const char value[])
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
if (!strcmp (key, "source")) if (!strcmp (key, "source"))
{ {
free_if_notnull (_obj->gen.source_name); free_if_notnull (env->gen.source_name);
if (!value) if (!value)
return -2; return -2;
_obj->gen.source_name = strdup (value); env->gen.source_name = strdup (value);
} }
else if (!strcmp (key, "sector")) else if (!strcmp (key, "sector"))
{ {
if (!strcmp (value, "2336")) if (!strcmp (value, "2336"))
_obj->sector_2336 = true; env->sector_2336 = true;
else if (!strcmp (value, "2352")) else if (!strcmp (value, "2352"))
_obj->sector_2336 = false; env->sector_2336 = false;
else else
return -2; return -2;
} }
else if (!strcmp (key, "cue")) else if (!strcmp (key, "cue"))
{ {
free_if_notnull (_obj->cue_name); free_if_notnull (env->cue_name);
if (!value) if (!value)
return -2; return -2;
_obj->cue_name = strdup (value); env->cue_name = strdup (value);
} }
else else
return -1; return -1;
@@ -705,14 +697,14 @@ _set_arg_bincue (void *env, const char key[], const char value[])
Return the value associated with the key "arg". Return the value associated with the key "arg".
*/ */
static const char * static const char *
_get_arg_bincue (void *env, const char key[]) _get_arg_bincue (void *user_data, const char key[])
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
if (!strcmp (key, "source")) { if (!strcmp (key, "source")) {
return _obj->gen.source_name; return env->gen.source_name;
} else if (!strcmp (key, "cue")) { } else if (!strcmp (key, "cue")) {
return _obj->cue_name; return env->cue_name;
} else if (!strcmp(key, "access-mode")) { } else if (!strcmp(key, "access-mode")) {
return "image"; return "image";
} }
@@ -763,7 +755,7 @@ cdio_get_default_device_bincue(void)
*/ */
static cdio_drive_cap_t static cdio_drive_cap_t
_get_drive_cap_bincue (const void *env) { _get_drive_cap_bincue (const void *user_data) {
/* There may be more in the future but these we can handle now. /* There may be more in the future but these we can handle now.
Also, we know we can't handle Also, we know we can't handle
@@ -777,16 +769,14 @@ _get_drive_cap_bincue (const void *env) {
CDIO_INVALID_TRACK is returned on error. CDIO_INVALID_TRACK is returned on error.
*/ */
static track_format_t static track_format_t
_get_track_format_bincue(void *env, track_t track_num) _get_track_format_bincue(void *user_data, track_t i_track)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
if (!_obj->gen.init) _bincue_init(_obj); if (i_track > env->i_tracks || i_track == 0)
if (track_num > _obj->total_tracks || track_num == 0)
return TRACK_FORMAT_ERROR; return TRACK_FORMAT_ERROR;
return _obj->tocent[track_num-1].track_format; return env->tocent[i_track-env->i_first_track].track_format;
} }
/*! /*!
@@ -798,35 +788,32 @@ _get_track_format_bincue(void *env, track_t track_num)
FIXME: there's gotta be a better design for this and get_track_format? FIXME: there's gotta be a better design for this and get_track_format?
*/ */
static bool static bool
_get_track_green_bincue(void *env, track_t track_num) _get_track_green_bincue(void *user_data, track_t i_track)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
if (!_obj->gen.init) _bincue_init(_obj); if (i_track > env->i_tracks || i_track == 0)
if (track_num > _obj->total_tracks || track_num == 0)
return false; return false;
return _obj->tocent[track_num-1].track_green; return env->tocent[i_track-env->i_first_track].track_green;
} }
/*! /*!
Return the starting LSN track number Return the starting LSN track number
track_num in obj. Track numbers start at 1. i_track in obj. Track numbers start at 1.
The "leadout" track is specified either by The "leadout" track is specified either by
using track_num LEADOUT_TRACK or the total tracks+1. using i_track LEADOUT_TRACK or the total tracks+1.
False is returned if there is no track entry. False is returned if there is no track entry.
*/ */
static lba_t static lba_t
_get_lba_track_bincue(void *env, track_t track_num) _get_lba_track_bincue(void *user_data, track_t i_track)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
_bincue_init (_obj);
if (track_num == CDIO_CDROM_LEADOUT_TRACK) track_num = _obj->total_tracks+1; if (i_track == CDIO_CDROM_LEADOUT_TRACK) i_track = env->i_tracks+1;
if (track_num <= _obj->total_tracks+1 && track_num != 0) { if (i_track < env->i_tracks && i_track != 0) {
return _obj->tocent[track_num-1].start_lba; return env->tocent[i_track-env->i_first_track].start_lba;
} else } else
return CDIO_INVALID_LBA; return CDIO_INVALID_LBA;
} }

View File

@@ -1,5 +1,5 @@
/* /*
$Id: cdrdao.c,v 1.8 2004/05/16 13:33:30 rocky Exp $ $Id: cdrdao.c,v 1.9 2004/06/01 11:15:58 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
toc reading routine adapted from cuetools toc reading routine adapted from cuetools
@@ -25,7 +25,7 @@
(*.cue). (*.cue).
*/ */
static const char _rcsid[] = "$Id: cdrdao.c,v 1.8 2004/05/16 13:33:30 rocky Exp $"; static const char _rcsid[] = "$Id: cdrdao.c,v 1.9 2004/06/01 11:15:58 rocky Exp $";
#include "cdio_assert.h" #include "cdio_assert.h"
#include "cdio_private.h" #include "cdio_private.h"
@@ -107,13 +107,13 @@ typedef struct {
char *mcn; /* Media Catalog Number (5.22.3) char *mcn; /* Media Catalog Number (5.22.3)
exactly 13 bytes */ exactly 13 bytes */
track_info_t tocent[100]; /* entry info for each track */ track_info_t tocent[100]; /* entry info for each track */
track_t total_tracks; /* number of tracks in image */ track_t i_tracks; /* number of tracks in image */
track_t first_track_num; /* track number of first track */ track_t i_first_track; /* track number of first track */
track_format_t mode; track_format_t mode;
bool b_have_cdrdao; bool b_have_cdrdao;
} _img_private_t; } _img_private_t;
static uint32_t _stat_size_cdrdao (void *env); static uint32_t _stat_size_cdrdao (void *user_data);
static bool parse_tocfile (_img_private_t *cd, const char *toc_name); static bool parse_tocfile (_img_private_t *cd, const char *toc_name);
#include "image_common.h" #include "image_common.h"
@@ -230,33 +230,33 @@ msf_lba_from_mmssff (char *s)
Initialize image structures. Initialize image structures.
*/ */
static bool static bool
_init_cdrdao (_img_private_t *_obj) _init_cdrdao (_img_private_t *env)
{ {
lsn_t lead_lsn; lsn_t lead_lsn;
if (_obj->gen.init) if (env->gen.init)
return false; return false;
/* Have to set init before calling _stat_size_cdrdao() or we will /* Have to set init before calling _stat_size_cdrdao() or we will
get into infinite recursion calling passing right here. get into infinite recursion calling passing right here.
*/ */
_obj->gen.init = true; env->gen.init = true;
_obj->first_track_num=1; env->i_first_track = 1;
_obj->mcn=NULL; env->mcn = NULL;
/* Read in TOC sheet. */ /* Read in TOC sheet. */
if ( !parse_tocfile(_obj, _obj->toc_name) ) return false; if ( !parse_tocfile(env, env->toc_name) ) return false;
lead_lsn = _stat_size_cdrdao( (_img_private_t *) _obj); lead_lsn = _stat_size_cdrdao( (_img_private_t *) env);
if (-1 == lead_lsn) if (-1 == lead_lsn)
return false; return false;
/* Fake out leadout track and sector count for last track*/ /* Fake out leadout track and sector count for last track*/
cdio_lsn_to_msf (lead_lsn, &_obj->tocent[_obj->total_tracks].start_msf); cdio_lsn_to_msf (lead_lsn, &env->tocent[env->i_tracks].start_msf);
_obj->tocent[_obj->total_tracks].start_lba = cdio_lsn_to_lba(lead_lsn); env->tocent[env->i_tracks].start_lba = cdio_lsn_to_lba(lead_lsn);
_obj->tocent[_obj->total_tracks-1].sec_count = env->tocent[env->i_tracks-env->i_first_track].sec_count =
cdio_lsn_to_lba(lead_lsn - _obj->tocent[_obj->total_tracks-1].start_lba); cdio_lsn_to_lba(lead_lsn - env->tocent[env->i_tracks-1].start_lba);
return true; return true;
} }
@@ -268,9 +268,9 @@ _init_cdrdao (_img_private_t *_obj)
information in each sector. information in each sector.
*/ */
static off_t static off_t
_lseek_cdrdao (void *env, off_t offset, int whence) _lseek_cdrdao (void *user_data, off_t offset, int whence)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
/* real_offset is the real byte offset inside the disk image /* real_offset is the real byte offset inside the disk image
The number below was determined empirically. I'm guessing The number below was determined empirically. I'm guessing
@@ -280,30 +280,30 @@ _lseek_cdrdao (void *env, off_t offset, int whence)
unsigned int i; unsigned int i;
_obj->pos.lba = 0; env->pos.lba = 0;
for (i=0; i<_obj->total_tracks; i++) { for (i=0; i<env->i_tracks; i++) {
track_info_t *this_track=&(_obj->tocent[i]); track_info_t *this_track=&(env->tocent[i]);
_obj->pos.index = i; env->pos.index = i;
if ( (this_track->sec_count*this_track->datasize) >= offset) { if ( (this_track->sec_count*this_track->datasize) >= offset) {
int blocks = offset / this_track->datasize; int blocks = offset / this_track->datasize;
int rem = offset % this_track->datasize; int rem = offset % this_track->datasize;
int block_offset = blocks * this_track->blocksize; int block_offset = blocks * this_track->blocksize;
real_offset += block_offset + rem; real_offset += block_offset + rem;
_obj->pos.buff_offset = rem; env->pos.buff_offset = rem;
_obj->pos.lba += blocks; env->pos.lba += blocks;
break; break;
} }
real_offset += this_track->sec_count*this_track->blocksize; real_offset += this_track->sec_count*this_track->blocksize;
offset -= this_track->sec_count*this_track->datasize; offset -= this_track->sec_count*this_track->datasize;
_obj->pos.lba += this_track->sec_count; env->pos.lba += this_track->sec_count;
} }
if (i==_obj->total_tracks) { if (i==env->i_tracks) {
cdio_warn ("seeking outside range of disk image"); cdio_warn ("seeking outside range of disk image");
return -1; return -1;
} else { } else {
real_offset += _obj->tocent[i].datastart; real_offset += env->tocent[i].datastart;
return cdio_stream_seek(_obj->tocent[i].data_source, real_offset, whence); return cdio_stream_seek(env->tocent[i].data_source, real_offset, whence);
} }
} }
@@ -315,18 +315,18 @@ _lseek_cdrdao (void *env, off_t offset, int whence)
boundaries. boundaries.
*/ */
static ssize_t static ssize_t
_read_cdrdao (void *env, void *data, size_t size) _read_cdrdao (void *user_data, void *data, size_t size)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, }; char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
char *p = data; char *p = data;
ssize_t final_size=0; ssize_t final_size=0;
ssize_t this_size; ssize_t this_size;
track_info_t *this_track=&(_obj->tocent[_obj->pos.index]); track_info_t *this_track=&(env->tocent[env->pos.index]);
ssize_t skip_size = this_track->datastart + this_track->endsize; ssize_t skip_size = this_track->datastart + this_track->endsize;
while (size > 0) { while (size > 0) {
int rem = this_track->datasize - _obj->pos.buff_offset; int rem = this_track->datasize - env->pos.buff_offset;
if (size <= rem) { if (size <= rem) {
this_size = cdio_stream_read(this_track->data_source, buf, size, 1); this_size = cdio_stream_read(this_track->data_source, buf, size, 1);
final_size += this_size; final_size += this_size;
@@ -349,13 +349,13 @@ _read_cdrdao (void *env, void *data, size_t size)
cdio_stream_read(this_track->data_source, buf, skip_size, 1); cdio_stream_read(this_track->data_source, buf, skip_size, 1);
/* Get ready to read another sector. */ /* Get ready to read another sector. */
_obj->pos.buff_offset=0; env->pos.buff_offset=0;
_obj->pos.lba++; env->pos.lba++;
/* Have gone into next track. */ /* Have gone into next track. */
if (_obj->pos.lba >= _obj->tocent[_obj->pos.index+1].start_lba) { if (env->pos.lba >= env->tocent[env->pos.index+1].start_lba) {
_obj->pos.index++; env->pos.index++;
this_track=&(_obj->tocent[_obj->pos.index]); this_track=&(env->tocent[env->pos.index]);
skip_size = this_track->datastart + this_track->endsize; skip_size = this_track->datastart + this_track->endsize;
} }
} }
@@ -366,21 +366,19 @@ _read_cdrdao (void *env, void *data, size_t size)
Return the size of the CD in logical block address (LBA) units. Return the size of the CD in logical block address (LBA) units.
*/ */
static uint32_t static uint32_t
_stat_size_cdrdao (void *env) _stat_size_cdrdao (void *user_data)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
long size; long size;
int blocksize = _obj->sector_2336 int blocksize = env->sector_2336
? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE_RAW; ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE_RAW;
_init_cdrdao (_obj); size = cdio_stream_stat (env->tocent[0].data_source);
size = cdio_stream_stat (_obj->tocent[0].data_source);
if (size % blocksize) if (size % blocksize)
{ {
cdio_warn ("image %s size (%ld) not multiple of blocksize (%d)", cdio_warn ("image %s size (%ld) not multiple of blocksize (%d)",
_obj->tocent[0].filename, size, blocksize); env->tocent[0].filename, size, blocksize);
if (size % M2RAW_SECTOR_SIZE == 0) if (size % M2RAW_SECTOR_SIZE == 0)
cdio_warn ("this may be a 2336-type disc image"); cdio_warn ("this may be a 2336-type disc image");
else if (size % CDIO_CD_FRAMESIZE_RAW == 0) else if (size % CDIO_CD_FRAMESIZE_RAW == 0)
@@ -790,7 +788,7 @@ parse_tocfile (_img_private_t *cd, const char *toc_name)
} }
} }
if (NULL != cd) cd->total_tracks = i+1; if (NULL != cd) cd->i_tracks = i+1;
return true; return true;
unimplimented_error: unimplimented_error:
@@ -816,31 +814,29 @@ parse_tocfile (_img_private_t *cd, const char *toc_name)
from lsn. Returns 0 if no error. from lsn. Returns 0 if no error.
*/ */
static int static int
_read_audio_sectors_cdrdao (void *env, void *data, lsn_t lsn, _read_audio_sectors_cdrdao (void *user_data, void *data, lsn_t lsn,
unsigned int nblocks) unsigned int nblocks)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
int ret; int ret;
_init_cdrdao (_obj);
/* Why the adjustment of 272, I don't know. It seems to work though */ /* Why the adjustment of 272, I don't know. It seems to work though */
if (lsn != 0) { if (lsn != 0) {
ret = cdio_stream_seek (_obj->tocent[0].data_source, ret = cdio_stream_seek (env->tocent[0].data_source,
(lsn * CDIO_CD_FRAMESIZE_RAW) - 272, SEEK_SET); (lsn * CDIO_CD_FRAMESIZE_RAW) - 272, SEEK_SET);
if (ret!=0) return ret; if (ret!=0) return ret;
ret = cdio_stream_read (_obj->tocent[0].data_source, data, ret = cdio_stream_read (env->tocent[0].data_source, data,
CDIO_CD_FRAMESIZE_RAW, nblocks); CDIO_CD_FRAMESIZE_RAW, nblocks);
} else { } else {
/* We need to pad out the first 272 bytes with 0's */ /* We need to pad out the first 272 bytes with 0's */
BZERO(data, 272); BZERO(data, 272);
ret = cdio_stream_seek (_obj->tocent[0].data_source, 0, SEEK_SET); ret = cdio_stream_seek (env->tocent[0].data_source, 0, SEEK_SET);
if (ret!=0) return ret; if (ret!=0) return ret;
ret = cdio_stream_read (_obj->tocent[0].data_source, (uint8_t *) data+272, ret = cdio_stream_read (env->tocent[0].data_source, (uint8_t *) data+272,
CDIO_CD_FRAMESIZE_RAW - 272, nblocks); CDIO_CD_FRAMESIZE_RAW - 272, nblocks);
} }
@@ -853,24 +849,22 @@ _read_audio_sectors_cdrdao (void *env, void *data, lsn_t lsn,
from lsn. Returns 0 if no error. from lsn. Returns 0 if no error.
*/ */
static int static int
_read_mode1_sector_cdrdao (void *env, void *data, lsn_t lsn, _read_mode1_sector_cdrdao (void *user_data, void *data, lsn_t lsn,
bool b_form2) bool b_form2)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
int ret; int ret;
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, }; char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
int blocksize = _obj->sector_2336 int blocksize = env->sector_2336
? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE_RAW; ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE_RAW;
_init_cdrdao (_obj); ret = cdio_stream_seek (env->tocent[0].data_source, lsn * blocksize,
ret = cdio_stream_seek (_obj->tocent[0].data_source, lsn * blocksize,
SEEK_SET); SEEK_SET);
if (ret!=0) return ret; if (ret!=0) return ret;
/* FIXME: Not completely sure the below is correct. */ /* FIXME: Not completely sure the below is correct. */
ret = cdio_stream_read (_obj->tocent[0].data_source, ret = cdio_stream_read (env->tocent[0].data_source,
_obj->sector_2336 env->sector_2336
? (buf + CDIO_CD_SYNC_SIZE + CDIO_CD_HEADER_SIZE) ? (buf + CDIO_CD_SYNC_SIZE + CDIO_CD_HEADER_SIZE)
: buf, : buf,
blocksize, 1); blocksize, 1);
@@ -888,16 +882,16 @@ _read_mode1_sector_cdrdao (void *env, void *data, lsn_t lsn,
Returns 0 if no error. Returns 0 if no error.
*/ */
static int static int
_read_mode1_sectors_cdrdao (void *env, void *data, lsn_t lsn, _read_mode1_sectors_cdrdao (void *user_data, void *data, lsn_t lsn,
bool b_form2, unsigned int nblocks) bool b_form2, unsigned int nblocks)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
int i; int i;
int retval; int retval;
unsigned int blocksize = b_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE; unsigned int blocksize = b_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE;
for (i = 0; i < nblocks; i++) { for (i = 0; i < nblocks; i++) {
if ( (retval = _read_mode1_sector_cdrdao (_obj, if ( (retval = _read_mode1_sector_cdrdao (env,
((char *)data) + (blocksize * i), ((char *)data) + (blocksize * i),
lsn + i, b_form2)) ) lsn + i, b_form2)) )
return retval; return retval;
@@ -910,10 +904,10 @@ _read_mode1_sectors_cdrdao (void *env, void *data, lsn_t lsn,
from lsn. Returns 0 if no error. from lsn. Returns 0 if no error.
*/ */
static int static int
_read_mode2_sector_cdrdao (void *env, void *data, lsn_t lsn, _read_mode2_sector_cdrdao (void *user_data, void *data, lsn_t lsn,
bool b_form2) bool b_form2)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
int ret; int ret;
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, }; char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
@@ -923,17 +917,15 @@ _read_mode2_sector_cdrdao (void *env, void *data, lsn_t lsn,
Review this sector 2336 stuff later. Review this sector 2336 stuff later.
*/ */
int blocksize = _obj->sector_2336 int blocksize = env->sector_2336
? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE_RAW; ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE_RAW;
_init_cdrdao (_obj); ret = cdio_stream_seek (env->tocent[0].data_source, lsn * blocksize,
ret = cdio_stream_seek (_obj->tocent[0].data_source, lsn * blocksize,
SEEK_SET); SEEK_SET);
if (ret!=0) return ret; if (ret!=0) return ret;
ret = cdio_stream_read (_obj->tocent[0].data_source, ret = cdio_stream_read (env->tocent[0].data_source,
_obj->sector_2336 env->sector_2336
? (buf + CDIO_CD_SYNC_SIZE + CDIO_CD_HEADER_SIZE) ? (buf + CDIO_CD_SYNC_SIZE + CDIO_CD_HEADER_SIZE)
: buf, : buf,
blocksize, 1); blocksize, 1);
@@ -956,16 +948,16 @@ _read_mode2_sector_cdrdao (void *env, void *data, lsn_t lsn,
Returns 0 if no error. Returns 0 if no error.
*/ */
static int static int
_read_mode2_sectors_cdrdao (void *env, void *data, lsn_t lsn, _read_mode2_sectors_cdrdao (void *user_data, void *data, lsn_t lsn,
bool b_form2, unsigned int nblocks) bool b_form2, unsigned int nblocks)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
int i; int i;
int retval; int retval;
unsigned int blocksize = b_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE; unsigned int blocksize = b_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE;
for (i = 0; i < nblocks; i++) { for (i = 0; i < nblocks; i++) {
if ( (retval = _read_mode2_sector_cdrdao (_obj, if ( (retval = _read_mode2_sector_cdrdao (env,
((char *)data) + (blocksize * i), ((char *)data) + (blocksize * i),
lsn + i, b_form2)) ) lsn + i, b_form2)) )
return retval; return retval;
@@ -984,7 +976,7 @@ _free_cdrdao (void *obj)
if (NULL == env) return; if (NULL == env) return;
free_if_notnull(env->mcn); free_if_notnull(env->mcn);
for (i=0; i<env->total_tracks; i++) { for (i=0; i<env->i_tracks; i++) {
if (env->tocent[i].data_source) if (env->tocent[i].data_source)
cdio_stdio_destroy (env->tocent[i].data_source); cdio_stdio_destroy (env->tocent[i].data_source);
free_if_notnull(env->tocent[i].isrc); free_if_notnull(env->tocent[i].isrc);
@@ -1014,27 +1006,27 @@ _eject_media_cdrdao(void *obj)
0 is returned if no error was found, and nonzero if there as an error. 0 is returned if no error was found, and nonzero if there as an error.
*/ */
static int static int
_set_arg_cdrdao (void *env, const char key[], const char value[]) _set_arg_cdrdao (void *user_data, const char key[], const char value[])
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
if (!strcmp (key, "sector")) if (!strcmp (key, "sector"))
{ {
if (!strcmp (value, "2336")) if (!strcmp (value, "2336"))
_obj->sector_2336 = true; env->sector_2336 = true;
else if (!strcmp (value, "2352")) else if (!strcmp (value, "2352"))
_obj->sector_2336 = false; env->sector_2336 = false;
else else
return -2; return -2;
} }
else if (!strcmp (key, "toc")) else if (!strcmp (key, "toc"))
{ {
free_if_notnull (_obj->toc_name); free_if_notnull (env->toc_name);
if (!value) if (!value)
return -2; return -2;
_obj->toc_name = strdup (value); env->toc_name = strdup (value);
} }
else else
return -1; return -1;
@@ -1046,14 +1038,14 @@ _set_arg_cdrdao (void *env, const char key[], const char value[])
Return the value associated with the key "arg". Return the value associated with the key "arg".
*/ */
static const char * static const char *
_get_arg_cdrdao (void *env, const char key[]) _get_arg_cdrdao (void *user_data, const char key[])
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
if (!strcmp (key, "source")) { if (!strcmp (key, "source")) {
return _obj->tocent[0].filename; return env->tocent[0].filename;
} else if (!strcmp (key, "toc")) { } else if (!strcmp (key, "toc")) {
return _obj->toc_name; return env->toc_name;
} else if (!strcmp(key, "access-mode")) { } else if (!strcmp(key, "access-mode")) {
return "image"; return "image";
} }
@@ -1104,7 +1096,7 @@ cdio_get_default_device_cdrdao(void)
*/ */
static cdio_drive_cap_t static cdio_drive_cap_t
_get_drive_cap_cdrdao (const void *env) { _get_drive_cap_cdrdao (const void *user_data) {
/* There may be more in the future but these we can handle now. /* There may be more in the future but these we can handle now.
Also, we know we can't handle Also, we know we can't handle
@@ -1118,16 +1110,16 @@ _get_drive_cap_cdrdao (const void *env) {
CDIO_INVALID_TRACK is returned on error. CDIO_INVALID_TRACK is returned on error.
*/ */
static track_format_t static track_format_t
_get_track_format_cdrdao(void *env, track_t track_num) _get_track_format_cdrdao(void *user_data, track_t i_track)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
if (!_obj->gen.init) _init_cdrdao(_obj); if (!env->gen.init) _init_cdrdao(env);
if (track_num > _obj->total_tracks || track_num == 0) if (i_track > env->i_tracks || i_track == 0)
return TRACK_FORMAT_ERROR; return TRACK_FORMAT_ERROR;
return _obj->tocent[track_num-1].track_format; return env->tocent[i_track-env->i_first_track].track_format;
} }
/*! /*!
@@ -1139,35 +1131,35 @@ _get_track_format_cdrdao(void *env, track_t track_num)
FIXME: there's gotta be a better design for this and get_track_format? FIXME: there's gotta be a better design for this and get_track_format?
*/ */
static bool static bool
_get_track_green_cdrdao(void *env, track_t track_num) _get_track_green_cdrdao(void *user_data, track_t i_track)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
if (!_obj->gen.init) _init_cdrdao(_obj); if (!env->gen.init) _init_cdrdao(env);
if (track_num > _obj->total_tracks || track_num == 0) if (i_track > env->i_tracks || i_track == 0)
return false; return false;
return _obj->tocent[track_num-1].track_green; return env->tocent[i_track-env->i_first_track].track_green;
} }
/*! /*!
Return the starting LSN track number Return the starting LSN track number
track_num in obj. Track numbers start at 1. i_track in obj. Track numbers start at 1.
The "leadout" track is specified either by The "leadout" track is specified either by
using track_num LEADOUT_TRACK or the total tracks+1. using i_track LEADOUT_TRACK or the total tracks+1.
False is returned if there is no track entry. False is returned if there is no track entry.
*/ */
static lba_t static lba_t
_get_lba_track_cdrdao(void *env, track_t track_num) _get_lba_track_cdrdao(void *user_data, track_t i_track)
{ {
_img_private_t *_obj = env; _img_private_t *env = user_data;
_init_cdrdao (_obj); _init_cdrdao (env);
if (track_num == CDIO_CDROM_LEADOUT_TRACK) track_num = _obj->total_tracks+1; if (i_track == CDIO_CDROM_LEADOUT_TRACK) i_track = env->i_tracks+1;
if (track_num <= _obj->total_tracks+1 && track_num != 0) { if (i_track <= env->i_tracks+1 && i_track != 0) {
return _obj->tocent[track_num-1].start_lba; return env->tocent[i_track-1].start_lba;
} else } else
return CDIO_INVALID_LBA; return CDIO_INVALID_LBA;
} }

View File

@@ -1,5 +1,5 @@
/* /*
$Id: nrg.c,v 1.19 2004/06/01 10:47:37 rocky Exp $ $Id: nrg.c,v 1.20 2004/06/01 11:15:58 rocky Exp $
Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 2001, 2003 Herbert Valerio Riedel <hvr@gnu.org> Copyright (C) 2001, 2003 Herbert Valerio Riedel <hvr@gnu.org>
@@ -49,7 +49,7 @@
#include "_cdio_stdio.h" #include "_cdio_stdio.h"
#include "nrg.h" #include "nrg.h"
static const char _rcsid[] = "$Id: nrg.c,v 1.19 2004/06/01 10:47:37 rocky Exp $"; static const char _rcsid[] = "$Id: nrg.c,v 1.20 2004/06/01 11:15:58 rocky Exp $";
/* reader */ /* reader */
@@ -100,8 +100,8 @@ typedef struct {
char *mcn; /* Media catalog number. */ char *mcn; /* Media catalog number. */
track_info_t tocent[100]; /* entry info for each track */ track_info_t tocent[100]; /* entry info for each track */
track_t total_tracks; /* number of tracks in image */ track_t i_tracks; /* number of tracks in image */
track_t first_track_num; /* track number of first track */ track_t i_first_track; /* track number of first track */
CdioList *mapping; /* List of track information */ CdioList *mapping; /* List of track information */
uint32_t size; uint32_t size;
} _img_private_t; } _img_private_t;
@@ -119,8 +119,8 @@ _register_mapping (_img_private_t *env, lsn_t start_lsn, uint32_t sec_count,
uint64_t img_offset, uint32_t blocksize, uint64_t img_offset, uint32_t blocksize,
track_format_t track_format, bool track_green) track_format_t track_format, bool track_green)
{ {
const int track_num=env->total_tracks; const int track_num=env->i_tracks;
track_info_t *this_track=&(env->tocent[env->total_tracks]); track_info_t *this_track=&(env->tocent[env->i_tracks]);
_mapping_t *_map = _cdio_malloc (sizeof (_mapping_t)); _mapping_t *_map = _cdio_malloc (sizeof (_mapping_t));
_map->start_lsn = start_lsn; _map->start_lsn = start_lsn;
@@ -194,10 +194,10 @@ _register_mapping (_img_private_t *env, lsn_t start_lsn, uint32_t sec_count,
default: default:
/*this_track->datasize=CDIO_CD_FRAMESIZE_RAW;*/ /*this_track->datasize=CDIO_CD_FRAMESIZE_RAW;*/
cdio_warn ("track %d has unknown format %d", cdio_warn ("track %d has unknown format %d",
env->total_tracks, this_track->track_format); env->i_tracks, this_track->track_format);
} }
env->total_tracks++; env->i_tracks++;
cdio_debug ("start lsn: %lu sector count: %0lu -> %8ld (%08lx)", cdio_debug ("start lsn: %lu sector count: %0lu -> %8ld (%08lx)",
(long unsigned int) start_lsn, (long unsigned int) start_lsn,
@@ -288,9 +288,9 @@ parse_nrg (_img_private_t *env, const char *psz_nrg_name)
cdio_info ("CUES type image detected" ); cdio_info ("CUES type image detected" );
/*cdio_assert (lsn == 0?);*/ /*cdio_assert (lsn == 0?);*/
env->is_cues = true; /* HACK alert. */ env->is_cues = true; /* HACK alert. */
env->total_tracks = 0; env->i_tracks = 0;
env->first_track_num = 1; env->i_first_track = 1;
for (idx = 1; idx < entries-1; idx += 2) { for (idx = 1; idx < entries-1; idx += 2) {
lsn_t sec_count; lsn_t sec_count;
@@ -386,7 +386,7 @@ parse_nrg (_img_private_t *env, const char *psz_nrg_name)
} }
if (0 == form2) { if (0 == form2) {
int i; int i;
for (i=0; i<env->total_tracks; i++) { for (i=0; i<env->i_tracks; i++) {
env->tocent[i].track_format= track_format; env->tocent[i].track_format= track_format;
env->tocent[i].datastart = 0; env->tocent[i].datastart = 0;
env->tocent[i].track_green = false; env->tocent[i].track_green = false;
@@ -401,7 +401,7 @@ parse_nrg (_img_private_t *env, const char *psz_nrg_name)
} }
} else if (2 == form2) { } else if (2 == form2) {
int i; int i;
for (i=0; i<env->total_tracks; i++) { for (i=0; i<env->i_tracks; i++) {
env->tocent[i].track_green = true; env->tocent[i].track_green = true;
env->tocent[i].track_format= track_format; env->tocent[i].track_format= track_format;
env->tocent[i].datasize = CDIO_CD_FRAMESIZE; env->tocent[i].datasize = CDIO_CD_FRAMESIZE;
@@ -658,10 +658,10 @@ parse_nrg (_img_private_t *env, const char *psz_nrg_name)
/* Don't use _stat_size_nrg since that will lead to recursion since /* Don't use _stat_size_nrg since that will lead to recursion since
we haven't fully initialized things yet. we haven't fully initialized things yet.
*/ */
cdio_lsn_to_msf (env->size, &env->tocent[env->total_tracks].start_msf); cdio_lsn_to_msf (env->size, &env->tocent[env->i_tracks].start_msf);
env->tocent[env->total_tracks].start_lba = cdio_lsn_to_lba(env->size); env->tocent[env->i_tracks].start_lba = cdio_lsn_to_lba(env->size);
env->tocent[env->total_tracks-1].sec_count = env->tocent[env->i_tracks-1].sec_count =
cdio_lsn_to_lba(env->size - env->tocent[env->total_tracks-1].start_lba); cdio_lsn_to_lba(env->size - env->tocent[env->i_tracks-1].start_lba);
free(footer_buf); free(footer_buf);
return true; return true;
@@ -713,7 +713,7 @@ _lseek_nrg (void *user_data, off_t offset, int whence)
unsigned int i; unsigned int i;
for (i=0; i<env->total_tracks; i++) { for (i=0; i<env->i_tracks; i++) {
track_info_t *this_track=&(env->tocent[i]); track_info_t *this_track=&(env->tocent[i]);
env->pos.index = i; env->pos.index = i;
if ( (this_track->sec_count*this_track->datasize) >= offset) { if ( (this_track->sec_count*this_track->datasize) >= offset) {
@@ -730,7 +730,7 @@ _lseek_nrg (void *user_data, off_t offset, int whence)
env->pos.lba += this_track->sec_count; env->pos.lba += this_track->sec_count;
} }
if (i==env->total_tracks) { if (i==env->i_tracks) {
cdio_warn ("seeking outside range of disk image"); cdio_warn ("seeking outside range of disk image");
return -1; return -1;
} else } else
@@ -1076,7 +1076,7 @@ _get_track_format_nrg(void *user_data, track_t track_num)
{ {
_img_private_t *env = user_data; _img_private_t *env = user_data;
if (track_num > env->total_tracks || track_num == 0) if (track_num > env->i_tracks || track_num == 0)
return TRACK_FORMAT_ERROR; return TRACK_FORMAT_ERROR;
if ( env->dtyp != DTYP_INVALID) { if ( env->dtyp != DTYP_INVALID) {
@@ -1106,7 +1106,7 @@ _get_track_green_nrg(void *user_data, track_t track_num)
{ {
_img_private_t *env = user_data; _img_private_t *env = user_data;
if (track_num > env->total_tracks || track_num == 0) if (track_num > env->i_tracks || track_num == 0)
return false; return false;
if ( MTYP_AUDIO_CD == env->mtyp) return false; if ( MTYP_AUDIO_CD == env->mtyp) return false;
@@ -1189,10 +1189,10 @@ cdio_open_nrg (const char *psz_source)
_data = _cdio_malloc (sizeof (_img_private_t)); _data = _cdio_malloc (sizeof (_img_private_t));
_data->gen.init = false; _data->gen.init = false;
_data->total_tracks = 0; _data->i_tracks = 0;
_data->mtyp = 0; _data->mtyp = 0;
_data->dtyp = DTYP_INVALID; _data->dtyp = DTYP_INVALID;
_data->first_track_num= 1; _data->i_first_track = 1;
_data->is_dao = false; _data->is_dao = false;
_data->is_cues = false; /* FIXME: remove is_cues. */ _data->is_cues = false; /* FIXME: remove is_cues. */