Reduce cut and paste - add common routine, to _cdio_generic.c:

cdio_read_mode1_sector.
This commit is contained in:
rocky
2004-06-26 00:39:00 +00:00
parent 8f47e3671e
commit e21255ec1a
6 changed files with 39 additions and 45 deletions

View File

@@ -1,5 +1,5 @@
/* /*
$Id: freebsd_ioctl.c,v 1.8 2004/06/25 20:45:41 rocky Exp $ $Id: freebsd_ioctl.c,v 1.9 2004/06/26 00:39:01 rocky Exp $
Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
@@ -27,7 +27,7 @@
# include "config.h" # include "config.h"
#endif #endif
static const char _rcsid[] = "$Id: freebsd_ioctl.c,v 1.8 2004/06/25 20:45:41 rocky Exp $"; static const char _rcsid[] = "$Id: freebsd_ioctl.c,v 1.9 2004/06/26 00:39:01 rocky Exp $";
#ifdef HAVE_FREEBSD_CDROM #ifdef HAVE_FREEBSD_CDROM
@@ -95,33 +95,19 @@ read_audio_sectors_freebsd_ioctl (_img_private_t *_obj, void *data, lsn_t lsn,
return 0; return 0;
} }
/*!
Reads a single form1 sector from cd device into data starting
from lsn. Returns 0 if no error.
*/
int
read_form1_sector_freebsd_ioctl (_img_private_t *env, void *data, lsn_t lsn)
{
if (0 > cdio_generic_lseek(env, CDIO_CD_FRAMESIZE*lsn, SEEK_SET))
return -1;
if (0 > cdio_generic_read(env, data, CDIO_CD_FRAMESIZE))
return -1;
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.
*/ */
int int
read_mode2_sector_freebsd_ioctl (_img_private_t *env, void *data, lsn_t lsn, read_mode2_sector_freebsd_ioctl (_img_private_t *env, void *data, lsn_t lsn,
bool b_form2) bool b_form2)
{ {
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, }; char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
int retval; int retval;
if ( !b_form2 ) if ( !b_form2 )
return read_form1_sector_freebsd_ioctl (env, buf, lsn); return cdio_generic_read_form1_sector (env, buf, lsn);
if ( (retval = read_audio_sectors_freebsd_ioctl (env, buf, lsn, 1)) ) if ( (retval = read_audio_sectors_freebsd_ioctl (env, buf, lsn, 1)) )
return retval; return retval;

View File

@@ -1,5 +1,5 @@
/* /*
$Id: _cdio_bsdi.c,v 1.27 2004/06/25 21:10:43 rocky Exp $ $Id: _cdio_bsdi.c,v 1.28 2004/06/26 00:39:00 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>
@@ -27,7 +27,7 @@
# include "config.h" # include "config.h"
#endif #endif
static const char _rcsid[] = "$Id: _cdio_bsdi.c,v 1.27 2004/06/25 21:10:43 rocky Exp $"; static const char _rcsid[] = "$Id: _cdio_bsdi.c,v 1.28 2004/06/26 00:39:00 rocky Exp $";
#include <cdio/sector.h> #include <cdio/sector.h>
#include <cdio/util.h> #include <cdio/util.h>
@@ -204,15 +204,11 @@ _read_mode1_sector_bsdi (void *user_data, void *data, lsn_t lsn,
bool b_form2) bool b_form2)
{ {
char buf[M2RAW_SECTOR_SIZE] = { 0, };
#if FIXED #if FIXED
char buf[M2RAW_SECTOR_SIZE] = { 0, };
do something here. do something here.
#else #else
if (0 > cdio_generic_lseek(user_data, CDIO_CD_FRAMESIZE*lsn, SEEK_SET)) return cdio_generic_read_form1_sector(user_data, data, lsn);
return -1;
if (0 > cdio_generic_read(user_data, buf, CDIO_CD_FRAMESIZE))
return -1;
memcpy (data, buf, b_form2 ? M2RAW_SECTOR_SIZE: CDIO_CD_FRAMESIZE);
#endif #endif
return 0; return 0;
} }

View File

@@ -1,5 +1,5 @@
/* /*
$Id: _cdio_generic.c,v 1.18 2004/06/25 21:10:43 rocky Exp $ $Id: _cdio_generic.c,v 1.19 2004/06/26 00:39:00 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>
@@ -27,7 +27,7 @@
# include "config.h" # include "config.h"
#endif #endif
static const char _rcsid[] = "$Id: _cdio_generic.c,v 1.18 2004/06/25 21:10:43 rocky Exp $"; static const char _rcsid[] = "$Id: _cdio_generic.c,v 1.19 2004/06/26 00:39:00 rocky Exp $";
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -103,6 +103,20 @@ cdio_generic_init (void *user_data)
return true; return true;
} }
/*!
Reads a single form1 sector from cd device into data starting
from lsn. Returns 0 if no error.
*/
int
cdio_generic_read_form1_sector (void * user_data, void *data, lsn_t lsn)
{
if (0 > cdio_generic_lseek(user_data, CDIO_CD_FRAMESIZE*lsn, SEEK_SET))
return -1;
if (0 > cdio_generic_read(user_data, data, CDIO_CD_FRAMESIZE))
return -1;
return 0;
}
/*! /*!
Reads into buf the next size bytes. Reads into buf the next size bytes.
Returns -1 on error. Returns -1 on error.

View File

@@ -1,5 +1,5 @@
/* /*
$Id: _cdio_linux.c,v 1.56 2004/06/25 21:10:43 rocky Exp $ $Id: _cdio_linux.c,v 1.57 2004/06/26 00:39:00 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>
@@ -27,7 +27,7 @@
# include "config.h" # include "config.h"
#endif #endif
static const char _rcsid[] = "$Id: _cdio_linux.c,v 1.56 2004/06/25 21:10:43 rocky Exp $"; static const char _rcsid[] = "$Id: _cdio_linux.c,v 1.57 2004/06/26 00:39:00 rocky Exp $";
#include <string.h> #include <string.h>
@@ -381,8 +381,8 @@ _read_mode1_sector_linux (void *env, void *data, lsn_t lsn,
bool b_form2) bool b_form2)
{ {
char buf[M2RAW_SECTOR_SIZE] = { 0, };
#if FIXED #if FIXED
char buf[M2RAW_SECTOR_SIZE] = { 0, };
struct cdrom_msf *msf = (struct cdrom_msf *) &buf; struct cdrom_msf *msf = (struct cdrom_msf *) &buf;
msf_t _msf; msf_t _msf;
@@ -437,11 +437,7 @@ _read_mode1_sector_linux (void *env, void *data, lsn_t lsn,
b_form2 ? M2RAW_SECTOR_SIZE: CDIO_CD_FRAMESIZE); b_form2 ? M2RAW_SECTOR_SIZE: CDIO_CD_FRAMESIZE);
#else #else
if (0 > cdio_generic_lseek(env, CDIO_CD_FRAMESIZE*lsn, SEEK_SET)) return cdio_generic_read_form1_sector(env, data, lsn);
return -1;
if (0 > cdio_generic_read(env, buf, CDIO_CD_FRAMESIZE))
return -1;
memcpy (data, buf, b_form2 ? M2RAW_SECTOR_SIZE: CDIO_CD_FRAMESIZE);
#endif #endif
return 0; return 0;
} }

View File

@@ -1,5 +1,5 @@
/* /*
$Id: _cdio_sunos.c,v 1.40 2004/06/25 21:10:44 rocky Exp $ $Id: _cdio_sunos.c,v 1.41 2004/06/26 00:39:01 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>
@@ -38,7 +38,7 @@
#ifdef HAVE_SOLARIS_CDROM #ifdef HAVE_SOLARIS_CDROM
static const char _rcsid[] = "$Id: _cdio_sunos.c,v 1.40 2004/06/25 21:10:44 rocky Exp $"; static const char _rcsid[] = "$Id: _cdio_sunos.c,v 1.41 2004/06/26 00:39:01 rocky Exp $";
#ifdef HAVE_GLOB_H #ifdef HAVE_GLOB_H
#include <glob.h> #include <glob.h>
@@ -186,15 +186,10 @@ _cdio_read_mode1_sector (void *env, void *data, lsn_t lsn,
bool b_form2) bool b_form2)
{ {
char buf[M2RAW_SECTOR_SIZE] = { 0, };
#if FIXED #if FIXED
do something here. do something here.
#else #else
if (0 > cdio_generic_lseek(env, CDIO_CD_FRAMESIZE*lsn, SEEK_SET)) return cdio_generic_read_form1_sector(env_data, data, lsn);
return -1;
if (0 > cdio_generic_read(env, buf, CDIO_CD_FRAMESIZE))
return -1;
memcpy (data, buf, b_form2 ? M2RAW_SECTOR_SIZE: CDIO_CD_FRAMESIZE);
#endif #endif
return 0; return 0;
} }

View File

@@ -1,5 +1,5 @@
/* /*
$Id: cdio_private.h,v 1.23 2004/05/27 01:11:50 rocky Exp $ $Id: cdio_private.h,v 1.24 2004/06/26 00:39:01 rocky Exp $
Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
@@ -296,6 +296,13 @@ extern "C" {
*/ */
ssize_t cdio_generic_read (void *env, void *buf, size_t size); ssize_t cdio_generic_read (void *env, void *buf, size_t size);
/*!
Reads a single form1 sector from cd device into data starting
from lsn. Returns 0 if no error.
*/
int cdio_generic_read_form1_sector (void * user_data, void *data,
lsn_t lsn);
/*! /*!
Release and free resources associated with stream or disk image. Release and free resources associated with stream or disk image.
*/ */