From 3f6cba2b0addb0d590ee80e7fd33a1aaf4ed67ce Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 11 May 2004 02:15:42 +0000 Subject: [PATCH] - Redo types of lsn and lba to allow negative values. Should model MMC3 specs. Add max/min values for lsn. - More complete MMC command set --- NEWS | 6 ++++-- include/cdio/scsi_mmc.h | 5 ++++- include/cdio/sector.h | 9 ++++++--- include/cdio/types.h | 25 ++++++++++++++--------- lib/image/bincue.c | 12 +++++------ lib/image/cdrdao.c | 12 +++++------ lib/image/nrg.c | 12 +++++------ lib/sector.c | 45 ++++++++++++++++++++++++++++++----------- 8 files changed, 81 insertions(+), 45 deletions(-) diff --git a/NEWS b/NEWS index 01e39bbf..c98b97f2 100644 --- a/NEWS +++ b/NEWS @@ -2,7 +2,9 @@ - Add interface returning drive capabilityes (cdio_get_drive_cap). - Minimal cdrdao image reading - Some important (I think) bug fixes - +- Redo types of lsn and lba to allow negative values. Should model MMC3 + specs. Add max/min values for lsn. +- More complete MMC command set 0.68 - More honest about mode1 reading in backends. Remove some of the bogusness. @@ -111,4 +113,4 @@ 0.1 Routines split off from VCDImager. -$Id: NEWS,v 1.39 2004/05/08 20:36:01 rocky Exp $ +$Id: NEWS,v 1.40 2004/05/11 02:15:42 rocky Exp $ diff --git a/include/cdio/scsi_mmc.h b/include/cdio/scsi_mmc.h index 399b6a10..c6467af6 100644 --- a/include/cdio/scsi_mmc.h +++ b/include/cdio/scsi_mmc.h @@ -1,5 +1,5 @@ /* - $Id: scsi_mmc.h,v 1.1 2004/05/10 03:28:52 rocky Exp $ + $Id: scsi_mmc.h,v 1.2 2004/05/11 02:15:47 rocky Exp $ Copyright (C) 2003, 2004 Rocky Bernstein @@ -41,9 +41,12 @@ #define CDIO_MMC_GPCMD_READ_10 0x28 #define CDIO_MMC_GPCMD_READ_SUBCHANNEL 0x42 #define CDIO_MMC_READ_TOC 0x43 +#define CDIO_MMC_MODE_SELECT 0x55 +#define CDIO_MMC_MODE_SELECT_6 0x15 #define CDIO_MMC_MODE_SENSE_10 0x5a #define CDIO_MMC_GPCMD_READ_12 0xa8 #define CDIO_MMC_GPCMD_READ_CD 0xbe +#define CDIO_MMC_GPCMD_READ_MSF 0xb9 #define CDIO_MMC_SET_COMMAND(rec, command) \ rec[0] = command diff --git a/include/cdio/sector.h b/include/cdio/sector.h index 565d5de9..26b2c667 100644 --- a/include/cdio/sector.h +++ b/include/cdio/sector.h @@ -1,5 +1,5 @@ /* - $Id: sector.h,v 1.11 2004/05/10 03:28:52 rocky Exp $ + $Id: sector.h,v 1.12 2004/05/11 02:15:49 rocky Exp $ Copyright (C) 2000 Herbert Valerio Riedel Copyright (C) 2003, 2004 Rocky Bernstein @@ -123,8 +123,11 @@ #define M2SUB_SECTOR_SIZE 2332 #define M2RAW_SECTOR_SIZE 2336 -#define CDIO_CD_MAX_TRACKS 99 -#define CDIO_CD_MIN_TRACK_NO 1 +#define CDIO_CD_MAX_TRACKS 99 +#define CDIO_CD_MIN_TRACK_NO 1 +#define CDIO_CD_MAX_LSN 450150 +#define CDIO_CD_MIN_LSN -450150 + #define CDIO_CD_FRAMES_PER_MIN \ (CDIO_CD_FRAMES_PER_SEC*CDIO_CD_SECS_PER_MIN) diff --git a/include/cdio/types.h b/include/cdio/types.h index 47833f28..52f77d74 100644 --- a/include/cdio/types.h +++ b/include/cdio/types.h @@ -1,5 +1,5 @@ /* - $Id: types.h,v 1.15 2004/05/08 14:07:09 rocky Exp $ + $Id: types.h,v 1.16 2004/05/11 02:15:57 rocky Exp $ Copyright (C) 2000 Herbert Valerio Riedel Copyright (C) 2002, 2003, 2004 Rocky Bernstein @@ -204,14 +204,19 @@ extern "C" { typedef uint8_t bitfield_t; #endif - /*! The type of a Logical Block Address. + /*! The type of a Logical Block Address. We allow for an lba to be + negative to be consistent with an lba, although I'm not sure this + this is possible. + + */ + typedef int32_t lba_t; + + /*! The type of a Logical Sector Number. Note that an lba lsn be negative + and the MMC3 specs allow for a conversion of a negative lba @see msf_t */ - typedef uint32_t lba_t; - - /*! The type of an Logical Sector Number. */ - typedef uint32_t lsn_t; + typedef int32_t lsn_t; /*! The type of an track number 0..99. */ typedef uint8_t track_t; @@ -222,14 +227,16 @@ extern "C" { #define CDIO_INVALID_TRACK 0xFF /*! - Constant for invalid LBA + Constant for invalid LBA. It is 151 less than the most negative + LBA -45150. This provide slack for the 150-frame offset in + LBA to LSN 150 conversions */ -#define CDIO_INVALID_LBA 0xFFFFFFFF +#define CDIO_INVALID_LBA -45301 /*! Constant for invalid LSN */ -#define CDIO_INVALID_LSN 0xFFFFFFFF +#define CDIO_INVALID_LSN CDIO_INVALID_LBA typedef int cdio_fs_anal_t; diff --git a/lib/image/bincue.c b/lib/image/bincue.c index c8e3d3b5..a31cdd98 100644 --- a/lib/image/bincue.c +++ b/lib/image/bincue.c @@ -1,5 +1,5 @@ /* - $Id: bincue.c,v 1.16 2004/04/30 06:54:15 rocky Exp $ + $Id: bincue.c,v 1.17 2004/05/11 02:15:58 rocky Exp $ Copyright (C) 2001 Herbert Valerio Riedel Copyright (C) 2002, 2003, 2004 Rocky Bernstein @@ -24,7 +24,7 @@ (*.cue). */ -static const char _rcsid[] = "$Id: bincue.c,v 1.16 2004/04/30 06:54:15 rocky Exp $"; +static const char _rcsid[] = "$Id: bincue.c,v 1.17 2004/05/11 02:15:58 rocky Exp $"; #include "cdio_assert.h" #include "cdio_private.h" @@ -546,8 +546,8 @@ _read_mode1_sector_bincue (void *env, void *data, lsn_t lsn, Returns 0 if no error. */ static int -_read_mode1_sectors_bincue (void *env, void *data, uint32_t lsn, - bool b_form2, unsigned int nblocks) +_read_mode1_sectors_bincue (void *env, void *data, lsn_t lsn, + bool b_form2, unsigned int nblocks) { _img_private_t *_obj = env; int i; @@ -613,8 +613,8 @@ _read_mode2_sector_bincue (void *env, void *data, lsn_t lsn, Returns 0 if no error. */ static int -_read_mode2_sectors_bincue (void *env, void *data, uint32_t lsn, - bool b_form2, unsigned int nblocks) +_read_mode2_sectors_bincue (void *env, void *data, lsn_t lsn, + bool b_form2, unsigned int nblocks) { _img_private_t *_obj = env; int i; diff --git a/lib/image/cdrdao.c b/lib/image/cdrdao.c index 15f8dc65..972ddba8 100644 --- a/lib/image/cdrdao.c +++ b/lib/image/cdrdao.c @@ -1,5 +1,5 @@ /* - $Id: cdrdao.c,v 1.5 2004/05/08 22:02:28 rocky Exp $ + $Id: cdrdao.c,v 1.6 2004/05/11 02:16:00 rocky Exp $ Copyright (C) 2004 Rocky Bernstein toc reading routine adapted from cuetools @@ -25,7 +25,7 @@ (*.cue). */ -static const char _rcsid[] = "$Id: cdrdao.c,v 1.5 2004/05/08 22:02:28 rocky Exp $"; +static const char _rcsid[] = "$Id: cdrdao.c,v 1.6 2004/05/11 02:16:00 rocky Exp $"; #include "cdio_assert.h" #include "cdio_private.h" @@ -888,8 +888,8 @@ _read_mode1_sector_cdrdao (void *env, void *data, lsn_t lsn, Returns 0 if no error. */ static int -_read_mode1_sectors_cdrdao (void *env, void *data, uint32_t lsn, - bool b_form2, unsigned int nblocks) +_read_mode1_sectors_cdrdao (void *env, void *data, lsn_t lsn, + bool b_form2, unsigned int nblocks) { _img_private_t *_obj = env; int i; @@ -956,8 +956,8 @@ _read_mode2_sector_cdrdao (void *env, void *data, lsn_t lsn, Returns 0 if no error. */ static int -_read_mode2_sectors_cdrdao (void *env, void *data, uint32_t lsn, - bool b_form2, unsigned int nblocks) +_read_mode2_sectors_cdrdao (void *env, void *data, lsn_t lsn, + bool b_form2, unsigned int nblocks) { _img_private_t *_obj = env; int i; diff --git a/lib/image/nrg.c b/lib/image/nrg.c index 549d5b0e..5b23e8fe 100644 --- a/lib/image/nrg.c +++ b/lib/image/nrg.c @@ -1,5 +1,5 @@ /* - $Id: nrg.c,v 1.12 2004/05/09 16:52:20 rocky Exp $ + $Id: nrg.c,v 1.13 2004/05/11 02:16:01 rocky Exp $ Copyright (C) 2001, 2003 Herbert Valerio Riedel Copyright (C) 2003, 2004 Rocky Bernstein @@ -48,7 +48,7 @@ #include "cdio_private.h" #include "_cdio_stdio.h" -static const char _rcsid[] = "$Id: nrg.c,v 1.12 2004/05/09 16:52:20 rocky Exp $"; +static const char _rcsid[] = "$Id: nrg.c,v 1.13 2004/05/11 02:16:01 rocky Exp $"; /* structures used */ @@ -898,8 +898,8 @@ _read_mode1_sector_nrg (void *env, void *data, lsn_t lsn, Returns 0 if no error. */ static int -_read_mode1_sectors_nrg (void *env, void *data, uint32_t lsn, - bool b_form2, unsigned nblocks) +_read_mode1_sectors_nrg (void *env, void *data, lsn_t lsn, + bool b_form2, unsigned nblocks) { _img_private_t *_obj = env; int i; @@ -971,8 +971,8 @@ _read_mode2_sector_nrg (void *env, void *data, lsn_t lsn, Returns 0 if no error. */ static int -_read_mode2_sectors_nrg (void *env, void *data, uint32_t lsn, - bool b_form2, unsigned nblocks) +_read_mode2_sectors_nrg (void *env, void *data, lsn_t lsn, + bool b_form2, unsigned nblocks) { _img_private_t *_obj = env; int i; diff --git a/lib/sector.c b/lib/sector.c index e9623493..a7b0e76b 100644 --- a/lib/sector.c +++ b/lib/sector.c @@ -1,5 +1,5 @@ /* - $Id: sector.c,v 1.6 2004/05/09 16:53:01 rocky Exp $ + $Id: sector.c,v 1.7 2004/05/11 02:15:58 rocky Exp $ Copyright (C) 2000 Herbert Valerio Riedel @@ -32,7 +32,7 @@ #endif -static const char _rcsid[] = "$Id: sector.c,v 1.6 2004/05/09 16:53:01 rocky Exp $"; +static const char _rcsid[] = "$Id: sector.c,v 1.7 2004/05/11 02:15:58 rocky Exp $"; lba_t cdio_lba_to_lsn (lba_t lba) @@ -42,14 +42,35 @@ cdio_lba_to_lsn (lba_t lba) return lba - CDIO_PREGAP_SECTORS; } +/* + The below is adapted from cdparanoia code which claims it is + straight from the MMC3 spec. +*/ + void -cdio_lba_to_msf (lba_t lba, msf_t *msf) +cdio_lsn_to_msf (lsn_t lsn, msf_t *msf) { + int m, s, f; + cdio_assert (msf != 0); - msf->m = to_bcd8 (lba / (60 * 75)); - msf->s = to_bcd8 ((lba / 75) % 60); - msf->f = to_bcd8 (lba % 75); + if ( lsn >= -CDIO_PREGAP_SECTORS ){ + m = (lsn + CDIO_PREGAP_SECTORS) / CDIO_CD_FRAMES_PER_MIN; + lsn -= m * CDIO_CD_FRAMES_PER_MIN; + s = (lsn + CDIO_PREGAP_SECTORS) / CDIO_CD_FRAMES_PER_SEC; + lsn -= s * CDIO_CD_FRAMES_PER_SEC; + f = lsn + CDIO_PREGAP_SECTORS; + } else { + m = (lsn + CDIO_CD_MAX_LSN) / CDIO_CD_FRAMES_PER_MIN; + lsn -= m * (CDIO_CD_FRAMES_PER_MIN); + s = (lsn+CDIO_CD_MAX_LSN) / CDIO_CD_FRAMES_PER_SEC; + lsn -= s * CDIO_CD_FRAMES_PER_SEC; + f = lsn + CDIO_CD_MAX_LSN; + } + + msf->m = to_bcd8 (m); + msf->s = to_bcd8 (s); + msf->f = to_bcd8 (f); } /* warning, returns new allocated string */ @@ -74,13 +95,13 @@ cdio_lsn_to_lba (lsn_t lsn) } void -cdio_lsn_to_msf (lsn_t lsn, msf_t *msf) +cdio_lba_to_msf (lba_t lba, msf_t *msf) { cdio_assert (msf != 0); - cdio_lba_to_msf(cdio_lsn_to_lba(lsn), msf); + cdio_lsn_to_msf(cdio_lba_to_lsn(lba), msf); } -uint32_t +lba_t cdio_msf_to_lba (const msf_t *msf) { uint32_t lba = 0; @@ -88,17 +109,17 @@ cdio_msf_to_lba (const msf_t *msf) cdio_assert (msf != 0); lba = from_bcd8 (msf->m); - lba *= 60; + lba *= CDIO_CD_SECS_PER_MIN; lba += from_bcd8 (msf->s); - lba *= 75; + lba *= CDIO_CD_FRAMES_PER_SEC; lba += from_bcd8 (msf->f); return lba; } -uint32_t +lba_t cdio_msf_to_lsn (const msf_t *msf) { return cdio_lba_to_lsn(cdio_msf_to_lba (msf));