From 9a97232136377b0b28ba68d21a662aac68ad6db8 Mon Sep 17 00:00:00 2001 From: rocky Date: Wed, 17 Sep 2003 12:13:07 +0000 Subject: [PATCH] Add cd-read.c for debugging CD reading problems. --- src/Makefile.am | 11 +++--- src/cd-read.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 src/cd-read.c diff --git a/src/Makefile.am b/src/Makefile.am index 0ef88402..9c69b82e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -# $Id: Makefile.am,v 1.14 2003/08/31 06:59:23 rocky Exp $ +# $Id: Makefile.am,v 1.15 2003/09/17 12:13:07 rocky Exp $ # # Copyright (C) 2003 Rocky Bernstein # @@ -25,16 +25,19 @@ if BUILD_CDINFO cd_info_SOURCES = cd-info.c cd_info_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBPOPT_LIBS) $(CDDB_LIBS) $(VCDINFO_LIBS) +cd_read_SOURCES = cd-read.c +cd_read_LDADD = $(LIBCDIO_LIBS) $(LIBPOPT_LIBS) + if BUILD_CDINFO_LINUX cdinfo_linux_SOURCES = cdinfo-linux.c cdinfo_linux_LDADD = $(LIBCDIO_LIBS) $(LIBPOPT_LIBS) -bin_PROGRAMS = cd-info cdinfo-linux +bin_PROGRAMS = cd-info cd-read cdinfo-linux else -bin_PROGRAMS = cd-info +bin_PROGRAMS = cd-info cd-read EXTRA_DIST = cdinfo-linux.c endif else -EXTRA_DIST = cdinfo-linux.c cd-info.c +EXTRA_DIST = cdinfo-linux.c cd-info.c cd-read.c endif INCLUDES = -I$(top_srcdir) $(LIBPOPT_CFLAGS) $(LIBCDIO_CFLAGS) $(VCDINFO_CFLAGS) diff --git a/src/cd-read.c b/src/cd-read.c new file mode 100644 index 00000000..c5ac5728 --- /dev/null +++ b/src/cd-read.c @@ -0,0 +1,95 @@ +/* + $Id: cd-read.c,v 1.1 2003/09/17 12:13:07 rocky Exp $ + + Copyright (C) 2003 Rocky Bernstein + + 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 +*/ + +/* Program to debug read routines audio, mode1, mode2 forms 1 & 2. */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include +#include + +static void +hexdump (uint8_t * buffer, unsigned int len) +{ + unsigned int i; + for (i = 0; i < len; i++, buffer++) + { + if (i % 16 == 0) + printf ("0x%04x: ", i); + printf ("%02x", *buffer); + if (i % 2 == 1) + printf (" "); + if (i % 16 == 15) { + printf (" "); + uint8_t *p; + for (p=buffer-15; p <= buffer; p++) { + printf("%c", isprint(*p) ? *p : '.'); + } + printf ("\n"); + } + } + printf ("\n"); +} + +int +main(int argc, const char *argv[]) +{ + uint8_t buffer[CDIO_CD_FRAMESIZE_RAW] = { 0, }; + lsn_t lsn; + + if (argc != 4) { + printf("need to give 3 things: device/filename, type of read, & lsn\n"); + return 10; + } + + CdIo *cdio = cdio_open (argv[1], DRIVER_UNKNOWN); + + lsn = atoi(argv[3]); + + switch (argv[2][0]) { + case '1': + cdio_read_audio_sector(cdio, &buffer, lsn); + break; + case '2': + cdio_read_mode1_sector(cdio, &buffer, lsn, false); + break; + case '3': + cdio_read_mode1_sector(cdio, &buffer, 16, true); + break; + case '4': + cdio_read_mode2_sector(cdio, &buffer, 0, false); + break; + case '5': + cdio_read_mode2_sector(cdio, &buffer, 16, true); + break; + default: + printf("Expecting 1..5 as the second argument.\n"); + return 20; + } + + hexdump(buffer, CDIO_CD_FRAMESIZE_RAW); + cdio_destroy(cdio); + return 0; +}