Straighten out mode1 vs mode2 mess.

This commit is contained in:
rocky
2003-08-31 14:26:06 +00:00
parent c031e71702
commit 19c7de3990
8 changed files with 122 additions and 68 deletions

View File

@@ -1,5 +1,5 @@
/* -*- c -*- /* -*- c -*-
$Id: cdio.h,v 1.16 2003/07/27 22:52:22 rocky Exp $ $Id: cdio.h,v 1.17 2003/08/31 14:26:06 rocky Exp $
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org> Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2003 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003 Rocky Bernstein <rocky@panix.com>
@@ -222,20 +222,27 @@ extern "C" {
Reads a single mode1 sector from cd device into data starting Reads a single mode1 sector from cd device into data starting
from lsn. Returns 0 if no error. from lsn. Returns 0 if no error.
*/ */
int cdio_read_yellow_sector (CdIo *obj, void *buf, lsn_t lsn, bool mode1); int cdio_read_mode1_sector (CdIo *obj, void *buf, lsn_t lsn, bool is_form2);
/*!
Reads nblocks of mode1 sectors from cd device into data starting
from lsn. Returns 0 if no error.
*/
int cdio_read_mode1_sectors (CdIo *obj, void *buf, lsn_t lsn, bool is_form2,
unsigned int num_sectors);
/*! /*!
Reads a single mode2 sector from cd device into data starting Reads a single mode2 sector from cd device into data starting
from lsn. Returns 0 if no error. from lsn. Returns 0 if no error.
*/ */
int cdio_read_mode2_sector (CdIo *obj, void *buf, lsn_t lsn, bool mode2raw); int cdio_read_mode2_sector (CdIo *obj, void *buf, lsn_t lsn, bool is_form2);
/*! /*!
Reads nblocks of mode2 sectors from cd device into data starting Reads nblocks of mode2 sectors from cd device into data starting
from lsn. from lsn.
Returns 0 if no error. Returns 0 if no error.
*/ */
int cdio_read_mode2_sectors (CdIo *obj, void *buf, lsn_t lsn, bool mode2raw, int cdio_read_mode2_sectors (CdIo *obj, void *buf, lsn_t lsn, bool is_form2,
unsigned int num_sectors); unsigned int num_sectors);
/*! /*!

View File

@@ -1,5 +1,5 @@
/* /*
$Id: iso9660.h,v 1.12 2003/08/31 09:32:24 rocky Exp $ $Id: iso9660.h,v 1.13 2003/08/31 14:26:06 rocky Exp $
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org> Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2003 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003 Rocky Bernstein <rocky@panix.com>
@@ -174,10 +174,11 @@ unsigned
iso9660_dir_calc_record_size (unsigned namelen, unsigned int su_len); iso9660_dir_calc_record_size (unsigned namelen, unsigned int su_len);
int int
iso9660_fs_stat (CdIo *obj,const char pathname[], iso9660_stat_t *buf); iso9660_fs_stat (CdIo *obj,const char pathname[], iso9660_stat_t *buf,
bool is_mode2);
void * /* list of char* -- caller must free it */ void * /* list of char* -- caller must free it */
iso9660_fs_readdir (CdIo *obj, const char pathname[]); iso9660_fs_readdir (CdIo *obj, const char pathname[], bool mode2);
uint8_t uint8_t
iso9660_get_dir_len(const iso9660_dir_t *idr); iso9660_get_dir_len(const iso9660_dir_t *idr);

View File

@@ -1,5 +1,5 @@
/* /*
$Id: sector.h,v 1.3 2003/05/26 03:11:06 rocky Exp $ $Id: sector.h,v 1.4 2003/08/31 14:26:06 rocky Exp $
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org> Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2003 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003 Rocky Bernstein <rocky@panix.com>
@@ -43,9 +43,9 @@
* format sector type user data size (bytes) * format sector type user data size (bytes)
* ----------------------------------------------------------------------------- * -----------------------------------------------------------------------------
* 1 (Red Book) CD-DA 2352 (CDIO_CD_FRAMESIZE_RAW) * 1 (Red Book) CD-DA 2352 (CDIO_CD_FRAMESIZE_RAW)
* 2 (Yellow Book) Mode1 Form1 2048 (M1F1_SECTOR_SIZE) * 2 (Yellow Book) Mode1 Form1 2048 (CDIO_CD_FRAMESIZE)
* 3 (Yellow Book) Mode1 Form2 2336 (M2RAW_SECTOR_SIZE) * 3 (Yellow Book) Mode1 Form2 2336 (M2RAW_SECTOR_SIZE)
* 4 (Green Book) Mode2 Form1 2048 (M2F1_SECTOR_SIZE) * 4 (Green Book) Mode2 Form1 2048 (CDIO_CD_FRAMESIZE)
* 5 (Green Book) Mode2 Form2 2328 (2324+4 spare bytes) * 5 (Green Book) Mode2 Form2 2328 (2324+4 spare bytes)
* *
* *

View File

@@ -1,5 +1,5 @@
/* /*
$Id: _cdio_bincue.c,v 1.22 2003/07/27 22:52:22 rocky Exp $ $Id: _cdio_bincue.c,v 1.23 2003/08/31 14:26:06 rocky Exp $
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org> Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2002,2003 Rocky Bernstein <rocky@panix.com> Copyright (C) 2002,2003 Rocky Bernstein <rocky@panix.com>
@@ -28,7 +28,7 @@
# include "config.h" # include "config.h"
#endif #endif
static const char _rcsid[] = "$Id: _cdio_bincue.c,v 1.22 2003/07/27 22:52:22 rocky Exp $"; static const char _rcsid[] = "$Id: _cdio_bincue.c,v 1.23 2003/08/31 14:26:06 rocky Exp $";
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
@@ -508,7 +508,7 @@ _cdio_read_mode2_sector (void *user_data, void *data, lsn_t lsn,
*/ */
static int static int
_cdio_read_mode2_sectors (void *user_data, void *data, uint32_t lsn, _cdio_read_mode2_sectors (void *user_data, void *data, uint32_t lsn,
bool mode2_form2, unsigned nblocks) bool mode2_form2, unsigned int nblocks)
{ {
_img_private_t *_obj = user_data; _img_private_t *_obj = user_data;
int i; int i;

View File

@@ -1,5 +1,5 @@
/* /*
$Id: cd_types.c,v 1.2 2003/08/31 03:35:36 rocky Exp $ $Id: cd_types.c,v 1.3 2003/08/31 14:26:06 rocky Exp $
Copyright (C) 2003 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003 Rocky Bernstein <rocky@panix.com>
@@ -136,7 +136,7 @@ _cdio_read_block(CdIo *cdio, int superblock, uint32_t offset, uint8_t bufnum,
offset+superblock, false)) offset+superblock, false))
return -1; return -1;
} else { } else {
if (0 > cdio_read_yellow_sector(cdio, buffer[bufnum], if (0 > cdio_read_mode1_sector(cdio, buffer[bufnum],
offset+superblock, false)) offset+superblock, false))
return -1; return -1;
} }

View File

@@ -1,5 +1,5 @@
/* /*
$Id: cdio.c,v 1.21 2003/06/22 22:41:29 rocky Exp $ $Id: cdio.c,v 1.22 2003/08/31 14:26:06 rocky Exp $
Copyright (C) 2003 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003 Rocky Bernstein <rocky@panix.com>
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org> Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
@@ -35,7 +35,7 @@
#include <cdio/logging.h> #include <cdio/logging.h>
#include "cdio_private.h" #include "cdio_private.h"
static const char _rcsid[] = "$Id: cdio.c,v 1.21 2003/06/22 22:41:29 rocky Exp $"; static const char _rcsid[] = "$Id: cdio.c,v 1.22 2003/08/31 14:26:06 rocky Exp $";
const char *track_format2str[6] = const char *track_format2str[6] =
@@ -495,13 +495,13 @@ cdio_read_audio_sector (CdIo *obj, void *buf, lsn_t lsn)
} }
/*! /*!
Reads a single yellow mode1 or mode2 sector from cd device Reads a single mode1 form1 or form2 sector from cd device
into data starting from lsn. Returns 0 if no error. into data starting from lsn. Returns 0 if no error.
*/ */
int int
cdio_read_yellow_sector (CdIo *obj, void *data, uint32_t lsn, bool mode1) cdio_read_mode1_sector (CdIo *obj, void *data, lsn_t lsn, bool is_form2)
{ {
uint32_t size = mode1 ? CDIO_CD_FRAMESIZE : M2RAW_SECTOR_SIZE; uint32_t size = is_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE ;
char buf[M2RAW_SECTOR_SIZE] = { 0, }; char buf[M2RAW_SECTOR_SIZE] = { 0, };
int ret; int ret;
@@ -516,7 +516,7 @@ cdio_read_yellow_sector (CdIo *obj, void *data, uint32_t lsn, bool mode1)
memcpy (data, buf, size); memcpy (data, buf, size);
return 0; return 0;
} else { } else {
ret = cdio_read_mode2_sector(obj, data, lsn, mode1); ret = cdio_read_mode2_sector(obj, data, lsn, is_form2);
if (ret == 0) if (ret == 0)
memcpy (data, buf+CDIO_CD_SUBHEADER_SIZE, size); memcpy (data, buf+CDIO_CD_SUBHEADER_SIZE, size);
} }
@@ -524,6 +524,46 @@ cdio_read_yellow_sector (CdIo *obj, void *data, uint32_t lsn, bool mode1)
} }
int
cdio_read_mode1_sectors (CdIo *obj, void *data, lsn_t lsn, bool is_form2,
unsigned int num_sectors)
{
uint32_t size = is_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE ;
int retval;
int i;
cdio_assert (obj != NULL);
for (i = 0; i < num_sectors; i++) {
if ( (retval = cdio_read_mode1_sector (obj,
((char *)data) + (size * i),
lsn + i, is_form2)) )
return retval;
}
return 0;
}
/*!
Reads a single mode2 sector from cd device into data starting
from lsn. Returns 0 if no error.
*/
int
cdio_read_mode2_sector (CdIo *obj, void *buf, uint32_t lsn, bool is_form2)
{
cdio_assert (obj != NULL);
cdio_assert (buf != NULL);
cdio_assert (obj->op.read_mode2_sector != NULL
|| obj->op.read_mode2_sectors != NULL);
if (obj->op.read_mode2_sector)
return obj->op.read_mode2_sector (obj->user_data, buf, lsn, is_form2);
/* fallback */
if (obj->op.read_mode2_sectors != NULL)
return cdio_read_mode2_sectors (obj, buf, lsn, is_form2, 1);
return 1;
}
int int
cdio_read_mode2_sectors (CdIo *obj, void *buf, lsn_t lsn, bool mode2raw, cdio_read_mode2_sectors (CdIo *obj, void *buf, lsn_t lsn, bool mode2raw,
unsigned num_sectors) unsigned num_sectors)
@@ -536,27 +576,6 @@ cdio_read_mode2_sectors (CdIo *obj, void *buf, lsn_t lsn, bool mode2raw,
mode2raw, num_sectors); mode2raw, num_sectors);
} }
/*!
Reads a single mode2 sector from cd device into data starting
from lsn. Returns 0 if no error.
*/
int
cdio_read_mode2_sector (CdIo *obj, void *buf, uint32_t lsn, bool mode2raw)
{
cdio_assert (obj != NULL);
cdio_assert (buf != NULL);
cdio_assert (obj->op.read_mode2_sector != NULL
|| obj->op.read_mode2_sectors != NULL);
if (obj->op.read_mode2_sector)
return obj->op.read_mode2_sector (obj->user_data, buf, lsn, mode2raw);
/* fallback */
if (obj->op.read_mode2_sectors != NULL)
return cdio_read_mode2_sectors (obj, buf, lsn, mode2raw, 1);
return 1;
}
uint32_t uint32_t
cdio_stat_size (CdIo *obj) cdio_stat_size (CdIo *obj)
{ {

View File

@@ -1,5 +1,5 @@
/* /*
$Id: iso9660_fs.c,v 1.3 2003/08/31 09:11:25 rocky Exp $ $Id: iso9660_fs.c,v 1.4 2003/08/31 14:26:06 rocky Exp $
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org> Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2003 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003 Rocky Bernstein <rocky@panix.com>
@@ -36,7 +36,7 @@
#include "bytesex.h" #include "bytesex.h"
#include "ds.h" #include "ds.h"
static const char _rcsid[] = "$Id: iso9660_fs.c,v 1.3 2003/08/31 09:11:25 rocky Exp $"; static const char _rcsid[] = "$Id: iso9660_fs.c,v 1.4 2003/08/31 14:26:06 rocky Exp $";
static void static void
_idr2statbuf (const iso9660_dir_t *idr, iso9660_stat_t *buf) _idr2statbuf (const iso9660_dir_t *idr, iso9660_stat_t *buf)
@@ -107,14 +107,19 @@ _idr2name (const iso9660_dir_t *idr)
static void static void
_fs_stat_root (CdIo *obj, iso9660_stat_t *buf) _fs_stat_root (CdIo *obj, iso9660_stat_t *buf, bool is_mode2)
{ {
char block[ISO_BLOCKSIZE] = { 0, }; char block[ISO_BLOCKSIZE] = { 0, };
const iso9660_pvd_t *pvd = (void *) &block; const iso9660_pvd_t *pvd = (void *) &block;
const iso9660_dir_t *idr = (void *) pvd->root_directory_record; const iso9660_dir_t *idr = (void *) pvd->root_directory_record;
if (cdio_read_mode2_sector (obj, &block, ISO_PVD_SECTOR, false)) if (is_mode2) {
cdio_assert_not_reached (); if (cdio_read_mode2_sector (obj, &block, ISO_PVD_SECTOR, false))
cdio_assert_not_reached ();
} else {
if (cdio_read_mode1_sector (obj, &block, ISO_PVD_SECTOR, false))
cdio_assert_not_reached ();
}
_idr2statbuf (idr, buf); _idr2statbuf (idr, buf);
} }
@@ -187,8 +192,8 @@ _fs_stat_traverse (CdIo *obj, const iso9660_stat_t *_root, char **splitpath,
} }
int int
iso9660_fs_stat (CdIo *obj, const char pathname[], iso9660_fs_stat (CdIo *obj, const char pathname[], iso9660_stat_t *buf,
iso9660_stat_t *buf) bool is_mode2)
{ {
iso9660_stat_t _root; iso9660_stat_t _root;
int retval; int retval;
@@ -198,7 +203,7 @@ iso9660_fs_stat (CdIo *obj, const char pathname[],
cdio_assert (pathname != NULL); cdio_assert (pathname != NULL);
cdio_assert (buf != NULL); cdio_assert (buf != NULL);
_fs_stat_root (obj, &_root); _fs_stat_root (obj, &_root, is_mode2);
splitpath = _cdio_strsplit (pathname, '/'); splitpath = _cdio_strsplit (pathname, '/');
retval = _fs_stat_traverse (obj, &_root, splitpath, buf); retval = _fs_stat_traverse (obj, &_root, splitpath, buf);
@@ -208,14 +213,14 @@ iso9660_fs_stat (CdIo *obj, const char pathname[],
} }
void * /* list of char* -- caller must free it */ void * /* list of char* -- caller must free it */
iso9660_fs_readdir (CdIo *obj, const char pathname[]) iso9660_fs_readdir (CdIo *obj, const char pathname[], bool is_mode2)
{ {
iso9660_stat_t _stat; iso9660_stat_t _stat;
cdio_assert (obj != NULL); cdio_assert (obj != NULL);
cdio_assert (pathname != NULL); cdio_assert (pathname != NULL);
if (iso9660_fs_stat (obj, pathname, &_stat)) if (iso9660_fs_stat (obj, pathname, &_stat, is_mode2))
return NULL; return NULL;
if (_stat.type != _STAT_DIR) if (_stat.type != _STAT_DIR)
@@ -234,9 +239,15 @@ iso9660_fs_readdir (CdIo *obj, const char pathname[])
_dirbuf = _cdio_malloc (_stat.secsize * ISO_BLOCKSIZE); _dirbuf = _cdio_malloc (_stat.secsize * ISO_BLOCKSIZE);
if (cdio_read_mode2_sectors (obj, _dirbuf, _stat.lsn, false, if (is_mode2) {
if (cdio_read_mode2_sectors (obj, _dirbuf, _stat.lsn, false,
_stat.secsize)) _stat.secsize))
cdio_assert_not_reached (); cdio_assert_not_reached ();
} else {
if (cdio_read_mode1_sectors (obj, _dirbuf, _stat.lsn, false,
_stat.secsize))
cdio_assert_not_reached ();
}
while (offset < (_stat.secsize * ISO_BLOCKSIZE)) while (offset < (_stat.secsize * ISO_BLOCKSIZE))
{ {

View File

@@ -1,5 +1,5 @@
/* /*
$Id: cd-info.c,v 1.26 2003/08/31 08:32:40 rocky Exp $ $Id: cd-info.c,v 1.27 2003/08/31 14:26:06 rocky Exp $
Copyright (C) 2003 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1996,1997,1998 Gerd Knorr <kraxel@bytesex.org> Copyright (C) 1996,1997,1998 Gerd Knorr <kraxel@bytesex.org>
@@ -598,13 +598,14 @@ print_vcd_info(void) {
#endif #endif
static void static void
print_iso9660_recurse (CdIo *cdio, const char pathname[], cdio_fs_anal_t fs) print_iso9660_recurse (CdIo *cdio, const char pathname[], cdio_fs_anal_t fs,
bool is_mode2)
{ {
CdioList *entlist; CdioList *entlist;
CdioList *dirlist = _cdio_list_new (); CdioList *dirlist = _cdio_list_new ();
CdioListNode *entnode; CdioListNode *entnode;
entlist = iso9660_fs_readdir (cdio, pathname); entlist = iso9660_fs_readdir (cdio, pathname, is_mode2);
printf ("%s:\n", pathname); printf ("%s:\n", pathname);
@@ -620,7 +621,7 @@ print_iso9660_recurse (CdIo *cdio, const char pathname[], cdio_fs_anal_t fs)
snprintf (_fullname, sizeof (_fullname), "%s%s", pathname, _name); snprintf (_fullname, sizeof (_fullname), "%s%s", pathname, _name);
if (iso9660_fs_stat (cdio, _fullname, &statbuf)) if (iso9660_fs_stat (cdio, _fullname, &statbuf, is_mode2))
cdio_assert_not_reached (); cdio_assert_not_reached ();
strncat (_fullname, "/", sizeof (_fullname)); strncat (_fullname, "/", sizeof (_fullname));
@@ -660,33 +661,47 @@ print_iso9660_recurse (CdIo *cdio, const char pathname[], cdio_fs_anal_t fs)
{ {
char *_fullname = _cdio_list_node_data (entnode); char *_fullname = _cdio_list_node_data (entnode);
print_iso9660_recurse (cdio, _fullname, fs); print_iso9660_recurse (cdio, _fullname, fs, is_mode2);
} }
_cdio_list_free (dirlist, true); _cdio_list_free (dirlist, true);
} }
static void static void
print_iso9660_fs (CdIo *cdio, cdio_fs_anal_t fs) print_iso9660_fs (CdIo *cdio, cdio_fs_anal_t fs, track_format_t track_format)
{ {
iso9660_pvd_t pvd; iso9660_pvd_t pvd;
if (cdio_read_mode2_sector (cdio, &pvd, ISO_PVD_SECTOR, false)) switch (track_format) {
case TRACK_FORMAT_AUDIO:
case TRACK_FORMAT_PSX:
case TRACK_FORMAT_ERROR:
return; return;
else { case TRACK_FORMAT_CDI:
case TRACK_FORMAT_XA:
if (cdio_read_mode2_sector (cdio, &pvd, ISO_PVD_SECTOR, false))
return;
break;
case TRACK_FORMAT_DATA:
if (cdio_read_mode1_sector (cdio, &pvd, ISO_PVD_SECTOR, true))
return;
}
{
const lsn_t extent = iso9660_get_root_lsn(&pvd); const lsn_t extent = iso9660_get_root_lsn(&pvd);
printf ("ISO9660 filesystem\n"); printf ("ISO9660 filesystem\n");
printf (" root dir in PVD set to lsn %d\n\n", extent); printf (" root dir in PVD set to lsn %d\n\n", extent);
print_iso9660_recurse (cdio, "/", fs); print_iso9660_recurse (cdio, "/", fs, track_format);
} }
} }
static void static void
print_analysis(int ms_offset, cdio_analysis_t cdio_analysis, print_analysis(int ms_offset, cdio_analysis_t cdio_analysis,
cdio_fs_anal_t fs, int first_data, unsigned int num_audio, cdio_fs_anal_t fs, int first_data, unsigned int num_audio,
track_t num_tracks, track_t first_track_num, CdIo *cdio) track_t num_tracks, track_t first_track_num,
track_format_t track_format, CdIo *cdio)
{ {
int need_lf; int need_lf;
@@ -744,7 +759,7 @@ print_analysis(int ms_offset, cdio_analysis_t cdio_analysis,
printf("ISO 9660: %i blocks, label `%.32s'\n", printf("ISO 9660: %i blocks, label `%.32s'\n",
cdio_analysis.isofs_size, cdio_analysis.iso_label); cdio_analysis.isofs_size, cdio_analysis.iso_label);
if (opts.print_iso9660) if (opts.print_iso9660)
print_iso9660_fs(cdio, fs); print_iso9660_fs(cdio, fs, track_format);
break; break;
} }
need_lf = 0; need_lf = 0;
@@ -1034,7 +1049,8 @@ main(int argc, const char *argv[])
} }
} }
print_analysis(ms_offset, cdio_analysis, fs, first_data, num_audio, print_analysis(ms_offset, cdio_analysis, fs, first_data, num_audio,
num_tracks, first_track_num, cdio); num_tracks, first_track_num,
cdio_get_track_format(cdio, 1), cdio);
} else { } else {
/* we have data track(s) */ /* we have data track(s) */
int j; int j;
@@ -1079,7 +1095,7 @@ main(int argc, const char *argv[])
fs |= CDIO_FS_ANAL_MULTISESSION; fs |= CDIO_FS_ANAL_MULTISESSION;
} else { } else {
print_analysis(ms_offset, cdio_analysis, fs, first_data, num_audio, print_analysis(ms_offset, cdio_analysis, fs, first_data, num_audio,
num_tracks, first_track_num, cdio); num_tracks, first_track_num, track_format, cdio);
} }
if ( !(CDIO_FSTYPE(fs) == CDIO_FS_ISO_9660 || if ( !(CDIO_FSTYPE(fs) == CDIO_FS_ISO_9660 ||