2003-03-24 19:01:09 +00:00
|
|
|
|
/*
|
2004-12-18 17:29:32 +00:00
|
|
|
|
$Id: nrg.c,v 1.1 2004/12/18 17:29:32 rocky Exp $
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-02-08 03:00:37 +00:00
|
|
|
|
Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
|
2004-06-01 10:43:23 +00:00
|
|
|
|
Copyright (C) 2001, 2003 Herbert Valerio Riedel <hvr@gnu.org>
|
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 the Nero native
|
|
|
|
|
|
CD-image format residing inside a disk file (*.nrg).
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2004-07-10 02:17:57 +00:00
|
|
|
|
#include "image.h"
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-09-29 02:56:22 +00:00
|
|
|
|
#ifdef HAVE_STDIO_H
|
2003-03-24 19:01:09 +00:00
|
|
|
|
#include <stdio.h>
|
2003-09-29 02:56:22 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef HAVE_STDLIB_H
|
2003-03-24 19:01:09 +00:00
|
|
|
|
#include <stdlib.h>
|
2003-09-29 02:56:22 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
2003-03-24 19:01:09 +00:00
|
|
|
|
#include <string.h>
|
2003-09-29 02:56:22 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef HAVE_GLOB_H
|
|
|
|
|
|
#include <glob.h>
|
|
|
|
|
|
#endif
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-10-22 01:13:38 +00:00
|
|
|
|
#include <cdio/bytesex.h>
|
2004-10-09 03:20:28 +00:00
|
|
|
|
#include <cdio/ds.h>
|
2003-04-22 12:09:08 +00:00
|
|
|
|
#include <cdio/logging.h>
|
|
|
|
|
|
#include <cdio/util.h>
|
2004-09-04 00:06:50 +00:00
|
|
|
|
#include <cdio/version.h>
|
2003-03-24 19:01:09 +00:00
|
|
|
|
#include "cdio_assert.h"
|
|
|
|
|
|
#include "_cdio_stdio.h"
|
2004-06-01 10:47:37 +00:00
|
|
|
|
#include "nrg.h"
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-12-18 17:29:32 +00:00
|
|
|
|
static const char _rcsid[] = "$Id: nrg.c,v 1.1 2004/12/18 17:29:32 rocky Exp $";
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-12-28 08:33:45 +00:00
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
/* reader */
|
|
|
|
|
|
|
|
|
|
|
|
#define DEFAULT_CDIO_DEVICE "image.nrg"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
Link element of track structure as a linked list.
|
|
|
|
|
|
Possibly redundant with above track_info_t */
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
|
uint32_t start_lsn;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
uint32_t sec_count; /* Number of sectors in track. Does not
|
|
|
|
|
|
include pregap before next entry. */
|
|
|
|
|
|
uint64_t img_offset; /* Bytes offset from beginning of disk image file.*/
|
2003-12-30 11:52:49 +00:00
|
|
|
|
uint32_t blocksize; /* Number of bytes in a block */
|
2004-06-14 09:52:17 +00:00
|
|
|
|
int flags; /* don't copy, 4 channel, pre-emphasis */
|
2003-03-24 19:01:09 +00:00
|
|
|
|
} _mapping_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-07 11:25:40 +00:00
|
|
|
|
internal_position_t pos;
|
2004-07-10 11:06:00 +00:00
|
|
|
|
|
|
|
|
|
|
/* This is common to all image drivers... */
|
|
|
|
|
|
char *psz_cue_name;
|
|
|
|
|
|
char *psz_mcn; /* Media Catalog Number (5.22.3) */
|
|
|
|
|
|
|
|
|
|
|
|
track_info_t tocent[CDIO_CD_MAX_TRACKS+1]; /* entry info for each track
|
|
|
|
|
|
add 1 for leadout. */
|
2004-07-24 14:23:37 +00:00
|
|
|
|
discmode_t disc_mode;
|
2004-07-10 11:06:00 +00:00
|
|
|
|
|
|
|
|
|
|
/* Nero Specific stuff. Note: for the image_free to work, this *must*
|
|
|
|
|
|
be last. */
|
2003-12-31 03:09:31 +00:00
|
|
|
|
bool is_dao; /* True if some of disk at once. False
|
|
|
|
|
|
if some sort of track at once. */
|
|
|
|
|
|
uint32_t mtyp; /* Value of MTYP (media type?) tag */
|
|
|
|
|
|
uint8_t dtyp; /* Value of DAOX media type tag */
|
2003-03-30 13:01:22 +00:00
|
|
|
|
|
2003-04-21 23:24:46 +00:00
|
|
|
|
/* This is a hack because I don't really understnad NERO better. */
|
|
|
|
|
|
bool is_cues;
|
|
|
|
|
|
|
2003-12-31 03:09:31 +00:00
|
|
|
|
CdioList *mapping; /* List of track information */
|
|
|
|
|
|
uint32_t size;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
} _img_private_t;
|
|
|
|
|
|
|
2004-07-10 11:06:00 +00:00
|
|
|
|
static bool parse_nrg (_img_private_t *env, const char *psz_cue_name);
|
2004-06-01 10:43:23 +00:00
|
|
|
|
static uint32_t _stat_size_nrg (void *user_data);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
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
|
|
|
|
/* Updates internal track TOC, so we can later
|
|
|
|
|
|
simulate ioctl(CDROMREADTOCENTRY).
|
|
|
|
|
|
*/
|
|
|
|
|
|
static void
|
2004-06-01 10:43:23 +00:00
|
|
|
|
_register_mapping (_img_private_t *env, lsn_t start_lsn, uint32_t sec_count,
|
2003-12-28 08:33:45 +00:00
|
|
|
|
uint64_t img_offset, uint32_t blocksize,
|
2004-06-14 09:52:17 +00:00
|
|
|
|
track_format_t track_format, bool track_green,
|
|
|
|
|
|
int flags)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-07-29 02:16:20 +00:00
|
|
|
|
const int track_num=env->gen.i_tracks;
|
|
|
|
|
|
track_info_t *this_track=&(env->tocent[env->gen.i_tracks]);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
_mapping_t *_map = _cdio_malloc (sizeof (_mapping_t));
|
|
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
_map->start_lsn = start_lsn;
|
|
|
|
|
|
_map->sec_count = sec_count;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
_map->img_offset = img_offset;
|
2003-12-30 11:52:49 +00:00
|
|
|
|
_map->blocksize = blocksize;
|
2004-06-18 22:55:24 +00:00
|
|
|
|
_map->flags = flags;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-06-01 10:43:23 +00:00
|
|
|
|
if (!env->mapping) env->mapping = _cdio_list_new ();
|
|
|
|
|
|
_cdio_list_append (env->mapping, _map);
|
2004-02-08 03:00:37 +00:00
|
|
|
|
|
2004-06-01 10:43:23 +00:00
|
|
|
|
env->size = MAX (env->size, (start_lsn + sec_count));
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-04-07 11:25:40 +00:00
|
|
|
|
/* Update *this_track and track_num. These structures are
|
2003-03-24 19:01:09 +00:00
|
|
|
|
in a sense redundant witht the obj->mapping list. Perhaps one
|
|
|
|
|
|
or the other can be eliminated.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2003-04-07 11:25:40 +00:00
|
|
|
|
cdio_lba_to_msf (cdio_lsn_to_lba(start_lsn), &(this_track->start_msf));
|
|
|
|
|
|
this_track->start_lba = cdio_msf_to_lba(&this_track->start_msf);
|
|
|
|
|
|
this_track->track_num = track_num+1;
|
|
|
|
|
|
this_track->blocksize = blocksize;
|
2004-06-01 10:43:23 +00:00
|
|
|
|
if (env->is_cues)
|
2003-12-30 11:52:49 +00:00
|
|
|
|
this_track->datastart = img_offset;
|
2003-04-21 23:24:46 +00:00
|
|
|
|
else
|
2003-12-30 11:52:49 +00:00
|
|
|
|
this_track->datastart = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (track_green)
|
|
|
|
|
|
this_track->datastart += CDIO_CD_SUBHEADER_SIZE;
|
2003-04-21 23:24:46 +00:00
|
|
|
|
|
2003-04-07 11:25:40 +00:00
|
|
|
|
this_track->sec_count = sec_count;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-12-28 08:33:45 +00:00
|
|
|
|
this_track->track_format= track_format;
|
|
|
|
|
|
this_track->track_green = track_green;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-12-31 03:09:31 +00:00
|
|
|
|
switch (this_track->track_format) {
|
|
|
|
|
|
case TRACK_FORMAT_AUDIO:
|
|
|
|
|
|
this_track->blocksize = CDIO_CD_FRAMESIZE_RAW;
|
|
|
|
|
|
this_track->datasize = CDIO_CD_FRAMESIZE_RAW;
|
|
|
|
|
|
/*this_track->datastart = 0;*/
|
|
|
|
|
|
this_track->endsize = 0;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case TRACK_FORMAT_CDI:
|
|
|
|
|
|
this_track->datasize=CDIO_CD_FRAMESIZE;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case TRACK_FORMAT_XA:
|
|
|
|
|
|
if (track_green) {
|
|
|
|
|
|
this_track->blocksize = CDIO_CD_FRAMESIZE;
|
|
|
|
|
|
/*this_track->datastart = CDIO_CD_SYNC_SIZE + CDIO_CD_HEADER_SIZE;*/
|
|
|
|
|
|
this_track->datasize = M2RAW_SECTOR_SIZE;
|
|
|
|
|
|
this_track->endsize = 0;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
/*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;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case TRACK_FORMAT_DATA:
|
|
|
|
|
|
if (track_green) {
|
|
|
|
|
|
/*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;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
/* Is the below correct? */
|
|
|
|
|
|
/*this_track->datastart = 0;*/
|
|
|
|
|
|
this_track->datasize = CDIO_CD_FRAMESIZE;
|
|
|
|
|
|
this_track->endsize = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
/*this_track->datasize=CDIO_CD_FRAMESIZE_RAW;*/
|
|
|
|
|
|
cdio_warn ("track %d has unknown format %d",
|
2004-07-29 02:16:20 +00:00
|
|
|
|
env->gen.i_tracks, this_track->track_format);
|
2003-12-31 03:09:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-07-29 02:16:20 +00:00
|
|
|
|
env->gen.i_tracks++;
|
2003-12-31 03:09:31 +00:00
|
|
|
|
|
2004-02-01 15:45:30 +00:00
|
|
|
|
cdio_debug ("start lsn: %lu sector count: %0lu -> %8ld (%08lx)",
|
2004-02-01 15:53:06 +00:00
|
|
|
|
(long unsigned int) start_lsn,
|
|
|
|
|
|
(long unsigned int) sec_count,
|
2003-12-30 11:52:49 +00:00
|
|
|
|
(long unsigned int) img_offset,
|
|
|
|
|
|
(long unsigned int) img_offset);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
Disk and track information for a Nero file are located at the end
|
|
|
|
|
|
of the file. This routine extracts that information.
|
2004-06-01 10:43:23 +00:00
|
|
|
|
|
|
|
|
|
|
FIXME: right now psz_nrg_name is not used. It will be in the future.
|
2003-03-24 19:01:09 +00:00
|
|
|
|
*/
|
|
|
|
|
|
static bool
|
2004-12-17 04:57:14 +00:00
|
|
|
|
parse_nrg (_img_private_t *p_env, const char *psz_nrg_name)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
long unsigned int footer_start;
|
|
|
|
|
|
long unsigned int size;
|
|
|
|
|
|
char *footer_buf = NULL;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
cdio_log_level_t log_level = (NULL == p_env) ? CDIO_LOG_INFO : CDIO_LOG_WARN;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
size = cdio_stream_stat (p_env->gen.data_source);
|
2003-10-03 08:32:32 +00:00
|
|
|
|
if (-1 == size) return false;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
{
|
2004-06-01 10:43:23 +00:00
|
|
|
|
_footer_t buf;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
cdio_assert (sizeof (buf) == 12);
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
cdio_stream_seek (p_env->gen.data_source, size - sizeof (buf), SEEK_SET);
|
|
|
|
|
|
cdio_stream_read (p_env->gen.data_source, (void *) &buf, sizeof (buf), 1);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-06-01 10:43:23 +00:00
|
|
|
|
if (buf.v50.ID == UINT32_TO_BE (NERO_ID)) {
|
|
|
|
|
|
cdio_info ("detected Nero version 5.0 (32-bit offsets) NRG magic");
|
|
|
|
|
|
footer_start = uint32_to_be (buf.v50.footer_ofs);
|
|
|
|
|
|
} else if (buf.v55.ID == UINT32_TO_BE (NER5_ID)) {
|
|
|
|
|
|
cdio_info ("detected Nero version 5.5.x (64-bit offsets) NRG magic");
|
|
|
|
|
|
footer_start = uint64_from_be (buf.v55.footer_ofs);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
cdio_log (log_level, "Image not recognized as either version 5.0 or "
|
2004-07-01 09:50:59 +00:00
|
|
|
|
"version 5.5.x-6.x type NRG");
|
2004-06-01 10:43:23 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-05-31 04:00:01 +00:00
|
|
|
|
cdio_debug (".NRG footer start = %ld, length = %ld",
|
2003-03-24 19:01:09 +00:00
|
|
|
|
(long) footer_start, (long) (size - footer_start));
|
|
|
|
|
|
|
|
|
|
|
|
cdio_assert (IN ((size - footer_start), 0, 4096));
|
|
|
|
|
|
|
|
|
|
|
|
footer_buf = _cdio_malloc (size - footer_start);
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
cdio_stream_seek (p_env->gen.data_source, footer_start, SEEK_SET);
|
|
|
|
|
|
cdio_stream_read (p_env->gen.data_source, footer_buf,
|
2004-06-01 10:43:23 +00:00
|
|
|
|
size - footer_start, 1);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
{
|
|
|
|
|
|
int pos = 0;
|
|
|
|
|
|
|
|
|
|
|
|
while (pos < size - footer_start) {
|
|
|
|
|
|
_chunk_t *chunk = (void *) (footer_buf + pos);
|
2003-12-31 04:41:08 +00:00
|
|
|
|
uint32_t opcode = UINT32_FROM_BE (chunk->id);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
bool break_out = false;
|
|
|
|
|
|
|
2003-12-31 04:41:08 +00:00
|
|
|
|
switch (opcode) {
|
2003-04-21 23:24:46 +00:00
|
|
|
|
|
2003-12-31 04:41:08 +00:00
|
|
|
|
case CUES_ID: /* "CUES" Seems to have sector size 2336 and 150 sector
|
|
|
|
|
|
pregap seems to be included at beginning of image.
|
|
|
|
|
|
*/
|
|
|
|
|
|
case CUEX_ID: /* "CUEX" */
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2003-12-31 04:41:08 +00:00
|
|
|
|
unsigned entries = UINT32_FROM_BE (chunk->len);
|
|
|
|
|
|
_cuex_array_t *_entries = (void *) chunk->data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
cdio_assert (p_env->mapping == NULL);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-12-31 04:41:08 +00:00
|
|
|
|
cdio_assert ( sizeof (_cuex_array_t) == 8 );
|
|
|
|
|
|
cdio_assert ( UINT32_FROM_BE (chunk->len) % sizeof(_cuex_array_t)
|
|
|
|
|
|
== 0 );
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-12-31 04:41:08 +00:00
|
|
|
|
entries /= sizeof (_cuex_array_t);
|
|
|
|
|
|
|
|
|
|
|
|
if (CUES_ID == opcode) {
|
|
|
|
|
|
lsn_t lsn = UINT32_FROM_BE (_entries[0].lsn);
|
|
|
|
|
|
int idx;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-12-31 04:41:08 +00:00
|
|
|
|
cdio_info ("CUES type image detected" );
|
2004-06-14 09:52:17 +00:00
|
|
|
|
|
|
|
|
|
|
/* CUES LSN has 150 pregap include at beginning? -/
|
|
|
|
|
|
cdio_assert (lsn == 0?);
|
|
|
|
|
|
*/
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->is_cues = true; /* HACK alert. */
|
|
|
|
|
|
p_env->gen.i_tracks = 0;
|
|
|
|
|
|
p_env->gen.i_first_track = 1;
|
2003-12-31 04:41:08 +00:00
|
|
|
|
for (idx = 1; idx < entries-1; idx += 2) {
|
|
|
|
|
|
lsn_t sec_count;
|
2004-06-14 09:52:17 +00:00
|
|
|
|
int addrtype = _entries[idx].addr_ctrl / 16;
|
|
|
|
|
|
int control = _entries[idx].addr_ctrl % 16;
|
|
|
|
|
|
int flags = 0;
|
|
|
|
|
|
if ( 1 == control )
|
|
|
|
|
|
flags &= ~CDIO_TRACK_FLAG_COPY_PERMITTED;
|
|
|
|
|
|
|
2003-12-31 04:41:08 +00:00
|
|
|
|
cdio_assert (_entries[idx].track == _entries[idx + 1].track);
|
|
|
|
|
|
|
|
|
|
|
|
/* lsn and sec_count*2 aren't correct, but it comes closer on the
|
|
|
|
|
|
single example I have: svcdgs.nrg
|
|
|
|
|
|
We are picking up the wrong fields and/or not interpreting
|
|
|
|
|
|
them correctly.
|
|
|
|
|
|
*/
|
2004-06-14 09:52:17 +00:00
|
|
|
|
|
|
|
|
|
|
switch (addrtype) {
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
lsn = UINT32_FROM_BE (_entries[idx].lsn);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
{
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
msf_t msf = (msf_t) _entries[idx].lsn;
|
|
|
|
|
|
lsn = cdio_msf_to_lsn(&msf);
|
|
|
|
|
|
#else
|
|
|
|
|
|
lsn = CDIO_INVALID_LSN;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
cdio_warn ("untested (i.e. probably wrong) CUE MSF code");
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
default:
|
|
|
|
|
|
lsn = CDIO_INVALID_LSN;
|
|
|
|
|
|
cdio_warn("unknown addrtype %d", addrtype);
|
|
|
|
|
|
}
|
2003-12-31 04:41:08 +00:00
|
|
|
|
|
|
|
|
|
|
sec_count = UINT32_FROM_BE (_entries[idx + 1].lsn);
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
_register_mapping (p_env, lsn, sec_count*2,
|
2003-12-31 04:41:08 +00:00
|
|
|
|
(lsn+CDIO_PREGAP_SECTORS) * M2RAW_SECTOR_SIZE,
|
2004-06-14 09:52:17 +00:00
|
|
|
|
M2RAW_SECTOR_SIZE, TRACK_FORMAT_XA, true,
|
|
|
|
|
|
flags);
|
2003-12-31 04:41:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
lsn_t lsn = UINT32_FROM_BE (_entries[0].lsn);
|
|
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
|
|
|
|
cdio_info ("CUEX type image detected");
|
2004-06-14 09:52:17 +00:00
|
|
|
|
|
|
|
|
|
|
/* LSN must start at -150 (LBA 0)? */
|
|
|
|
|
|
cdio_assert (lsn == -150);
|
2003-12-31 04:41:08 +00:00
|
|
|
|
|
|
|
|
|
|
for (idx = 2; idx < entries; idx += 2) {
|
|
|
|
|
|
lsn_t sec_count;
|
2004-06-14 09:52:17 +00:00
|
|
|
|
int addrtype = _entries[idx].addr_ctrl >> 4;
|
|
|
|
|
|
int control = _entries[idx].addr_ctrl & 0xf;
|
|
|
|
|
|
int flags = 0;
|
|
|
|
|
|
if ( 1 == control )
|
|
|
|
|
|
flags &= ~CDIO_TRACK_FLAG_COPY_PERMITTED;
|
|
|
|
|
|
|
|
|
|
|
|
/* extractnrg.pl has addrtype for LBA's 0, and
|
|
|
|
|
|
for MSF 1. ???
|
2004-06-18 22:55:24 +00:00
|
|
|
|
|
|
|
|
|
|
FIXME: Should decode as appropriate for addrtype.
|
2004-06-14 09:52:17 +00:00
|
|
|
|
*/
|
2004-06-18 22:55:24 +00:00
|
|
|
|
cdio_assert ( addrtype == 0 || addrtype == 1 );
|
2004-06-14 09:52:17 +00:00
|
|
|
|
|
2003-12-31 04:41:08 +00:00
|
|
|
|
cdio_assert (_entries[idx].track != _entries[idx + 1].track);
|
|
|
|
|
|
|
|
|
|
|
|
lsn = UINT32_FROM_BE (_entries[idx].lsn);
|
|
|
|
|
|
sec_count = UINT32_FROM_BE (_entries[idx + 1].lsn);
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
_register_mapping (p_env, lsn, sec_count - lsn,
|
2003-12-31 04:41:08 +00:00
|
|
|
|
(lsn + CDIO_PREGAP_SECTORS)*M2RAW_SECTOR_SIZE,
|
2004-06-14 09:52:17 +00:00
|
|
|
|
M2RAW_SECTOR_SIZE, TRACK_FORMAT_XA, true,
|
|
|
|
|
|
flags);
|
2003-12-31 04:41:08 +00:00
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
2003-12-31 04:41:08 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-12-31 04:41:08 +00:00
|
|
|
|
case DAOX_ID: /* "DAOX" */
|
2004-05-26 06:27:03 +00:00
|
|
|
|
case DAOI_ID: /* "DAOI" */
|
2003-12-30 11:52:49 +00:00
|
|
|
|
{
|
2003-12-31 03:09:31 +00:00
|
|
|
|
track_format_t track_format;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
int disc_mode;
|
2004-05-26 06:27:03 +00:00
|
|
|
|
|
2004-06-27 15:29:20 +00:00
|
|
|
|
/* We include an extra 0 byte so these can be used as C strings.*/
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->psz_mcn = _cdio_malloc (CDIO_MCN_SIZE+1);
|
2004-05-31 14:16:34 +00:00
|
|
|
|
|
2004-05-31 04:00:01 +00:00
|
|
|
|
if (DAOX_ID == opcode) {
|
|
|
|
|
|
_daox_array_t *_entries = (void *) chunk->data;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
disc_mode = _entries->_unknown[1];
|
|
|
|
|
|
p_env->dtyp = _entries->_unknown[19];
|
|
|
|
|
|
memcpy(p_env->psz_mcn, &(_entries->psz_mcn), CDIO_MCN_SIZE);
|
|
|
|
|
|
p_env->psz_mcn[CDIO_MCN_SIZE] = '\0';
|
2004-05-31 04:00:01 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
_daoi_array_t *_entries = (void *) chunk->data;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
disc_mode = _entries->_unknown[1];
|
|
|
|
|
|
p_env->dtyp = _entries->_unknown[19];
|
|
|
|
|
|
memcpy(p_env->psz_mcn, &(_entries->psz_mcn), CDIO_MCN_SIZE);
|
|
|
|
|
|
p_env->psz_mcn[CDIO_MCN_SIZE] = '\0';
|
2004-05-31 04:00:01 +00:00
|
|
|
|
}
|
2004-05-31 14:16:34 +00:00
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->is_dao = true;
|
|
|
|
|
|
cdio_debug ("DAO%c tag detected, track format %d, mode %x\n",
|
|
|
|
|
|
opcode==DAOX_ID ? 'X': 'I', p_env->dtyp, disc_mode);
|
|
|
|
|
|
switch (p_env->dtyp) {
|
2003-12-31 03:09:31 +00:00
|
|
|
|
case 0:
|
2004-05-26 06:27:03 +00:00
|
|
|
|
/* Mode 1 */
|
2004-12-17 04:57:14 +00:00
|
|
|
|
track_format = TRACK_FORMAT_DATA;
|
|
|
|
|
|
p_env->disc_mode = CDIO_DISC_MODE_CD_DATA;
|
2003-12-31 03:09:31 +00:00
|
|
|
|
break;
|
2004-05-26 06:27:03 +00:00
|
|
|
|
case 2:
|
|
|
|
|
|
/* Mode 2 form 1 */
|
2004-12-17 04:57:14 +00:00
|
|
|
|
disc_mode = 0;
|
|
|
|
|
|
track_format = TRACK_FORMAT_XA;
|
|
|
|
|
|
p_env->disc_mode = CDIO_DISC_MODE_CD_XA;
|
2004-05-26 06:27:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
/* Mode 2 */
|
2004-12-17 04:57:14 +00:00
|
|
|
|
track_format = TRACK_FORMAT_XA;
|
|
|
|
|
|
p_env->disc_mode = CDIO_DISC_MODE_CD_XA; /* ?? */
|
2004-05-26 06:27:03 +00:00
|
|
|
|
break;
|
2003-12-31 04:41:08 +00:00
|
|
|
|
case 0x6:
|
2004-05-26 06:27:03 +00:00
|
|
|
|
/* Mode2 form mix */
|
2004-12-17 04:57:14 +00:00
|
|
|
|
track_format = TRACK_FORMAT_XA;
|
|
|
|
|
|
p_env->disc_mode = CDIO_DISC_MODE_CD_MIXED;
|
2004-07-10 11:31:42 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 0x20: /* ??? Mode2 form 2, Mode2 raw?? */
|
2004-12-17 04:57:14 +00:00
|
|
|
|
track_format = TRACK_FORMAT_XA;
|
|
|
|
|
|
p_env->disc_mode = CDIO_DISC_MODE_CD_XA; /* ??. */
|
2003-12-31 03:09:31 +00:00
|
|
|
|
break;
|
2003-12-31 04:41:08 +00:00
|
|
|
|
case 0x7:
|
2004-12-17 04:57:14 +00:00
|
|
|
|
track_format = TRACK_FORMAT_AUDIO;
|
|
|
|
|
|
p_env->disc_mode = CDIO_DISC_MODE_CD_DA;
|
2003-12-31 04:41:08 +00:00
|
|
|
|
break;
|
2003-12-31 03:09:31 +00:00
|
|
|
|
default:
|
2004-06-01 10:43:23 +00:00
|
|
|
|
cdio_log (log_level, "Unknown track format %x\n",
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->dtyp);
|
2003-12-31 03:09:31 +00:00
|
|
|
|
track_format = TRACK_FORMAT_AUDIO;
|
|
|
|
|
|
}
|
2004-12-17 04:57:14 +00:00
|
|
|
|
if (0 == disc_mode) {
|
2003-12-30 11:52:49 +00:00
|
|
|
|
int i;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
for (i=0; i<p_env->gen.i_tracks; i++) {
|
|
|
|
|
|
cdtext_init (&(p_env->gen.cdtext_track[i]));
|
|
|
|
|
|
p_env->tocent[i].track_format= track_format;
|
|
|
|
|
|
p_env->tocent[i].datastart = 0;
|
|
|
|
|
|
p_env->tocent[i].track_green = false;
|
2003-12-31 04:41:08 +00:00
|
|
|
|
if (TRACK_FORMAT_AUDIO == track_format) {
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->tocent[i].blocksize = CDIO_CD_FRAMESIZE_RAW;
|
|
|
|
|
|
p_env->tocent[i].datasize = CDIO_CD_FRAMESIZE_RAW;
|
|
|
|
|
|
p_env->tocent[i].endsize = 0;
|
2003-12-31 04:41:08 +00:00
|
|
|
|
} else {
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->tocent[i].datasize = CDIO_CD_FRAMESIZE;
|
|
|
|
|
|
p_env->tocent[i].datastart = 0;
|
2003-12-31 04:41:08 +00:00
|
|
|
|
}
|
2003-12-30 11:52:49 +00:00
|
|
|
|
}
|
2004-12-17 04:57:14 +00:00
|
|
|
|
} else if (2 == disc_mode) {
|
2003-12-30 11:52:49 +00:00
|
|
|
|
int i;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
for (i=0; i<p_env->gen.i_tracks; i++) {
|
|
|
|
|
|
cdtext_init (&(p_env->gen.cdtext_track[i]));
|
|
|
|
|
|
p_env->tocent[i].track_green = true;
|
|
|
|
|
|
p_env->tocent[i].track_format= track_format;
|
|
|
|
|
|
p_env->tocent[i].datasize = CDIO_CD_FRAMESIZE;
|
2003-12-31 04:41:08 +00:00
|
|
|
|
if (TRACK_FORMAT_XA == track_format) {
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->tocent[i].datastart = CDIO_CD_SYNC_SIZE
|
2003-12-31 04:41:08 +00:00
|
|
|
|
+ CDIO_CD_HEADER_SIZE + CDIO_CD_SUBHEADER_SIZE;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->tocent[i].endsize = CDIO_CD_SYNC_SIZE
|
2003-12-31 04:41:08 +00:00
|
|
|
|
+ CDIO_CD_ECC_SIZE;
|
|
|
|
|
|
} else {
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->tocent[i].datastart = CDIO_CD_SYNC_SIZE
|
2003-12-31 04:41:08 +00:00
|
|
|
|
+ CDIO_CD_HEADER_SIZE;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->tocent[i].endsize = CDIO_CD_EDC_SIZE
|
2003-12-31 04:41:08 +00:00
|
|
|
|
+ CDIO_CD_M1F1_ZERO_SIZE + CDIO_CD_ECC_SIZE;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2003-12-30 11:52:49 +00:00
|
|
|
|
}
|
2004-12-17 04:57:14 +00:00
|
|
|
|
} else if (0x20 == disc_mode) {
|
|
|
|
|
|
cdio_debug ("Mixed mode CD?\n");
|
2004-06-01 10:43:23 +00:00
|
|
|
|
} else {
|
2004-12-17 04:57:14 +00:00
|
|
|
|
/* Mixed mode CD */
|
|
|
|
|
|
cdio_log (log_level,
|
|
|
|
|
|
"Don't know if mode 1, mode 2 or mixed: %x\n",
|
|
|
|
|
|
disc_mode);
|
2003-12-30 11:52:49 +00:00
|
|
|
|
}
|
2003-12-28 08:33:45 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2004-05-26 06:27:03 +00:00
|
|
|
|
case NERO_ID:
|
|
|
|
|
|
case NER5_ID:
|
2003-12-31 04:41:08 +00:00
|
|
|
|
cdio_error ("unexpected nrg magic ID NER%c detected",
|
|
|
|
|
|
opcode==NERO_ID ? 'O': '5');
|
2004-02-08 03:00:37 +00:00
|
|
|
|
free(footer_buf);
|
|
|
|
|
|
return false;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case END1_ID: /* "END!" */
|
|
|
|
|
|
cdio_debug ("nrg end tag detected");
|
|
|
|
|
|
break_out = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case ETNF_ID: /* "ETNF" */ {
|
|
|
|
|
|
unsigned entries = UINT32_FROM_BE (chunk->len);
|
|
|
|
|
|
_etnf_array_t *_entries = (void *) chunk->data;
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
cdio_assert (p_env->mapping == NULL);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
cdio_assert ( sizeof (_etnf_array_t) == 20 );
|
|
|
|
|
|
cdio_assert ( UINT32_FROM_BE(chunk->len) % sizeof(_etnf_array_t)
|
|
|
|
|
|
== 0 );
|
|
|
|
|
|
|
|
|
|
|
|
entries /= sizeof (_etnf_array_t);
|
|
|
|
|
|
|
|
|
|
|
|
cdio_info ("SAO type image (ETNF) detected");
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
int idx;
|
|
|
|
|
|
for (idx = 0; idx < entries; idx++) {
|
|
|
|
|
|
uint32_t _len = UINT32_FROM_BE (_entries[idx].length);
|
|
|
|
|
|
uint32_t _start = UINT32_FROM_BE (_entries[idx].start_lsn);
|
|
|
|
|
|
uint32_t _start2 = UINT32_FROM_BE (_entries[idx].start);
|
2003-12-28 08:33:45 +00:00
|
|
|
|
uint32_t track_mode= uint32_from_be (_entries[idx].type);
|
|
|
|
|
|
bool track_green = true;
|
|
|
|
|
|
track_format_t track_format = TRACK_FORMAT_XA;
|
|
|
|
|
|
uint16_t blocksize;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-12-28 08:33:45 +00:00
|
|
|
|
switch (track_mode) {
|
|
|
|
|
|
case 0:
|
2004-07-10 11:31:42 +00:00
|
|
|
|
/* Mode 1 */
|
2004-07-24 14:23:37 +00:00
|
|
|
|
track_format = TRACK_FORMAT_DATA;
|
|
|
|
|
|
track_green = false; /* ?? */
|
|
|
|
|
|
blocksize = CDIO_CD_FRAMESIZE;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->disc_mode = CDIO_DISC_MODE_CD_DATA;
|
2003-12-28 08:33:45 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
2004-07-10 11:31:42 +00:00
|
|
|
|
/* Mode 2 form 1 */
|
2004-07-24 14:23:37 +00:00
|
|
|
|
track_format = TRACK_FORMAT_XA;
|
|
|
|
|
|
track_green = false; /* ?? */
|
|
|
|
|
|
blocksize = CDIO_CD_FRAMESIZE;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->disc_mode = CDIO_DISC_MODE_CD_XA;
|
2003-12-28 08:33:45 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
2004-07-10 11:31:42 +00:00
|
|
|
|
/* Mode 2 */
|
2004-07-24 14:23:37 +00:00
|
|
|
|
track_format = TRACK_FORMAT_XA;
|
|
|
|
|
|
track_green = true;
|
|
|
|
|
|
blocksize = M2RAW_SECTOR_SIZE;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->disc_mode = CDIO_DISC_MODE_CD_XA; /* ?? */
|
2004-07-10 11:31:42 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 06:
|
|
|
|
|
|
/* Mode2 form mix */
|
2004-07-24 14:23:37 +00:00
|
|
|
|
track_format = TRACK_FORMAT_XA;
|
|
|
|
|
|
track_green = true;
|
|
|
|
|
|
blocksize = M2RAW_SECTOR_SIZE;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->disc_mode = CDIO_DISC_MODE_CD_MIXED;
|
2004-07-10 11:31:42 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case 0x20: /* ??? Mode2 form 2, Mode2 raw?? */
|
2004-07-24 14:23:37 +00:00
|
|
|
|
track_format = TRACK_FORMAT_XA;
|
|
|
|
|
|
track_green = true;
|
|
|
|
|
|
blocksize = M2RAW_SECTOR_SIZE;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->disc_mode = CDIO_DISC_MODE_CD_XA; /* ??. */
|
2003-12-28 08:33:45 +00:00
|
|
|
|
break;
|
2004-01-03 13:50:17 +00:00
|
|
|
|
case 7:
|
2004-07-24 14:23:37 +00:00
|
|
|
|
track_format = TRACK_FORMAT_AUDIO;
|
|
|
|
|
|
track_green = false;
|
|
|
|
|
|
blocksize = CDIO_CD_FRAMESIZE_RAW;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->disc_mode = CDIO_DISC_MODE_CD_DA;
|
2004-01-03 13:50:17 +00:00
|
|
|
|
break;
|
2003-12-28 08:33:45 +00:00
|
|
|
|
default:
|
2004-06-01 10:43:23 +00:00
|
|
|
|
cdio_log (log_level,
|
|
|
|
|
|
"Don't know how to handle track mode (%lu)?",
|
|
|
|
|
|
(long unsigned int) track_mode);
|
2004-02-08 03:00:37 +00:00
|
|
|
|
free(footer_buf);
|
2003-12-28 08:33:45 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-12-28 08:33:45 +00:00
|
|
|
|
cdio_assert (_len % blocksize == 0);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-12-28 08:33:45 +00:00
|
|
|
|
_len /= blocksize;
|
|
|
|
|
|
|
|
|
|
|
|
cdio_assert (_start * blocksize == _start2);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
_start += idx * CDIO_PREGAP_SECTORS;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
_register_mapping (p_env, _start, _len, _start2, blocksize,
|
2004-06-14 09:52:17 +00:00
|
|
|
|
track_format, track_green, 0);
|
2003-04-21 23:24:46 +00:00
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case ETN2_ID: { /* "ETN2", same as above, but with 64bit stuff instead */
|
|
|
|
|
|
unsigned entries = uint32_from_be (chunk->len);
|
|
|
|
|
|
_etn2_array_t *_entries = (void *) chunk->data;
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
cdio_assert (p_env->mapping == NULL);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
cdio_assert (sizeof (_etn2_array_t) == 32);
|
|
|
|
|
|
cdio_assert (uint32_from_be (chunk->len) % sizeof (_etn2_array_t) == 0);
|
|
|
|
|
|
|
|
|
|
|
|
entries /= sizeof (_etn2_array_t);
|
|
|
|
|
|
|
|
|
|
|
|
cdio_info ("SAO type image (ETN2) detected");
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
int idx;
|
|
|
|
|
|
for (idx = 0; idx < entries; idx++) {
|
|
|
|
|
|
uint32_t _len = uint64_from_be (_entries[idx].length);
|
|
|
|
|
|
uint32_t _start = uint32_from_be (_entries[idx].start_lsn);
|
|
|
|
|
|
uint32_t _start2 = uint64_from_be (_entries[idx].start);
|
2003-12-28 08:33:45 +00:00
|
|
|
|
uint32_t track_mode= uint32_from_be (_entries[idx].type);
|
|
|
|
|
|
bool track_green = true;
|
|
|
|
|
|
track_format_t track_format = TRACK_FORMAT_XA;
|
|
|
|
|
|
uint16_t blocksize;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (track_mode) {
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
track_format = TRACK_FORMAT_DATA;
|
|
|
|
|
|
track_green = false; /* ?? */
|
|
|
|
|
|
blocksize = CDIO_CD_FRAMESIZE;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
track_format = TRACK_FORMAT_XA;
|
|
|
|
|
|
track_green = false; /* ?? */
|
|
|
|
|
|
blocksize = CDIO_CD_FRAMESIZE;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
track_format = TRACK_FORMAT_XA;
|
|
|
|
|
|
track_green = true;
|
|
|
|
|
|
blocksize = M2RAW_SECTOR_SIZE;
|
|
|
|
|
|
break;
|
2004-01-03 13:50:17 +00:00
|
|
|
|
case 7:
|
|
|
|
|
|
track_format = TRACK_FORMAT_AUDIO;
|
|
|
|
|
|
track_green = false;
|
|
|
|
|
|
blocksize = CDIO_CD_FRAMESIZE_RAW;
|
|
|
|
|
|
break;
|
2003-12-28 08:33:45 +00:00
|
|
|
|
default:
|
2004-06-01 10:43:23 +00:00
|
|
|
|
cdio_log (log_level,
|
|
|
|
|
|
"Don't know how to handle track mode (%lu)?",
|
|
|
|
|
|
(long unsigned int) track_mode);
|
2004-02-08 03:00:37 +00:00
|
|
|
|
free(footer_buf);
|
2003-12-28 08:33:45 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-01-03 13:50:17 +00:00
|
|
|
|
if (_len % blocksize != 0) {
|
2004-06-01 10:43:23 +00:00
|
|
|
|
cdio_log (log_level,
|
|
|
|
|
|
"length is not a multiple of blocksize "
|
2004-02-01 15:45:30 +00:00
|
|
|
|
"len %lu, size %d, rem %lu",
|
2004-02-01 15:53:06 +00:00
|
|
|
|
(long unsigned int) _len, blocksize,
|
|
|
|
|
|
(long unsigned int) _len % blocksize);
|
2004-01-03 13:50:17 +00:00
|
|
|
|
if (0 == _len % CDIO_CD_FRAMESIZE) {
|
2004-06-01 10:43:23 +00:00
|
|
|
|
cdio_log(log_level, "Adjusting blocksize to %d",
|
|
|
|
|
|
CDIO_CD_FRAMESIZE);
|
2004-01-03 13:50:17 +00:00
|
|
|
|
blocksize = CDIO_CD_FRAMESIZE;
|
|
|
|
|
|
} else if (0 == _len % M2RAW_SECTOR_SIZE) {
|
2004-06-01 10:43:23 +00:00
|
|
|
|
cdio_log(log_level,
|
|
|
|
|
|
"Adjusting blocksize to %d", M2RAW_SECTOR_SIZE);
|
2004-01-03 13:50:17 +00:00
|
|
|
|
blocksize = M2RAW_SECTOR_SIZE;
|
|
|
|
|
|
} else if (0 == _len % CDIO_CD_FRAMESIZE_RAW) {
|
2004-06-01 10:43:23 +00:00
|
|
|
|
cdio_log(log_level,
|
|
|
|
|
|
"Adjusting blocksize to %d", CDIO_CD_FRAMESIZE_RAW);
|
2004-01-03 13:50:17 +00:00
|
|
|
|
blocksize = CDIO_CD_FRAMESIZE_RAW;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2003-12-28 08:33:45 +00:00
|
|
|
|
_len /= blocksize;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-01-03 13:50:17 +00:00
|
|
|
|
if (_start * blocksize != _start2) {
|
2004-06-01 10:43:23 +00:00
|
|
|
|
cdio_log (log_level,
|
|
|
|
|
|
"%lu * %d != %lu",
|
2004-02-01 15:53:06 +00:00
|
|
|
|
(long unsigned int) _start, blocksize,
|
|
|
|
|
|
(long unsigned int) _start2);
|
2004-01-03 13:50:17 +00:00
|
|
|
|
if (_start * CDIO_CD_FRAMESIZE == _start2) {
|
2004-06-01 10:43:23 +00:00
|
|
|
|
cdio_log(log_level,
|
|
|
|
|
|
"Adjusting blocksize to %d", CDIO_CD_FRAMESIZE);
|
2004-01-03 13:50:17 +00:00
|
|
|
|
blocksize = CDIO_CD_FRAMESIZE;
|
|
|
|
|
|
} else if (_start * M2RAW_SECTOR_SIZE == _start2) {
|
2004-06-01 10:43:23 +00:00
|
|
|
|
cdio_log(log_level,
|
|
|
|
|
|
"Adjusting blocksize to %d", M2RAW_SECTOR_SIZE);
|
2004-01-03 13:50:17 +00:00
|
|
|
|
blocksize = M2RAW_SECTOR_SIZE;
|
|
|
|
|
|
} else if (0 == _start * CDIO_CD_FRAMESIZE_RAW == _start2) {
|
2004-06-01 10:43:23 +00:00
|
|
|
|
cdio_log(log_level,
|
|
|
|
|
|
"Adjusting blocksize to %d", CDIO_CD_FRAMESIZE_RAW);
|
2004-01-03 13:50:17 +00:00
|
|
|
|
blocksize = CDIO_CD_FRAMESIZE_RAW;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
_start += idx * CDIO_PREGAP_SECTORS;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
_register_mapping (p_env, _start, _len, _start2, blocksize,
|
2004-06-14 09:52:17 +00:00
|
|
|
|
track_format, track_green, 0);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case SINF_ID: { /* "SINF" */
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t *_sessions = (void *) chunk->data;
|
|
|
|
|
|
|
|
|
|
|
|
cdio_assert (UINT32_FROM_BE (chunk->len) == 4);
|
|
|
|
|
|
|
2003-09-14 07:02:17 +00:00
|
|
|
|
cdio_debug ("SINF: %lu sessions",
|
|
|
|
|
|
(long unsigned int) UINT32_FROM_BE (*_sessions));
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2003-10-07 03:11:38 +00:00
|
|
|
|
case MTYP_ID: { /* "MTYP" */
|
|
|
|
|
|
uint32_t *mtyp_p = (void *) chunk->data;
|
|
|
|
|
|
uint32_t mtyp = UINT32_FROM_BE (*mtyp_p);
|
|
|
|
|
|
|
|
|
|
|
|
cdio_assert (UINT32_FROM_BE (chunk->len) == 4);
|
|
|
|
|
|
|
2003-11-09 15:50:50 +00:00
|
|
|
|
cdio_debug ("MTYP: %lu",
|
|
|
|
|
|
(long unsigned int) UINT32_FROM_BE (*mtyp_p));
|
|
|
|
|
|
|
2003-10-07 03:11:38 +00:00
|
|
|
|
if (mtyp != MTYP_AUDIO_CD) {
|
2004-06-01 10:43:23 +00:00
|
|
|
|
cdio_log (log_level,
|
|
|
|
|
|
"Unknown MTYP value: %u", (unsigned int) mtyp);
|
2003-10-07 03:11:38 +00:00
|
|
|
|
}
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->mtyp = mtyp;
|
2003-10-07 03:11:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2004-07-01 09:50:59 +00:00
|
|
|
|
case CDTX_ID: { /* "CD TEXT" */
|
|
|
|
|
|
|
|
|
|
|
|
cdio_log (log_level,
|
|
|
|
|
|
"Don't know how to handle CD TEXT yet" );
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
default:
|
2004-06-01 10:43:23 +00:00
|
|
|
|
cdio_log (log_level,
|
|
|
|
|
|
"unknown tag %8.8x seen",
|
|
|
|
|
|
(unsigned int) UINT32_FROM_BE (chunk->id));
|
2003-03-24 19:01:09 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (break_out)
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
pos += 8;
|
|
|
|
|
|
pos += UINT32_FROM_BE (chunk->len);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Fake out leadout track. */
|
2004-04-25 14:48:17 +00:00
|
|
|
|
/* Don't use _stat_size_nrg since that will lead to recursion since
|
2003-03-24 19:01:09 +00:00
|
|
|
|
we haven't fully initialized things yet.
|
|
|
|
|
|
*/
|
2004-12-17 04:57:14 +00:00
|
|
|
|
cdio_lsn_to_msf (p_env->size, &p_env->tocent[p_env->gen.i_tracks].start_msf);
|
|
|
|
|
|
p_env->tocent[p_env->gen.i_tracks].start_lba = cdio_lsn_to_lba(p_env->size);
|
|
|
|
|
|
p_env->tocent[p_env->gen.i_tracks-1].sec_count =
|
|
|
|
|
|
cdio_lsn_to_lba(p_env->size - p_env->tocent[p_env->gen.i_tracks-1].start_lba);
|
|
|
|
|
|
|
|
|
|
|
|
p_env->gen.b_cdtext_init = true;
|
|
|
|
|
|
p_env->gen.b_cdtext_error = false;
|
|
|
|
|
|
p_env->gen.toc_init = true;
|
2004-02-08 03:00:37 +00:00
|
|
|
|
free(footer_buf);
|
2003-12-28 08:33:45 +00:00
|
|
|
|
return true;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Initialize image structures.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static bool
|
2004-12-17 04:57:14 +00:00
|
|
|
|
_init_nrg (_img_private_t *p_env)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-12-17 04:57:14 +00:00
|
|
|
|
if (p_env->gen.init) {
|
2003-03-24 19:01:09 +00:00
|
|
|
|
cdio_error ("init called more than once");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
if (!(p_env->gen.data_source = cdio_stdio_new (p_env->gen.source_name))) {
|
2004-06-01 10:43:23 +00:00
|
|
|
|
cdio_warn ("can't open nrg image file %s for reading",
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->gen.source_name);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->psz_mcn = NULL;
|
|
|
|
|
|
p_env->disc_mode = CDIO_DISC_MODE_NO_INFO;
|
2004-07-11 14:25:07 +00:00
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
cdtext_init (&(p_env->gen.cdtext));
|
2004-07-11 02:28:06 +00:00
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
if ( !parse_nrg (p_env, p_env->gen.source_name) ) {
|
2004-06-01 10:43:23 +00:00
|
|
|
|
cdio_warn ("image file %s is not a Nero image",
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->gen.source_name);
|
2004-06-01 10:43:23 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->gen.init = true;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-29 17:32:00 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
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 10:43:23 +00:00
|
|
|
|
_lseek_nrg (void *user_data, off_t offset, int whence)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
{
|
2004-12-17 04:57:14 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
|
|
|
|
|
/* real_offset is the real byte offset inside the disk image
|
2003-12-30 11:52:49 +00:00
|
|
|
|
The number below was determined empirically.
|
2003-03-29 17:32:00 +00:00
|
|
|
|
*/
|
2004-12-17 04:57:14 +00:00
|
|
|
|
off_t real_offset= p_env->is_dao ? 0x4b000 : 0;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
|
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
for (i=0; i<p_env->gen.i_tracks; i++) {
|
|
|
|
|
|
track_info_t *this_track=&(p_env->tocent[i]);
|
|
|
|
|
|
p_env->pos.index = i;
|
2003-12-31 03:09:31 +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;
|
|
|
|
|
|
real_offset += block_offset + rem;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->pos.buff_offset = rem;
|
|
|
|
|
|
p_env->pos.lba += blocks;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2003-12-31 03:09:31 +00:00
|
|
|
|
real_offset += this_track->sec_count*this_track->blocksize;
|
|
|
|
|
|
offset -= this_track->sec_count*this_track->datasize;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
p_env->pos.lba += this_track->sec_count;
|
2003-03-29 17:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
if (i==p_env->gen.i_tracks) {
|
2003-03-29 17:32:00 +00:00
|
|
|
|
cdio_warn ("seeking outside range of disk image");
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
} else
|
2004-12-17 04:57:14 +00:00
|
|
|
|
real_offset += p_env->tocent[i].datastart;
|
|
|
|
|
|
return cdio_stream_seek(p_env->gen.data_source, real_offset, whence);
|
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 10:43:23 +00:00
|
|
|
|
_read_nrg (void *user_data, void *buf, size_t size)
|
2003-03-29 17:32:00 +00:00
|
|
|
|
{
|
2004-12-17 04:57:14 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
|
|
|
|
|
return cdio_stream_read(p_env->gen.data_source, buf, size, 1);
|
2003-03-29 17:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
static uint32_t
|
2004-06-01 10:43:23 +00:00
|
|
|
|
_stat_size_nrg (void *user_data)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-12-17 04:57:14 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
return p_env->size;
|
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-04-07 11:25:40 +00:00
|
|
|
|
static int
|
2004-06-01 10:43:23 +00:00
|
|
|
|
_read_audio_sectors_nrg (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-12-17 04:57:14 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2003-04-10 07:22:56 +00:00
|
|
|
|
|
|
|
|
|
|
CdioListNode *node;
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
if (lsn >= p_env->size)
|
2003-04-10 07:22:56 +00:00
|
|
|
|
{
|
2003-09-14 07:02:17 +00:00
|
|
|
|
cdio_warn ("trying to read beyond image size (%lu >= %lu)",
|
2004-12-17 04:57:14 +00:00
|
|
|
|
(long unsigned int) lsn, (long unsigned int) p_env->size);
|
2003-04-10 07:22:56 +00:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
_CDIO_LIST_FOREACH (node, p_env->mapping) {
|
2003-04-10 07:22:56 +00:00
|
|
|
|
_mapping_t *_map = _cdio_list_node_data (node);
|
|
|
|
|
|
|
|
|
|
|
|
if (IN (lsn, _map->start_lsn, (_map->start_lsn + _map->sec_count - 1))) {
|
|
|
|
|
|
int ret;
|
|
|
|
|
|
long int img_offset = _map->img_offset;
|
|
|
|
|
|
|
|
|
|
|
|
img_offset += (lsn - _map->start_lsn) * CDIO_CD_FRAMESIZE_RAW;
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
ret = cdio_stream_seek (p_env->gen.data_source, img_offset,
|
2003-04-10 07:22:56 +00:00
|
|
|
|
SEEK_SET);
|
|
|
|
|
|
if (ret!=0) return ret;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
ret = cdio_stream_read (p_env->gen.data_source, data,
|
2003-09-20 12:34:02 +00:00
|
|
|
|
CDIO_CD_FRAMESIZE_RAW, nblocks);
|
2003-04-10 07:22:56 +00:00
|
|
|
|
if (ret==0) return ret;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-09-14 07:02:17 +00:00
|
|
|
|
if (!node) cdio_warn ("reading into pre gap (lsn %lu)",
|
|
|
|
|
|
(long unsigned int) lsn);
|
2003-04-10 07:22:56 +00:00
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-03-06 03:22:50 +00:00
|
|
|
|
static int
|
2004-06-01 10:43:23 +00:00
|
|
|
|
_read_mode1_sector_nrg (void *user_data, void *data, lsn_t lsn,
|
2004-03-06 18:22:07 +00:00
|
|
|
|
bool b_form2)
|
2004-03-06 03:22:50 +00:00
|
|
|
|
{
|
2004-12-17 04:57:14 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2004-03-06 03:22:50 +00:00
|
|
|
|
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
|
|
|
|
|
|
|
|
|
|
|
|
CdioListNode *node;
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
if (lsn >= p_env->size)
|
2004-03-06 03:22:50 +00:00
|
|
|
|
{
|
|
|
|
|
|
cdio_warn ("trying to read beyond image size (%lu >= %lu)",
|
2004-12-17 04:57:14 +00:00
|
|
|
|
(long unsigned int) lsn, (long unsigned int) p_env->size);
|
2004-03-06 03:22:50 +00:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
_CDIO_LIST_FOREACH (node, p_env->mapping) {
|
2004-03-06 03:22:50 +00:00
|
|
|
|
_mapping_t *_map = _cdio_list_node_data (node);
|
|
|
|
|
|
|
|
|
|
|
|
if (IN (lsn, _map->start_lsn, (_map->start_lsn + _map->sec_count - 1))) {
|
|
|
|
|
|
int ret;
|
|
|
|
|
|
long int img_offset = _map->img_offset;
|
|
|
|
|
|
|
|
|
|
|
|
img_offset += (lsn - _map->start_lsn) * _map->blocksize;
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
ret = cdio_stream_seek (p_env->gen.data_source, img_offset,
|
2004-03-06 03:22:50 +00:00
|
|
|
|
SEEK_SET);
|
|
|
|
|
|
if (ret!=0) return ret;
|
|
|
|
|
|
|
|
|
|
|
|
/* FIXME: Not completely sure the below is correct. */
|
2004-12-17 04:57:14 +00:00
|
|
|
|
ret = cdio_stream_read (p_env->gen.data_source,
|
2004-03-06 03:22:50 +00:00
|
|
|
|
(M2RAW_SECTOR_SIZE == _map->blocksize)
|
|
|
|
|
|
? (buf + CDIO_CD_SYNC_SIZE + CDIO_CD_HEADER_SIZE)
|
|
|
|
|
|
: buf,
|
|
|
|
|
|
_map->blocksize, 1);
|
|
|
|
|
|
if (ret==0) return ret;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!node)
|
|
|
|
|
|
cdio_warn ("reading into pre gap (lsn %lu)", (long unsigned int) lsn);
|
|
|
|
|
|
|
|
|
|
|
|
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-06 03:22:50 +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 10:43:23 +00:00
|
|
|
|
_read_mode1_sectors_nrg (void *user_data, void *data, lsn_t lsn,
|
2004-05-11 02:15:42 +00:00
|
|
|
|
bool b_form2, unsigned nblocks)
|
2004-03-06 03:22:50 +00:00
|
|
|
|
{
|
2004-12-17 04:57:14 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2004-03-06 03:22:50 +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-06 03:22:50 +00:00
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nblocks; i++) {
|
2004-12-17 04:57:14 +00:00
|
|
|
|
if ( (retval = _read_mode1_sector_nrg (p_env,
|
2004-03-06 03:22:50 +00:00
|
|
|
|
((char *)data) + (blocksize * i),
|
2004-03-06 18:22:07 +00:00
|
|
|
|
lsn + i, b_form2)) )
|
2004-03-06 03:22:50 +00:00
|
|
|
|
return retval;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-04-10 07:22:56 +00:00
|
|
|
|
static int
|
2004-06-01 10:43:23 +00:00
|
|
|
|
_read_mode2_sector_nrg (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-12-17 04:57:14 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2003-04-06 17:57:20 +00:00
|
|
|
|
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
|
2003-04-07 11:25:40 +00:00
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
CdioListNode *node;
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
if (lsn >= p_env->size)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2003-09-14 07:02:17 +00:00
|
|
|
|
cdio_warn ("trying to read beyond image size (%lu >= %lu)",
|
2004-12-17 04:57:14 +00:00
|
|
|
|
(long unsigned int) lsn, (long unsigned int) p_env->size);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
_CDIO_LIST_FOREACH (node, p_env->mapping) {
|
2003-04-10 07:22:56 +00:00
|
|
|
|
_mapping_t *_map = _cdio_list_node_data (node);
|
|
|
|
|
|
|
|
|
|
|
|
if (IN (lsn, _map->start_lsn, (_map->start_lsn + _map->sec_count - 1))) {
|
|
|
|
|
|
int ret;
|
|
|
|
|
|
long int img_offset = _map->img_offset;
|
|
|
|
|
|
|
2003-12-30 11:52:49 +00:00
|
|
|
|
img_offset += (lsn - _map->start_lsn) * _map->blocksize;
|
2003-04-10 07:22:56 +00:00
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
ret = cdio_stream_seek (p_env->gen.data_source, img_offset,
|
2003-04-10 07:22:56 +00:00
|
|
|
|
SEEK_SET);
|
|
|
|
|
|
if (ret!=0) return ret;
|
2004-12-17 04:57:14 +00:00
|
|
|
|
ret = cdio_stream_read (p_env->gen.data_source,
|
2003-12-30 11:52:49 +00:00
|
|
|
|
(M2RAW_SECTOR_SIZE == _map->blocksize)
|
2003-04-10 07:22:56 +00:00
|
|
|
|
? (buf + CDIO_CD_SYNC_SIZE + CDIO_CD_HEADER_SIZE)
|
|
|
|
|
|
: buf,
|
2003-12-30 11:52:49 +00:00
|
|
|
|
_map->blocksize, 1);
|
2003-04-10 07:22:56 +00:00
|
|
|
|
if (ret==0) return ret;
|
|
|
|
|
|
break;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
2003-04-10 07:22:56 +00:00
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
if (!node)
|
2003-09-14 07:02:17 +00:00
|
|
|
|
cdio_warn ("reading into pre gap (lsn %lu)", (long unsigned int) lsn);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-03-06 18:22:07 +00:00
|
|
|
|
if (b_form2)
|
2003-04-06 18:12:37 +00:00
|
|
|
|
memcpy (data, buf + CDIO_CD_SYNC_SIZE + CDIO_CD_HEADER_SIZE,
|
|
|
|
|
|
M2RAW_SECTOR_SIZE);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
else
|
2003-04-06 18:12:37 +00:00
|
|
|
|
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 10:43:23 +00:00
|
|
|
|
_read_mode2_sectors_nrg (void *user_data, void *data, lsn_t lsn,
|
2004-05-11 02:15:42 +00:00
|
|
|
|
bool b_form2, unsigned nblocks)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-12-17 04:57:14 +00:00
|
|
|
|
_img_private_t *p_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-12-17 04:57:14 +00:00
|
|
|
|
if ( (retval = _read_mode2_sector_nrg (p_env,
|
2004-03-06 03:22:50 +00:00
|
|
|
|
((char *)data) + (blocksize * i),
|
2004-03-06 18:22:07 +00:00
|
|
|
|
lsn + i, b_form2)) )
|
2004-03-06 03:22:50 +00:00
|
|
|
|
return retval;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-02-26 02:31:24 +00:00
|
|
|
|
/*
|
|
|
|
|
|
Free memory resources associated with NRG object.
|
|
|
|
|
|
*/
|
2004-02-08 03:00:37 +00:00
|
|
|
|
static void
|
2004-06-01 10:43:23 +00:00
|
|
|
|
_free_nrg (void *user_data)
|
2004-02-08 03:00:37 +00:00
|
|
|
|
{
|
2004-12-17 04:57:14 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2004-02-08 03:00:37 +00:00
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
if (NULL == p_env) return;
|
|
|
|
|
|
if (NULL != p_env->mapping)
|
|
|
|
|
|
_cdio_list_free (p_env->mapping, true);
|
2004-07-10 11:06:00 +00:00
|
|
|
|
|
|
|
|
|
|
/* The remaining part of the image is like the other image drivers,
|
|
|
|
|
|
so free that in the same way. */
|
|
|
|
|
|
_free_image(user_data);
|
2004-02-08 03:00:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-04-25 14:48:17 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Eject media -- there's nothing to do here except free resources.
|
|
|
|
|
|
We always return 2.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static int
|
|
|
|
|
|
_eject_media_nrg(void *obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
_free_nrg (obj);
|
|
|
|
|
|
return 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
/*!
|
2003-09-30 03:26:11 +00:00
|
|
|
|
Return an array of strings giving possible NRG disk images.
|
2003-03-24 19:01:09 +00:00
|
|
|
|
*/
|
2003-09-30 03:26:11 +00:00
|
|
|
|
char **
|
|
|
|
|
|
cdio_get_devices_nrg (void)
|
2003-09-29 02:56:22 +00:00
|
|
|
|
{
|
|
|
|
|
|
char **drives = NULL;
|
|
|
|
|
|
unsigned int num_files=0;
|
|
|
|
|
|
#ifdef HAVE_GLOB_H
|
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
glob_t globbuf;
|
|
|
|
|
|
globbuf.gl_offs = 0;
|
|
|
|
|
|
glob("*.nrg", 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-04-10 04:13:41 +00:00
|
|
|
|
char *
|
2003-09-29 02:56:22 +00:00
|
|
|
|
cdio_get_default_device_nrg(void)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2003-09-30 03:26:11 +00:00
|
|
|
|
char **drives = cdio_get_devices_nrg();
|
2003-09-29 02:56:22 +00:00
|
|
|
|
char *drive = (drives[0] == NULL) ? NULL : strdup(drives[0]);
|
|
|
|
|
|
cdio_free_device_list(drives);
|
|
|
|
|
|
return drive;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-09-04 00:06:50 +00:00
|
|
|
|
static bool
|
|
|
|
|
|
get_hwinfo_nrg ( const CdIo *p_cdio, /*out*/ cdio_hwinfo_t *hw_info)
|
|
|
|
|
|
{
|
|
|
|
|
|
strcpy(hw_info->psz_vendor, "libcdio");
|
|
|
|
|
|
strcpy(hw_info->psz_model, "Nero");
|
|
|
|
|
|
strcpy(hw_info->psz_revision, CDIO_VERSION);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-09-04 00:06:50 +00:00
|
|
|
|
get_track_format_nrg(void *user_data, track_t track_num)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-12-17 04:57:14 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
if (track_num > p_env->gen.i_tracks || track_num == 0)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return TRACK_FORMAT_ERROR;
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
if ( p_env->dtyp != DTYP_INVALID) {
|
|
|
|
|
|
switch (p_env->dtyp) {
|
2003-12-28 08:33:45 +00:00
|
|
|
|
case DTYP_MODE2_XA:
|
|
|
|
|
|
return TRACK_FORMAT_XA;
|
|
|
|
|
|
case DTYP_MODE1:
|
|
|
|
|
|
return TRACK_FORMAT_DATA;
|
|
|
|
|
|
default: ;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
/*if ( MTYP_AUDIO_CD == p_env->mtyp) return TRACK_FORMAT_AUDIO; */
|
|
|
|
|
|
return p_env->tocent[track_num-1].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 10:43:23 +00:00
|
|
|
|
_get_track_green_nrg(void *user_data, track_t track_num)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-12-17 04:57:14 +00:00
|
|
|
|
_img_private_t *p_env = user_data;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
if (track_num > p_env->gen.i_tracks || track_num == 0)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
2004-12-17 04:57:14 +00:00
|
|
|
|
if ( MTYP_AUDIO_CD == p_env->mtyp) return false;
|
|
|
|
|
|
return p_env->tocent[track_num-1].track_green;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-05-09 16:52:20 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Check that a NRG file is valid.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
/* Later we'll probably do better. For now though, this gets us
|
|
|
|
|
|
started for now.
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool
|
|
|
|
|
|
cdio_is_nrg(const char *psz_nrg)
|
|
|
|
|
|
{
|
2004-06-01 10:43:23 +00:00
|
|
|
|
unsigned int i;
|
2004-05-09 16:52:20 +00:00
|
|
|
|
|
|
|
|
|
|
if (psz_nrg == NULL) return false;
|
|
|
|
|
|
|
|
|
|
|
|
i=strlen(psz_nrg)-strlen("nrg");
|
|
|
|
|
|
|
|
|
|
|
|
if (i>0) {
|
|
|
|
|
|
if (psz_nrg[i]=='n' && psz_nrg[i+1]=='r' && psz_nrg[i+2]=='g') {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (psz_nrg[i]=='N' && psz_nrg[i+1]=='R' && psz_nrg[i+2]=='G') {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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_nrg (const char *psz_source_name, const char *psz_access_mode)
|
|
|
|
|
|
{
|
2004-05-13 01:50:10 +00:00
|
|
|
|
if (psz_access_mode != NULL && strcmp(psz_access_mode, "image"))
|
2004-04-30 06:54:15 +00:00
|
|
|
|
cdio_warn ("there is only one access mode for nrg. Arg %s ignored",
|
|
|
|
|
|
psz_access_mode);
|
|
|
|
|
|
return cdio_open_nrg(psz_source_name);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
CdIo *
|
2004-05-09 16:52:20 +00:00
|
|
|
|
cdio_open_nrg (const char *psz_source)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
CdIo *ret;
|
|
|
|
|
|
_img_private_t *_data;
|
|
|
|
|
|
|
2004-09-03 23:20:11 +00:00
|
|
|
|
cdio_funcs _funcs;
|
|
|
|
|
|
|
2004-10-31 06:07:26 +00:00
|
|
|
|
memset( &_funcs, 0, sizeof(_funcs) );
|
|
|
|
|
|
|
2004-09-03 23:20:11 +00:00
|
|
|
|
_funcs.eject_media = _eject_media_nrg;
|
|
|
|
|
|
_funcs.free = _free_nrg;
|
|
|
|
|
|
_funcs.get_arg = _get_arg_image;
|
|
|
|
|
|
_funcs.get_cdtext = get_cdtext_generic;
|
|
|
|
|
|
_funcs.get_devices = cdio_get_devices_nrg;
|
|
|
|
|
|
_funcs.get_default_device = cdio_get_default_device_nrg;
|
|
|
|
|
|
_funcs.get_discmode = _get_discmode_image;
|
|
|
|
|
|
_funcs.get_drive_cap = _get_drive_cap_image;
|
|
|
|
|
|
_funcs.get_first_track_num= _get_first_track_num_image;
|
2004-09-04 00:06:50 +00:00
|
|
|
|
_funcs.get_hwinfo = get_hwinfo_nrg;
|
2004-09-03 23:20:11 +00:00
|
|
|
|
_funcs.get_mcn = _get_mcn_image;
|
|
|
|
|
|
_funcs.get_num_tracks = _get_num_tracks_image;
|
2004-09-04 00:06:50 +00:00
|
|
|
|
_funcs.get_track_format = get_track_format_nrg;
|
2004-09-03 23:20:11 +00:00
|
|
|
|
_funcs.get_track_green = _get_track_green_nrg;
|
|
|
|
|
|
_funcs.get_track_lba = NULL; /* Will use generic routine via msf */
|
|
|
|
|
|
_funcs.get_track_msf = _get_track_msf_image;
|
|
|
|
|
|
_funcs.lseek = _lseek_nrg;
|
|
|
|
|
|
_funcs.read = _read_nrg;
|
|
|
|
|
|
_funcs.read_audio_sectors = _read_audio_sectors_nrg;
|
|
|
|
|
|
_funcs.read_mode1_sector = _read_mode1_sector_nrg;
|
|
|
|
|
|
_funcs.read_mode1_sectors = _read_mode1_sectors_nrg;
|
|
|
|
|
|
_funcs.read_mode2_sector = _read_mode2_sector_nrg;
|
|
|
|
|
|
_funcs.read_mode2_sectors = _read_mode2_sectors_nrg;
|
|
|
|
|
|
_funcs.set_arg = _set_arg_image;
|
|
|
|
|
|
_funcs.stat_size = _stat_size_nrg;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-07-29 02:16:20 +00:00
|
|
|
|
_data = _cdio_malloc (sizeof (_img_private_t));
|
|
|
|
|
|
_data->gen.init = false;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-07-29 02:16:20 +00:00
|
|
|
|
_data->gen.i_tracks = 0;
|
|
|
|
|
|
_data->mtyp = 0;
|
|
|
|
|
|
_data->dtyp = DTYP_INVALID;
|
|
|
|
|
|
_data->gen.i_first_track= 1;
|
|
|
|
|
|
_data->is_dao = false;
|
|
|
|
|
|
_data->is_cues = false; /* FIXME: remove is_cues. */
|
2003-04-21 23:24:46 +00:00
|
|
|
|
|
2004-07-26 02:54:37 +00:00
|
|
|
|
ret = cdio_new ((void *)_data, &_funcs);
|
2004-05-09 16:52:20 +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-10 11:06:00 +00:00
|
|
|
|
_set_arg_image(_data, "source", (NULL == psz_source)
|
|
|
|
|
|
? DEFAULT_CDIO_DEVICE: psz_source);
|
|
|
|
|
|
|
|
|
|
|
|
_data->psz_cue_name = strdup(_get_arg_image(_data, "source"));
|
|
|
|
|
|
|
|
|
|
|
|
if (!cdio_is_nrg(_data->psz_cue_name)) {
|
2004-05-09 16:52:20 +00:00
|
|
|
|
cdio_debug ("source name %s is not recognized as a NRG image",
|
2004-07-10 11:06:00 +00:00
|
|
|
|
_data->psz_cue_name);
|
|
|
|
|
|
_free_nrg(_data);
|
2004-05-09 16:52:20 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-07-10 11:06:00 +00:00
|
|
|
|
_set_arg_image (_data, "cue", _data->psz_cue_name);
|
|
|
|
|
|
|
2004-06-01 10:43:23 +00:00
|
|
|
|
if (_init_nrg(_data))
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return ret;
|
|
|
|
|
|
else {
|
2004-06-01 10:43:23 +00:00
|
|
|
|
_free_nrg(_data);
|
2004-07-10 11:06:00 +00:00
|
|
|
|
free(ret);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
cdio_have_nrg (void)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|