sample9: A program to show issuing a SCSI-MMC command.

sample8: cdio->p_cdio; update copyright
This commit is contained in:
rocky
2004-07-29 05:26:46 +00:00
parent af2d3d31c0
commit fbe0efc195
4 changed files with 104 additions and 23 deletions

View File

@@ -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 <rocky@panix.com> # Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
# #
@@ -21,7 +21,7 @@
#################################################### ####################################################
# #
noinst_PROGRAMS = sample1 sample2 sample3 sample4 sample5 sample6 \ noinst_PROGRAMS = sample1 sample2 sample3 sample4 sample5 sample6 \
sample7 sample8 sample7 sample8 sample9
INCLUDES = -I$(top_srcdir) $(LIBCDIO_CFLAGS) INCLUDES = -I$(top_srcdir) $(LIBCDIO_CFLAGS)
@@ -33,3 +33,4 @@ sample5_LDADD = $(LIBCDIO_LIBS)
sample6_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) sample6_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS)
sample7_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) sample7_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS)
sample8_LDADD = $(LIBCDIO_LIBS) sample8_LDADD = $(LIBCDIO_LIBS)
sample9_LDADD = $(LIBCDIO_LIBS)

View File

@@ -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 This directory contains some simple examples of the use of the libcdio
library. 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. sample8.c: A program to show CD-TEXT and CD disc mode info.
sample9.c: A program to show issuing a SCSI-MMC command.

View File

@@ -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 <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@@ -29,8 +29,8 @@
static void static void
print_cdtext_track_info(CdIo *cdio, track_t i_track, const char *message) { print_cdtext_track_info(CdIo *p_cdio, track_t i_track, const char *message) {
const cdtext_t *cdtext = cdio_get_cdtext(cdio, 0); const cdtext_t *cdtext = cdio_get_cdtext(p_cdio, 0);
if (NULL != cdtext) { if (NULL != cdtext) {
cdtext_field_t i; cdtext_field_t i;
@@ -46,17 +46,17 @@ print_cdtext_track_info(CdIo *cdio, track_t i_track, const char *message) {
} }
static void 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; 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]); 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++ ) { for ( ; i_first_track < i_last_track; i_first_track++ ) {
char msg[50]; char 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(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_first_track;
track_t i_tracks; 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"); printf("Couldn't open ../test/cdda.cue with BIN/CUE driver.\n");
} else { } else {
i_first_track = cdio_get_first_track_num(cdio); i_first_track = cdio_get_first_track_num(p_cdio);
i_tracks = cdio_get_num_tracks(cdio); i_tracks = cdio_get_num_tracks(p_cdio);
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);
} }
cdio = cdio_open (NULL, DRIVER_UNKNOWN); p_cdio = cdio_open (NULL, DRIVER_UNKNOWN);
i_first_track = cdio_get_first_track_num(cdio); i_first_track = cdio_get_first_track_num(p_cdio);
i_tracks = cdio_get_num_tracks(cdio); i_tracks = cdio_get_num_tracks(p_cdio);
if (NULL == cdio) { if (NULL == p_cdio) {
printf("Couldn't find CD\n"); printf("Couldn't find CD\n");
return 1; return 1;
} else { } 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; return 0;
} }

78
example/sample9.c Normal file
View File

@@ -0,0 +1,78 @@
/*
$Id: sample9.c,v 1.1 2004/07/29 05:26:46 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
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 <stdio.h>
#include <sys/types.h>
#include <cdio/cdio.h>
#include <cdio/scsi_mmc.h>
#include <string.h>
/* 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;
}