First commit after CVS conversion. Should be just administrative changes.
This commit is contained in:
15
example/C++/.cvsignore
Normal file
15
example/C++/.cvsignore
Normal file
@@ -0,0 +1,15 @@
|
||||
Makefile
|
||||
Makefile.in
|
||||
.deps
|
||||
.libs
|
||||
copying
|
||||
device
|
||||
eject
|
||||
isolist
|
||||
isofile
|
||||
isofile2
|
||||
mmc1
|
||||
mmc2
|
||||
paranoia
|
||||
paranoia2
|
||||
|
||||
3
example/C++/.gitignore
vendored
Normal file
3
example/C++/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/.deps
|
||||
/Makefile
|
||||
/Makefile.in
|
||||
67
example/C++/Makefile.am
Normal file
67
example/C++/Makefile.am
Normal file
@@ -0,0 +1,67 @@
|
||||
# $Id: Makefile.am,v 1.13 2008/08/31 13:38:21 flameeyes Exp $
|
||||
#
|
||||
# Copyright (C) 2005, 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
#
|
||||
# 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
##########################################################
|
||||
# Sample C++ programs using libcdio (without OO wrapper)
|
||||
#########################################################
|
||||
#
|
||||
SUBDIRS = OO
|
||||
|
||||
if BUILD_CD_PARANOIA
|
||||
paranoia_progs = paranoia paranoia2
|
||||
endif
|
||||
if BUILD_EXAMPLES
|
||||
noinst_PROGRAMS = device eject isofile isofile2 isolist \
|
||||
mmc1 mmc2 $(paranoia_progs)
|
||||
endif
|
||||
|
||||
INCLUDES = -I$(top_srcdir) $(LIBCDIO_CFLAGS)
|
||||
|
||||
device_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
device_SOURCES = device.cpp
|
||||
device_LDADD = $(LIBCDIO_LIBS)
|
||||
|
||||
eject_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
eject_SOURCES = eject.cpp
|
||||
eject_LDADD = $(LIBCDIO_LIBS)
|
||||
|
||||
if BUILD_CD_PARANOIA
|
||||
paranoia_SOURCES = paranoia.cpp
|
||||
paranoia_LDADD = $(LIBCDIO_PARANOIA_LIBS) $(LIBCDIO_CDDA_LIBS) \
|
||||
$(LIBCDIO_LIBS)
|
||||
paranoia2_SOURCES = paranoia.cpp
|
||||
paranoia2_LDADD = $(LIBCDIO_PARANOIA_LIBS) $(LIBCDIO_CDDA_LIBS) \
|
||||
$(LIBCDIO_LIBS)
|
||||
endif
|
||||
|
||||
isofile_SOURCES = isofile.cpp
|
||||
isofile_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
isofile2_SOURCES = isofile2.cpp
|
||||
isofile2_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
isolist_SOURCES = isolist.cpp
|
||||
isolist_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
|
||||
mmc1_SOURCES = mmc1.cpp
|
||||
mmc1_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
mmc1_LDADD = $(LIBCDIO_LIBS)
|
||||
|
||||
mmc2_SOURCES = mmc2.cpp
|
||||
mmc2_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
mmc2_LDADD = $(LIBCDIO_LIBS)
|
||||
|
||||
# iso programs create file "copying"
|
||||
MOSTLYCLEANFILES = copying
|
||||
17
example/C++/OO/.cvsignore
Normal file
17
example/C++/OO/.cvsignore
Normal file
@@ -0,0 +1,17 @@
|
||||
.deps
|
||||
.libs
|
||||
Makefile
|
||||
Makefile.am
|
||||
Makefile.in
|
||||
cdtext
|
||||
copying
|
||||
device
|
||||
drives
|
||||
eject
|
||||
iso4
|
||||
isofile2
|
||||
isofile
|
||||
isolist
|
||||
mmc1
|
||||
mmc2
|
||||
tracks
|
||||
3
example/C++/OO/.gitignore
vendored
Normal file
3
example/C++/OO/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/.deps
|
||||
/Makefile
|
||||
/Makefile.in
|
||||
69
example/C++/OO/Makefile.am
Normal file
69
example/C++/OO/Makefile.am
Normal file
@@ -0,0 +1,69 @@
|
||||
# $Id: Makefile.am,v 1.13 2008/08/31 13:38:21 flameeyes Exp $
|
||||
#
|
||||
# Copyright (C) 2005, 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
#
|
||||
# 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
############################################################
|
||||
# Sample C++ programs using libcdio++ (with C++ OO wrapper)
|
||||
############################################################
|
||||
#
|
||||
noinst_PROGRAMS = cdtext device drives eject \
|
||||
isofile isofile2 isolist iso4 mmc1 mmc2 tracks
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/include $(LIBCDIO_CFLAGS)
|
||||
|
||||
cdtext_SOURCES = cdtext.cpp
|
||||
cdtext_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
cdtext_LDADD = $(LIBCDIOPP_LIBS) $(LIBCDIO_LIBS)
|
||||
|
||||
device_SOURCES = device.cpp
|
||||
device_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
device_LDADD = $(LIBCDIOPP_LIBS) $(LIBCDIO_LIBS)
|
||||
|
||||
drives_SOURCES = drives.cpp
|
||||
drives_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
drives_LDADD = $(LIBCDIOPP_LIBS) $(LIBCDIO_LIBS)
|
||||
|
||||
eject_SOURCES = eject.cpp
|
||||
eject_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
eject_LDADD = $(LIBCDIOPP_LIBS) $(LIBCDIO_LIBS)
|
||||
|
||||
isofile_SOURCES = isofile.cpp
|
||||
isofile_LDADD = $(LIBISO9660PP_LIBS) $(LIBISO9660_LIBS) \
|
||||
$(LIBCDIOPP_LIBS) $(LTLIBICONV)
|
||||
|
||||
isofile2_SOURCES = isofile2.cpp
|
||||
isofile2_LDADD = $(LIBISO9660PP_LIBS) $(LIBISO9660_LIBS) \
|
||||
$(LIBCDIOPP_LIBS) $(LTLIBICONV)
|
||||
|
||||
isolist_SOURCES = isolist.cpp
|
||||
isolist_LDADD = $(LIBISO9660PP_LIBS) $(LIBISO9660_LIBS) \
|
||||
$(LIBCDIOPP_LIBS) $(LTLIBICONV)
|
||||
|
||||
iso4_SOURCES = iso4.cpp
|
||||
iso4_LDADD = $(LIBISO9660PP_LIBS) $(LIBISO9660_LIBS) \
|
||||
$(LIBCDIOPP_LIBS) $(LTLIBICONV)
|
||||
|
||||
mmc1_SOURCES = mmc1.cpp
|
||||
mmc1_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
mmc1_LDADD = $(LIBCDIOPP_LIBS) $(LIBCDIO_LIBS)
|
||||
|
||||
mmc2_SOURCES = mmc2.cpp
|
||||
mmc2_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
mmc2_LDADD = $(LIBCDIOPP_LIBS) $(LIBCDIO_LIBS)
|
||||
|
||||
tracks_SOURCES = tracks.cpp
|
||||
tracks_LDADD = $(LIBCDIOPP_LIBS) $(LIBCDIO_LIBS)
|
||||
|
||||
105
example/C++/OO/cdtext.cpp
Normal file
105
example/C++/OO/cdtext.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
$Id: cdtext.cpp,v 1.4 2008/03/24 15:30:57 karl Exp $
|
||||
|
||||
Copyright (C) 2005, 2008 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Simple program to list CD-Text info of a Compact Disc using
|
||||
libcdio. An optional drive name can be supplied as an argument.
|
||||
See also corresponding C program of a similar name.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDIO_H
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include <cdio++/cdio.hpp>
|
||||
|
||||
/* Set up a CD-DA image to test on which is in the libcdio distribution. */
|
||||
#define CDDA_IMAGE_PATH "../../../test/"
|
||||
#define CDDA_IMAGE CDDA_IMAGE_PATH "cdda.cue"
|
||||
|
||||
static void
|
||||
print_cdtext_track_info(CdioDevice *device, track_t i_track,
|
||||
const char *psz_msg) {
|
||||
cdtext_t *cdtext = device->getCdtext(0);
|
||||
if (NULL != cdtext) {
|
||||
cdtext_field_t i;
|
||||
|
||||
printf("%s\n", psz_msg);
|
||||
|
||||
for (i= (cdtext_field_t) MIN_CDTEXT_FIELD; i < MAX_CDTEXT_FIELDS; i++) {
|
||||
if (cdtext->field[i]) {
|
||||
printf("\t%s: %s\n", cdtext_field2str(i), cdtext->field[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_disc_info(CdioDevice *device, track_t i_tracks, track_t i_first_track) {
|
||||
track_t i_last_track = i_first_track+i_tracks;
|
||||
discmode_t cd_discmode = device->getDiscmode();
|
||||
|
||||
printf("%s\n", discmode2str[cd_discmode]);
|
||||
|
||||
print_cdtext_track_info(device, 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);
|
||||
print_cdtext_track_info(device, i_first_track, psz_msg);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
track_t i_first_track;
|
||||
track_t i_tracks;
|
||||
CdioDevice *device = new CdioDevice;
|
||||
const char *psz_drive = NULL;
|
||||
|
||||
if (!device->open(CDDA_IMAGE, DRIVER_BINCUE)) {
|
||||
printf("Couldn't open " CDDA_IMAGE " with BIN/CUE driver.\n");
|
||||
} else {
|
||||
i_first_track = device->getFirstTrackNum();
|
||||
i_tracks = device->getNumTracks();
|
||||
print_disc_info(device, i_tracks, i_first_track);
|
||||
}
|
||||
|
||||
if (argc > 1) psz_drive = argv[1];
|
||||
|
||||
if (!device->open(psz_drive, DRIVER_DEVICE)) {
|
||||
printf("Couldn't find CD\n");
|
||||
return 1;
|
||||
} else {
|
||||
i_first_track = device->getFirstTrackNum();
|
||||
i_tracks = device->getNumTracks();
|
||||
print_disc_info(device, i_tracks, i_first_track);
|
||||
}
|
||||
|
||||
delete(device);
|
||||
|
||||
return 0;
|
||||
}
|
||||
138
example/C++/OO/device.cpp
Normal file
138
example/C++/OO/device.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
$Id: device.cpp,v 1.4 2008/03/24 15:30:57 karl Exp $
|
||||
|
||||
Copyright (C) 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Simple program to show drivers installed and what the default
|
||||
CD-ROM drive is. See also corresponding C program of a similar
|
||||
name. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#ifdef HAVE_STDIO_H
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include <cdio++/cdio.hpp>
|
||||
|
||||
#define _(x) x
|
||||
|
||||
/* Prints out drive capabilities */
|
||||
static void
|
||||
print_drive_capabilities(cdio_drive_read_cap_t i_read_cap,
|
||||
cdio_drive_write_cap_t i_write_cap,
|
||||
cdio_drive_misc_cap_t i_misc_cap)
|
||||
{
|
||||
if (CDIO_DRIVE_CAP_ERROR == i_misc_cap) {
|
||||
printf("Error in getting drive hardware properties\n");
|
||||
} else {
|
||||
printf(_("Hardware : %s\n"),
|
||||
i_misc_cap & CDIO_DRIVE_CAP_MISC_FILE
|
||||
? "Disk Image" : "CD-ROM or DVD");
|
||||
printf(_("Can eject : %s\n"),
|
||||
i_misc_cap & CDIO_DRIVE_CAP_MISC_EJECT ? "Yes" : "No");
|
||||
printf(_("Can close tray : %s\n"),
|
||||
i_misc_cap & CDIO_DRIVE_CAP_MISC_CLOSE_TRAY ? "Yes" : "No");
|
||||
printf(_("Can disable manual eject : %s\n"),
|
||||
i_misc_cap & CDIO_DRIVE_CAP_MISC_LOCK ? "Yes" : "No");
|
||||
printf(_("Can select juke-box disc : %s\n\n"),
|
||||
i_misc_cap & CDIO_DRIVE_CAP_MISC_SELECT_DISC ? "Yes" : "No");
|
||||
|
||||
printf(_("Can set drive speed : %s\n"),
|
||||
i_misc_cap & CDIO_DRIVE_CAP_MISC_SELECT_SPEED ? "Yes" : "No");
|
||||
printf(_("Can detect if CD changed : %s\n"),
|
||||
i_misc_cap & CDIO_DRIVE_CAP_MISC_MEDIA_CHANGED ? "Yes" : "No");
|
||||
printf(_("Can read multiple sessions : %s\n"),
|
||||
i_misc_cap & CDIO_DRIVE_CAP_MISC_MULTI_SESSION ? "Yes" : "No");
|
||||
printf(_("Can hard reset device : %s\n\n"),
|
||||
i_misc_cap & CDIO_DRIVE_CAP_MISC_RESET ? "Yes" : "No");
|
||||
}
|
||||
|
||||
|
||||
if (CDIO_DRIVE_CAP_ERROR == i_read_cap) {
|
||||
printf("Error in getting drive reading properties\n");
|
||||
} else {
|
||||
printf("Reading....\n");
|
||||
printf(_(" Can play audio : %s\n"),
|
||||
i_read_cap & CDIO_DRIVE_CAP_READ_AUDIO ? "Yes" : "No");
|
||||
printf(_(" Can read CD-R : %s\n"),
|
||||
i_read_cap & CDIO_DRIVE_CAP_READ_CD_R ? "Yes" : "No");
|
||||
printf(_(" Can read CD-RW : %s\n"),
|
||||
i_read_cap & CDIO_DRIVE_CAP_READ_CD_RW ? "Yes" : "No");
|
||||
printf(_(" Can read DVD-ROM : %s\n"),
|
||||
i_read_cap & CDIO_DRIVE_CAP_READ_DVD_ROM ? "Yes" : "No");
|
||||
}
|
||||
|
||||
|
||||
if (CDIO_DRIVE_CAP_ERROR == i_write_cap) {
|
||||
printf("Error in getting drive writing properties\n");
|
||||
} else {
|
||||
printf("\nWriting....\n");
|
||||
printf(_(" Can write CD-RW : %s\n"),
|
||||
i_read_cap & CDIO_DRIVE_CAP_READ_CD_RW ? "Yes" : "No");
|
||||
printf(_(" Can write DVD-R : %s\n"),
|
||||
i_write_cap & CDIO_DRIVE_CAP_READ_DVD_R ? "Yes" : "No");
|
||||
printf(_(" Can write DVD-RAM : %s\n"),
|
||||
i_write_cap & CDIO_DRIVE_CAP_READ_DVD_RAM ? "Yes" : "No");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
CdioDevice device;
|
||||
|
||||
if (device.open(NULL)) {
|
||||
char *default_device = device.getDevice();
|
||||
cdio_drive_read_cap_t i_read_cap;
|
||||
cdio_drive_write_cap_t i_write_cap;
|
||||
cdio_drive_misc_cap_t i_misc_cap;
|
||||
|
||||
printf("The driver selected is %s\n", device.getDriverName());
|
||||
|
||||
if (default_device)
|
||||
printf("The default device for this driver is %s\n", default_device);
|
||||
|
||||
device.getDriveCap(i_read_cap, i_write_cap, i_misc_cap);
|
||||
print_drive_capabilities(i_read_cap, i_write_cap, i_misc_cap);
|
||||
|
||||
free(default_device);
|
||||
printf("\n");
|
||||
|
||||
} else {
|
||||
printf("Problem in trying to find a driver.\n\n");
|
||||
}
|
||||
|
||||
{
|
||||
driver_id_t driver_id;
|
||||
for (driver_id=CDIO_MIN_DRIVER; driver_id<=CDIO_MAX_DRIVER; driver_id++)
|
||||
if (cdio_have_driver(driver_id))
|
||||
printf("We have: %s\n", cdio_driver_describe(driver_id));
|
||||
else
|
||||
printf("We don't have: %s\n", cdio_driver_describe(driver_id));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
90
example/C++/OO/drives.cpp
Normal file
90
example/C++/OO/drives.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
$Id: drives.cpp,v 1.6 2008/03/24 15:30:57 karl Exp $
|
||||
|
||||
Copyright (C) 2003, 2004, 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Simple program to show drivers installed and what the default
|
||||
CD-ROM drive is and what CD drives are available. */
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#ifdef HAVE_STDIO_H
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include <cdio++/cdio.hpp>
|
||||
#include <cdio/cd_types.h>
|
||||
#include <cdio/logging.h>
|
||||
|
||||
static void
|
||||
log_handler (cdio_log_level_t level, const char message[])
|
||||
{
|
||||
switch(level) {
|
||||
case CDIO_LOG_DEBUG:
|
||||
case CDIO_LOG_INFO:
|
||||
return;
|
||||
default:
|
||||
printf("cdio %d message: %s\n", level, message);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_drive_class(const char *psz_msg, cdio_fs_anal_t bitmask,
|
||||
bool b_any=false) {
|
||||
char **ppsz_cd_drives=NULL, **c;
|
||||
|
||||
printf("%s...\n", psz_msg);
|
||||
ppsz_cd_drives = getDevices(NULL, bitmask, b_any);
|
||||
if (NULL != ppsz_cd_drives)
|
||||
for( c = ppsz_cd_drives; *c != NULL; c++ ) {
|
||||
printf("Drive %s\n", *c);
|
||||
}
|
||||
|
||||
freeDeviceList(ppsz_cd_drives);
|
||||
printf("-----\n");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
char **ppsz_cd_drives=NULL, **c;
|
||||
|
||||
cdio_log_set_handler (log_handler);
|
||||
|
||||
/* Print out a list of CD-drives */
|
||||
printf("All CD-ROM/DVD drives...\n");
|
||||
ppsz_cd_drives = getDevices();
|
||||
if (NULL != ppsz_cd_drives)
|
||||
for( c = ppsz_cd_drives; *c != NULL; c++ ) {
|
||||
printf("Drive %s\n", *c);
|
||||
}
|
||||
|
||||
freeDeviceList(ppsz_cd_drives);
|
||||
|
||||
print_drive_class("All CD-ROM drives (again)", CDIO_FS_MATCH_ALL);
|
||||
print_drive_class("CD-ROM drives with a CD-DA loaded...", CDIO_FS_AUDIO);
|
||||
print_drive_class("CD-ROM drives with some sort of ISO 9660 filesystem...",
|
||||
CDIO_FS_ANAL_ISO9660_ANY, true);
|
||||
print_drive_class("(S)VCD drives...", CDIO_FS_ANAL_VCD_ANY, true);
|
||||
return 0;
|
||||
|
||||
}
|
||||
83
example/C++/OO/eject.cpp
Normal file
83
example/C++/OO/eject.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
$Id: eject.cpp,v 1.7 2008/03/24 15:30:57 karl Exp $
|
||||
|
||||
Copyright (C) 2005, 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Simple program to eject a CD-ROM drive door and then close it again.
|
||||
|
||||
If a single argument is given, it is used as the CD-ROM device to
|
||||
eject/close. Otherwise a CD-ROM drive will be scanned for.
|
||||
|
||||
See also corresponding C program of a similar name.
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <cdio++/cdio.hpp>
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
driver_return_code_t ret;
|
||||
driver_id_t driver_id = DRIVER_DEVICE;
|
||||
char *psz_drive = NULL;
|
||||
CdioDevice device;
|
||||
|
||||
if (argc > 1)
|
||||
psz_drive = strdup(argv[1]);
|
||||
|
||||
if (!psz_drive) {
|
||||
psz_drive = getDefaultDevice(driver_id);
|
||||
if (!psz_drive) {
|
||||
printf("Can't find a CD-ROM to perform eject operation\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
try {
|
||||
ejectMedia(psz_drive);
|
||||
printf("CD in CD-ROM drive %s ejected.\n", psz_drive);
|
||||
}
|
||||
catch ( DriverOpUninit e ) {
|
||||
printf("Can't Eject CD from CD-ROM drive: driver is not initialized.\n",
|
||||
psz_drive);
|
||||
}
|
||||
catch ( DriverOpException e ) {
|
||||
printf("Ejecting CD from CD-ROM drive %s operation error:\n\t%s.\n",
|
||||
psz_drive, e.get_msg());
|
||||
}
|
||||
|
||||
try {
|
||||
closeTray(psz_drive);
|
||||
printf("Closed CD-ROM %s tray.\n", psz_drive);
|
||||
}
|
||||
catch ( DriverOpException e ) {
|
||||
printf("Closing CD-ROM %s tray operation error error:\n\t%s.\n",
|
||||
psz_drive, e.get_msg());
|
||||
}
|
||||
free(psz_drive);
|
||||
|
||||
return 0;
|
||||
}
|
||||
118
example/C++/OO/iso4.cpp
Normal file
118
example/C++/OO/iso4.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
$Id: iso4.cpp,v 1.2 2008/03/24 15:30:57 karl Exp $
|
||||
|
||||
Copyright (C) 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Simple program to show using libiso9660 to list files in a directory of
|
||||
an ISO-9660 image and give some iso9660 information. See the code
|
||||
to iso-info for a more complete example.
|
||||
|
||||
If a single argument is given, it is used as the ISO 9660 image to
|
||||
use in the listing. Otherwise a compiled-in default ISO 9660 image
|
||||
name (that comes with the libcdio distribution) will be used.
|
||||
|
||||
This program can be compiled with either a C or C++ compiler. In
|
||||
the distributuion we perfer C++ just to make sure we haven't broken
|
||||
things on the C++ side.
|
||||
*/
|
||||
|
||||
/* Set up a CD-DA image to test on which is in the libcdio distribution. */
|
||||
#define ISO9660_IMAGE_PATH "../../../"
|
||||
#define ISO9660_IMAGE ISO9660_IMAGE_PATH "test/isofs-m1.cue"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <cdio++/iso9660.hpp>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#define print_vd_info(title, fn) \
|
||||
psz_str = p_pvd->fn(); \
|
||||
if (psz_str) { \
|
||||
printf(title ": %s\n", psz_str); \
|
||||
free(psz_str); \
|
||||
psz_str = NULL; \
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
stat_vector_t stat_vector;
|
||||
ISO9660::FS *p_iso = new ISO9660::FS;
|
||||
char const *psz_fname;
|
||||
const char *psz_path="/";
|
||||
ISO9660::PVD *p_pvd;
|
||||
|
||||
if (argc > 1)
|
||||
psz_fname = argv[1];
|
||||
else
|
||||
psz_fname = ISO9660_IMAGE;
|
||||
|
||||
if (!p_iso->open(psz_fname, DRIVER_UNKNOWN)) {
|
||||
fprintf(stderr, "Sorry, couldn't open %s as a CD or CD image.\n",
|
||||
psz_fname);
|
||||
return 1;
|
||||
}
|
||||
|
||||
p_pvd = p_iso->read_pvd();
|
||||
if (p_pvd) {
|
||||
char *psz_str = NULL;
|
||||
print_vd_info("Application", get_application_id);
|
||||
print_vd_info("Preparer ", get_preparer_id);
|
||||
print_vd_info("Publisher ", get_publisher_id);
|
||||
print_vd_info("System ", get_system_id);
|
||||
print_vd_info("Volume ", get_volume_id);
|
||||
print_vd_info("Volume Set ", get_volumeset_id);
|
||||
}
|
||||
|
||||
if (p_iso->readdir (psz_path, stat_vector))
|
||||
{
|
||||
/* Iterate over the list of files. */
|
||||
stat_vector_iterator_t i;
|
||||
for(i=stat_vector.begin(); i != stat_vector.end(); ++i)
|
||||
{
|
||||
char filename[4096];
|
||||
ISO9660::Stat *p_s = *i;
|
||||
iso9660_name_translate(p_s->p_stat->filename, filename);
|
||||
printf ("%s [LSN %6d] %8u %s%s\n",
|
||||
2 == p_s->p_stat->type ? "d" : "-",
|
||||
p_s->p_stat->lsn, p_s->p_stat->size, psz_path, filename);
|
||||
delete(p_s);
|
||||
}
|
||||
|
||||
stat_vector.clear();
|
||||
}
|
||||
|
||||
delete(p_iso);
|
||||
return 0;
|
||||
}
|
||||
|
||||
158
example/C++/OO/isofile.cpp
Normal file
158
example/C++/OO/isofile.cpp
Normal file
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
$Id: isofile.cpp,v 1.2 2008/03/24 15:30:57 karl Exp $
|
||||
|
||||
Copyright (C) 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Simple program to show using libiso9660 to extract a file from an
|
||||
ISO-9660 image.
|
||||
|
||||
If a single argument is given, it is used as the ISO 9660 image to
|
||||
use in the extraction. Otherwise a compiled in default ISO 9660 image
|
||||
name (that comes with the libcdio distribution) will be used.
|
||||
*/
|
||||
|
||||
/* This is the ISO 9660 image. */
|
||||
#define ISO9660_IMAGE_PATH "../../../"
|
||||
#define ISO9660_IMAGE ISO9660_IMAGE_PATH "test/copying.iso"
|
||||
|
||||
#define LOCAL_FILENAME "copying"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "portable.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <cdio++/iso9660.hpp>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#define CEILING(x, y) ((x+(y-1))/y)
|
||||
|
||||
#define my_exit(rc) \
|
||||
fclose (p_outfd); \
|
||||
delete (p_stat); \
|
||||
delete (p_iso); \
|
||||
return rc; \
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
ISO9660::Stat *p_stat;
|
||||
FILE *p_outfd;
|
||||
int i;
|
||||
char const *psz_image;
|
||||
char const *psz_fname;
|
||||
ISO9660::IFS *p_iso = new ISO9660::IFS;
|
||||
|
||||
if (argc > 3) {
|
||||
printf("usage %s [ISO9660-image.ISO [filename]]\n", argv[0]);
|
||||
printf("Extracts filename from ISO-9660-image.ISO.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (argc > 1)
|
||||
psz_image = argv[1];
|
||||
else
|
||||
psz_image = ISO9660_IMAGE;
|
||||
|
||||
if (argc > 2)
|
||||
psz_fname = argv[2];
|
||||
else
|
||||
psz_fname = LOCAL_FILENAME;
|
||||
|
||||
if (!p_iso->open(psz_image)) {
|
||||
fprintf(stderr, "Sorry, couldn't open ISO 9660 image %s\n", psz_image);
|
||||
return 1;
|
||||
}
|
||||
|
||||
p_stat = p_iso->stat(psz_fname, true);
|
||||
|
||||
if (!p_stat)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Could not get ISO-9660 file information for file %s\n",
|
||||
psz_fname);
|
||||
delete(p_iso);
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (!(p_outfd = fopen (psz_fname, "wb")))
|
||||
{
|
||||
perror ("fopen()");
|
||||
delete (p_stat);
|
||||
delete (p_iso);
|
||||
return 3;
|
||||
}
|
||||
|
||||
/* Copy the blocks from the ISO-9660 filesystem to the local filesystem. */
|
||||
{
|
||||
const unsigned int i_blocks = CEILING(p_stat->p_stat->size, ISO_BLOCKSIZE);
|
||||
for (i = 0; i < i_blocks ; i++)
|
||||
{
|
||||
char buf[ISO_BLOCKSIZE];
|
||||
const lsn_t lsn = p_stat->p_stat->lsn + i;
|
||||
|
||||
memset (buf, 0, ISO_BLOCKSIZE);
|
||||
|
||||
if ( ISO_BLOCKSIZE != p_iso->seek_read (buf, lsn, 1) )
|
||||
{
|
||||
fprintf(stderr, "Error reading ISO 9660 file %s at LSN %lu\n",
|
||||
psz_fname, (long unsigned int) lsn);
|
||||
my_exit(4);
|
||||
}
|
||||
|
||||
fwrite (buf, ISO_BLOCKSIZE, 1, p_outfd);
|
||||
|
||||
if (ferror (p_outfd))
|
||||
{
|
||||
perror ("fwrite()");
|
||||
my_exit(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fflush (p_outfd);
|
||||
|
||||
/* Make sure the file size has the exact same byte size. Without the
|
||||
truncate below, the file will a multiple of ISO_BLOCKSIZE.
|
||||
*/
|
||||
if (ftruncate (fileno (p_outfd), p_stat->p_stat->size))
|
||||
perror ("ftruncate()");
|
||||
|
||||
printf("Extraction of file '%s' from %s successful.\n",
|
||||
psz_fname, psz_image);
|
||||
|
||||
my_exit(0);
|
||||
}
|
||||
178
example/C++/OO/isofile2.cpp
Normal file
178
example/C++/OO/isofile2.cpp
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
$Id: isofile2.cpp,v 1.2 2008/03/24 15:30:57 karl Exp $
|
||||
|
||||
Copyright (C) 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Simple program to show using libiso9660 to extract a file from a
|
||||
CUE/BIN CD image.
|
||||
|
||||
If a single argument is given, it is used as the CUE file of a CD image
|
||||
to use. Otherwise a compiled-in default image name (that
|
||||
comes with the libcdio distribution) will be used.
|
||||
|
||||
This program can be compiled with either a C or C++ compiler. In
|
||||
the distribution we prefer C++ just to make sure we haven't broken
|
||||
things on the C++ side.
|
||||
*/
|
||||
|
||||
/* This is the CD-image with an ISO-9660 filesystem */
|
||||
#define ISO9660_IMAGE_PATH "../../../"
|
||||
#define ISO9660_IMAGE ISO9660_IMAGE_PATH "test/isofs-m1.cue"
|
||||
|
||||
#define ISO9660_PATH "/"
|
||||
#define ISO9660_FILENAME "COPYING"
|
||||
#define LOCAL_FILENAME "copying"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "portable.h"
|
||||
|
||||
#include <cdio++/cdio.hpp>
|
||||
#include <cdio++/iso9660.hpp>
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDIO_H
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#define CEILING(x, y) ((x+(y-1))/y)
|
||||
|
||||
#define my_exit(rc) \
|
||||
fclose (p_outfd); \
|
||||
delete (p_stat); \
|
||||
delete (p_iso); \
|
||||
return rc; \
|
||||
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
ISO9660::Stat *p_stat;
|
||||
FILE *p_outfd;
|
||||
unsigned int i;
|
||||
char const *psz_image;
|
||||
char const *psz_fname;
|
||||
char translated_name[256];
|
||||
char untranslated_name[256] = ISO9660_PATH;
|
||||
ISO9660::FS *p_iso = new ISO9660::FS;
|
||||
|
||||
if (argc > 3) {
|
||||
printf("usage %s [CD-ROM-or-image [filename]]\n", argv[0]);
|
||||
printf("Extracts filename from CD-ROM-or-image.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (argc > 1)
|
||||
psz_image = argv[1];
|
||||
else
|
||||
psz_image = ISO9660_IMAGE;
|
||||
|
||||
if (argc > 2)
|
||||
psz_fname = argv[2];
|
||||
else
|
||||
psz_fname = ISO9660_FILENAME;
|
||||
|
||||
strcat(untranslated_name, psz_fname);
|
||||
|
||||
if (!p_iso->open(psz_image, DRIVER_UNKNOWN)) {
|
||||
fprintf(stderr, "Sorry, couldn't open %s\n", psz_image);
|
||||
return 1;
|
||||
}
|
||||
|
||||
p_stat = p_iso->stat(psz_fname);
|
||||
|
||||
if (!p_stat)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Could not get ISO-9660 file information for file %s\n",
|
||||
untranslated_name);
|
||||
delete(p_iso);
|
||||
return 2;
|
||||
}
|
||||
|
||||
iso9660_name_translate(psz_fname, translated_name);
|
||||
|
||||
if (!(p_outfd = fopen (translated_name, "wb")))
|
||||
{
|
||||
perror ("fopen()");
|
||||
delete (p_stat);
|
||||
delete (p_iso);
|
||||
return 3;
|
||||
}
|
||||
|
||||
/* Copy the blocks from the ISO-9660 filesystem to the local filesystem. */
|
||||
{
|
||||
const unsigned int i_blocks = CEILING(p_stat->p_stat->size, ISO_BLOCKSIZE);
|
||||
for (i = 0; i < i_blocks; i ++)
|
||||
{
|
||||
char buf[ISO_BLOCKSIZE];
|
||||
const lsn_t lsn = p_stat->p_stat->lsn + i;
|
||||
|
||||
memset (buf, 0, ISO_BLOCKSIZE);
|
||||
|
||||
try {
|
||||
p_iso->readDataBlocks(buf, lsn, ISO_BLOCKSIZE);
|
||||
}
|
||||
catch ( DriverOpException e ) {
|
||||
fprintf(stderr, "Error reading ISO 9660 file at lsn %lu:\n\t%s.\n",
|
||||
(long unsigned int) lsn, e.get_msg());
|
||||
my_exit(4);
|
||||
}
|
||||
|
||||
fwrite (buf, ISO_BLOCKSIZE, 1, p_outfd);
|
||||
|
||||
if (ferror (p_outfd))
|
||||
{
|
||||
perror ("fwrite()");
|
||||
my_exit(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fflush (p_outfd);
|
||||
|
||||
/* Make sure the file size has the exact same byte size. Without the
|
||||
truncate below, the file will a multiple of ISO_BLOCKSIZE.
|
||||
*/
|
||||
if (ftruncate (fileno (p_outfd), p_stat->p_stat->size))
|
||||
perror ("ftruncate()");
|
||||
|
||||
printf("Extraction of file '%s' from '%s' successful.\n",
|
||||
translated_name, untranslated_name);
|
||||
|
||||
my_exit(0);
|
||||
}
|
||||
117
example/C++/OO/isolist.cpp
Normal file
117
example/C++/OO/isolist.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
$Id: isolist.cpp,v 1.2 2008/03/24 15:30:57 karl Exp $
|
||||
|
||||
Copyright (C) 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Simple program to show using libiso9660 to list files in a directory of
|
||||
an ISO-9660 image and give some iso9660 information. See the code
|
||||
to iso-info for a more complete example.
|
||||
|
||||
If a single argument is given, it is used as the ISO 9660 image to
|
||||
use in the listing. Otherwise a compiled-in default ISO 9660 image
|
||||
name (that comes with the libcdio distribution) will be used.
|
||||
|
||||
This program can be compiled with either a C or C++ compiler. In
|
||||
the distributuion we perfer C++ just to make sure we haven't broken
|
||||
things on the C++ side.
|
||||
*/
|
||||
|
||||
/* Set up a CD-DA image to test on which is in the libcdio distribution. */
|
||||
#define ISO9660_IMAGE_PATH "../../../"
|
||||
#define ISO9660_IMAGE ISO9660_IMAGE_PATH "test/copying.iso"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <cdio++/iso9660.hpp>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#define print_vd_info(title, fn) \
|
||||
if (p_iso->fn(psz_str)) { \
|
||||
printf(title ": %s\n", psz_str); \
|
||||
} \
|
||||
free(psz_str); \
|
||||
psz_str = NULL;
|
||||
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
stat_vector_t stat_vector;
|
||||
ISO9660::IFS *p_iso = new ISO9660::IFS;
|
||||
char const *psz_fname;
|
||||
const char *psz_path="/";
|
||||
|
||||
if (argc > 1)
|
||||
psz_fname = argv[1];
|
||||
else
|
||||
psz_fname = ISO9660_IMAGE;
|
||||
|
||||
if (!p_iso->open(psz_fname)) {
|
||||
fprintf(stderr, "Sorry, couldn't open %s as an ISO-9660 image\n",
|
||||
psz_fname);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Show basic CD info from the Primary Volume Descriptor. */
|
||||
{
|
||||
char *psz_str = NULL;
|
||||
print_vd_info("Application", get_application_id);
|
||||
print_vd_info("Preparer ", get_preparer_id);
|
||||
print_vd_info("Publisher ", get_publisher_id);
|
||||
print_vd_info("System ", get_system_id);
|
||||
print_vd_info("Volume ", get_volume_id);
|
||||
print_vd_info("Volume Set ", get_volumeset_id);
|
||||
}
|
||||
|
||||
if (p_iso->readdir (psz_path, stat_vector))
|
||||
{
|
||||
/* Iterate over the list of files. */
|
||||
stat_vector_iterator_t i;
|
||||
for(i=stat_vector.begin(); i != stat_vector.end(); ++i)
|
||||
{
|
||||
char filename[4096];
|
||||
ISO9660::Stat *p_s = *i;
|
||||
iso9660_name_translate(p_s->p_stat->filename, filename);
|
||||
printf ("%s [LSN %6d] %8u %s%s\n",
|
||||
2 == p_s->p_stat->type ? "d" : "-",
|
||||
p_s->p_stat->lsn, p_s->p_stat->size, psz_path, filename);
|
||||
delete(p_s);
|
||||
}
|
||||
|
||||
stat_vector.clear();
|
||||
}
|
||||
|
||||
delete(p_iso);
|
||||
return 0;
|
||||
}
|
||||
|
||||
85
example/C++/OO/mmc1.cpp
Normal file
85
example/C++/OO/mmc1.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
$Id: mmc1.cpp,v 1.2 2008/03/24 15:30:57 karl Exp $
|
||||
|
||||
Copyright (C) 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Sample program to show use of the MMC interface.
|
||||
An optional drive name can be supplied as an argument.
|
||||
This basically the libdio mmc_get_hwinfo() routine.
|
||||
See also corresponding C and non OO C++ program.
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#include <cdio++/cdio.hpp>
|
||||
|
||||
/* Set how long to wait for MMC commands to complete */
|
||||
#define DEFAULT_TIMEOUT_MS 10000
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
CdioDevice device;
|
||||
const char *psz_drive = NULL;
|
||||
|
||||
if (argc > 1) psz_drive = argv[1];
|
||||
|
||||
if (!device.open(psz_drive)) {
|
||||
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 */
|
||||
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 = device.mmcRunCmd(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");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
189
example/C++/OO/mmc2.cpp
Normal file
189
example/C++/OO/mmc2.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
$Id: mmc2.cpp,v 1.2 2008/03/24 15:30:57 karl Exp $
|
||||
|
||||
Copyright (C) 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* 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 <stdio.h>
|
||||
#ifdef HAVE_SYS_TYPE_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#include <cdio++/cdio.hpp>
|
||||
|
||||
/* Set how long do wto wait for SCSI-MMC commands to complete */
|
||||
#define DEFAULT_TIMEOUT_MS 10000
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
CdioDevice device;
|
||||
const char *psz_drive = NULL;
|
||||
|
||||
if (argc > 1) psz_drive = argv[1];
|
||||
|
||||
if (!device.open(psz_drive)) {
|
||||
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 */
|
||||
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 = device.mmcRunCmd(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");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
64
example/C++/OO/tracks.cpp
Normal file
64
example/C++/OO/tracks.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
$Id: tracks.cpp,v 1.2 2008/03/24 15:30:57 karl Exp $
|
||||
|
||||
Copyright (C) 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Simple program to list track numbers and logical sector numbers of
|
||||
a Compact Disc using libcdio. */
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include <cdio++/cdio.hpp>
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
CdioDevice device;
|
||||
track_t i_first_track;
|
||||
track_t i_tracks;
|
||||
int j, i;
|
||||
CdioTrack *track;
|
||||
|
||||
if (!device.open (NULL)) {
|
||||
printf("Couldn't find a driver.. leaving.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
i_tracks = device.getNumTracks();
|
||||
i_first_track = i = device.getFirstTrackNum();
|
||||
|
||||
printf("CD-ROM Track List (%i - %i)\n", i_first_track, i_tracks);
|
||||
|
||||
printf(" #: LSN\n");
|
||||
|
||||
for (j = 0; j < i_tracks; i++, j++) {
|
||||
track = device.getTrackFromNum(i);
|
||||
lsn_t lsn = track->getLsn();
|
||||
if (CDIO_INVALID_LSN != lsn)
|
||||
printf("%3d: %06lu\n", (int) i, (long unsigned int) lsn);
|
||||
delete(track);
|
||||
}
|
||||
|
||||
track = device.getTrackFromNum(CDIO_CDROM_LEADOUT_TRACK);
|
||||
printf("%3X: %06lu leadout\n", CDIO_CDROM_LEADOUT_TRACK,
|
||||
(long unsigned int) track->getLsn());
|
||||
delete(track);
|
||||
return 0;
|
||||
}
|
||||
41
example/C++/README
Normal file
41
example/C++/README
Normal file
@@ -0,0 +1,41 @@
|
||||
$Id: README,v 1.4 2006/04/15 16:22:49 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...
|
||||
|
||||
device.cpp: A program to show drivers installed and what the default
|
||||
CD-ROM drive is and what CD drives are available.
|
||||
|
||||
eject.cpp: A program eject a CD from a CD-ROM drive and then close the door
|
||||
again.
|
||||
|
||||
isofile.cpp: A program to show using libiso9660 to extract a file from an
|
||||
ISO-9660 image.
|
||||
|
||||
isofile2.cpp: A program to show using libiso9660 to extract a file
|
||||
from a CDRWIN cue/bin CD image.
|
||||
|
||||
isolist.cpp: A program to show using libiso9660 to list files in a
|
||||
directory of an ISO-9660 image and give basic iso9660
|
||||
information.
|
||||
|
||||
mmc1.cpp: A program to show issuing a simple MMC command (INQUIRY).
|
||||
|
||||
mmc2.cpp: A more involved MMC command to list features from
|
||||
a MMC GET_CONFIGURATION command.
|
||||
|
||||
paranoia.cpp: A program to show using CD-DA paranoia (a library for jitter
|
||||
detection and audio-read error correction). This program uses
|
||||
an interface compatible (mostly) with cdparanoia.
|
||||
|
||||
paranoia2.cpp: Another program to show using CD-DA paranoia using a more
|
||||
libcdio-oriented initialization. Probably more suited to
|
||||
things that otherwise use libcdio such as media players
|
||||
(e.g. for getting CDDB or CD-Text info)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
140
example/C++/device.cpp
Normal file
140
example/C++/device.cpp
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
$Id: device.cpp,v 1.3 2008/03/24 15:30:56 karl Exp $
|
||||
|
||||
Copyright (C) 2003, 2004, 2005, 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Simple program to show drivers installed and what the default
|
||||
CD-ROM drive is. See also corresponding C program of a similar
|
||||
name. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#ifdef HAVE_STDIO_H
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include <cdio/cdio.h>
|
||||
|
||||
#define _(x) x
|
||||
|
||||
/* Prints out drive capabilities */
|
||||
static void
|
||||
print_drive_capabilities(cdio_drive_read_cap_t i_read_cap,
|
||||
cdio_drive_write_cap_t i_write_cap,
|
||||
cdio_drive_misc_cap_t i_misc_cap)
|
||||
{
|
||||
if (CDIO_DRIVE_CAP_ERROR == i_misc_cap) {
|
||||
printf("Error in getting drive hardware properties\n");
|
||||
} else {
|
||||
printf(_("Hardware : %s\n"),
|
||||
i_misc_cap & CDIO_DRIVE_CAP_MISC_FILE
|
||||
? "Disk Image" : "CD-ROM or DVD");
|
||||
printf(_("Can eject : %s\n"),
|
||||
i_misc_cap & CDIO_DRIVE_CAP_MISC_EJECT ? "Yes" : "No");
|
||||
printf(_("Can close tray : %s\n"),
|
||||
i_misc_cap & CDIO_DRIVE_CAP_MISC_CLOSE_TRAY ? "Yes" : "No");
|
||||
printf(_("Can disable manual eject : %s\n"),
|
||||
i_misc_cap & CDIO_DRIVE_CAP_MISC_LOCK ? "Yes" : "No");
|
||||
printf(_("Can select juke-box disc : %s\n\n"),
|
||||
i_misc_cap & CDIO_DRIVE_CAP_MISC_SELECT_DISC ? "Yes" : "No");
|
||||
|
||||
printf(_("Can set drive speed : %s\n"),
|
||||
i_misc_cap & CDIO_DRIVE_CAP_MISC_SELECT_SPEED ? "Yes" : "No");
|
||||
printf(_("Can detect if CD changed : %s\n"),
|
||||
i_misc_cap & CDIO_DRIVE_CAP_MISC_MEDIA_CHANGED ? "Yes" : "No");
|
||||
printf(_("Can read multiple sessions : %s\n"),
|
||||
i_misc_cap & CDIO_DRIVE_CAP_MISC_MULTI_SESSION ? "Yes" : "No");
|
||||
printf(_("Can hard reset device : %s\n\n"),
|
||||
i_misc_cap & CDIO_DRIVE_CAP_MISC_RESET ? "Yes" : "No");
|
||||
}
|
||||
|
||||
|
||||
if (CDIO_DRIVE_CAP_ERROR == i_read_cap) {
|
||||
printf("Error in getting drive reading properties\n");
|
||||
} else {
|
||||
printf("Reading....\n");
|
||||
printf(_(" Can play audio : %s\n"),
|
||||
i_read_cap & CDIO_DRIVE_CAP_READ_AUDIO ? "Yes" : "No");
|
||||
printf(_(" Can read CD-R : %s\n"),
|
||||
i_read_cap & CDIO_DRIVE_CAP_READ_CD_R ? "Yes" : "No");
|
||||
printf(_(" Can read CD-RW : %s\n"),
|
||||
i_read_cap & CDIO_DRIVE_CAP_READ_CD_RW ? "Yes" : "No");
|
||||
printf(_(" Can read DVD-ROM : %s\n"),
|
||||
i_read_cap & CDIO_DRIVE_CAP_READ_DVD_ROM ? "Yes" : "No");
|
||||
}
|
||||
|
||||
|
||||
if (CDIO_DRIVE_CAP_ERROR == i_write_cap) {
|
||||
printf("Error in getting drive writing properties\n");
|
||||
} else {
|
||||
printf("\nWriting....\n");
|
||||
printf(_(" Can write CD-RW : %s\n"),
|
||||
i_read_cap & CDIO_DRIVE_CAP_READ_CD_RW ? "Yes" : "No");
|
||||
printf(_(" Can write DVD-R : %s\n"),
|
||||
i_write_cap & CDIO_DRIVE_CAP_READ_DVD_R ? "Yes" : "No");
|
||||
printf(_(" Can write DVD-RAM : %s\n"),
|
||||
i_write_cap & CDIO_DRIVE_CAP_READ_DVD_RAM ? "Yes" : "No");
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
driver_id_t &operator++(driver_id_t &d)
|
||||
{
|
||||
return d = driver_id_t(d + 1);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
CdIo_t *p_cdio = cdio_open (NULL, DRIVER_UNKNOWN);
|
||||
driver_id_t driver_id;
|
||||
|
||||
if (NULL != p_cdio) {
|
||||
char *default_device = cdio_get_default_device(p_cdio);
|
||||
cdio_drive_read_cap_t i_read_cap;
|
||||
cdio_drive_write_cap_t i_write_cap;
|
||||
cdio_drive_misc_cap_t i_misc_cap;
|
||||
|
||||
printf("The driver selected is %s\n", cdio_get_driver_name(p_cdio));
|
||||
|
||||
if (default_device)
|
||||
printf("The default device for this driver is %s\n", default_device);
|
||||
|
||||
cdio_get_drive_cap(p_cdio, &i_read_cap, &i_write_cap, &i_misc_cap);
|
||||
print_drive_capabilities(i_read_cap, i_write_cap, i_misc_cap);
|
||||
|
||||
free(default_device);
|
||||
cdio_destroy(p_cdio);
|
||||
printf("\n");
|
||||
|
||||
} else {
|
||||
printf("Problem in trying to find a driver.\n\n");
|
||||
}
|
||||
|
||||
for (driver_id=CDIO_MIN_DRIVER; driver_id<=CDIO_MAX_DRIVER; ++driver_id)
|
||||
if (cdio_have_driver(driver_id))
|
||||
printf("We have: %s\n", cdio_driver_describe(driver_id));
|
||||
else
|
||||
printf("We don't have: %s\n", cdio_driver_describe(driver_id));
|
||||
return 0;
|
||||
}
|
||||
99
example/C++/eject.cpp
Normal file
99
example/C++/eject.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
$Id: eject.cpp,v 1.4 2008/03/24 15:30:56 karl Exp $
|
||||
|
||||
Copyright (C) 2005, 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Simple program to eject a CD-ROM drive door and then close it again.
|
||||
|
||||
If a single argument is given, it is used as the CD-ROM device to
|
||||
eject/close. Otherwise a CD-ROM drive will be scanned for.
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#ifdef HAVE_STDIO_H
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <cdio/cdio.h>
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
driver_return_code_t ret;
|
||||
driver_id_t driver_id = DRIVER_DEVICE;
|
||||
char *psz_drive = NULL;
|
||||
|
||||
if (argc > 1)
|
||||
psz_drive = strdup(argv[1]);
|
||||
|
||||
if (!psz_drive) {
|
||||
psz_drive = cdio_get_default_device_driver(&driver_id);
|
||||
if (!psz_drive) {
|
||||
printf("Can't find a CD-ROM to eject\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
ret = cdio_eject_media_drive(psz_drive);
|
||||
switch(ret) {
|
||||
case DRIVER_OP_UNSUPPORTED:
|
||||
printf("Eject not supported for %s.\n", psz_drive);
|
||||
break;
|
||||
case DRIVER_OP_SUCCESS:
|
||||
printf("CD-ROM drive %s ejected.\n", psz_drive);
|
||||
break;
|
||||
default:
|
||||
printf("Eject of CD-ROM drive %s failed.\n", psz_drive);
|
||||
break;
|
||||
}
|
||||
|
||||
if (DRIVER_OP_SUCCESS == cdio_close_tray(psz_drive, &driver_id)) {
|
||||
printf("Closed tray of CD-ROM drive %s.\n", psz_drive);
|
||||
} else {
|
||||
printf("Closing tray of CD-ROM drive %s failed.\n", psz_drive);
|
||||
}
|
||||
free(psz_drive);
|
||||
|
||||
ret = cdio_eject_media_drive(NULL);
|
||||
switch(ret) {
|
||||
case DRIVER_OP_UNSUPPORTED:
|
||||
printf("Eject not supported for default device.\n");
|
||||
break;
|
||||
case DRIVER_OP_SUCCESS:
|
||||
printf("CD-ROM drive ejected for default device.\n");
|
||||
break;
|
||||
default:
|
||||
printf("Eject of CD-ROM drive failed for default device.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
driver_id = DRIVER_DEVICE;
|
||||
if (DRIVER_OP_SUCCESS == cdio_close_tray(NULL, &driver_id)) {
|
||||
printf("Closed tray of CD-ROM drive for default disc driver:\n\t%s\n",
|
||||
cdio_driver_describe(driver_id));
|
||||
} else {
|
||||
printf("Closing tray of CD-ROM drive failed for default "
|
||||
"disc driver:\n\t%s\n", cdio_driver_describe(driver_id));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
161
example/C++/isofile.cpp
Normal file
161
example/C++/isofile.cpp
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
$Id: isofile.cpp,v 1.2 2008/03/24 15:30:56 karl Exp $
|
||||
|
||||
Copyright (C) 2004, 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Simple program to show using libiso9660 to extract a file from an
|
||||
ISO-9660 image.
|
||||
|
||||
If a single argument is given, it is used as the ISO 9660 image to
|
||||
use in the extraction. Otherwise a compiled in default ISO 9660 image
|
||||
name (that comes with the libcdio distribution) will be used.
|
||||
*/
|
||||
|
||||
/* This is the ISO 9660 image. */
|
||||
#define ISO9660_IMAGE_PATH "../../"
|
||||
#define ISO9660_IMAGE ISO9660_IMAGE_PATH "test/copying.iso"
|
||||
|
||||
#define LOCAL_FILENAME "copying"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "portable.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <cdio/cdio.h>
|
||||
#include <cdio/iso9660.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#define CEILING(x, y) ((x+(y-1))/y)
|
||||
|
||||
#define my_exit(rc) \
|
||||
fclose (p_outfd); \
|
||||
free(p_statbuf); \
|
||||
iso9660_close(p_iso); \
|
||||
return rc; \
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
iso9660_stat_t *p_statbuf;
|
||||
FILE *p_outfd;
|
||||
int i;
|
||||
char const *psz_image;
|
||||
char const *psz_fname;
|
||||
iso9660_t *p_iso;
|
||||
|
||||
if (argc > 3) {
|
||||
printf("usage %s [ISO9660-image.ISO [filename]]\n", argv[0]);
|
||||
printf("Extracts filename from ISO-9660-image.ISO.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (argc > 1)
|
||||
psz_image = argv[1];
|
||||
else
|
||||
psz_image = ISO9660_IMAGE;
|
||||
|
||||
if (argc > 2)
|
||||
psz_fname = argv[2];
|
||||
else
|
||||
psz_fname = LOCAL_FILENAME;
|
||||
|
||||
p_iso = iso9660_open (psz_image);
|
||||
|
||||
if (NULL == p_iso) {
|
||||
fprintf(stderr, "Sorry, couldn't open ISO 9660 image %s\n", psz_image);
|
||||
return 1;
|
||||
}
|
||||
|
||||
p_statbuf = iso9660_ifs_stat_translate (p_iso, psz_fname);
|
||||
|
||||
if (NULL == p_statbuf)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Could not get ISO-9660 file information for file %s\n",
|
||||
psz_fname);
|
||||
iso9660_close(p_iso);
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (!(p_outfd = fopen (psz_fname, "wb")))
|
||||
{
|
||||
perror ("fopen()");
|
||||
free(p_statbuf);
|
||||
iso9660_close(p_iso);
|
||||
return 3;
|
||||
}
|
||||
|
||||
/* Copy the blocks from the ISO-9660 filesystem to the local filesystem. */
|
||||
{
|
||||
const unsigned int i_blocks = CEILING(p_statbuf->size, ISO_BLOCKSIZE);
|
||||
for (i = 0; i < i_blocks ; i++)
|
||||
{
|
||||
char buf[ISO_BLOCKSIZE];
|
||||
const lsn_t lsn = p_statbuf->lsn + i;
|
||||
|
||||
memset (buf, 0, ISO_BLOCKSIZE);
|
||||
|
||||
if ( ISO_BLOCKSIZE != iso9660_iso_seek_read (p_iso, buf, lsn, 1) )
|
||||
{
|
||||
fprintf(stderr, "Error reading ISO 9660 file %s at LSN %lu\n",
|
||||
psz_fname, (long unsigned int) lsn);
|
||||
my_exit(4);
|
||||
}
|
||||
|
||||
fwrite (buf, ISO_BLOCKSIZE, 1, p_outfd);
|
||||
|
||||
if (ferror (p_outfd))
|
||||
{
|
||||
perror ("fwrite()");
|
||||
my_exit(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fflush (p_outfd);
|
||||
|
||||
/* Make sure the file size has the exact same byte size. Without the
|
||||
truncate below, the file will a multiple of ISO_BLOCKSIZE.
|
||||
*/
|
||||
if (ftruncate (fileno (p_outfd), p_statbuf->size))
|
||||
perror ("ftruncate()");
|
||||
|
||||
printf("Extraction of file '%s' from %s successful.\n",
|
||||
psz_fname, psz_image);
|
||||
|
||||
my_exit(0);
|
||||
}
|
||||
161
example/C++/isofile2.cpp
Normal file
161
example/C++/isofile2.cpp
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
$Id: isofile2.cpp,v 1.2 2008/03/24 15:30:56 karl Exp $
|
||||
|
||||
Copyright (C) 2004, 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Simple program to show using libiso9660 to extract a file from an
|
||||
ISO-9660 image.
|
||||
|
||||
If a single argument is given, it is used as the ISO 9660 image to
|
||||
use in the extraction. Otherwise a compiled in default ISO 9660 image
|
||||
name (that comes with the libcdio distribution) will be used.
|
||||
*/
|
||||
|
||||
/* This is the ISO 9660 image. */
|
||||
#define ISO9660_IMAGE_PATH "../../"
|
||||
#define ISO9660_IMAGE ISO9660_IMAGE_PATH "test/copying.iso"
|
||||
|
||||
#define LOCAL_FILENAME "copying"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "portable.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <cdio/cdio.h>
|
||||
#include <cdio/iso9660.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#define CEILING(x, y) ((x+(y-1))/y)
|
||||
|
||||
#define my_exit(rc) \
|
||||
fclose (p_outfd); \
|
||||
free(p_statbuf); \
|
||||
iso9660_close(p_iso); \
|
||||
return rc; \
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
iso9660_stat_t *p_statbuf;
|
||||
FILE *p_outfd;
|
||||
int i;
|
||||
char const *psz_image;
|
||||
char const *psz_fname;
|
||||
iso9660_t *p_iso;
|
||||
|
||||
if (argc > 3) {
|
||||
printf("usage %s [ISO9660-image.ISO [filename]]\n", argv[0]);
|
||||
printf("Extracts filename from ISO-9660-image.ISO.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (argc > 1)
|
||||
psz_image = argv[1];
|
||||
else
|
||||
psz_image = ISO9660_IMAGE;
|
||||
|
||||
if (argc > 2)
|
||||
psz_fname = argv[2];
|
||||
else
|
||||
psz_fname = LOCAL_FILENAME;
|
||||
|
||||
p_iso = iso9660_open (psz_image);
|
||||
|
||||
if (NULL == p_iso) {
|
||||
fprintf(stderr, "Sorry, couldn't open ISO 9660 image %s\n", psz_image);
|
||||
return 1;
|
||||
}
|
||||
|
||||
p_statbuf = iso9660_ifs_stat_translate (p_iso, psz_fname);
|
||||
|
||||
if (NULL == p_statbuf)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Could not get ISO-9660 file information for file %s\n",
|
||||
psz_fname);
|
||||
iso9660_close(p_iso);
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (!(p_outfd = fopen (psz_fname, "wb")))
|
||||
{
|
||||
perror ("fopen()");
|
||||
free(p_statbuf);
|
||||
iso9660_close(p_iso);
|
||||
return 3;
|
||||
}
|
||||
|
||||
/* Copy the blocks from the ISO-9660 filesystem to the local filesystem. */
|
||||
{
|
||||
const unsigned int i_blocks = CEILING(p_statbuf->size, ISO_BLOCKSIZE);
|
||||
for (i = 0; i < i_blocks ; i++)
|
||||
{
|
||||
char buf[ISO_BLOCKSIZE];
|
||||
const lsn_t lsn = p_statbuf->lsn + i;
|
||||
|
||||
memset (buf, 0, ISO_BLOCKSIZE);
|
||||
|
||||
if ( ISO_BLOCKSIZE != iso9660_iso_seek_read (p_iso, buf, lsn, 1) )
|
||||
{
|
||||
fprintf(stderr, "Error reading ISO 9660 file %s at LSN %lu\n",
|
||||
psz_fname, (long unsigned int) lsn);
|
||||
my_exit(4);
|
||||
}
|
||||
|
||||
fwrite (buf, ISO_BLOCKSIZE, 1, p_outfd);
|
||||
|
||||
if (ferror (p_outfd))
|
||||
{
|
||||
perror ("fwrite()");
|
||||
my_exit(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fflush (p_outfd);
|
||||
|
||||
/* Make sure the file size has the exact same byte size. Without the
|
||||
truncate below, the file will a multiple of ISO_BLOCKSIZE.
|
||||
*/
|
||||
if (ftruncate (fileno (p_outfd), p_statbuf->size))
|
||||
perror ("ftruncate()");
|
||||
|
||||
printf("Extraction of file '%s' from %s successful.\n",
|
||||
psz_fname, psz_image);
|
||||
|
||||
my_exit(0);
|
||||
}
|
||||
121
example/C++/isolist.cpp
Normal file
121
example/C++/isolist.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
$Id: isolist.cpp,v 1.2 2008/03/24 15:30:56 karl Exp $
|
||||
|
||||
Copyright (C) 2004, 2006, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Simple program to show using libiso9660 to list files in a directory of
|
||||
an ISO-9660 image and give some iso9660 information. See the code
|
||||
to iso-info for a more complete example.
|
||||
|
||||
If a single argument is given, it is used as the ISO 9660 image to
|
||||
use in the listing. Otherwise a compiled-in default ISO 9660 image
|
||||
name (that comes with the libcdio distribution) will be used.
|
||||
|
||||
This program can be compiled with either a C or C++ compiler. In
|
||||
the distributuion we perfer C++ just to make sure we haven't broken
|
||||
things on the C++ side.
|
||||
*/
|
||||
|
||||
/* Set up a CD-DA image to test on which is in the libcdio distribution. */
|
||||
#define ISO9660_IMAGE_PATH "../../"
|
||||
#define ISO9660_IMAGE ISO9660_IMAGE_PATH "test/copying.iso"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include <cdio/iso9660.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#define print_vd_info(title, fn) \
|
||||
if (fn(p_iso, &psz_str)) { \
|
||||
printf(title ": %s\n", psz_str); \
|
||||
} \
|
||||
free(psz_str); \
|
||||
psz_str = NULL;
|
||||
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
CdioList_t *p_entlist;
|
||||
CdioListNode_t *p_entnode;
|
||||
char const *psz_fname;
|
||||
iso9660_t *p_iso;
|
||||
const char *psz_path="/";
|
||||
|
||||
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 %s as an ISO-9660 image\n",
|
||||
psz_fname);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Show basic CD info from the Primary Volume Descriptor. */
|
||||
{
|
||||
char *psz_str = NULL;
|
||||
print_vd_info("Application", iso9660_ifs_get_application_id);
|
||||
print_vd_info("Preparer ", iso9660_ifs_get_preparer_id);
|
||||
print_vd_info("Publisher ", iso9660_ifs_get_publisher_id);
|
||||
print_vd_info("System ", iso9660_ifs_get_system_id);
|
||||
print_vd_info("Volume ", iso9660_ifs_get_volume_id);
|
||||
print_vd_info("Volume Set ", iso9660_ifs_get_volumeset_id);
|
||||
}
|
||||
|
||||
p_entlist = iso9660_ifs_readdir (p_iso, psz_path);
|
||||
|
||||
/* Iterate over the list of nodes that iso9660_ifs_readdir gives */
|
||||
|
||||
if (p_entlist) {
|
||||
_CDIO_LIST_FOREACH (p_entnode, p_entlist)
|
||||
{
|
||||
char filename[4096];
|
||||
iso9660_stat_t *p_statbuf =
|
||||
(iso9660_stat_t *) _cdio_list_node_data (p_entnode);
|
||||
iso9660_name_translate(p_statbuf->filename, filename);
|
||||
printf ("%s [LSN %6d] %8u %s%s\n",
|
||||
2 == p_statbuf->type ? "d" : "-",
|
||||
p_statbuf->lsn, p_statbuf->size, psz_path, filename);
|
||||
}
|
||||
|
||||
_cdio_list_free (p_entlist, true);
|
||||
}
|
||||
|
||||
|
||||
iso9660_close(p_iso);
|
||||
return 0;
|
||||
}
|
||||
|
||||
86
example/C++/mmc1.cpp
Normal file
86
example/C++/mmc1.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
$Id: mmc1.cpp,v 1.4 2008/03/24 15:30:56 karl Exp $
|
||||
|
||||
Copyright (C) 2004, 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Sample program to show use of the MMC interface.
|
||||
An optional drive name can be supplied as an argument.
|
||||
This basically the libdio mmc_get_hwinfo() routine.
|
||||
See also corresponding C and OO C++ program.
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <cdio/cdio.h>
|
||||
#include <cdio/mmc.h>
|
||||
#include <string.h>
|
||||
|
||||
/* 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;
|
||||
const char *psz_drive = NULL;
|
||||
|
||||
if (argc > 1) psz_drive = argv[1];
|
||||
|
||||
p_cdio = cdio_open (psz_drive, 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 */
|
||||
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;
|
||||
}
|
||||
187
example/C++/mmc2.cpp
Normal file
187
example/C++/mmc2.cpp
Normal file
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
$Id: mmc2.cpp,v 1.3 2008/03/24 15:30:56 karl Exp $
|
||||
|
||||
Copyright (C) 2004, 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* 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 <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <cdio/cdio.h>
|
||||
#include <cdio/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_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 */
|
||||
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;
|
||||
}
|
||||
119
example/C++/paranoia.cpp
Normal file
119
example/C++/paranoia.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
$Id: paranoia.cpp,v 1.3 2008/03/24 15:30:56 karl Exp $
|
||||
|
||||
Copyright (C) 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Simple program to show using libcdio's version of the CD-DA paranoia.
|
||||
library. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <cdio/paranoia.h>
|
||||
#include <cdio/cd_types.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
cdrom_drive_t *d = NULL; /* Place to store handle given by cd-paranoia. */
|
||||
char **ppsz_cd_drives; /* List of all drives with a loaded CDDA in it. */
|
||||
|
||||
/* See if we can find a device with a loaded CD-DA in it. */
|
||||
ppsz_cd_drives = cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false);
|
||||
|
||||
if (ppsz_cd_drives) {
|
||||
/* Found such a CD-ROM with a CD-DA loaded. Use the first drive in
|
||||
the list. */
|
||||
d=cdda_identify(*ppsz_cd_drives, 1, NULL);
|
||||
} else {
|
||||
printf("Unable find or access a CD-ROM drive with an audio CD in it.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Don't need a list of CD's with CD-DA's any more. */
|
||||
cdio_free_device_list(ppsz_cd_drives);
|
||||
|
||||
if ( !d ) {
|
||||
printf("Unable to identify audio CD disc.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* We'll set for verbose paranoia messages. */
|
||||
cdda_verbose_set(d, CDDA_MESSAGE_PRINTIT, CDDA_MESSAGE_PRINTIT);
|
||||
|
||||
if ( 0 != cdda_open(d) ) {
|
||||
printf("Unable to open disc.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Okay now set up to read up to the first 300 frames of the first
|
||||
audio track of the Audio CD. */
|
||||
{
|
||||
cdrom_paranoia_t *p = paranoia_init(d);
|
||||
lsn_t i_first_lsn = cdda_disc_firstsector(d);
|
||||
|
||||
if ( -1 == i_first_lsn ) {
|
||||
printf("Trouble getting starting LSN\n");
|
||||
} else {
|
||||
lsn_t i_cursor;
|
||||
track_t i_track = cdda_sector_gettrack(d, i_first_lsn);
|
||||
lsn_t i_last_lsn = cdda_track_lastsector(d, i_track);
|
||||
|
||||
/* For demo purposes we'll read only 300 frames (about 4
|
||||
seconds). We don't want this to take too long. On the other
|
||||
hand, I suppose it should be something close to a real test.
|
||||
*/
|
||||
if ( i_last_lsn - i_first_lsn > 300) i_last_lsn = i_first_lsn + 299;
|
||||
|
||||
printf("Reading track %d from LSN %ld to LSN %ld\n", i_track,
|
||||
(long int) i_first_lsn, (long int) i_last_lsn);
|
||||
|
||||
/* Set reading mode for full paranoia, but allow skipping sectors. */
|
||||
paranoia_modeset(p, PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP);
|
||||
|
||||
paranoia_seek(p, i_first_lsn, SEEK_SET);
|
||||
|
||||
for ( i_cursor = i_first_lsn; i_cursor <= i_last_lsn; i_cursor ++) {
|
||||
/* read a sector */
|
||||
int16_t *p_readbuf=paranoia_read(p, NULL);
|
||||
char *psz_err=cdda_errors(d);
|
||||
char *psz_mes=cdda_messages(d);
|
||||
|
||||
if (psz_mes || psz_err)
|
||||
printf("%s%s\n", psz_mes ? psz_mes: "", psz_err ? psz_err: "");
|
||||
|
||||
if (psz_err) free(psz_err);
|
||||
if (psz_mes) free(psz_mes);
|
||||
if( !p_readbuf ) {
|
||||
printf("paranoia read error. Stopping.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
paranoia_free(p);
|
||||
}
|
||||
|
||||
cdda_close(d);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
101
example/C++/paranoia2.cpp
Normal file
101
example/C++/paranoia2.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
$Id: paranoia2.cpp,v 1.2 2008/03/24 15:30:57 karl Exp $
|
||||
|
||||
Copyright (C) 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Simple program to show using libcdio's version of the CD-DA
|
||||
paranoia library. But in this version, we'll open a cdio object before
|
||||
calling paranoia's open. I imagine in many cases such as media
|
||||
players this may be what will be done since, one may want to get
|
||||
CDDB/CD-Text info beforehand. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <cdio/cdda.h>
|
||||
#include <cdio/cd_types.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
cdrom_drive_t *d = NULL; /* Place to store handle given by cd-paranoia. */
|
||||
char **ppsz_cd_drives; /* List of all drives with a loaded CDDA in it. */
|
||||
CdIo_t *p_cdio = NULL;
|
||||
|
||||
/* See if we can find a device with a loaded CD-DA in it. */
|
||||
ppsz_cd_drives = cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false);
|
||||
|
||||
if (ppsz_cd_drives) {
|
||||
/* Found such a CD-ROM with a CD-DA loaded. Use the first drive in
|
||||
the list. */
|
||||
p_cdio = cdio_open(*ppsz_cd_drives, DRIVER_UNKNOWN);
|
||||
d=cdio_cddap_identify_cdio(p_cdio, 1, NULL);
|
||||
} else {
|
||||
printf("Unable find or access a CD-ROM drive with an audio CD in it.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Don't need a list of CD's with CD-DA's any more. */
|
||||
cdio_free_device_list(ppsz_cd_drives);
|
||||
|
||||
if ( !d ) {
|
||||
printf("Unable to identify audio CD disc.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* We'll set for verbose paranoia messages. */
|
||||
cdio_cddap_verbose_set(d, CDDA_MESSAGE_PRINTIT, CDDA_MESSAGE_PRINTIT);
|
||||
|
||||
if ( 0 != cdio_cddap_open(d) ) {
|
||||
printf("Unable to open disc.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* In the paranoia example was a reading. Here we are going to do
|
||||
something trivial (but I think neat any way - get the Endian-ness
|
||||
of the drive. */
|
||||
{
|
||||
const int i_endian = data_bigendianp(d);
|
||||
switch (i_endian) {
|
||||
case 0:
|
||||
printf("Drive returns audio data Little Endian."
|
||||
" Your drive is like most.\n");
|
||||
break;
|
||||
case 1:
|
||||
printf("Drive returns audio data Big Endian.\n");
|
||||
break;
|
||||
case -1:
|
||||
printf("Don't know whether drive is Big or Little Endian.\n");
|
||||
break;
|
||||
default:
|
||||
printf("Whoah - got a return result I'm not expecting %d.\n",
|
||||
i_endian);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cdio_cddap_close_no_free_cdio(d);
|
||||
cdio_destroy( p_cdio );
|
||||
|
||||
exit(0);
|
||||
}
|
||||
Reference in New Issue
Block a user