Work on mode1 reading. Remove some of the bogusity in cdio.c and bincue.c

win2, now works!
This commit is contained in:
rocky
2004-03-05 04:23:52 +00:00
parent 3ec145f777
commit 98b9f3719c
6 changed files with 229 additions and 52 deletions

View File

@@ -1,5 +1,5 @@
/* /*
$Id: _cdio_bincue.c,v 1.42 2004/02/26 03:57:42 rocky Exp $ $Id: _cdio_bincue.c,v 1.43 2004/03/05 04:23:52 rocky Exp $
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org> 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>
@@ -24,7 +24,7 @@
(*.cue). (*.cue).
*/ */
static const char _rcsid[] = "$Id: _cdio_bincue.c,v 1.42 2004/02/26 03:57:42 rocky Exp $"; static const char _rcsid[] = "$Id: _cdio_bincue.c,v 1.43 2004/03/05 04:23:52 rocky Exp $";
#include "cdio_assert.h" #include "cdio_assert.h"
#include "cdio_private.h" #include "cdio_private.h"
@@ -510,6 +510,70 @@ _cdio_read_audio_sectors (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
_cdio_read_mode1_sector (void *env, void *data, lsn_t lsn,
bool mode1_form2)
{
_img_private_t *_obj = env;
int ret;
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
int blocksize = _obj->sector_2336
? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE_RAW;
_cdio_init (_obj);
ret = cdio_stream_seek (_obj->gen.data_source, lsn * blocksize, SEEK_SET);
if (ret!=0) return ret;
ret = cdio_stream_read (_obj->gen.data_source,
_obj->sector_2336
? (buf + CDIO_CD_SYNC_SIZE + CDIO_CD_HEADER_SIZE)
: buf,
blocksize, 1);
if (ret==0) return ret;
memcpy (data, buf + CDIO_CD_SYNC_SIZE + CDIO_CD_HEADER_SIZE,
mode1_form2 ? M2RAW_SECTOR_SIZE: CDIO_CD_FRAMESIZE);
return 0;
}
/*!
Reads nblocks of mode1 sectors from cd device into data starting
from lsn.
Returns 0 if no error.
*/
static int
_cdio_read_mode1_sectors (void *env, void *data, uint32_t lsn,
bool mode1_form2, unsigned int nblocks)
{
_img_private_t *_obj = env;
int i;
int retval;
for (i = 0; i < nblocks; i++) {
if (mode1_form2) {
if ( (retval = _cdio_read_mode1_sector (_obj,
((char *)data)
+ (M2RAW_SECTOR_SIZE * i),
lsn + i, true)) )
return retval;
} else {
char buf[M2RAW_SECTOR_SIZE] = { 0, };
if ( (retval = _cdio_read_mode1_sector (_obj, buf, lsn + i, false)) )
return retval;
memcpy (((char *)data) + (CDIO_CD_FRAMESIZE * i),
buf, CDIO_CD_FRAMESIZE);
}
}
return 0;
}
/*!
Reads a single mode1 sector from cd device into data starting
from lsn. Returns 0 if no error.
*/
static int
_cdio_read_mode2_sector (void *env, void *data, lsn_t lsn, _cdio_read_mode2_sector (void *env, void *data, lsn_t lsn,
bool mode2_form2) bool mode2_form2)
{ {
@@ -531,11 +595,8 @@ _cdio_read_mode2_sector (void *env, void *data, lsn_t lsn,
blocksize, 1); blocksize, 1);
if (ret==0) return ret; if (ret==0) return ret;
if (mode2_form2) memcpy (data, buf + CDIO_CD_XA_SYNC_HEADER,
memcpy (data, buf + CDIO_CD_SYNC_SIZE + CDIO_CD_HEADER_SIZE, mode2_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE);
M2RAW_SECTOR_SIZE);
else
memcpy (data, buf + CDIO_CD_XA_SYNC_HEADER, CDIO_CD_FRAMESIZE);
return 0; return 0;
} }
@@ -896,6 +957,8 @@ cdio_open_common (_img_private_t **_data)
.lseek = _cdio_lseek, .lseek = _cdio_lseek,
.read = _cdio_read, .read = _cdio_read,
.read_audio_sectors = _cdio_read_audio_sectors, .read_audio_sectors = _cdio_read_audio_sectors,
.read_mode1_sector = _cdio_read_mode1_sector,
.read_mode1_sectors = _cdio_read_mode1_sectors,
.read_mode2_sector = _cdio_read_mode2_sector, .read_mode2_sector = _cdio_read_mode2_sector,
.read_mode2_sectors = _cdio_read_mode2_sectors, .read_mode2_sectors = _cdio_read_mode2_sectors,
.set_arg = _cdio_set_arg, .set_arg = _cdio_set_arg,

View File

@@ -1,5 +1,5 @@
/* /*
$Id: _cdio_win32.c,v 1.27 2004/03/03 02:41:18 rocky Exp $ $Id: _cdio_win32.c,v 1.28 2004/03/05 04:23:52 rocky Exp $
Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
@@ -26,7 +26,7 @@
# include "config.h" # include "config.h"
#endif #endif
static const char _rcsid[] = "$Id: _cdio_win32.c,v 1.27 2004/03/03 02:41:18 rocky Exp $"; static const char _rcsid[] = "$Id: _cdio_win32.c,v 1.28 2004/03/05 04:23:52 rocky Exp $";
#include <cdio/cdio.h> #include <cdio/cdio.h>
#include <cdio/sector.h> #include <cdio/sector.h>
@@ -145,6 +145,68 @@ _cdio_read_audio_sectors (void *user_data, void *data, lsn_t lsn,
} }
} }
/*!
Reads a single mode1 sector from cd device into data starting
from lsn. Returns 0 if no error.
*/
static int
_cdio_read_mode1_sector (void *user_data, void *data, lsn_t lsn,
bool mode1_form2)
{
_img_private_t *env = user_data;
if (env->gen.ioctls_debugged == 75)
cdio_debug ("only displaying every 75th ioctl from now on");
if (env->gen.ioctls_debugged == 30 * 75)
cdio_debug ("only displaying every 30*75th ioctl from now on");
if (env->gen.ioctls_debugged < 75
|| (env->gen.ioctls_debugged < (30 * 75)
&& env->gen.ioctls_debugged % 75 == 0)
|| env->gen.ioctls_debugged % (30 * 75) == 0)
cdio_debug ("reading %lu", (unsigned long int) lsn);
env->gen.ioctls_debugged++;
if ( env->hASPI ) {
return 1;
} else {
return win32ioctl_read_mode1_sector( env, data, lsn, mode1_form2 );
}
}
/*!
Reads nblocks of mode1 sectors from cd device into data starting
from lsn.
Returns 0 if no error.
*/
static int
_cdio_read_mode1_sectors (void *user_data, void *data, lsn_t lsn,
bool mode1_form2, unsigned int nblocks)
{
_img_private_t *env = user_data;
int i;
int retval;
for (i = 0; i < nblocks; i++) {
if (mode1_form2) {
if ( (retval = _cdio_read_mode1_sector (env,
((char *)data) + (M2RAW_SECTOR_SIZE * i),
lsn + i, true)) )
return retval;
} else {
char buf[M2RAW_SECTOR_SIZE] = { 0, };
if ( (retval = _cdio_read_mode1_sector (env, buf, lsn + i, false)) )
return retval;
memcpy (((char *)data) + (CDIO_CD_FRAMESIZE * i),
buf, CDIO_CD_FRAMESIZE);
}
}
return 0;
}
/*! /*!
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.
@@ -191,7 +253,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, lsn_t lsn, _cdio_read_mode2_sectors (void *user_data, void *data, lsn_t lsn,
bool mode2_form2, unsigned int nblocks) bool mode2_form2, unsigned int nblocks)
{ {
_img_private_t *env = user_data; _img_private_t *env = user_data;
int i; int i;
@@ -200,7 +262,8 @@ _cdio_read_mode2_sectors (void *user_data, void *data, lsn_t lsn,
for (i = 0; i < nblocks; i++) { for (i = 0; i < nblocks; i++) {
if (mode2_form2) { if (mode2_form2) {
if ( (retval = _cdio_read_mode2_sector (env, if ( (retval = _cdio_read_mode2_sector (env,
((char *)data) + (M2RAW_SECTOR_SIZE * i), ((char *)data)
+ (M2RAW_SECTOR_SIZE * i),
lsn + i, true)) ) lsn + i, true)) )
return retval; return retval;
} else { } else {
@@ -577,6 +640,8 @@ cdio_open_win32 (const char *source_name)
.lseek = NULL, .lseek = NULL,
.read = NULL, .read = NULL,
.read_audio_sectors = _cdio_read_audio_sectors, .read_audio_sectors = _cdio_read_audio_sectors,
.read_mode1_sector = _cdio_read_mode1_sector,
.read_mode1_sectors = _cdio_read_mode1_sectors,
.read_mode2_sector = _cdio_read_mode2_sector, .read_mode2_sector = _cdio_read_mode2_sector,
.read_mode2_sectors = _cdio_read_mode2_sectors, .read_mode2_sectors = _cdio_read_mode2_sectors,
.set_arg = _cdio_set_arg, .set_arg = _cdio_set_arg,

View File

@@ -1,5 +1,5 @@
/* /*
$Id: _cdio_win32.h,v 1.3 2004/02/05 03:02:16 rocky Exp $ $Id: _cdio_win32.h,v 1.4 2004/03/05 04:23:52 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
@@ -60,6 +60,14 @@ int
win32ioctl_read_mode2_sector (_img_private_t *env, void *data, lsn_t lsn, win32ioctl_read_mode2_sector (_img_private_t *env, void *data, lsn_t lsn,
bool mode2_form2); bool mode2_form2);
/*!
Reads a single mode1 sector using the DeviceIoControl method into
data starting from lsn. Returns 0 if no error.
*/
int
win32ioctl_read_mode1_sector (_img_private_t *env, void *data, lsn_t lsn,
bool mode2_form2);
const char *win32ioctl_is_cdrom(const char drive_letter); const char *win32ioctl_is_cdrom(const char drive_letter);
/*! /*!

View File

@@ -1,5 +1,5 @@
/* /*
$Id: cdio.c,v 1.38 2004/02/07 02:40:20 rocky Exp $ $Id: cdio.c,v 1.39 2004/03/05 04:23:52 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>
@@ -37,7 +37,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.38 2004/02/07 02:40:20 rocky Exp $"; static const char _rcsid[] = "$Id: cdio.c,v 1.39 2004/03/05 04:23:52 rocky Exp $";
const char *track_format2str[6] = const char *track_format2str[6] =
@@ -678,44 +678,35 @@ cdio_read_mode1_sector (const CdIo *cdio, void *data, lsn_t lsn, bool is_form2)
{ {
uint32_t size = is_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE ; 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;
cdio_assert (cdio != NULL); cdio_assert (cdio != NULL);
cdio_assert (data != NULL); cdio_assert (data != NULL);
if (cdio->op.lseek && cdio->op.read) { if (cdio->op.read_mode1_sector && cdio->op.read_mode1_sector) {
return cdio->op.read_mode1_sector(cdio->env, data, lsn, is_form2);
} else if (cdio->op.lseek && cdio->op.read) {
if (0 > cdio_lseek(cdio, CDIO_CD_FRAMESIZE*lsn, SEEK_SET)) if (0 > cdio_lseek(cdio, CDIO_CD_FRAMESIZE*lsn, SEEK_SET))
return -1; return -1;
if (0 > cdio_read(cdio, buf, CDIO_CD_FRAMESIZE)) if (0 > cdio_read(cdio, buf, CDIO_CD_FRAMESIZE))
return -1; return -1;
memcpy (data, buf, size); memcpy (data, buf, size);
return 0; return 0;
} else { }
ret = cdio_read_mode2_sector(cdio, data, lsn, is_form2);
if (ret == 0) return 1;
memcpy (data, buf+CDIO_CD_SUBHEADER_SIZE, size);
}
return ret;
} }
int int
cdio_read_mode1_sectors (const CdIo *cdio, void *data, lsn_t lsn, cdio_read_mode1_sectors (const CdIo *cdio, void *buf, lsn_t lsn,
bool is_form2, unsigned int num_sectors) bool is_form2, unsigned int num_sectors)
{ {
uint32_t size = is_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE ;
int retval;
int i;
cdio_assert (cdio != NULL); cdio_assert (cdio != NULL);
cdio_assert (buf != NULL);
cdio_assert (cdio->op.read_mode1_sectors != NULL);
for (i = 0; i < num_sectors; i++) { return cdio->op.read_mode1_sectors (cdio->env, buf, lsn, is_form2,
if ( (retval = cdio_read_mode1_sector (cdio, num_sectors);
((char *)data) + (size * i),
lsn + i, is_form2)) )
return retval;
}
return 0;
} }
/*! /*!
@@ -741,15 +732,15 @@ cdio_read_mode2_sector (const CdIo *cdio, void *buf, lsn_t lsn,
} }
int int
cdio_read_mode2_sectors (const CdIo *cdio, void *buf, lsn_t lsn, bool mode2raw, cdio_read_mode2_sectors (const CdIo *cdio, void *buf, lsn_t lsn,
unsigned num_sectors) bool is_form2, unsigned int num_sectors)
{ {
cdio_assert (cdio != NULL); cdio_assert (cdio != NULL);
cdio_assert (buf != NULL); cdio_assert (buf != NULL);
cdio_assert (cdio->op.read_mode2_sectors != NULL); cdio_assert (cdio->op.read_mode2_sectors != NULL);
return cdio->op.read_mode2_sectors (cdio->env, buf, lsn, return cdio->op.read_mode2_sectors (cdio->env, buf, lsn,
mode2raw, num_sectors); is_form2, num_sectors);
} }
uint32_t uint32_t

View File

@@ -1,7 +1,7 @@
/* /*
$Id: cdio_private.h,v 1.18 2004/02/07 18:53:02 rocky Exp $ $Id: cdio_private.h,v 1.19 2004/03/05 04:23:52 rocky Exp $
Copyright (C) 2003 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
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
@@ -146,7 +146,7 @@ extern "C" {
from lsn. Returns 0 if no error. from lsn. Returns 0 if no error.
*/ */
int (*read_mode2_sector) (void *env, void *buf, lsn_t lsn, int (*read_mode2_sector) (void *env, void *buf, lsn_t lsn,
bool mode2raw); bool mode2_form2);
/*! /*!
Reads nblocks of mode2 sectors from cd device into data starting Reads nblocks of mode2 sectors from cd device into data starting
@@ -154,7 +154,22 @@ extern "C" {
Returns 0 if no error. Returns 0 if no error.
*/ */
int (*read_mode2_sectors) (void *env, void *buf, lsn_t lsn, int (*read_mode2_sectors) (void *env, void *buf, lsn_t lsn,
bool mode2raw, unsigned int nblocks); bool mode2_form2, unsigned int nblocks);
/*!
Reads a single mode1 sector from cd device into buf starting
from lsn. Returns 0 if no error.
*/
int (*read_mode1_sector) (void *env, void *buf, lsn_t lsn,
bool mode1_form2);
/*!
Reads nblocks of mode1 sectors from cd device into data starting
from lsn.
Returns 0 if no error.
*/
int (*read_mode1_sectors) (void *env, void *buf, lsn_t lsn,
bool mode1_form2, unsigned int nblocks);
/*! /*!
Set the arg "key" with "value" in the source device. Set the arg "key" with "value" in the source device.

View File

@@ -1,5 +1,5 @@
/* /*
$Id: win32ioctl.c,v 1.5 2004/03/04 04:01:30 rocky Exp $ $Id: win32ioctl.c,v 1.6 2004/03/05 04:23:52 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
@@ -26,7 +26,7 @@
# include "config.h" # include "config.h"
#endif #endif
static const char _rcsid[] = "$Id: win32ioctl.c,v 1.5 2004/03/04 04:01:30 rocky Exp $"; static const char _rcsid[] = "$Id: win32ioctl.c,v 1.6 2004/03/05 04:23:52 rocky Exp $";
#include <cdio/cdio.h> #include <cdio/cdio.h>
#include <cdio/sector.h> #include <cdio/sector.h>
@@ -224,14 +224,12 @@ win32ioctl_read_audio_sectors (_img_private_t *env, void *data, lsn_t lsn,
} }
/*! /*!
Reads a single mode2 sector using the DeviceIoControl method into Reads a single raw sector using the DeviceIoControl method into
data starting from lsn. Returns 0 if no error. data starting from lsn. Returns 0 if no error.
*/ */
int static int
win32ioctl_read_mode2_sector (_img_private_t *env, void *data, lsn_t lsn, win32ioctl_read_raw_sector (_img_private_t *env, void *buf, lsn_t lsn)
bool mode2_form2)
{ {
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
SCSI_PASS_THROUGH_DIRECT sptd; SCSI_PASS_THROUGH_DIRECT sptd;
BOOL success; BOOL success;
DWORD dwBytesReturned; DWORD dwBytesReturned;
@@ -279,12 +277,49 @@ win32ioctl_read_mode2_sector (_img_private_t *env, void *data, lsn_t lsn,
return 1; return 1;
} }
if (mode2_form2) return 0;
memcpy (data, buf + 24, M2RAW_SECTOR_SIZE); }
else
memcpy (((char *)data), buf + 24, CDIO_CD_FRAMESIZE); /*!
Reads a single mode2 sector using the DeviceIoControl method into
data starting from lsn. Returns 0 if no error.
*/
int
win32ioctl_read_mode2_sector (_img_private_t *env, void *data, lsn_t lsn,
bool mode2_form2)
{
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
int ret = win32ioctl_read_raw_sector (env, buf, lsn);
if ( 0 != ret) return ret;
memcpy (data,
buf + CDIO_CD_SYNC_SIZE + CDIO_CD_XA_HEADER,
mode2_form2 ? M2RAW_SECTOR_SIZE: CDIO_CD_FRAMESIZE);
return 0; return 0;
}
/*!
Reads a single mode2 sector using the DeviceIoControl method into
data starting from lsn. Returns 0 if no error.
*/
int
win32ioctl_read_mode1_sector (_img_private_t *env, void *data, lsn_t lsn,
bool mode2_form2)
{
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
int ret = win32ioctl_read_raw_sector (env, buf, lsn);
if ( 0 != ret) return ret;
memcpy (data,
buf + CDIO_CD_SYNC_SIZE+CDIO_CD_HEADER_SIZE,
mode2_form2 ? M2RAW_SECTOR_SIZE: CDIO_CD_FRAMESIZE);
return 0;
} }
/*! /*!