diff --git a/example/C++/.cvsignore b/example/C++/.cvsignore new file mode 100644 index 00000000..70d89482 --- /dev/null +++ b/example/C++/.cvsignore @@ -0,0 +1,8 @@ +Makefile +.deps +.libs +iso1 +iso2 +iso3 +mmc1 +mmc2 diff --git a/example/C++/Makefile.am b/example/C++/Makefile.am new file mode 100644 index 00000000..143daadd --- /dev/null +++ b/example/C++/Makefile.am @@ -0,0 +1,41 @@ +# $Id: Makefile.am,v 1.1 2005/02/19 11:42:18 rocky Exp $ +# +# Copyright (C) 2005 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 +# +#################################################### +# Things to regression testing +#################################################### +# +noinst_PROGRAMS = iso1 iso2 iso3 mmc1 mmc2 + +INCLUDES = -I$(top_srcdir) $(LIBCDIO_CFLAGS) + +iso1_SOURCES = iso1.cpp +iso1_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) +iso2_SOURCES = iso2.cpp +iso2_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) +iso3_SOURCES = iso3.cpp +iso3_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) + +mmc1_SOURCES = mmc1.cpp +mmc1_LDADD = $(LIBCDIO_LIBS) + +mmc2_SOURCES = mmc2.cpp +mmc2_LDADD = $(LIBCDIO_LIBS) + +# iso programs create file "copying" +MOSTLYCLEANFILES = copying diff --git a/example/C++/README b/example/C++/README new file mode 100644 index 00000000..851240d2 --- /dev/null +++ b/example/C++/README @@ -0,0 +1,16 @@ +$Id: README,v 1.1 2005/02/19 11:42:18 rocky Exp $ + +This directory contains some simple C++ examples of the use of the libcdio +library. + +Descriptions of the programs in this example directory are as follows... + +iso1.cpp: A program to show using libiso9660 to list files in a + directory of an ISO-9660 image. + +iso2.cpp: A program to show using libiso9660 to extract a file + from a CDRWIN cue/bin CD image. + +iso3.cpp: A program to show using libiso9660 to extract a file from an + ISO-9660 image. + diff --git a/example/iso1cpp.cpp b/example/C++/iso1.cpp similarity index 89% rename from example/iso1cpp.cpp rename to example/C++/iso1.cpp index b0ff1d0c..619c036e 100644 --- a/example/iso1cpp.cpp +++ b/example/C++/iso1.cpp @@ -1,5 +1,5 @@ /* - $Id: iso1cpp.cpp,v 1.1 2004/11/22 01:03:53 rocky Exp $ + $Id: iso1.cpp,v 1.1 2005/02/19 11:42:18 rocky Exp $ Copyright (C) 2004 Rocky Bernstein @@ -27,7 +27,7 @@ */ /* This is the ISO 9660 image. */ -#define ISO9660_IMAGE_PATH "../" +#define ISO9660_IMAGE_PATH "../../" #define ISO9660_IMAGE ISO9660_IMAGE_PATH "test/copying.iso" #ifdef HAVE_CONFIG_H @@ -58,8 +58,15 @@ main(int argc, const char *argv[]) { CdioList *entlist; CdioListNode *entnode; + char const *psz_fname; + iso9660_t *p_iso; - iso9660_t *p_iso = iso9660_open (ISO9660_IMAGE); + if (argc > 1) + psz_fname = argv[1]; + else + psz_fname = ISO9660_IMAGE; + + p_iso = iso9660_open (psz_fname); if (NULL == p_iso) { fprintf(stderr, "Sorry, couldn't open ISO 9660 image %s\n", ISO9660_IMAGE); diff --git a/example/iso2cpp.cpp b/example/C++/iso2.cpp similarity index 91% rename from example/iso2cpp.cpp rename to example/C++/iso2.cpp index 121cb163..6a2314a5 100644 --- a/example/iso2cpp.cpp +++ b/example/C++/iso2.cpp @@ -1,5 +1,5 @@ /* - $Id: iso2cpp.cpp,v 1.1 2004/11/22 01:03:53 rocky Exp $ + $Id: iso2.cpp,v 1.1 2005/02/19 11:42:18 rocky Exp $ Copyright (C) 2003, 2004 Rocky Bernstein @@ -27,10 +27,10 @@ */ /* This is the CD-image with an ISO-9660 filesystem */ -#define ISO9660_IMAGE_PATH "../" +#define ISO9660_IMAGE_PATH "../../" #define ISO9660_IMAGE ISO9660_IMAGE_PATH "test/isofs-m1.cue" -#define ISO9660_FILENAME "/COPYING.;1" +#define ISO9660_FILENAME "COPYING.;1" #define LOCAL_FILENAME "copying" #ifdef HAVE_CONFIG_H @@ -76,9 +76,16 @@ main(int argc, const char *argv[]) { iso9660_stat_t *p_statbuf; FILE *p_outfd; + char const *psz_fname; + CdIo_t *p_cdio; int i; - CdIo *p_cdio = cdio_open (ISO9660_IMAGE, DRIVER_BINCUE); + if (argc > 1) + psz_fname = argv[1]; + else + psz_fname = ISO9660_IMAGE; + + p_cdio = cdio_open (psz_fname, DRIVER_BINCUE); if (NULL == p_cdio) { fprintf(stderr, "Sorry, couldn't open BIN/CUE image %s\n", ISO9660_IMAGE); diff --git a/example/iso3cpp.cpp b/example/C++/iso3.cpp similarity index 92% rename from example/iso3cpp.cpp rename to example/C++/iso3.cpp index 0b697c48..9f827264 100644 --- a/example/iso3cpp.cpp +++ b/example/C++/iso3.cpp @@ -1,5 +1,5 @@ /* - $Id: iso3cpp.cpp,v 1.1 2004/11/22 03:36:50 rocky Exp $ + $Id: iso3.cpp,v 1.1 2005/02/19 11:42:18 rocky Exp $ Copyright (C) 2004 Rocky Bernstein @@ -23,7 +23,7 @@ */ /* This is the ISO 9660 image. */ -#define ISO9660_IMAGE_PATH "../" +#define ISO9660_IMAGE_PATH "../../" #define ISO9660_IMAGE ISO9660_IMAGE_PATH "test/copying.iso" #define LOCAL_FILENAME "copying" @@ -68,8 +68,15 @@ main(int argc, const char *argv[]) iso9660_stat_t *p_statbuf; FILE *p_outfd; int i; + char const *psz_fname; + iso9660_t *p_iso; - iso9660_t *p_iso = iso9660_open (ISO9660_IMAGE); + if (argc > 1) + psz_fname = argv[1]; + else + psz_fname = ISO9660_IMAGE; + + p_iso = iso9660_open (psz_fname); if (NULL == p_iso) { fprintf(stderr, "Sorry, couldn't open ISO 9660 image %s\n", ISO9660_IMAGE); diff --git a/example/C++/mmc1.cpp b/example/C++/mmc1.cpp new file mode 100644 index 00000000..77e547ad --- /dev/null +++ b/example/C++/mmc1.cpp @@ -0,0 +1,82 @@ +/* + $Id: mmc1.cpp,v 1.1 2005/02/19 11:42:18 rocky Exp $ + + Copyright (C) 2004 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 +*/ + +/* Simple program to show use of SCSI MMC interface. Is basically the + the libdio scsi_mmc_get_hwinfo() routine. +*/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#include +#include +#include +#include +#include + +/* Set how long to wait for MMC commands to complete */ +#define DEFAULT_TIMEOUT_MS 10000 + +int +main(int argc, const char *argv[]) +{ + CdIo_t *p_cdio; + + p_cdio = cdio_open (NULL, DRIVER_UNKNOWN); + + if (NULL == p_cdio) { + printf("Couldn't find CD\n"); + return 1; + } else { + int i_status; /* Result of MMC command */ + char buf[36] = { 0, }; /* Place to hold returned data */ + scsi_mmc_cdb_t cdb = {{0, }}; /* Command Descriptor Buffer */ + + CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_INQUIRY); + cdb.field[4] = sizeof(buf); + + i_status = mmc_run_cmd(p_cdio, DEFAULT_TIMEOUT_MS, &cdb, + SCSI_MMC_DATA_READ, sizeof(buf), &buf); + if (i_status == 0) { + char psz_vendor[CDIO_MMC_HW_VENDOR_LEN+1]; + char psz_model[CDIO_MMC_HW_MODEL_LEN+1]; + char psz_rev[CDIO_MMC_HW_REVISION_LEN+1]; + + memcpy(psz_vendor, buf + 8, sizeof(psz_vendor)-1); + psz_vendor[sizeof(psz_vendor)-1] = '\0'; + memcpy(psz_model, + buf + 8 + CDIO_MMC_HW_VENDOR_LEN, + sizeof(psz_model)-1); + psz_model[sizeof(psz_model)-1] = '\0'; + memcpy(psz_rev, + buf + 8 + CDIO_MMC_HW_VENDOR_LEN +CDIO_MMC_HW_MODEL_LEN, + sizeof(psz_rev)-1); + psz_rev[sizeof(psz_rev)-1] = '\0'; + + printf("Vendor: %s\nModel: %s\nRevision: %s\n", + psz_vendor, psz_model, psz_rev); + } else { + printf("Couldn't get INQUIRY data (vendor, model, and revision).\n"); + } + } + + cdio_destroy(p_cdio); + + return 0; +} diff --git a/example/C++/mmc2.cpp b/example/C++/mmc2.cpp new file mode 100644 index 00000000..41ba99c5 --- /dev/null +++ b/example/C++/mmc2.cpp @@ -0,0 +1,188 @@ +/* + $Id: mmc2.cpp,v 1.1 2005/02/19 11:42:18 rocky Exp $ + + Copyright (C) 2004, 2005 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 +*/ + +/* A program to using the MMC interface to list CD and drive features + from the MMC GET_CONFIGURATION command . */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#include +#include +#include +#include +#include + +/* Set how long do wto wait for SCSI-MMC commands to complete */ +#define DEFAULT_TIMEOUT_MS 10000 + +int +main(int argc, const char *argv[]) +{ + CdIo_t *p_cdio; + + p_cdio = cdio_open (NULL, DRIVER_UNKNOWN); + + if (NULL == p_cdio) { + printf("Couldn't find CD\n"); + return 1; + } else { + int i_status; /* Result of MMC command */ + uint8_t buf[500] = { 0, }; /* Place to hold returned data */ + scsi_mmc_cdb_t cdb = {{0, }}; /* Command Descriptor Buffer */ + + CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_GET_CONFIGURATION); + CDIO_MMC_SET_READ_LENGTH8(cdb.field, sizeof(buf)); + cdb.field[1] = CDIO_MMC_GET_CONF_ALL_FEATURES; + cdb.field[3] = 0x0; + + i_status = mmc_run_cmd(p_cdio, 0, &cdb, SCSI_MMC_DATA_READ, sizeof(buf), + &buf); + if (i_status == 0) { + uint8_t *p; + uint32_t i_data; + uint8_t *p_max = buf + 65530; + + i_data = (unsigned int) CDIO_MMC_GET_LEN32(buf); + /* set to first sense feature code, and then walk through the masks */ + p = buf + 8; + while( (p < &(buf[i_data])) && (p < p_max) ) { + uint16_t i_feature; + uint8_t i_feature_additional = p[3]; + + i_feature = CDIO_MMC_GET_LEN16(p); + { + uint8_t *q; + const char *feature_str = mmc_feature2str(i_feature); + printf("%s Feature\n", feature_str); + switch( i_feature ) + { + case CDIO_MMC_FEATURE_PROFILE_LIST: + for ( q = p+4 ; q < p + i_feature_additional ; q += 4 ) { + int i_profile=CDIO_MMC_GET_LEN16(q); + const char *feature_profile_str = + mmc_feature_profile2str(i_profile); + printf( "\t%s", feature_profile_str ); + if (q[2] & 1) { + printf(" - on"); + } + printf("\n"); + } + printf("\n"); + + break; + case CDIO_MMC_FEATURE_CORE: + { + uint8_t *q = p+4; + uint32_t i_interface_standard = CDIO_MMC_GET_LEN32(q); + switch(i_interface_standard) { + case 0: + printf("\tunspecified interface\n"); + break; + case 1: + printf("\tSCSI interface\n"); + break; + case 2: + printf("\tATAPI interface\n"); + break; + case 3: + printf("\tIEEE 1394 interface\n"); + break; + case 4: + printf("\tIEEE 1394A interface\n"); + break; + case 5: + printf("\tFibre Channel interface\n"); + } + printf("\n"); + break; + } + case CDIO_MMC_FEATURE_REMOVABLE_MEDIUM: + switch(p[4] >> 5) { + case 0: + printf("\tCaddy/Slot type loading mechanism\n"); + break; + case 1: + printf("\tTray type loading mechanism\n"); + break; + case 2: + printf("\tPop-up type loading mechanism\n"); + break; + case 4: + printf("\tEmbedded changer with individually changeable discs\n"); + break; + case 5: + printf("\tEmbedded changer using a magazine mechanism\n"); + break; + default: + printf("\tUnknown changer mechanism\n"); + } + + printf("\tcan%s eject the medium or magazine via the normal " + "START/STOP command\n", + (p[4] & 8) ? "": "not"); + printf("\tcan%s be locked into the Logical Unit\n", + (p[4] & 1) ? "": "not"); + printf("\n"); + break; + case CDIO_MMC_FEATURE_CD_READ: + printf("CD Read Feature\n"); + printf("\tC2 Error pointers are %ssupported\n", + (p[4] & 2) ? "": "not "); + printf("\tCD-Text is %ssupported\n", + (p[4] & 1) ? "": "not "); + printf("\n"); + break; + case CDIO_MMC_FEATURE_CDDA_EXT_PLAY: + printf("\tSCAN command is %ssupported\n", + (p[4] & 4) ? "": "not "); + printf("\taudio channels can %sbe muted separately\n", + (p[4] & 2) ? "": "not "); + printf("\taudio channels can %shave separate volume levels\n", + (p[4] & 1) ? "": "not "); + { + uint8_t *q = p+6; + uint16_t i_vol_levels = CDIO_MMC_GET_LEN16(q); + printf("\t%d volume levels can be set\n", i_vol_levels); + } + printf("\n"); + break; + case CDIO_MMC_FEATURE_LU_SN: { + uint8_t i_serial = *(p+3); + char serial[257] = { '\0', }; + memcpy(serial, p+4, i_serial); + printf("\t%s\n\n", serial); + break; + } + default: + printf("\n"); + break; + } + p += i_feature_additional + 4; + } + } + } else { + printf("Didn't get all feature codes\n"); + } + } + + cdio_destroy(p_cdio); + + return 0; +} diff --git a/example/Makefile.am b/example/Makefile.am index ddbcdd99..8f55ee82 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -1,4 +1,4 @@ -# $Id: Makefile.am,v 1.18 2005/02/09 02:50:47 rocky Exp $ +# $Id: Makefile.am,v 1.19 2005/02/19 11:42:18 rocky Exp $ # # Copyright (C) 2003, 2004, 2005 Rocky Bernstein # @@ -20,14 +20,11 @@ # Things to regression testing #################################################### # -if DISABLE_CPP -noinst_PROGRAMS = cdtext device drives iso1 iso2 iso3 isofuzzy mmc1 mmc2 \ - paranoia paranoia2 tracks sample3 sample4 -else -noinst_PROGRAMS = cdtext device drives iso1 iso2 iso3 isofuzzy mmc1 mmc2 \ - paranoia paranoia2 tracks sample3 sample4 \ - iso1cpp iso2cpp iso3cpp +if !DISABLE_CPP +SUBDIRS = C++ endif +noinst_PROGRAMS = cdtext device drives iso1 iso2 iso3 isofuzzy mmc1 mmc2 \ + mmc4 paranoia paranoia2 tracks sample3 sample4 INCLUDES = -I$(top_srcdir) $(LIBCDIO_CFLAGS) @@ -45,17 +42,9 @@ iso2_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) iso3_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) isofuzzy_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) -if !DISABLE_CPP -iso1cpp_SOURCES = iso1cpp.cpp -iso1cpp_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) -iso2cpp_SOURCES = iso2cpp.cpp -iso2cpp_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) -iso3cpp_SOURCES = iso3cpp.cpp -iso3cpp_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) -endif - mmc1_LDADD = $(LIBCDIO_LIBS) mmc2_LDADD = $(LIBCDIO_LIBS) +mmc4_LDADD = $(LIBCDIO_LIBS) sample3_LDADD = $(LIBCDIO_LIBS) sample4_LDADD = $(LIBCDIO_LIBS) diff --git a/example/iso3.c b/example/iso3.c index 86f0c638..765ee974 100644 --- a/example/iso3.c +++ b/example/iso3.c @@ -1,5 +1,5 @@ /* - $Id: iso3.c,v 1.3 2004/11/22 01:03:53 rocky Exp $ + $Id: iso3.c,v 1.4 2005/02/19 11:42:18 rocky Exp $ Copyright (C) 2004 Rocky Bernstein @@ -68,8 +68,15 @@ main(int argc, const char *argv[]) iso9660_stat_t *p_statbuf; FILE *p_outfd; int i; + char const *psz_fname; + iso9660_t *p_iso; - iso9660_t *p_iso = iso9660_open (ISO9660_IMAGE); + if (argc > 1) + psz_fname = argv[1]; + else + psz_fname = ISO9660_IMAGE; + + p_iso = iso9660_open (psz_fname); if (NULL == p_iso) { fprintf(stderr, "Sorry, couldn't open ISO 9660 image %s\n", ISO9660_IMAGE);