diff --git a/example/.cvsignore b/example/.cvsignore index 7ccb795d..8fba6b1a 100644 --- a/example/.cvsignore +++ b/example/.cvsignore @@ -1,16 +1,16 @@ .cvsignore .deps .libs -Makefile.in Makefile +Makefile.in +cdtext copying drives iso? iso?cpp -cdtext +mmc1 +mmc2 paranoia paranoia2 sample? -scsi-mmc1 -scsi-mmc2 tracks diff --git a/example/Makefile.am b/example/Makefile.am index 6f6a40af..7af420db 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -1,4 +1,4 @@ -# $Id: Makefile.am,v 1.15 2005/01/22 03:41:50 rocky Exp $ +# $Id: Makefile.am,v 1.16 2005/02/04 23:12:16 rocky Exp $ # # Copyright (C) 2003, 2004, 2005 Rocky Bernstein # @@ -21,10 +21,10 @@ #################################################### # if DISABLE_CPP -noinst_PROGRAMS = cdtext drives iso1 iso2 iso3 scsi-mmc1 scsi-mmc2 \ +noinst_PROGRAMS = cdtext drives iso1 iso2 iso3 iso4 mmc1 mmc2 \ paranoia paranoia2 tracks sample2 sample3 sample4 else -noinst_PROGRAMS = cdtext drives iso1 iso2 iso3 paranoia scsi-mmc1 scsi-mmc2 \ +noinst_PROGRAMS = cdtext drives iso1 iso2 iso3 iso4 mmc1 mmc2 \ paranoia paranoia2 tracks sample2 sample3 sample4 \ iso1cpp iso2cpp iso3cpp endif @@ -41,6 +41,7 @@ paranoia2_LDADD = $(LIBCDIO_PARANOIA_LIBS) $(LIBCDIO_CDDA_LIBS) $(LIBCDIO_LIBS) iso1_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) iso2_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) iso3_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) +iso4_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) if !DISABLE_CPP iso1cpp_SOURCES = iso1cpp.cpp @@ -51,8 +52,8 @@ iso3cpp_SOURCES = iso3cpp.cpp iso3cpp_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) endif -scsi_mmc1_LDADD = $(LIBCDIO_LIBS) -scsi_mmc2_LDADD = $(LIBCDIO_LIBS) +mmc1_LDADD = $(LIBCDIO_LIBS) +mmc2_LDADD = $(LIBCDIO_LIBS) sample2_LDADD = $(LIBCDIO_LIBS) sample3_LDADD = $(LIBCDIO_LIBS) diff --git a/example/iso4.c b/example/iso4.c new file mode 100644 index 00000000..0c575752 --- /dev/null +++ b/example/iso4.c @@ -0,0 +1,96 @@ +/* + $Id: iso4.c,v 1.1 2005/02/04 23:12:16 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 +*/ + +/* Program to show using libiso9660 with fuzzy search to get file info. + */ + +/* This is the BIN we think there is an ISO 9660 image inside of. */ +#define ISO9660_IMAGE_PATH "/tmp/" +#define ISO9660_IMAGE ISO9660_IMAGE_PATH "vcd_demo.bin" + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "portable.h" + +#include +#include +#include + +#include + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +int +main(int argc, const char *argv[]) +{ + CdioList_t *entlist; + CdioListNode_t *entnode; + char const *psz_fname; + iso9660_t *p_iso; + + if (argc > 1) + psz_fname = argv[1]; + else + psz_fname = ISO9660_IMAGE; + + p_iso = iso9660_open_fuzzy (psz_fname, 5); + + if (NULL == p_iso) { + fprintf(stderr, "Sorry, could not find ISO 9660 image from %s\n", + psz_fname); + return 1; + } + + entlist = iso9660_ifs_readdir (p_iso, "/"); + + /* Iterate over the list of nodes that iso9660_ifs_readdir gives */ + + if (entlist) { + _CDIO_LIST_FOREACH (entnode, entlist) + { + char filename[4096]; + iso9660_stat_t *p_statbuf = + (iso9660_stat_t *) _cdio_list_node_data (entnode); + iso9660_name_translate(p_statbuf->filename, filename); + printf ("/%s\n", filename); + } + + _cdio_list_free (entlist, true); + } + + iso9660_close(p_iso); + exit(0); +} diff --git a/example/mmc1.c b/example/mmc1.c new file mode 100644 index 00000000..fa3a1406 --- /dev/null +++ b/example/mmc1.c @@ -0,0 +1,83 @@ +/* + $Id: mmc1.c,v 1.1 2005/02/04 23:12:16 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 = scsi_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/mmc2.c b/example/mmc2.c new file mode 100644 index 00000000..0cff0f25 --- /dev/null +++ b/example/mmc2.c @@ -0,0 +1,324 @@ +/* + $Id: mmc2.c,v 1.1 2005/02/04 23:12:16 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 +*/ + +/* 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 = scsi_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); + switch( i_feature ) + { + uint8_t *q; + case CDIO_MMC_FEATURE_PROFILE_LIST: + printf("Profile List Feature\n"); + for ( q = p+4 ; q < p + i_feature_additional ; q += 4 ) { + int i_profile=CDIO_MMC_GET_LEN16(q); + switch (i_profile) { + case CDIO_MMC_FEATURE_PROF_NON_REMOVABLE: + printf("\tRe-writable disk, capable of changing behavior"); + break; + case CDIO_MMC_FEATURE_PROF_REMOVABLE: + printf("\tdisk Re-writable; with removable media"); + break; + case CDIO_MMC_FEATURE_PROF_MO_ERASABLE: + printf("\tErasable Magneto-Optical disk with sector erase capability"); + break; + case CDIO_MMC_FEATURE_PROF_MO_WRITE_ONCE: + printf("\tWrite Once Magneto-Optical write once"); + break; + case CDIO_MMC_FEATURE_PROF_AS_MO: + printf("\tAdvance Storage Magneto-Optical"); + break; + case CDIO_MMC_FEATURE_PROF_CD_ROM: + printf("\tRead only Compact Disc capable"); + break; + case CDIO_MMC_FEATURE_PROF_CD_R: + printf("\tWrite once Compact Disc capable"); + break; + case CDIO_MMC_FEATURE_PROF_CD_RW: + printf("\tCD-RW Re-writable Compact Disc capable"); + break; + case CDIO_MMC_FEATURE_PROF_DVD_ROM: + printf("\tRead only DVD"); + break; + case CDIO_MMC_FEATURE_PROF_DVD_R_SEQ: + printf("\tRe-recordable DVD using Sequential recording"); + break; + case CDIO_MMC_FEATURE_PROF_DVD_RAM: + printf("\tRe-writable DVD"); + break; + case CDIO_MMC_FEATURE_PROF_DVD_RW_RO: + printf("\tRe-recordable DVD using Restricted Overwrite"); + break; + case CDIO_MMC_FEATURE_PROF_DVD_RW_SEQ: + printf("\tRe-recordable DVD using Sequential recording"); + break; + case CDIO_MMC_FEATURE_PROF_DVD_PRW: + printf("\tDVD+RW - DVD ReWritable"); + break; + case CDIO_MMC_FEATURE_PROF_DVD_PR: + printf("\tDVD+R - DVD Recordable"); + break; + case CDIO_MMC_FEATURE_PROF_DDCD_ROM: + printf("\tRead only DDCD"); + break; + case CDIO_MMC_FEATURE_PROF_DDCD_R: + printf("\tDDCD-R Write only DDCD"); + break; + case CDIO_MMC_FEATURE_PROF_DDCD_RW: + printf("\tRe-Write only DDCD"); + break; + case CDIO_MMC_FEATURE_PROF_NON_CONFORM: + printf("\tThe Logical Unit does not conform to any Profile."); + break; + default: + printf("\tUnknown Profile %x", i_profile); + break; + } + 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); + printf("Core Feature\n"); + 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: + printf("Removable Medium Feature\n"); + 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_WRITE_PROTECT: + printf("Write Protect Feature\n"); + break; + case CDIO_MMC_FEATURE_RANDOM_READABLE: + printf("Random Readable Feature\n"); + break; + case CDIO_MMC_FEATURE_MULTI_READ: + printf("Multi-Read Feature\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_DVD_READ: + printf("DVD Read Feature\n"); + break; + case CDIO_MMC_FEATURE_RANDOM_WRITABLE: + printf("Random Writable Feature\n"); + break; + case CDIO_MMC_FEATURE_INCR_WRITE: + printf("Incremental Streaming Writable Feature\n"); + break; + case CDIO_MMC_FEATURE_SECTOR_ERASE: + printf("Sector Erasable Feature\n"); + break; + case CDIO_MMC_FEATURE_FORMATABLE: + printf("Formattable Feature\n"); + break; + case CDIO_MMC_FEATURE_DEFECT_MGMT: + printf("Management Ability of the Logical Unit/media system " + "to provide an apparently defect-free space.\n"); + break; + case CDIO_MMC_FEATURE_WRITE_ONCE: + printf("Write Once Feature\n"); + break; + case CDIO_MMC_FEATURE_RESTRICT_OVERW: + printf("Restricted Overwrite Feature\n"); + break; + case CDIO_MMC_FEATURE_CD_RW_CAV: + printf("CD-RW CAV Write Feature\n"); + break; + case CDIO_MMC_FEATURE_MRW: + printf("MRW Feature\n"); + break; + case CDIO_MMC_FEATURE_DVD_PRW: + printf("DVD+RW Feature\n"); + break; + case CDIO_MMC_FEATURE_DVD_PR: + printf("DVD+R Feature\n"); + break; + case CDIO_MMC_FEATURE_CD_TAO: + printf("CD Track at Once Feature\n"); + break; + case CDIO_MMC_FEATURE_CD_SAO: + printf("CD Mastering (Session at Once) Feature\n"); + break; + case CDIO_MMC_FEATURE_POWER_MGMT: + printf("Initiator and device directed power management\n"); + break; + case CDIO_MMC_FEATURE_CDDA_EXT_PLAY: + printf("CD Audio External Play Feature\n"); + 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_MCODE_UPGRADE: + printf("Ability for the device to accept new microcode via " + "the interface\n"); + break; + case CDIO_MMC_FEATURE_TIME_OUT: + printf("Ability to respond to all commands within a " + "specific time\n"); + break; + case CDIO_MMC_FEATURE_DVD_CSS: + printf("Ability to perform DVD CSS/CPPM authentication and" + " RPC\n"); + break; + case CDIO_MMC_FEATURE_RT_STREAMING: + printf("Ability to read and write using Initiator requested performance parameters\n"); + break; + case CDIO_MMC_FEATURE_LU_SN: { + uint8_t i_serial = *(p+3); + char serial[257] = { '\0', }; + + printf("The Logical Unit has a unique identifier:\n"); + memcpy(serial, p+4, i_serial); + printf("\t%s\n\n", serial); + + break; + } + default: + if ( 0 != (i_feature & 0xFF00) ) { + printf("Vendor-specific feature code %x\n", i_feature); + } else { + printf("Unknown feature code %x\n", i_feature); + } + } + p += i_feature_additional + 4; + } + } else { + printf("Didn't get all feature codes\n"); + } + } + + cdio_destroy(p_cdio); + + return 0; +}