diff --git a/doc/libcdio.texi b/doc/libcdio.texi index 0fac4a95..aa056bf5 100644 --- a/doc/libcdio.texi +++ b/doc/libcdio.texi @@ -46,7 +46,7 @@ development.'' @titlepage @title GNU libcdio library -@subtitle $Id: libcdio.texi,v 1.26 2004/08/07 11:27:03 rocky Exp $ +@subtitle $Id: libcdio.texi,v 1.27 2004/10/10 00:21:08 rocky Exp $ @author Rocky Bernstein et al. @page @@ -558,16 +558,17 @@ Other sources for examples would be the larger utility programs @menu * Example 1:: list out tracks and LSNs * Example 2:: list drivers available and default CD device -* Example 3:: list out tracks and LSNs +* Example 3:: figure out what kind of CD (image) we've got * Example 4:: use libiso9660 to extract a file from an ISO-9660 image * Example 5:: list CD-Text and CD disc mode info +* Example 6:: run a SCSI-MMC INQUIRY command * All sample programs:: list of all programs in the example directory @end menu @node Example 1 @section Example 1: list out tracks and LSNs Here we will give an annotated example which can be found in the -distribution as @file{example/sample1.c}. +distribution as @file{example/tracks.c}. @smallexample 1: #include @@ -685,11 +686,11 @@ device that is right for it. @node Example 3 -@section Example 3: figure out what kind of CD image we've got +@section Example 3: figure out what kind of CD (image) we've got In this example is a somewhat simplified program to show the use of @command{cdio_guess_cd_type()} to figure out the kind of CD image -we've got. This can be in the distribution as @file{example/sample3.c}. +we've got. This can be found in the distribution as @file{example/sample3.c}. @smallexample #ifdef HAVE_CONFIG_H @@ -875,8 +876,8 @@ main(int argc, const char *argv[]) @section Example 4: use libiso9660 to extract a file from an ISO-9660 image Next a program to show using @command{libiso9660} to extract a file -from an ISO-9660 image. This can be in the distribution as -@file{example/sample7.c}. A more complete and expanded version of this +from an ISO-9660 image. This can be found in the distribution as +@file{example/iso3.c}. A more complete and expanded version of this is @command{iso-read}, part of this distribution. @smallexample @@ -989,10 +990,10 @@ main(int argc, const char *argv[]) @section Example 5: list CD-Text and disc mode info Next a program to show using @command{libcdio} to list CD-TEXT data. -This can be in the distribution as @file{example/sample8.c}. +This can be found in the distribution as @file{example/cdtext.c}. @smallexample -/* Simple program to list CD-TEXT info of a Compact Disc using libcdio. */ +/* Simple program to list CD-Text info of a Compact Disc using libcdio. */ #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -1026,10 +1027,10 @@ print_disc_info(CdIo *p_cdio, track_t i_tracks, track_t i_first_track) @{ printf("%s\n", discmode2str[cd_discmode]); - print_cdtext_track_info(p_cdio, 0, "\nCD-TEXT for Disc:"); + print_cdtext_track_info(p_cdio, 0, "\nCD-Text for Disc:"); for ( ; i_first_track < i_last_track; i_first_track++ ) @{ char psz_msg[50]; - sprintf(msg, "CD-TEXT for Track %d:", i_first_track); + sprintf(msg, "CD-Text for Track %d:", i_first_track); print_cdtext_track_info(p_cdio, i_first_track, psz_msg); @} @} @@ -1057,6 +1058,80 @@ main(int argc, const char *argv[]) @} @end smallexample +@node Example 6 +@section Example 6: Using SCSI-MMC to run an @code{INQURY} command + +Now a program to show issuing a simple SCSI-MMC command +(@code{INQUIRY}). This MMC command retrieves the vendor, model and +firmware revision number of a CD drive. For this command to work, +usually a CD to be loaded into the drive; odd since the CD itself is +not used. + +This can be found in the distribution as @file{example/scsi-mmc1.c}. + +@smallexample +#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 *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 SCSI MMC command */ + char buf[36] = @{ 0, @}; /* Place to hold returned data */ + scsi_mmc_cdb_t cdb = @{@{0, @}@}; /* Command Descriptor Block */ + + 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; +@} +@end smallexample + @node All sample programs @section A list of all sample progrmas in the @code{example} directory @@ -1071,7 +1146,40 @@ Descriptions of the sample are as follows... @table @code -@item @code{sample1.c} +@item @code{iso1.c} + +A program to show using @code{libiso9660} to list files in a + directory of an ISO-9660 image. + +@item @code{iso2.c} + +A program to show using @code{libiso9660} to extract a file from a +CDRWIN cue/bin CD image. + +@item @code{iso3.c} + +A program to show using libiso9660 to extract a file from an ISO-9660 +image. + +@item @code{cdtext.c} + +A program to show CD-Text and CD disc mode info. + +@item @code{drives.c} + +A program to show drivers installed and what the default CD-ROM drive +is and what CD drives are available. + +@item @code{scsi-mmc1.c} + +A program to show issuing a simple SCSI-MMC command (@code{INQUIRY}). + +@item @code{scsi-mmc2.c} + +A more involved SCSI-MMC command to list CD and drive features from a +SCSI-MMC @code{GET_CONFIGURATION} command. + +@item @code{tracks.c} A simple program to list track numbers and logical sector numbers of a Compact Disc using @value{libcdio}. @@ -1091,34 +1199,6 @@ the kind of CD image we've got. A slightly improved sample3 program: we handle cdio logging and take an optional CD-location. -@item @code{sample5.c} - -A program to show drivers installed and what the default CD-ROM drive -is and what CD drives are available. - -@item @code{sample6.c} - -A simple program to show using @code{libiso9660} to extract a file from a -CDRWIN cue/bin CD image. - -@item @code{sample7.c} - -A program to show using libiso9660 to extract a file from an ISO-9660 -image. - -@item @code{sample8.c} - -A program to show CD-Text and CD disc mode info. - -@item @code{sample9.c} - -A program to show issuing a simple SCSI-MMC command (@code{INQUIRY}). - -@item @code{sample10.c} - -A more involved SCSI-MMC command to list features from a SCSI-MMC -@code{GET_CONFIGURATION} command. - @end table @node Utility Programs diff --git a/example/.cvsignore b/example/.cvsignore index 20db22ea..e31e9f88 100644 --- a/example/.cvsignore +++ b/example/.cvsignore @@ -4,5 +4,10 @@ Makefile.in Makefile copying +drives +iso? +cdtext sample? -sample?? +scsi-mmc1 +scsi-mmc2 +tracks diff --git a/example/Makefile.am b/example/Makefile.am index 3a5f0822..ac73f662 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -1,4 +1,4 @@ -# $Id: Makefile.am,v 1.8 2004/10/09 03:20:28 rocky Exp $ +# $Id: Makefile.am,v 1.9 2004/10/10 00:21:08 rocky Exp $ # # Copyright (C) 2003, 2004 Rocky Bernstein # @@ -20,19 +20,24 @@ # Things to regression testing #################################################### # -noinst_PROGRAMS = sample1 sample2 sample3 sample4 sample5 sample6 \ - sample7 sample8 sample9 sample10 iso1 +noinst_PROGRAMS = cdtext drives iso1 iso2 iso3 scsi-mmc1 scsi-mmc2 \ + tracks sample2 sample3 sample4 INCLUDES = -I$(top_srcdir) $(LIBCDIO_CFLAGS) +cdtext_LDADD = $(LIBCDIO_LIBS) + +drives_LDADD = $(LIBCDIO_LIBS) + iso1_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) -sample1_LDADD = $(LIBCDIO_LIBS) +iso2_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) +iso3_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) + +scsi_mmc1_LDADD = $(LIBCDIO_LIBS) +scsi_mmc2_LDADD = $(LIBCDIO_LIBS) + sample2_LDADD = $(LIBCDIO_LIBS) sample3_LDADD = $(LIBCDIO_LIBS) sample4_LDADD = $(LIBCDIO_LIBS) -sample5_LDADD = $(LIBCDIO_LIBS) -sample6_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) -sample7_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) -sample8_LDADD = $(LIBCDIO_LIBS) -sample9_LDADD = $(LIBCDIO_LIBS) -sample10_LDADD = $(LIBCDIO_LIBS) + +tracks_LDADD = $(LIBCDIO_LIBS) diff --git a/example/README b/example/README index 41a02f9e..e17912a2 100644 --- a/example/README +++ b/example/README @@ -1,4 +1,4 @@ -$Id: README,v 1.8 2004/08/07 10:40:29 rocky Exp $ +$Id: README,v 1.9 2004/10/10 00:21:08 rocky Exp $ This directory contains some simple examples of the use of the libcdio library. @@ -8,6 +8,22 @@ iso-info and iso-read programs in the src directory. Descriptions of the programs here are as follows... +cdtext.c: A program to show CD-Text and CD disc mode info. + +iso1.c: A program to show using libiso9660 to list files in a + directory of an ISO-9660 image. + +iso2.c: A simple program to show using libiso9660 to extract a file + from a CDRWIN cue/bin CD image. + +iso3.c: A program to show using libiso9660 to extract a file from an + ISO-9660 image. + +scsi-mmc1.c: A program to show issuing a simple SCSI-MMC command (INQUIRY). + +scsi-mmc2.c: A more involved SCSI-MMC command to list features from + a SCSI GET_CONFIGURATION command. + sample1.c: A simple program to list track numbers and logical sector numbers of a Compact Disc using libcdio. @@ -23,17 +39,4 @@ sample4.c: A slightly improved sample3 program: we handle cdio logging sample5.c: A program to show drivers installed and what the default CD-ROM drive is and what CD drives are available. -sample6.c: A simple program to show using libiso9660 to extract a file - from a CDRWIN cue/bin CD image. - -sample7.c: A program to show using libiso9660 to extract a file from an - ISO-9660 image. - -sample8.c: A program to show CD-Text and CD disc mode info. - -sample9.c: A program to show issuing a simple SCSI-MMC command (INQUIRY). - -sample10.c: A more involved SCSI-MMC command to list features from - a SCSI GET_CONFIGURATION command. - diff --git a/example/sample8.c b/example/cdtext.c similarity index 91% rename from example/sample8.c rename to example/cdtext.c index 2043969b..55f2b85f 100644 --- a/example/sample8.c +++ b/example/cdtext.c @@ -1,5 +1,5 @@ /* - $Id: sample8.c,v 1.12 2004/07/29 05:32:55 rocky Exp $ + $Id: cdtext.c,v 1.1 2004/10/10 00:21:08 rocky Exp $ Copyright (C) 2004 Rocky Bernstein @@ -18,7 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* Simple program to list CD-TEXT info of a Compact Disc using libcdio. */ +/* Simple program to list CD-Text info of a Compact Disc using libcdio. */ #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -52,10 +52,10 @@ print_disc_info(CdIo *p_cdio, track_t i_tracks, track_t i_first_track) { printf("%s\n", discmode2str[cd_discmode]); - print_cdtext_track_info(p_cdio, 0, "\nCD-TEXT for Disc:"); + print_cdtext_track_info(p_cdio, 0, "\nCD-Text for Disc:"); for ( ; i_first_track < i_last_track; i_first_track++ ) { char psz_msg[50]; - sprintf(psz_msg, "CD-TEXT for Track %d:", i_first_track); + sprintf(psz_msg, "CD-Text for Track %d:", i_first_track); print_cdtext_track_info(p_cdio, i_first_track, psz_msg); } } diff --git a/example/sample5.c b/example/drives.c similarity index 98% rename from example/sample5.c rename to example/drives.c index d3da9391..a8e16a9c 100644 --- a/example/sample5.c +++ b/example/drives.c @@ -1,5 +1,5 @@ /* - $Id: sample5.c,v 1.7 2004/08/27 11:32:12 rocky Exp $ + $Id: drives.c,v 1.1 2004/10/10 00:21:08 rocky Exp $ Copyright (C) 2003, 2004 Rocky Bernstein diff --git a/example/iso1.c b/example/iso1.c new file mode 100644 index 00000000..710609e1 --- /dev/null +++ b/example/iso1.c @@ -0,0 +1,82 @@ +/* + $Id: iso1.c,v 1.1 2004/10/10 00:21:08 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 using libiso9660 to list files in a directory of + an ISO-9660 image. + */ + +/* This is the ISO 9660 image. */ +#define ISO9660_IMAGE_PATH "../" +#define ISO9660_IMAGE ISO9660_IMAGE_PATH "test/copying.iso" + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#include +#include +#include + +#include + +#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 *entlist; + CdioListNode *entnode; + + iso9660_t *p_iso = iso9660_open (ISO9660_IMAGE); + + if (NULL == p_iso) { + fprintf(stderr, "Sorry, couldn't open ISO 9660 image %s\n", ISO9660_IMAGE); + return 1; + } + + entlist = iso9660_ifs_readdir (p_iso, "/"); + + /* Iterate over the list of nodes that iso9660_ifs_readdir gives */ + + _CDIO_LIST_FOREACH (entnode, entlist) + { + char filename[4096]; + iso9660_stat_t *p_statbuf = _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); + return 0; +} + diff --git a/example/sample6.c b/example/iso2.c similarity index 98% rename from example/sample6.c rename to example/iso2.c index 1dd9c6ff..ebef1cea 100644 --- a/example/sample6.c +++ b/example/iso2.c @@ -1,5 +1,5 @@ /* - $Id: sample6.c,v 1.8 2004/08/27 11:34:44 rocky Exp $ + $Id: iso2.c,v 1.1 2004/10/10 00:21:08 rocky Exp $ Copyright (C) 2003, 2004 Rocky Bernstein diff --git a/example/sample7.c b/example/iso3.c similarity index 98% rename from example/sample7.c rename to example/iso3.c index bcd583e7..04194fbd 100644 --- a/example/sample7.c +++ b/example/iso3.c @@ -1,5 +1,5 @@ /* - $Id: sample7.c,v 1.8 2004/08/27 11:36:45 rocky Exp $ + $Id: iso3.c,v 1.1 2004/10/10 00:21:08 rocky Exp $ Copyright (C) 2004 Rocky Bernstein diff --git a/example/sample9.c b/example/scsi-mmc1.c similarity index 97% rename from example/sample9.c rename to example/scsi-mmc1.c index c530120a..102b79e9 100644 --- a/example/sample9.c +++ b/example/scsi-mmc1.c @@ -1,5 +1,5 @@ /* - $Id: sample9.c,v 1.2 2004/08/27 11:53:38 rocky Exp $ + $Id: scsi-mmc1.c,v 1.1 2004/10/10 00:21:08 rocky Exp $ Copyright (C) 2004 Rocky Bernstein diff --git a/example/sample10.c b/example/scsi-mmc2.c similarity index 98% rename from example/sample10.c rename to example/scsi-mmc2.c index e8a0d084..d3bfc1a4 100644 --- a/example/sample10.c +++ b/example/scsi-mmc2.c @@ -1,5 +1,5 @@ /* - $Id: sample10.c,v 1.8 2004/08/10 11:58:14 rocky Exp $ + $Id: scsi-mmc2.c,v 1.1 2004/10/10 00:21:08 rocky Exp $ Copyright (C) 2004 Rocky Bernstein @@ -18,7 +18,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* Simple program to show use of SCSI MMC interface. */ +/* A program to using the SCSI-MMC interface to list CD and drive features + from the MMC GET_CONFIGURATION command . */ #ifdef HAVE_CONFIG_H # include "config.h" #endif diff --git a/example/sample1.c b/example/tracks.c similarity index 97% rename from example/sample1.c rename to example/tracks.c index a51bac6b..c11fc306 100644 --- a/example/sample1.c +++ b/example/tracks.c @@ -1,5 +1,5 @@ /* - $Id: sample1.c,v 1.6 2004/08/07 10:50:03 rocky Exp $ + $Id: tracks.c,v 1.1 2004/10/10 00:21:08 rocky Exp $ Copyright (C) 2003, 2004 Rocky Bernstein