From fbe0efc1954419f0cb46d5c82256b508cf2e4308 Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 29 Jul 2004 05:26:46 +0000 Subject: [PATCH] sample9: A program to show issuing a SCSI-MMC command. sample8: cdio->p_cdio; update copyright --- example/Makefile.am | 5 +-- example/README | 4 ++- example/sample8.c | 40 +++++++++++------------ example/sample9.c | 78 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 23 deletions(-) create mode 100644 example/sample9.c diff --git a/example/Makefile.am b/example/Makefile.am index 40902a26..b3c2075b 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -1,4 +1,4 @@ -# $Id: Makefile.am,v 1.5 2004/07/08 01:27:57 rocky Exp $ +# $Id: Makefile.am,v 1.6 2004/07/29 05:26:46 rocky Exp $ # # Copyright (C) 2003, 2004 Rocky Bernstein # @@ -21,7 +21,7 @@ #################################################### # noinst_PROGRAMS = sample1 sample2 sample3 sample4 sample5 sample6 \ - sample7 sample8 + sample7 sample8 sample9 INCLUDES = -I$(top_srcdir) $(LIBCDIO_CFLAGS) @@ -33,3 +33,4 @@ sample5_LDADD = $(LIBCDIO_LIBS) sample6_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) sample7_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) sample8_LDADD = $(LIBCDIO_LIBS) +sample9_LDADD = $(LIBCDIO_LIBS) diff --git a/example/README b/example/README index ec3f5b00..5f2f5e7d 100644 --- a/example/README +++ b/example/README @@ -1,4 +1,4 @@ -$Id: README,v 1.5 2004/07/24 06:11:30 rocky Exp $ +$Id: README,v 1.6 2004/07/29 05:26:46 rocky Exp $ This directory contains some simple examples of the use of the libcdio library. @@ -31,4 +31,6 @@ sample7.c: A program to show using libiso9660 to extract a file from an sample8.c: A program to show CD-TEXT and CD disc mode info. +sample9.c: A program to show issuing a SCSI-MMC command. + diff --git a/example/sample8.c b/example/sample8.c index f15c44ca..df1365ae 100644 --- a/example/sample8.c +++ b/example/sample8.c @@ -1,7 +1,7 @@ /* - $Id: sample8.c,v 1.10 2004/07/28 22:03:35 rocky Exp $ + $Id: sample8.c,v 1.11 2004/07/29 05:26:46 rocky Exp $ - Copyright (C) 2003 Rocky Bernstein + 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 @@ -29,8 +29,8 @@ static void -print_cdtext_track_info(CdIo *cdio, track_t i_track, const char *message) { - const cdtext_t *cdtext = cdio_get_cdtext(cdio, 0); +print_cdtext_track_info(CdIo *p_cdio, track_t i_track, const char *message) { + const cdtext_t *cdtext = cdio_get_cdtext(p_cdio, 0); if (NULL != cdtext) { cdtext_field_t i; @@ -46,17 +46,17 @@ print_cdtext_track_info(CdIo *cdio, track_t i_track, const char *message) { } static void -print_disc_info(CdIo *cdio, track_t i_tracks, track_t i_first_track) { +print_disc_info(CdIo *p_cdio, track_t i_tracks, track_t i_first_track) { track_t i_last_track = i_first_track+i_tracks; - discmode_t cd_discmode = cdio_get_discmode(cdio); + discmode_t cd_discmode = cdio_get_discmode(p_cdio); printf("%s\n", discmode2str[cd_discmode]); - print_cdtext_track_info(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 msg[50]; sprintf(msg, "CD-TEXT for Track %d:", i_first_track); - print_cdtext_track_info(cdio, i_first_track, msg); + print_cdtext_track_info(p_cdio, i_first_track, msg); } } @@ -65,30 +65,30 @@ main(int argc, const char *argv[]) { track_t i_first_track; track_t i_tracks; - CdIo *cdio = cdio_open ("../test/cdda.cue", DRIVER_BINCUE); + CdIo *p_cdio = cdio_open ("../test/cdda.cue", DRIVER_BINCUE); - if (NULL == cdio) { + if (NULL == p_cdio) { printf("Couldn't open ../test/cdda.cue with BIN/CUE driver.\n"); } else { - i_first_track = cdio_get_first_track_num(cdio); - i_tracks = cdio_get_num_tracks(cdio); - print_disc_info(cdio, i_tracks, i_first_track); - cdio_destroy(cdio); + i_first_track = cdio_get_first_track_num(p_cdio); + i_tracks = cdio_get_num_tracks(p_cdio); + print_disc_info(p_cdio, i_tracks, i_first_track); + cdio_destroy(p_cdio); } - cdio = cdio_open (NULL, DRIVER_UNKNOWN); - i_first_track = cdio_get_first_track_num(cdio); - i_tracks = cdio_get_num_tracks(cdio); + p_cdio = cdio_open (NULL, DRIVER_UNKNOWN); + i_first_track = cdio_get_first_track_num(p_cdio); + i_tracks = cdio_get_num_tracks(p_cdio); - if (NULL == cdio) { + if (NULL == p_cdio) { printf("Couldn't find CD\n"); return 1; } else { - print_disc_info(cdio, i_tracks, i_first_track); + print_disc_info(p_cdio, i_tracks, i_first_track); } - cdio_destroy(cdio); + cdio_destroy(p_cdio); return 0; } diff --git a/example/sample9.c b/example/sample9.c new file mode 100644 index 00000000..6f8de706 --- /dev/null +++ b/example/sample9.c @@ -0,0 +1,78 @@ +/* + $Id: sample9.c,v 1.1 2004/07/29 05:26:46 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. */ +#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 vendor[CDIO_MMC_HW_VENDOR_LEN+1]; + char model[CDIO_MMC_HW_MODEL_LEN+1]; + char rev[CDIO_MMC_HW_REVISION_LEN+1]; + + memcpy(vendor, buf + 8, sizeof(vendor)-1); + vendor[sizeof(vendor)-1] = '\0'; + memcpy(model, buf + 8 + CDIO_MMC_HW_VENDOR_LEN, sizeof(model)-1); + model[sizeof(model)-1] = '\0'; + memcpy(rev, buf + 8 + CDIO_MMC_HW_VENDOR_LEN +CDIO_MMC_HW_MODEL_LEN, + sizeof(rev)-1); + rev[sizeof(rev)-1] = '\0'; + + printf("Vendor: %s\nModel: %s\nRevision: %s\n", + vendor, model, rev); + } else { + printf("Couldn't get INQUIRY data (vendor, model, and revision\n"); + } + } + + cdio_destroy(p_cdio); + + return 0; +}