First commit after CVS conversion. Should be just administrative changes.
This commit is contained in:
3
example/.gitignore
vendored
Normal file
3
example/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/.deps
|
||||
/Makefile
|
||||
/Makefile.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);
|
||||
}
|
||||
97
example/Makefile.am
Normal file
97
example/Makefile.am
Normal file
@@ -0,0 +1,97 @@
|
||||
# $Id: Makefile.am,v 1.44 2008/08/31 13:38:21 flameeyes 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/>.
|
||||
|
||||
####################################################
|
||||
# Sample programs
|
||||
####################################################
|
||||
#
|
||||
if ENABLE_CPP
|
||||
SUBDIRS = C++
|
||||
endif
|
||||
if BUILD_CD_PARANOIA
|
||||
paranoia_progs = paranoia paranoia2
|
||||
endif
|
||||
if BUILD_EXAMPLES
|
||||
noinst_PROGRAMS = audio cdchange cdtext device drives eject \
|
||||
isofile isofile2 isofuzzy isolist isolsn \
|
||||
mmc1 mmc2 mmc2a mmc3 $(paranoia_progs) tracks \
|
||||
sample3 sample4 udf1 udffile cdio-eject
|
||||
endif
|
||||
|
||||
INCLUDES = -I$(top_srcdir) $(LIBCDIO_CFLAGS)
|
||||
|
||||
audio_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
audio_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
|
||||
cdchange_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
cdchange_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
|
||||
cdtext_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
cdtext_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
|
||||
device_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
device_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
|
||||
drives_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
drives_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
|
||||
eject_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
eject_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
|
||||
cdio_eject_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
cdio_eject_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
|
||||
if BUILD_CD_PARANOIA
|
||||
paranoia_LDADD = $(LIBCDIO_PARANOIA_LIBS) $(LIBCDIO_CDDA_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
paranoia2_LDADD = $(LIBCDIO_PARANOIA_LIBS) $(LIBCDIO_CDDA_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
endif
|
||||
|
||||
isofile_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
isofile2_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
isofuzzy_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
isolist_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
isolsn_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
|
||||
mmc1_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
mmc1_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
mmc2_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
mmc2_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
|
||||
mmc2a_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
mmc2a_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
|
||||
mmc3_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
mmc3_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
|
||||
sample3_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
sample3_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
|
||||
sample4_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
sample4_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
|
||||
tracks_DEPENDENCIES = $(LIBCDIO_DEPS)
|
||||
tracks_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
|
||||
udf1_DEPENDENCIES = $(LIBUDF_LIBS) $(LIBCDIO_DEPS)
|
||||
udf1_LDADD = $(LIBUDF_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
|
||||
udffile_DEPENDENCIES = $(LIBUDF_LIBS) $(LIBCDIO_DEPS)
|
||||
udffile_LDADD = $(LIBUDF_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||
|
||||
|
||||
# iso programs create file "copying"
|
||||
MOSTLYCLEANFILES = copying
|
||||
@@ -1,86 +0,0 @@
|
||||
$Id: README,v 1.28 2007/08/12 00:56:10 rocky Exp $
|
||||
|
||||
This directory contains some simple examples of the use of the libcdio
|
||||
library.
|
||||
|
||||
One might also possibly find useful C code among the regression tests
|
||||
(directory test), e.g. testbincue.c, testdefault.c, testiso9660.c,
|
||||
testparanoia.c, or testtoc.c
|
||||
|
||||
Larger more-complicated examples are the cd-drive, cd-info, cd-read,
|
||||
cdda-player, iso-info and iso-read programs in the src directory.
|
||||
|
||||
And going further there's the cd-paranoia program (in
|
||||
src/cd-paranoia), and "real-world' code in the xine VCD plugin, or the
|
||||
vlc CD-DA plugin which are part of those distributions.
|
||||
|
||||
Descriptions of the programs in this example directory are as follows...
|
||||
|
||||
audio.c: Sample program to show audio controls.
|
||||
|
||||
cdchange.c: A program to test if a CD has been changed since the last
|
||||
change test.
|
||||
|
||||
cdio-eject.c: a stripped-down "eject" command to open or close a CDROM
|
||||
tray
|
||||
|
||||
cdtext.c: A program to show CD-Text and CD disc mode info.
|
||||
|
||||
drives.c: A program to show drivers installed and what the default
|
||||
CD-ROM drive is and what CD drives are available.
|
||||
|
||||
eject.c: A program eject a CD from a CD-ROM drive and then close the door
|
||||
again.
|
||||
|
||||
isofile.c: A program to show using libiso9660 to extract a file from an
|
||||
ISO-9660 image.
|
||||
|
||||
isofile2.c: A program to show using libiso9660 to extract a file
|
||||
from a CDRWIN cue/bin CD image.
|
||||
|
||||
isofuzzy.c : A program showing fuzzy ISO-9660 detection/reading.
|
||||
|
||||
isolist.c: A program to show using libiso9660 to list files in a
|
||||
directory of an ISO-9660 image and give basic iso9660
|
||||
information.
|
||||
|
||||
isolsn.c: A program to show using libiso9660 to get the file
|
||||
path for a given LSN.
|
||||
|
||||
mmc1.c: A program to show issuing a simple MMC command (INQUIRY).
|
||||
|
||||
mmc2.c: A more involved MMC command to list features from
|
||||
a MMC GET_CONFIGURATION command.
|
||||
|
||||
mmc2a.c: Show MODE_SENSE page 2A paramaters:
|
||||
CD/DVD Capabilities and Mechanical Status Page
|
||||
|
||||
paranoia: 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: 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)
|
||||
|
||||
sample2.c: A simple program to show drivers installed and what the
|
||||
default CD-ROM drive is.
|
||||
|
||||
sample3.c: A simple program to show the use of cdio_guess_cd_type().
|
||||
Figure out the kind of CD image we've got.
|
||||
|
||||
sample4.c: A slightly improved sample3 program: we handle cdio logging
|
||||
and take an optional CD-location.
|
||||
|
||||
tracks.c: A program to list track numbers and logical sector
|
||||
numbers of a Compact Disc using libcdio.
|
||||
|
||||
udf1.c: A program to show using libudf to list files in a directory of
|
||||
an UDF image.
|
||||
|
||||
udf2.c: A program to show using libudf to extract a file from
|
||||
an UDF image.
|
||||
|
||||
Many of the above programs can be compiled in C++. See that directory
|
||||
for C++ examples which include some of the above.
|
||||
490
example/audio.c
Normal file
490
example/audio.c
Normal file
@@ -0,0 +1,490 @@
|
||||
/*
|
||||
$Id: audio.c,v 1.10 2008/06/19 15:44:10 flameeyes Exp $
|
||||
|
||||
Copyright (C) 2005, 2008 Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
Adapted from Gerd Knorr's player.c program <kraxel@bytesex.org>
|
||||
Copyright (C) 1997, 1998
|
||||
|
||||
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 show use of audio controls. For a more expanded
|
||||
CDDA player program using curses display see cdda-player in this
|
||||
distribution.
|
||||
*/
|
||||
#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_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef HAVE_GETOPT_H
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include <cdio/cdio.h>
|
||||
#include <cdio/mmc.h>
|
||||
#include <cdio/util.h>
|
||||
#include <cdio/cd_types.h>
|
||||
|
||||
static bool play_track(track_t t1, track_t t2);
|
||||
|
||||
static CdIo_t *p_cdio = NULL; /* libcdio handle */
|
||||
static driver_id_t driver_id = DRIVER_DEVICE;
|
||||
|
||||
/* cdrom data */
|
||||
static track_t i_first_track;
|
||||
static track_t i_last_track;
|
||||
static track_t i_first_audio_track;
|
||||
static track_t i_last_audio_track;
|
||||
static track_t i_tracks;
|
||||
static msf_t toc[CDIO_CDROM_LEADOUT_TRACK+1];
|
||||
static cdio_subchannel_t sub; /* subchannel last time read */
|
||||
static int i_data; /* # of data tracks present ? */
|
||||
static int start_track = 0;
|
||||
static int stop_track = 0;
|
||||
static int one_track = 0;
|
||||
|
||||
static bool b_cd = false;
|
||||
static bool auto_mode = false;
|
||||
static bool b_verbose = false;
|
||||
static bool debug = false;
|
||||
static bool b_record = false; /* we have a record for
|
||||
the inserted CD */
|
||||
|
||||
static char *psz_device=NULL;
|
||||
static char *psz_program;
|
||||
|
||||
inline static void
|
||||
xperror(const char *psz_msg)
|
||||
{
|
||||
if (b_verbose) {
|
||||
fprintf(stderr, "error: ");
|
||||
perror(psz_msg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
oops(const char *psz_msg, int rc)
|
||||
{
|
||||
cdio_destroy (p_cdio);
|
||||
free (psz_device);
|
||||
exit (rc);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
/*! Stop playing audio CD */
|
||||
static bool
|
||||
cd_stop(CdIo_t *p_cdio)
|
||||
{
|
||||
bool b_ok = true;
|
||||
if (b_cd && p_cdio) {
|
||||
i_last_audio_track = CDIO_INVALID_TRACK;
|
||||
b_ok = DRIVER_OP_SUCCESS == cdio_audio_stop(p_cdio);
|
||||
if ( !b_ok )
|
||||
xperror("stop");
|
||||
}
|
||||
return b_ok;
|
||||
}
|
||||
|
||||
/*! Eject CD */
|
||||
static bool
|
||||
cd_eject(void)
|
||||
{
|
||||
bool b_ok = true;
|
||||
if (p_cdio) {
|
||||
cd_stop(p_cdio);
|
||||
b_ok = DRIVER_OP_SUCCESS == cdio_eject_media(&p_cdio);
|
||||
if (!b_ok)
|
||||
xperror("eject");
|
||||
b_cd = false;
|
||||
p_cdio = NULL;
|
||||
}
|
||||
return b_ok;
|
||||
}
|
||||
|
||||
/*! Close CD tray */
|
||||
static bool
|
||||
cd_close(const char *psz_device)
|
||||
{
|
||||
bool b_ok = true;
|
||||
if (!b_cd) {
|
||||
b_ok = DRIVER_OP_SUCCESS == cdio_close_tray(psz_device, &driver_id);
|
||||
if (!b_ok)
|
||||
xperror("close");
|
||||
}
|
||||
return b_ok;
|
||||
}
|
||||
|
||||
/*! Pause playing audio CD */
|
||||
static bool
|
||||
cd_pause(CdIo_t *p_cdio)
|
||||
{
|
||||
bool b_ok = true;
|
||||
if (sub.audio_status == CDIO_MMC_READ_SUB_ST_PLAY) {
|
||||
b_ok = DRIVER_OP_SUCCESS == cdio_audio_pause(p_cdio);
|
||||
if (!b_ok)
|
||||
xperror("pause");
|
||||
}
|
||||
return b_ok;
|
||||
}
|
||||
|
||||
/*! Get status/track/position info of an audio CD */
|
||||
static bool
|
||||
read_subchannel(CdIo_t *p_cdio)
|
||||
{
|
||||
bool b_ok = true;
|
||||
if (!b_cd) return false;
|
||||
|
||||
b_ok = DRIVER_OP_SUCCESS == cdio_audio_read_subchannel(p_cdio, &sub);
|
||||
if (!b_ok) {
|
||||
xperror("read subchannel");
|
||||
b_cd = 0;
|
||||
}
|
||||
if (auto_mode && sub.audio_status == CDIO_MMC_READ_SUB_ST_COMPLETED)
|
||||
cd_eject();
|
||||
return b_ok;
|
||||
}
|
||||
|
||||
/*! Read CD TOC and set CD information. */
|
||||
static void
|
||||
read_toc(CdIo_t *p_cdio)
|
||||
{
|
||||
track_t i;
|
||||
|
||||
i_first_track = cdio_get_first_track_num(p_cdio);
|
||||
i_last_track = cdio_get_last_track_num(p_cdio);
|
||||
i_tracks = cdio_get_num_tracks(p_cdio);
|
||||
i_first_audio_track = i_first_track;
|
||||
i_last_audio_track = i_last_track;
|
||||
|
||||
|
||||
if ( CDIO_INVALID_TRACK == i_first_track ||
|
||||
CDIO_INVALID_TRACK == i_last_track ) {
|
||||
xperror("read toc header");
|
||||
b_cd = false;
|
||||
b_record = false;
|
||||
} else {
|
||||
b_cd = true;
|
||||
i_data = 0;
|
||||
for (i = i_first_track; i <= i_last_track+1; i++) {
|
||||
if ( !cdio_get_track_msf(p_cdio, i, &(toc[i])) )
|
||||
{
|
||||
xperror("read toc entry");
|
||||
b_cd = false;
|
||||
return;
|
||||
}
|
||||
if ( TRACK_FORMAT_AUDIO != cdio_get_track_format(p_cdio, i) ) {
|
||||
if ((i != i_last_track+1) ) {
|
||||
i_data++;
|
||||
if (i == i_first_track) {
|
||||
if (i == i_last_track)
|
||||
i_first_audio_track = CDIO_CDROM_LEADOUT_TRACK;
|
||||
else
|
||||
i_first_audio_track++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
b_record = true;
|
||||
read_subchannel(p_cdio);
|
||||
if (auto_mode && sub.audio_status != CDIO_MMC_READ_SUB_ST_PLAY)
|
||||
play_track(1, CDIO_CDROM_LEADOUT_TRACK);
|
||||
}
|
||||
}
|
||||
|
||||
/*! Play an audio track. */
|
||||
static bool
|
||||
play_track(track_t i_start_track, track_t i_end_track)
|
||||
{
|
||||
bool b_ok = true;
|
||||
|
||||
if (!b_cd) {
|
||||
cd_close(psz_device);
|
||||
read_toc(p_cdio);
|
||||
}
|
||||
|
||||
read_subchannel(p_cdio);
|
||||
if (!b_cd || i_first_track == CDIO_CDROM_LEADOUT_TRACK)
|
||||
return false;
|
||||
|
||||
if (debug)
|
||||
fprintf(stderr,"play tracks: %d-%d => ", i_start_track, i_end_track);
|
||||
if (i_start_track < i_first_track) i_start_track = i_first_track;
|
||||
if (i_start_track > i_last_audio_track) i_start_track = i_last_audio_track;
|
||||
if (i_end_track < i_first_track) i_end_track = i_first_track;
|
||||
if (i_end_track > i_last_audio_track) i_end_track = i_last_audio_track;
|
||||
if (debug)
|
||||
fprintf(stderr,"%d-%d\n",i_start_track, i_end_track);
|
||||
|
||||
cd_pause(p_cdio);
|
||||
b_ok = (DRIVER_OP_SUCCESS == cdio_audio_play_msf(p_cdio,
|
||||
&(toc[i_start_track]),
|
||||
&(toc[i_end_track])) );
|
||||
if (!b_ok) xperror("play");
|
||||
return b_ok;
|
||||
}
|
||||
|
||||
static void
|
||||
usage(char *prog)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s is a simple interface to issuing CD audio comamnds\n"
|
||||
"\n"
|
||||
"usage: %s [options] [device]\n"
|
||||
"\n"
|
||||
"default for to search for a CD-ROM device with a CD-DA loaded\n"
|
||||
"\n"
|
||||
"These command line options available:\n"
|
||||
" -h print this help\n"
|
||||
" -a start up in auto-mode\n"
|
||||
" -v verbose\n"
|
||||
"\n"
|
||||
" Use only one of these:\n"
|
||||
" -C close CD-ROM tray. If you use this option,\n"
|
||||
" a CD-ROM device name must be specified.\n"
|
||||
" -p play the whole CD\n"
|
||||
" -t n play track >n<\n"
|
||||
" -t a-b play all tracks between a and b (inclusive)\n"
|
||||
" -L set volume level\n"
|
||||
" -s stop playing\n"
|
||||
" -S list audio subchannel information\n"
|
||||
" -e eject cdrom\n"
|
||||
"\n"
|
||||
"That's all. Oh, maybe a few words more about the auto-mode. This\n"
|
||||
"is the 'dont-touch-any-key' feature. You load a CD, player starts\n"
|
||||
"to play it, and when it is done it ejects the CD. Start it that\n"
|
||||
"way on a spare console and forget about it...\n"
|
||||
"\n"
|
||||
"(c) 1997,98 Gerd Knorr <kraxel@goldbach.in-berlin.de>\n"
|
||||
"(c) 2005 Rocky Bernstein <rocky@panix.com>\n"
|
||||
, prog, prog);
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
NO_OP=0,
|
||||
PLAY_CD=1,
|
||||
PLAY_TRACK=2,
|
||||
STOP_PLAYING=3,
|
||||
EJECT_CD=4,
|
||||
CLOSE_CD=5,
|
||||
SET_VOLUME=6,
|
||||
LIST_SUBCHANNEL=7,
|
||||
} cd_operation_t;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c, nostop=0;
|
||||
char *h;
|
||||
int i_rc = 0;
|
||||
int i_volume_level = -1;
|
||||
cd_operation_t todo = NO_OP; /* operation to do in non-interactive mode */
|
||||
|
||||
psz_program = strrchr(argv[0],'/');
|
||||
psz_program = psz_program ? psz_program+1 : argv[0];
|
||||
|
||||
/* parse options */
|
||||
while ( 1 ) {
|
||||
if (-1 == (c = getopt(argc, argv, "aCdehkpL:sSt:vx")))
|
||||
break;
|
||||
switch (c) {
|
||||
case 'v':
|
||||
b_verbose = true;
|
||||
break;
|
||||
case 'd':
|
||||
debug = 1;
|
||||
break;
|
||||
case 'a':
|
||||
auto_mode = 1;
|
||||
break;
|
||||
case 'L':
|
||||
if (NULL != (h = strchr(optarg,'-'))) {
|
||||
i_volume_level = atoi(optarg);
|
||||
todo = SET_VOLUME;
|
||||
}
|
||||
case 't':
|
||||
if (NULL != (h = strchr(optarg,'-'))) {
|
||||
*h = 0;
|
||||
start_track = atoi(optarg);
|
||||
stop_track = atoi(h+1)+1;
|
||||
if (0 == start_track) start_track = 1;
|
||||
if (1 == stop_track) stop_track = CDIO_CDROM_LEADOUT_TRACK;
|
||||
} else {
|
||||
start_track = atoi(optarg);
|
||||
stop_track = start_track+1;
|
||||
one_track = 1;
|
||||
}
|
||||
todo = PLAY_TRACK;
|
||||
break;
|
||||
case 'p':
|
||||
todo = PLAY_CD;
|
||||
break;
|
||||
case 'C':
|
||||
todo = CLOSE_CD;
|
||||
break;
|
||||
break;
|
||||
case 's':
|
||||
todo = STOP_PLAYING;
|
||||
break;
|
||||
case 'S':
|
||||
todo = LIST_SUBCHANNEL;
|
||||
break;
|
||||
case 'e':
|
||||
todo = EJECT_CD;
|
||||
break;
|
||||
case 'h':
|
||||
usage(psz_program);
|
||||
exit(1);
|
||||
default:
|
||||
usage(psz_program);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > optind) {
|
||||
psz_device = strdup(argv[optind]);
|
||||
} else {
|
||||
char **ppsz_cdda_drives=NULL;
|
||||
char **ppsz_all_cd_drives = cdio_get_devices_ret(&driver_id);
|
||||
|
||||
if (!ppsz_all_cd_drives) {
|
||||
fprintf(stderr, "Can't find a CD-ROM drive\n");
|
||||
exit(2);
|
||||
}
|
||||
ppsz_cdda_drives = cdio_get_devices_with_cap(ppsz_all_cd_drives,
|
||||
CDIO_FS_AUDIO, false);
|
||||
if (!ppsz_cdda_drives || !ppsz_cdda_drives[0]) {
|
||||
fprintf(stderr, "Can't find a CD-ROM drive with a CD-DA in it\n");
|
||||
exit(3);
|
||||
}
|
||||
psz_device = strdup(ppsz_cdda_drives[0]);
|
||||
cdio_free_device_list(ppsz_all_cd_drives);
|
||||
cdio_free_device_list(ppsz_cdda_drives);
|
||||
}
|
||||
|
||||
if (!b_cd && todo != EJECT_CD) {
|
||||
cd_close(psz_device);
|
||||
}
|
||||
|
||||
/* open device */
|
||||
if (b_verbose)
|
||||
fprintf(stderr,"open %s... ", psz_device);
|
||||
|
||||
p_cdio = cdio_open (psz_device, driver_id);
|
||||
|
||||
if (!p_cdio) {
|
||||
if (b_verbose)
|
||||
fprintf(stderr, "error: %s\n", strerror(errno));
|
||||
else
|
||||
fprintf(stderr, "open %s: %s\n", psz_device, strerror(errno));
|
||||
exit(1);
|
||||
} else
|
||||
if (b_verbose)
|
||||
fprintf(stderr,"ok\n");
|
||||
|
||||
{
|
||||
nostop=1;
|
||||
if (EJECT_CD == todo) {
|
||||
i_rc = cd_eject() ? 0 : 1;
|
||||
} else {
|
||||
read_toc(p_cdio);
|
||||
if (!b_cd) {
|
||||
cd_close(psz_device);
|
||||
read_toc(p_cdio);
|
||||
}
|
||||
if (b_cd)
|
||||
switch (todo) {
|
||||
case NO_OP:
|
||||
break;
|
||||
case STOP_PLAYING:
|
||||
i_rc = cd_stop(p_cdio) ? 0 : 1;
|
||||
break;
|
||||
case EJECT_CD:
|
||||
/* Should have been handled above. */
|
||||
cd_eject();
|
||||
break;
|
||||
case PLAY_TRACK:
|
||||
/* play just this one track */
|
||||
play_track(start_track, stop_track);
|
||||
break;
|
||||
case PLAY_CD:
|
||||
play_track(1,CDIO_CDROM_LEADOUT_TRACK);
|
||||
break;
|
||||
case CLOSE_CD:
|
||||
i_rc = cdio_close_tray(psz_device, NULL) ? 0 : 1;
|
||||
break;
|
||||
case SET_VOLUME:
|
||||
{
|
||||
cdio_audio_volume_t volume;
|
||||
volume.level[0] = i_volume_level;
|
||||
i_rc = (DRIVER_OP_SUCCESS == cdio_audio_set_volume(p_cdio,
|
||||
&volume))
|
||||
? 0 : 1;
|
||||
break;
|
||||
}
|
||||
case LIST_SUBCHANNEL:
|
||||
if (read_subchannel(p_cdio)) {
|
||||
if (sub.audio_status == CDIO_MMC_READ_SUB_ST_PAUSED ||
|
||||
sub.audio_status == CDIO_MMC_READ_SUB_ST_PLAY) {
|
||||
{
|
||||
printf("track %2d - %02x:%02x (%02x:%02x abs) ",
|
||||
sub.track, sub.rel_addr.m, sub.rel_addr.s,
|
||||
sub.abs_addr.m, sub.abs_addr.s);
|
||||
}
|
||||
}
|
||||
printf("drive state: %s\n",
|
||||
mmc_audio_state2str(sub.audio_status));
|
||||
} else {
|
||||
i_rc = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr,"no CD in drive (%s)\n", psz_device);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!nostop) cd_stop(p_cdio);
|
||||
oops("bye", i_rc);
|
||||
|
||||
return 0; /* keep compiler happy */
|
||||
}
|
||||
100
example/cdchange.c
Normal file
100
example/cdchange.c
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
$Id: cdchange.c,v 1.9 2008/06/25 08:01:53 rocky Exp $
|
||||
|
||||
Copyright (C) 2005, 2006, 2007, 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/>.
|
||||
*/
|
||||
|
||||
/* Test media changed */
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef HAVE_LIMITS_H
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ERRNO_H
|
||||
# include <errno.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SLEEP
|
||||
static void
|
||||
sleep(unsigned int ms)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
Sleep(ms);
|
||||
#else
|
||||
#error sleep() unimplemented
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#include <cdio/cdio.h>
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
CdIo_t *p_cdio;
|
||||
unsigned long i_sleep=30;
|
||||
|
||||
if (argc > 1) {
|
||||
p_cdio = cdio_open (argv[1], DRIVER_DEVICE);
|
||||
if (argc > 2) {
|
||||
errno = 0;
|
||||
i_sleep = strtol(argv[2], (char **)NULL, 10);
|
||||
if ( (LONG_MIN == i_sleep || LONG_MAX == i_sleep) && errno != 0 ) {
|
||||
printf("Invalid sleep parameter %s\n", argv[2]);
|
||||
printf("Error reported back from strtol: %s\n", strerror(errno));
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
p_cdio = cdio_open (NULL, DRIVER_DEVICE);
|
||||
}
|
||||
|
||||
if (NULL == p_cdio) {
|
||||
printf("Couldn't find a driver.. leaving.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (cdio_get_media_changed(p_cdio))
|
||||
printf("Initial media status: changed\n");
|
||||
else
|
||||
printf("Initial media status: not changed\n");
|
||||
|
||||
printf("Giving you %lu seconds to change CD if you want to do so.\n",
|
||||
i_sleep);
|
||||
sleep(30);
|
||||
if (cdio_get_media_changed(p_cdio))
|
||||
printf("Media status: changed\n");
|
||||
else
|
||||
printf("Media status: not changed\n");
|
||||
|
||||
cdio_destroy(p_cdio);
|
||||
return 0;
|
||||
}
|
||||
82
example/cdio-eject.c
Normal file
82
example/cdio-eject.c
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
$Id: cdio-eject.c,v 1.4 2008/03/24 15:30:55 karl Exp $
|
||||
|
||||
Copyright (C) 2007, 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/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <cdio/cdio.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static void usage(char * progname)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-t] <device>\n", progname);
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
driver_return_code_t err;
|
||||
int close_tray = 0;
|
||||
const char * device = NULL;
|
||||
|
||||
if(argc < 2 || argc > 3)
|
||||
{
|
||||
usage(argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if((argc == 3) && strcmp(argv[1], "-t"))
|
||||
{
|
||||
usage(argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(argc == 2)
|
||||
device = argv[1];
|
||||
else if(argc == 3)
|
||||
{
|
||||
close_tray = 1;
|
||||
device = argv[2];
|
||||
}
|
||||
|
||||
if(close_tray)
|
||||
{
|
||||
err = cdio_close_tray(device, NULL);
|
||||
if(err)
|
||||
{
|
||||
fprintf(stderr, "Closing tray failed for device %s: %s\n",
|
||||
device, cdio_driver_errmsg(err));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
err = cdio_eject_media_drive(device);
|
||||
if(err)
|
||||
{
|
||||
fprintf(stderr, "Ejecting failed for device %s: %s\n",
|
||||
device, cdio_driver_errmsg(err));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
101
example/cdtext.c
Normal file
101
example/cdtext.c
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
$Id: cdtext.c,v 1.5 2008/03/24 15:30:55 karl Exp $
|
||||
|
||||
Copyright (C) 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 list CD-Text info of a Compact Disc using
|
||||
libcdio. See also corresponding C++ programs of similar names. */
|
||||
|
||||
#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.h>
|
||||
#include <cdio/cdtext.h>
|
||||
|
||||
|
||||
static void
|
||||
print_cdtext_track_info(CdIo_t *p_cdio, track_t i_track, const char *psz_msg) {
|
||||
const cdtext_t *cdtext = cdio_get_cdtext(p_cdio, 0);
|
||||
if (NULL != cdtext) {
|
||||
cdtext_field_t i;
|
||||
|
||||
printf("%s\n", psz_msg);
|
||||
|
||||
for (i=0; 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(CdIo_t *p_cdio, track_t i_tracks, track_t i_first_track) {
|
||||
track_t i_last_track = i_first_track+i_tracks;
|
||||
discmode_t cd_discmode = cdio_get_discmode(p_cdio);
|
||||
|
||||
printf("%s\n", discmode2str[cd_discmode]);
|
||||
|
||||
print_cdtext_track_info(p_cdio, 0, "\nCD-Text for Disc:");
|
||||
for ( ; i_first_track < i_last_track; i_first_track++ ) {
|
||||
char psz_msg[50];
|
||||
snprintf(psz_msg, sizeof(psz_msg), "CD-Text for Track %d:", i_first_track);
|
||||
print_cdtext_track_info(p_cdio, i_first_track, psz_msg);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
track_t i_first_track;
|
||||
track_t i_tracks;
|
||||
CdIo_t *p_cdio = cdio_open ("../test/cdda.cue", DRIVER_BINCUE);
|
||||
|
||||
|
||||
if (NULL == p_cdio) {
|
||||
printf("Couldn't open ../test/cdda.cue with BIN/CUE driver.\n");
|
||||
} else {
|
||||
i_first_track = cdio_get_first_track_num(p_cdio);
|
||||
i_tracks = cdio_get_num_tracks(p_cdio);
|
||||
print_disc_info(p_cdio, i_tracks, i_first_track);
|
||||
cdio_destroy(p_cdio);
|
||||
}
|
||||
|
||||
p_cdio = cdio_open (NULL, DRIVER_DEVICE);
|
||||
i_first_track = cdio_get_first_track_num(p_cdio);
|
||||
i_tracks = cdio_get_num_tracks(p_cdio);
|
||||
|
||||
if (NULL == p_cdio) {
|
||||
printf("Couldn't find CD\n");
|
||||
return 1;
|
||||
} else {
|
||||
print_disc_info(p_cdio, i_tracks, i_first_track);
|
||||
}
|
||||
|
||||
cdio_destroy(p_cdio);
|
||||
|
||||
return 0;
|
||||
}
|
||||
135
example/device.c
Normal file
135
example/device.c
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
$Id: device.c,v 1.3 2008/03/24 15:30:55 karl Exp $
|
||||
|
||||
Copyright (C) 2003, 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/>.
|
||||
*/
|
||||
|
||||
/* Simple program to show drivers installed and what the default
|
||||
CD-ROM drive is. See also corresponding C++ programs of similar
|
||||
names .*/
|
||||
#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");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
CdIo_t *p_cdio = cdio_open (NULL, DRIVER_UNKNOWN);
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
{
|
||||
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;
|
||||
}
|
||||
93
example/drives.c
Normal file
93
example/drives.c
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
$Id: drives.c,v 1.6 2008/03/24 15:30:55 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.h>
|
||||
#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) {
|
||||
char **ppsz_cd_drives=NULL, **c;
|
||||
|
||||
printf("%s...\n", psz_msg);
|
||||
ppsz_cd_drives = cdio_get_devices_with_cap(NULL, bitmask, b_any);
|
||||
if (NULL != ppsz_cd_drives)
|
||||
for( c = ppsz_cd_drives; *c != NULL; c++ ) {
|
||||
printf("Drive %s\n", *c);
|
||||
}
|
||||
|
||||
cdio_free_device_list(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 */
|
||||
ppsz_cd_drives = cdio_get_devices(DRIVER_DEVICE);
|
||||
if (NULL != ppsz_cd_drives)
|
||||
for( c = ppsz_cd_drives; *c != NULL; c++ ) {
|
||||
printf("Drive %s\n", *c);
|
||||
}
|
||||
|
||||
cdio_free_device_list(ppsz_cd_drives);
|
||||
ppsz_cd_drives = NULL;
|
||||
|
||||
printf("-----\n");
|
||||
|
||||
/* Print out a list of CD-drives the harder way. */
|
||||
print_drive_class("All CD-ROM drives (again)", CDIO_FS_MATCH_ALL, false);
|
||||
print_drive_class("CD-ROM drives with a CD-DA loaded...",
|
||||
CDIO_FS_AUDIO, false);
|
||||
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;
|
||||
|
||||
}
|
||||
101
example/eject.c
Normal file
101
example/eject.c
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
$Id: eject.c,v 1.5 2008/03/24 15:30:55 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
|
||||
#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/isofile.c
Normal file
161
example/isofile.c
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
$Id: isofile.c,v 1.2 2008/03/24 15:30:55 karl Exp $
|
||||
|
||||
Copyright (C) 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 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);
|
||||
}
|
||||
180
example/isofile2.c
Normal file
180
example/isofile2.c
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
$Id: isofile2.c,v 1.2 2008/03/24 15:30:55 karl Exp $
|
||||
|
||||
Copyright (C) 2003, 2004, 2005, 2006 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.h>
|
||||
#include <cdio/iso9660.h>
|
||||
|
||||
#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); \
|
||||
free(p_statbuf); \
|
||||
cdio_destroy(p_cdio); \
|
||||
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;
|
||||
char translated_name[256];
|
||||
char untranslated_name[256] = ISO9660_PATH;
|
||||
CdIo_t *p_cdio;
|
||||
unsigned int i_fname=sizeof(ISO9660_FILENAME);
|
||||
|
||||
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];
|
||||
i_fname = strlen(psz_fname)+1;
|
||||
} else
|
||||
psz_fname = ISO9660_FILENAME;
|
||||
|
||||
strncat(untranslated_name, psz_fname, i_fname);
|
||||
|
||||
p_cdio = cdio_open (psz_image, DRIVER_UNKNOWN);
|
||||
if (!p_cdio) {
|
||||
fprintf(stderr, "Sorry, couldn't open %s\n", psz_image);
|
||||
return 1;
|
||||
}
|
||||
|
||||
p_statbuf = iso9660_fs_stat (p_cdio, untranslated_name);
|
||||
|
||||
if (NULL == p_statbuf)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Could not get ISO-9660 file information for file %s\n",
|
||||
untranslated_name);
|
||||
cdio_destroy(p_cdio);
|
||||
return 2;
|
||||
}
|
||||
|
||||
iso9660_name_translate(psz_fname, translated_name);
|
||||
|
||||
if (!(p_outfd = fopen (translated_name, "wb")))
|
||||
{
|
||||
perror ("fopen()");
|
||||
cdio_destroy(p_cdio);
|
||||
free(p_statbuf);
|
||||
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 ( 0 != cdio_read_data_sectors (p_cdio, buf, lsn, ISO_BLOCKSIZE, 1) )
|
||||
{
|
||||
fprintf(stderr, "Error reading ISO 9660 file at lsn %lu\n",
|
||||
(long unsigned int) p_statbuf->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",
|
||||
translated_name, untranslated_name);
|
||||
|
||||
my_exit(0);
|
||||
}
|
||||
99
example/isofuzzy.c
Normal file
99
example/isofuzzy.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
$Id: isofuzzy.c,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/>.
|
||||
*/
|
||||
|
||||
/* Program to show using libiso9660 with fuzzy search to get file info.
|
||||
|
||||
If a single argument is given, it is used as the ISO 9660 image.
|
||||
Otherwise we use a compiled-in default ISO 9660 image
|
||||
name.
|
||||
*/
|
||||
|
||||
/* This is the BIN we think there is an ISO 9660 image inside of. */
|
||||
#define ISO9660_IMAGE_PATH "/tmp/"
|
||||
#define ISO9660_IMAGE ISO9660_IMAGE_PATH "vcd_demo.bin"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "portable.h"
|
||||
|
||||
#include <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
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
CdioList_t *entlist;
|
||||
CdioListNode_t *entnode;
|
||||
char const *psz_fname;
|
||||
iso9660_t *p_iso;
|
||||
|
||||
if (argc > 1)
|
||||
psz_fname = argv[1];
|
||||
else
|
||||
psz_fname = ISO9660_IMAGE;
|
||||
|
||||
p_iso = iso9660_open_fuzzy (psz_fname, 5);
|
||||
|
||||
if (NULL == p_iso) {
|
||||
fprintf(stderr, "Sorry, could not find an ISO 9660 image from %s\n",
|
||||
psz_fname);
|
||||
return 1;
|
||||
}
|
||||
|
||||
entlist = iso9660_ifs_readdir (p_iso, "/");
|
||||
|
||||
/* Iterate over the list of nodes that iso9660_ifs_readdir gives */
|
||||
|
||||
if (entlist) {
|
||||
_CDIO_LIST_FOREACH (entnode, entlist)
|
||||
{
|
||||
char filename[4096];
|
||||
iso9660_stat_t *p_statbuf =
|
||||
(iso9660_stat_t *) _cdio_list_node_data (entnode);
|
||||
iso9660_name_translate(p_statbuf->filename, filename);
|
||||
printf ("/%s\n", filename);
|
||||
}
|
||||
|
||||
_cdio_list_free (entlist, true);
|
||||
}
|
||||
|
||||
iso9660_close(p_iso);
|
||||
exit(0);
|
||||
}
|
||||
119
example/isolist.c
Normal file
119
example/isolist.c
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
$Id: isolist.c,v 1.3 2008/03/24 15:30:56 karl Exp $
|
||||
|
||||
Copyright (C) 2004, 2005, 2006, 2007, 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.
|
||||
*/
|
||||
|
||||
/* Set up a CD-DA image to test on which is in the libcdio distribution. */
|
||||
#define ISO9660_IMAGE_PATH "../test/"
|
||||
#define ISO9660_IMAGE ISO9660_IMAGE_PATH "copying.iso"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <cdio/cdio.h>
|
||||
#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",
|
||||
_STAT_DIR == 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;
|
||||
}
|
||||
|
||||
98
example/isolsn.c
Normal file
98
example/isolsn.c
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
$Id: isolsn.c,v 1.2 2008/03/24 15:30:56 karl Exp $
|
||||
|
||||
Copyright (C) 2004, 2005, 2006, 2007, 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 get a file path
|
||||
for a given LSN of an ISO-9660 image.
|
||||
|
||||
If a single argument is given, it is used as the LSN to search for.
|
||||
Otherwise we use a built-in default value.
|
||||
|
||||
If a second argument is given, it is 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.
|
||||
*/
|
||||
|
||||
/* Set up a CD-DA image to test on which is in the libcdio distribution. */
|
||||
#define ISO9660_IMAGE_PATH "../test/"
|
||||
#define ISO9660_IMAGE ISO9660_IMAGE_PATH "copying.iso"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <cdio/cdio.h>
|
||||
#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[])
|
||||
{
|
||||
char const *psz_fname;
|
||||
iso9660_t *p_iso;
|
||||
lsn_t lsn = 24;
|
||||
char *psz_path = NULL;
|
||||
|
||||
if (argc > 1)
|
||||
lsn = strtol(argv[1], (char **)NULL, 10);
|
||||
|
||||
if (argc > 2)
|
||||
psz_fname = argv[2];
|
||||
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;
|
||||
}
|
||||
|
||||
iso9660_ifs_find_lsn_with_path (p_iso, lsn, &psz_path);
|
||||
if (psz_path != NULL) {
|
||||
printf("File at LSN %u is %s\n", lsn, psz_path);
|
||||
free(psz_path);
|
||||
}
|
||||
|
||||
iso9660_close(p_iso);
|
||||
return 0;
|
||||
}
|
||||
|
||||
89
example/mmc1.c
Normal file
89
example/mmc1.c
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
$Id: mmc1.c,v 1.7 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++ programs.
|
||||
*/
|
||||
#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.h>
|
||||
#include <cdio/mmc.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 (!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;
|
||||
}
|
||||
196
example/mmc2.c
Normal file
196
example/mmc2.c
Normal file
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
$Id: mmc2.c,v 1.8 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>
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#include <cdio/cdio.h>
|
||||
#include <cdio/mmc.h>
|
||||
|
||||
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_DEVICE);
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
if (mmc_have_interface(p_cdio, CDIO_MMC_FEATURE_INTERFACE_ATAPI))
|
||||
printf("CD-ROM is an ATAPI interface.\n");
|
||||
else
|
||||
printf("CD-ROM is not an ATAPI interface.\n");
|
||||
|
||||
cdio_destroy(p_cdio);
|
||||
|
||||
return 0;
|
||||
}
|
||||
234
example/mmc2a.c
Normal file
234
example/mmc2a.c
Normal file
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
$Id: mmc2a.c,v 1.5 2008/03/24 15:30:56 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/>.
|
||||
*/
|
||||
|
||||
/* Sample program to show use of the MMC interface.
|
||||
An optional drive name can be supplied as an argument.
|
||||
This basically calls to the libdio mmc_mode_sense_10() and mmc_mode_sense_6
|
||||
routines.
|
||||
*/
|
||||
#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
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <cdio/cdio.h>
|
||||
#include <cdio/mmc.h>
|
||||
|
||||
static void
|
||||
print_mode_sense (const char *psz_drive, const char *six_or_ten,
|
||||
const uint8_t buf[22])
|
||||
{
|
||||
printf("Mode sense %s information for %s:\n", six_or_ten, psz_drive);
|
||||
if (buf[2] & 0x01) {
|
||||
printf("\tReads CD-R media.\n");
|
||||
}
|
||||
if (buf[2] & 0x02) {
|
||||
printf("\tReads CD-RW media.\n");
|
||||
}
|
||||
if (buf[2] & 0x04) {
|
||||
printf("\tReads fixed-packet tracks when Addressing type is method 2.\n");
|
||||
}
|
||||
if (buf[2] & 0x08) {
|
||||
printf("\tReads DVD ROM media.\n");
|
||||
}
|
||||
if (buf[2] & 0x10) {
|
||||
printf("\tReads DVD-R media.\n");
|
||||
}
|
||||
if (buf[2] & 0x20) {
|
||||
printf("\tReads DVD-RAM media.\n");
|
||||
}
|
||||
if (buf[2] & 0x40) {
|
||||
printf("\tReads DVD-RAM media.\n");
|
||||
}
|
||||
if (buf[3] & 0x01) {
|
||||
printf("\tWrites CD-R media.\n");
|
||||
}
|
||||
if (buf[3] & 0x02) {
|
||||
printf("\tWrites CD-RW media.\n");
|
||||
}
|
||||
if (buf[3] & 0x04) {
|
||||
printf("\tSupports emulation write.\n");
|
||||
}
|
||||
if (buf[3] & 0x10) {
|
||||
printf("\tWrites DVD-R media.\n");
|
||||
}
|
||||
if (buf[3] & 0x20) {
|
||||
printf("\tWrites DVD-RAM media.\n");
|
||||
}
|
||||
if (buf[4] & 0x01) {
|
||||
printf("\tCan play audio.\n");
|
||||
}
|
||||
if (buf[4] & 0x02) {
|
||||
printf("\tDelivers composition A/V stream.\n");
|
||||
}
|
||||
if (buf[4] & 0x04) {
|
||||
printf("\tSupports digital output on port 2.\n");
|
||||
}
|
||||
if (buf[4] & 0x08) {
|
||||
printf("\tSupports digital output on port 1.\n");
|
||||
}
|
||||
if (buf[4] & 0x10) {
|
||||
printf("\tReads Mode-2 form 1 (e.g. XA) media.\n");
|
||||
}
|
||||
if (buf[4] & 0x20) {
|
||||
printf("\tReads Mode-2 form 2 media.\n");
|
||||
}
|
||||
if (buf[4] & 0x40) {
|
||||
printf("\tReads multi-session CD media.\n");
|
||||
}
|
||||
if (buf[4] & 0x80) {
|
||||
printf("\tSupports Buffer under-run free recording on CD-R/RW media.\n");
|
||||
}
|
||||
if (buf[4] & 0x01) {
|
||||
printf("\tCan read audio data with READ CD.\n");
|
||||
}
|
||||
if (buf[4] & 0x02) {
|
||||
printf("\tREAD CD data stream is accurate.\n");
|
||||
}
|
||||
if (buf[5] & 0x04) {
|
||||
printf("\tReads R-W subchannel information.\n");
|
||||
}
|
||||
if (buf[5] & 0x08) {
|
||||
printf("\tReads de-interleaved R-W subchannel.\n");
|
||||
}
|
||||
if (buf[5] & 0x10) {
|
||||
printf("\tSupports C2 error pointers.\n");
|
||||
}
|
||||
if (buf[5] & 0x20) {
|
||||
printf("\tReads ISRC information.\n");
|
||||
}
|
||||
if (buf[5] & 0x40) {
|
||||
printf("\tReads ISRC informaton.\n");
|
||||
}
|
||||
if (buf[5] & 0x40) {
|
||||
printf("\tReads media catalog number (MCN also known as UPC).\n");
|
||||
}
|
||||
if (buf[5] & 0x80) {
|
||||
printf("\tReads bar codes.\n");
|
||||
}
|
||||
if (buf[6] & 0x01) {
|
||||
printf("\tPREVENT/ALLOW may lock media.\n");
|
||||
}
|
||||
printf("\tLock state is %slocked.\n", (buf[6] & 0x02) ? "" : "un");
|
||||
printf("\tPREVENT/ALLOW jumper is %spresent.\n", (buf[6] & 0x04) ? "": "not ");
|
||||
if (buf[6] & 0x08) {
|
||||
printf("\tEjects media with START STOP UNIT.\n");
|
||||
}
|
||||
{
|
||||
const unsigned int i_load_type = (buf[6]>>5 & 0x07);
|
||||
printf("\tLoading mechanism type is %d: ", i_load_type);
|
||||
switch (buf[6]>>5 & 0x07) {
|
||||
case 0:
|
||||
printf("caddy type loading mechanism.\n");
|
||||
break;
|
||||
case 1:
|
||||
printf("tray type loading mechanism.\n");
|
||||
break;
|
||||
case 2:
|
||||
printf("popup type loading mechanism.\n");
|
||||
break;
|
||||
case 3:
|
||||
printf("reserved\n");
|
||||
break;
|
||||
case 4:
|
||||
printf("changer with individually changeable discs.\n");
|
||||
break;
|
||||
case 5:
|
||||
printf("changer using Magazine mechanism.\n");
|
||||
break;
|
||||
case 6:
|
||||
printf("changer using Magazine mechanism.\n");
|
||||
break;
|
||||
default:
|
||||
printf("Invalid.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (buf[7] & 0x01) {
|
||||
printf("\tVolume controls each channel separately.\n");
|
||||
}
|
||||
if (buf[7] & 0x02) {
|
||||
printf("\tHas a changer that supports disc present reporting.\n");
|
||||
}
|
||||
if (buf[7] & 0x04) {
|
||||
printf("\tCan load empty slot in changer.\n");
|
||||
}
|
||||
if (buf[7] & 0x08) {
|
||||
printf("\tSide change capable.\n");
|
||||
}
|
||||
if (buf[7] & 0x10) {
|
||||
printf("\tReads raw R-W subchannel information from lead in.\n");
|
||||
}
|
||||
{
|
||||
const unsigned int i_speed_Kbs = CDIO_MMC_GETPOS_LEN16(buf, 8);
|
||||
printf("\tMaximum read speed is %d K bytes/sec (about %dX)\n",
|
||||
i_speed_Kbs, i_speed_Kbs / 176) ;
|
||||
}
|
||||
printf("\tNumber of Volume levels is %d\n", CDIO_MMC_GETPOS_LEN16(buf, 10));
|
||||
printf("\tBuffers size for data is %d KB\n", CDIO_MMC_GETPOS_LEN16(buf, 12));
|
||||
printf("\tCurrent read speed is %d KB\n", CDIO_MMC_GETPOS_LEN16(buf, 14));
|
||||
printf("\tMaximum write speed is %d KB\n", CDIO_MMC_GETPOS_LEN16(buf, 18));
|
||||
printf("\tCurrent write speed is %d KB\n", CDIO_MMC_GETPOS_LEN16(buf, 28));
|
||||
}
|
||||
|
||||
|
||||
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 (!p_cdio) {
|
||||
printf("Couldn't find CD\n");
|
||||
return 1;
|
||||
} else {
|
||||
uint8_t buf[22] = { 0, }; /* Place to hold returned data */
|
||||
char *psz_cd = cdio_get_default_device(p_cdio);
|
||||
if (DRIVER_OP_SUCCESS == mmc_mode_sense_6(p_cdio, buf, sizeof(buf),
|
||||
CDIO_MMC_CAPABILITIES_PAGE) ) {
|
||||
print_mode_sense(psz_cd, "6", buf);
|
||||
} else {
|
||||
printf("Couldn't get MODE_SENSE 6 data.\n");
|
||||
}
|
||||
if (DRIVER_OP_SUCCESS == mmc_mode_sense_10(p_cdio, buf, sizeof(buf),
|
||||
CDIO_MMC_CAPABILITIES_PAGE) ) {
|
||||
print_mode_sense(psz_cd, "10", buf);
|
||||
} else {
|
||||
printf("Couldn't get MODE_SENSE 10 data.\n");
|
||||
}
|
||||
free(psz_cd);
|
||||
}
|
||||
|
||||
cdio_destroy(p_cdio);
|
||||
|
||||
return 0;
|
||||
}
|
||||
130
example/mmc3.c
Normal file
130
example/mmc3.c
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
$Id: mmc3.c,v 1.2 2008/03/24 15:30:56 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 use of SCSI MMC interface. Is basically the
|
||||
the libdio scsi_mmc_get_hwinfo() routine.
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#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;
|
||||
driver_return_code_t ret;
|
||||
driver_id_t driver_id = DRIVER_DEVICE;
|
||||
char *psz_drive = NULL;
|
||||
bool do_eject = false;
|
||||
|
||||
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\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
p_cdio = cdio_open (psz_drive, driver_id);
|
||||
if (!p_cdio) {
|
||||
printf("Can't open %s\n", psz_drive);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
ret = mmc_get_tray_status(p_cdio);
|
||||
switch(ret) {
|
||||
case 0:
|
||||
printf("CD-ROM drive %s is closed.\n", psz_drive);
|
||||
do_eject = true;
|
||||
break;
|
||||
case 1:
|
||||
printf("CD-ROM drive %s is open.\n", psz_drive);
|
||||
break;
|
||||
default:
|
||||
printf("Error status for drive %s: %s.\n", psz_drive,
|
||||
cdio_driver_errmsg(ret));
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = mmc_get_media_changed(p_cdio);
|
||||
switch(ret) {
|
||||
case 0:
|
||||
printf("CD-ROM drive %s media not changed since last test.\n", psz_drive);
|
||||
break;
|
||||
case 1:
|
||||
printf("CD-ROM drive %s media changed since last test.\n", psz_drive);
|
||||
break;
|
||||
default:
|
||||
printf("Error status for drive %s: %s.\n", psz_drive,
|
||||
cdio_driver_errmsg(ret));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (do_eject)
|
||||
ret = cdio_eject_media_drive(psz_drive);
|
||||
else
|
||||
ret = cdio_close_tray(psz_drive, &driver_id);
|
||||
|
||||
ret = mmc_get_tray_status(p_cdio);
|
||||
switch(ret) {
|
||||
case 0:
|
||||
printf("CD-ROM drive %s is closed.\n", psz_drive);
|
||||
break;
|
||||
case 1:
|
||||
printf("CD-ROM drive %s is open.\n", psz_drive);
|
||||
break;
|
||||
default:
|
||||
printf("Error status for drive %s: %s.\n", psz_drive,
|
||||
cdio_driver_errmsg(ret));
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = mmc_get_media_changed(p_cdio);
|
||||
switch(ret) {
|
||||
case 0:
|
||||
printf("CD-ROM drive %s media not changed since last test.\n", psz_drive);
|
||||
break;
|
||||
case 1:
|
||||
printf("CD-ROM drive %s media changed since last test.\n", psz_drive);
|
||||
break;
|
||||
default:
|
||||
printf("Error status for drive %s: %s.\n", psz_drive,
|
||||
cdio_driver_errmsg(ret));
|
||||
return 1;
|
||||
}
|
||||
|
||||
free(psz_drive);
|
||||
cdio_destroy(p_cdio);
|
||||
|
||||
return 0;
|
||||
}
|
||||
119
example/paranoia.c
Normal file
119
example/paranoia.c
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
$Id: paranoia.c,v 1.9 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 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);
|
||||
}
|
||||
102
example/paranoia2.c
Normal file
102
example/paranoia2.c
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
$Id: paranoia2.c,v 1.8 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 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);
|
||||
}
|
||||
200
example/sample3.c
Normal file
200
example/sample3.c
Normal file
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
$Id: sample3.c,v 1.10 2008/03/24 15:30:56 karl Exp $
|
||||
|
||||
Copyright (C) 2003, 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 somewhat simplified program to show the use of cdio_guess_cd_type().
|
||||
Figure out the kind of CD image we've got.
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <cdio/cdio.h>
|
||||
#include <cdio/cd_types.h>
|
||||
|
||||
static void
|
||||
print_analysis(cdio_iso_analysis_t cdio_iso_analysis,
|
||||
cdio_fs_anal_t fs, int first_data, unsigned int num_audio,
|
||||
track_t num_tracks, track_t first_track_num, CdIo_t *p_cdio)
|
||||
{
|
||||
switch(CDIO_FSTYPE(fs)) {
|
||||
case CDIO_FS_AUDIO:
|
||||
break;
|
||||
case CDIO_FS_ISO_9660:
|
||||
printf("CD-ROM with ISO 9660 filesystem");
|
||||
if (fs & CDIO_FS_ANAL_JOLIET) {
|
||||
printf(" and joliet extension level %d", cdio_iso_analysis.joliet_level);
|
||||
}
|
||||
if (fs & CDIO_FS_ANAL_ROCKRIDGE)
|
||||
printf(" and rockridge extensions");
|
||||
printf("\n");
|
||||
break;
|
||||
case CDIO_FS_ISO_9660_INTERACTIVE:
|
||||
printf("CD-ROM with CD-RTOS and ISO 9660 filesystem\n");
|
||||
break;
|
||||
case CDIO_FS_HIGH_SIERRA:
|
||||
printf("CD-ROM with High Sierra filesystem\n");
|
||||
break;
|
||||
case CDIO_FS_INTERACTIVE:
|
||||
printf("CD-Interactive%s\n", num_audio > 0 ? "/Ready" : "");
|
||||
break;
|
||||
case CDIO_FS_HFS:
|
||||
printf("CD-ROM with Macintosh HFS\n");
|
||||
break;
|
||||
case CDIO_FS_ISO_HFS:
|
||||
printf("CD-ROM with both Macintosh HFS and ISO 9660 filesystem\n");
|
||||
break;
|
||||
case CDIO_FS_UFS:
|
||||
printf("CD-ROM with Unix UFS\n");
|
||||
break;
|
||||
case CDIO_FS_EXT2:
|
||||
printf("CD-ROM with Linux second extended filesystem\n");
|
||||
break;
|
||||
case CDIO_FS_3DO:
|
||||
printf("CD-ROM with Panasonic 3DO filesystem\n");
|
||||
break;
|
||||
case CDIO_FS_UNKNOWN:
|
||||
printf("CD-ROM with unknown filesystem\n");
|
||||
break;
|
||||
}
|
||||
switch(CDIO_FSTYPE(fs)) {
|
||||
case CDIO_FS_ISO_9660:
|
||||
case CDIO_FS_ISO_9660_INTERACTIVE:
|
||||
case CDIO_FS_ISO_HFS:
|
||||
printf("ISO 9660: %i blocks, label `%.32s'\n",
|
||||
cdio_iso_analysis.isofs_size, cdio_iso_analysis.iso_label);
|
||||
break;
|
||||
}
|
||||
if (first_data == 1 && num_audio > 0)
|
||||
printf("mixed mode CD ");
|
||||
if (fs & CDIO_FS_ANAL_XA)
|
||||
printf("XA sectors ");
|
||||
if (fs & CDIO_FS_ANAL_MULTISESSION)
|
||||
printf("Multisession");
|
||||
if (fs & CDIO_FS_ANAL_HIDDEN_TRACK)
|
||||
printf("Hidden Track ");
|
||||
if (fs & CDIO_FS_ANAL_PHOTO_CD)
|
||||
printf("%sPhoto CD ",
|
||||
num_audio > 0 ? " Portfolio " : "");
|
||||
if (fs & CDIO_FS_ANAL_CDTV)
|
||||
printf("Commodore CDTV ");
|
||||
if (first_data > 1)
|
||||
printf("CD-Plus/Extra ");
|
||||
if (fs & CDIO_FS_ANAL_BOOTABLE)
|
||||
printf("bootable CD ");
|
||||
if (fs & CDIO_FS_ANAL_VIDEOCD && num_audio == 0) {
|
||||
printf("Video CD ");
|
||||
}
|
||||
if (fs & CDIO_FS_ANAL_SVCD)
|
||||
printf("Super Video CD (SVCD) or Chaoji Video CD (CVD)");
|
||||
if (fs & CDIO_FS_ANAL_CVD)
|
||||
printf("Chaoji Video CD (CVD)");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
CdIo_t *p_cdio = cdio_open (NULL, DRIVER_UNKNOWN);
|
||||
cdio_fs_anal_t fs=0;
|
||||
|
||||
track_t num_tracks;
|
||||
track_t first_track_num;
|
||||
lsn_t start_track; /* first sector of track */
|
||||
lsn_t data_start =0; /* start of data area */
|
||||
|
||||
int first_data = -1; /* # of first data track */
|
||||
int first_audio = -1; /* # of first audio track */
|
||||
unsigned int num_data = 0; /* # of data tracks */
|
||||
unsigned int num_audio = 0; /* # of audio tracks */
|
||||
unsigned int i;
|
||||
|
||||
if (NULL == p_cdio) {
|
||||
printf("Problem in trying to find a driver.\n\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
first_track_num = cdio_get_first_track_num(p_cdio);
|
||||
num_tracks = cdio_get_num_tracks(p_cdio);
|
||||
|
||||
/* Count the number of data and audio tracks. */
|
||||
for (i = first_track_num; i <= num_tracks; i++) {
|
||||
if (TRACK_FORMAT_AUDIO == cdio_get_track_format(p_cdio, i)) {
|
||||
num_audio++;
|
||||
if (-1 == first_audio) first_audio = i;
|
||||
} else {
|
||||
num_data++;
|
||||
if (-1 == first_data) first_data = i;
|
||||
}
|
||||
}
|
||||
|
||||
/* try to find out what sort of CD we have */
|
||||
if (0 == num_data) {
|
||||
printf("Audio CD\n");
|
||||
} else {
|
||||
/* we have data track(s) */
|
||||
int j;
|
||||
cdio_iso_analysis_t cdio_iso_analysis;
|
||||
|
||||
memset(&cdio_iso_analysis, 0, sizeof(cdio_iso_analysis));
|
||||
|
||||
for (j = 2, i = first_data; i <= num_tracks; i++) {
|
||||
lsn_t lsn;
|
||||
track_format_t track_format = cdio_get_track_format(p_cdio, i);
|
||||
|
||||
lsn = cdio_get_track_lsn(p_cdio, i);
|
||||
|
||||
switch ( track_format ) {
|
||||
case TRACK_FORMAT_AUDIO:
|
||||
case TRACK_FORMAT_ERROR:
|
||||
break;
|
||||
case TRACK_FORMAT_CDI:
|
||||
case TRACK_FORMAT_XA:
|
||||
case TRACK_FORMAT_DATA:
|
||||
case TRACK_FORMAT_PSX:
|
||||
;
|
||||
}
|
||||
|
||||
start_track = (i == 1) ? 0 : lsn;
|
||||
|
||||
/* save the start of the data area */
|
||||
if (i == first_data)
|
||||
data_start = start_track;
|
||||
|
||||
/* skip tracks which belong to the current walked session */
|
||||
if (start_track < data_start + cdio_iso_analysis.isofs_size)
|
||||
continue;
|
||||
|
||||
fs = cdio_guess_cd_type(p_cdio, start_track, i, &cdio_iso_analysis);
|
||||
|
||||
print_analysis(cdio_iso_analysis, fs, first_data, num_audio,
|
||||
num_tracks, first_track_num, p_cdio);
|
||||
|
||||
if ( !(CDIO_FSTYPE(fs) == CDIO_FS_ISO_9660 ||
|
||||
CDIO_FSTYPE(fs) == CDIO_FS_ISO_HFS ||
|
||||
CDIO_FSTYPE(fs) == CDIO_FS_ISO_9660_INTERACTIVE) )
|
||||
/* no method for non-ISO9660 multisessions */
|
||||
break;
|
||||
}
|
||||
}
|
||||
cdio_destroy(p_cdio);
|
||||
return 0;
|
||||
}
|
||||
221
example/sample4.c
Normal file
221
example/sample4.c
Normal file
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
$Id: sample4.c,v 1.8 2008/03/24 15:30:56 karl Exp $
|
||||
|
||||
Copyright (C) 2003, 2004 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 slightly improved sample3 program: we handle cdio logging and
|
||||
take an optional CD-location.
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <cdio/cdio.h>
|
||||
#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_analysis(cdio_iso_analysis_t cdio_iso_analysis,
|
||||
cdio_fs_anal_t fs, int first_data, unsigned int num_audio,
|
||||
track_t num_tracks, track_t first_track_num, CdIo_t *p_cdio)
|
||||
{
|
||||
switch(CDIO_FSTYPE(fs)) {
|
||||
case CDIO_FS_AUDIO:
|
||||
break;
|
||||
case CDIO_FS_ISO_9660:
|
||||
printf("CD-ROM with ISO 9660 filesystem");
|
||||
if (fs & CDIO_FS_ANAL_JOLIET) {
|
||||
printf(" and joliet extension level %d", cdio_iso_analysis.joliet_level);
|
||||
}
|
||||
if (fs & CDIO_FS_ANAL_ROCKRIDGE)
|
||||
printf(" and rockridge extensions");
|
||||
printf("\n");
|
||||
break;
|
||||
case CDIO_FS_ISO_9660_INTERACTIVE:
|
||||
printf("CD-ROM with CD-RTOS and ISO 9660 filesystem\n");
|
||||
break;
|
||||
case CDIO_FS_HIGH_SIERRA:
|
||||
printf("CD-ROM with High Sierra filesystem\n");
|
||||
break;
|
||||
case CDIO_FS_INTERACTIVE:
|
||||
printf("CD-Interactive%s\n", num_audio > 0 ? "/Ready" : "");
|
||||
break;
|
||||
case CDIO_FS_HFS:
|
||||
printf("CD-ROM with Macintosh HFS\n");
|
||||
break;
|
||||
case CDIO_FS_ISO_HFS:
|
||||
printf("CD-ROM with both Macintosh HFS and ISO 9660 filesystem\n");
|
||||
break;
|
||||
case CDIO_FS_UFS:
|
||||
printf("CD-ROM with Unix UFS\n");
|
||||
break;
|
||||
case CDIO_FS_EXT2:
|
||||
printf("CD-ROM with Linux second extended filesystem\n");
|
||||
break;
|
||||
case CDIO_FS_3DO:
|
||||
printf("CD-ROM with Panasonic 3DO filesystem\n");
|
||||
break;
|
||||
case CDIO_FS_UNKNOWN:
|
||||
printf("CD-ROM with unknown filesystem\n");
|
||||
break;
|
||||
}
|
||||
switch(CDIO_FSTYPE(fs)) {
|
||||
case CDIO_FS_ISO_9660:
|
||||
case CDIO_FS_ISO_9660_INTERACTIVE:
|
||||
case CDIO_FS_ISO_HFS:
|
||||
printf("ISO 9660: %i blocks, label `%.32s'\n",
|
||||
cdio_iso_analysis.isofs_size, cdio_iso_analysis.iso_label);
|
||||
break;
|
||||
}
|
||||
if (first_data == 1 && num_audio > 0)
|
||||
printf("mixed mode CD ");
|
||||
if (fs & CDIO_FS_ANAL_XA)
|
||||
printf("XA sectors ");
|
||||
if (fs & CDIO_FS_ANAL_MULTISESSION)
|
||||
printf("Multisession");
|
||||
if (fs & CDIO_FS_ANAL_HIDDEN_TRACK)
|
||||
printf("Hidden Track ");
|
||||
if (fs & CDIO_FS_ANAL_PHOTO_CD)
|
||||
printf("%sPhoto CD ",
|
||||
num_audio > 0 ? " Portfolio " : "");
|
||||
if (fs & CDIO_FS_ANAL_CDTV)
|
||||
printf("Commodore CDTV ");
|
||||
if (first_data > 1)
|
||||
printf("CD-Plus/Extra ");
|
||||
if (fs & CDIO_FS_ANAL_BOOTABLE)
|
||||
printf("bootable CD ");
|
||||
if (fs & CDIO_FS_ANAL_VIDEOCD && num_audio == 0) {
|
||||
printf("Video CD ");
|
||||
}
|
||||
if (fs & CDIO_FS_ANAL_SVCD)
|
||||
printf("Super Video CD (SVCD) or Chaoji Video CD (CVD)");
|
||||
if (fs & CDIO_FS_ANAL_CVD)
|
||||
printf("Chaoji Video CD (CVD)");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
CdIo_t *p_cdio;
|
||||
cdio_fs_anal_t fs=0;
|
||||
|
||||
track_t num_tracks;
|
||||
track_t first_track_num;
|
||||
lsn_t start_track; /* first sector of track */
|
||||
lsn_t data_start =0; /* start of data area */
|
||||
|
||||
int first_data = -1; /* # of first data track */
|
||||
int first_audio = -1; /* # of first audio track */
|
||||
unsigned int num_data = 0; /* # of data tracks */
|
||||
unsigned int num_audio = 0; /* # of audio tracks */
|
||||
unsigned int i;
|
||||
char *cd_image_name = NULL;
|
||||
|
||||
if (argc > 1)
|
||||
cd_image_name = strdup(argv[1]);
|
||||
|
||||
cdio_log_set_handler (log_handler);
|
||||
|
||||
p_cdio = cdio_open (cd_image_name, DRIVER_UNKNOWN);
|
||||
|
||||
if (NULL == p_cdio) {
|
||||
printf("Problem in trying to find a driver.\n\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
first_track_num = cdio_get_first_track_num(p_cdio);
|
||||
num_tracks = cdio_get_num_tracks(p_cdio);
|
||||
|
||||
/* Count the number of data and audio tracks. */
|
||||
for (i = first_track_num; i <= num_tracks; i++) {
|
||||
if (TRACK_FORMAT_AUDIO == cdio_get_track_format(p_cdio, i)) {
|
||||
num_audio++;
|
||||
if (-1 == first_audio) first_audio = i;
|
||||
} else {
|
||||
num_data++;
|
||||
if (-1 == first_data) first_data = i;
|
||||
}
|
||||
}
|
||||
|
||||
/* try to find out what sort of CD we have */
|
||||
if (0 == num_data) {
|
||||
printf("Audio CD\n");
|
||||
} else {
|
||||
/* we have data track(s) */
|
||||
int j;
|
||||
cdio_iso_analysis_t cdio_iso_analysis;
|
||||
|
||||
memset(&cdio_iso_analysis, 0, sizeof(cdio_iso_analysis));
|
||||
|
||||
for (j = 2, i = first_data; i <= num_tracks; i++) {
|
||||
lsn_t lsn;
|
||||
track_format_t track_format = cdio_get_track_format(p_cdio, i);
|
||||
|
||||
lsn = cdio_get_track_lsn(p_cdio, i);
|
||||
|
||||
switch ( track_format ) {
|
||||
case TRACK_FORMAT_AUDIO:
|
||||
case TRACK_FORMAT_ERROR:
|
||||
break;
|
||||
case TRACK_FORMAT_CDI:
|
||||
case TRACK_FORMAT_XA:
|
||||
case TRACK_FORMAT_DATA:
|
||||
case TRACK_FORMAT_PSX:
|
||||
;
|
||||
}
|
||||
|
||||
start_track = (i == 1) ? 0 : lsn;
|
||||
|
||||
/* save the start of the data area */
|
||||
if (i == first_data)
|
||||
data_start = start_track;
|
||||
|
||||
/* skip tracks which belong to the current walked session */
|
||||
if (start_track < data_start + cdio_iso_analysis.isofs_size)
|
||||
continue;
|
||||
|
||||
fs = cdio_guess_cd_type(p_cdio, start_track, i, &cdio_iso_analysis);
|
||||
|
||||
print_analysis(cdio_iso_analysis, fs, first_data, num_audio,
|
||||
num_tracks, first_track_num, p_cdio);
|
||||
|
||||
if ( !(CDIO_FSTYPE(fs) == CDIO_FS_ISO_9660 ||
|
||||
CDIO_FSTYPE(fs) == CDIO_FS_ISO_HFS ||
|
||||
CDIO_FSTYPE(fs) == CDIO_FS_ISO_9660_INTERACTIVE) )
|
||||
/* no method for non-ISO9660 multisessions */
|
||||
break;
|
||||
}
|
||||
}
|
||||
cdio_destroy(p_cdio);
|
||||
return 0;
|
||||
}
|
||||
64
example/tracks.c
Normal file
64
example/tracks.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
$Id: tracks.c,v 1.7 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 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.h>
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
CdIo_t *p_cdio = cdio_open (NULL, DRIVER_UNKNOWN);
|
||||
track_t i_first_track;
|
||||
track_t i_tracks;
|
||||
int j, i;
|
||||
|
||||
|
||||
if (NULL == p_cdio) {
|
||||
printf("Couldn't find a driver.. leaving.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Disc last LSN: %d\n", cdio_get_disc_last_lsn(p_cdio));
|
||||
|
||||
i_tracks = cdio_get_num_tracks(p_cdio);
|
||||
i_first_track = i = cdio_get_first_track_num(p_cdio);
|
||||
|
||||
printf("CD-ROM Track List (%i - %i)\n", i_first_track,
|
||||
i_first_track+i_tracks-1);
|
||||
|
||||
printf(" #: LSN\n");
|
||||
|
||||
for (j = 0; j < i_tracks; i++, j++) {
|
||||
lsn_t lsn = cdio_get_track_lsn(p_cdio, i);
|
||||
if (CDIO_INVALID_LSN != lsn)
|
||||
printf("%3d: %06lu\n", (int) i, (long unsigned int) lsn);
|
||||
}
|
||||
printf("%3X: %06lu leadout\n", CDIO_CDROM_LEADOUT_TRACK,
|
||||
(long unsigned int) cdio_get_track_lsn(p_cdio,
|
||||
CDIO_CDROM_LEADOUT_TRACK));
|
||||
cdio_destroy(p_cdio);
|
||||
return 0;
|
||||
}
|
||||
144
example/udf1.c
Normal file
144
example/udf1.c
Normal file
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
$Id: udf1.c,v 1.19 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 libudf to list files in a directory of
|
||||
an UDF image.
|
||||
*/
|
||||
|
||||
/* This is the UDF image. */
|
||||
#define UDF_IMAGE_PATH "../"
|
||||
#define UDF_IMAGE "/src2/cd-images/udf/UDF102ISO.iso"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <cdio/cdio.h>
|
||||
#include <cdio/udf.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 udf_PATH_DELIMITERS "/\\"
|
||||
|
||||
static void
|
||||
print_file_info(const udf_dirent_t *p_udf_dirent, const char* psz_dirname)
|
||||
{
|
||||
time_t mod_time = udf_get_modification_time(p_udf_dirent);
|
||||
char psz_mode[11]="invalid";
|
||||
const char *psz_fname= psz_dirname
|
||||
? psz_dirname : udf_get_filename(p_udf_dirent);
|
||||
|
||||
/* Print directory attributes*/
|
||||
printf("%s ", udf_mode_string(udf_get_posix_filemode(p_udf_dirent),
|
||||
psz_mode));
|
||||
printf("%4d ", udf_get_link_count(p_udf_dirent));
|
||||
printf("%lu ", (long unsigned int) udf_get_file_length(p_udf_dirent));
|
||||
printf("%s %s", *psz_fname ? psz_fname : "/", ctime(&mod_time));
|
||||
}
|
||||
|
||||
static udf_dirent_t *
|
||||
list_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const char *psz_path)
|
||||
{
|
||||
if (!p_udf_dirent) return NULL;
|
||||
|
||||
print_file_info(p_udf_dirent, psz_path);
|
||||
|
||||
while (udf_readdir(p_udf_dirent)) {
|
||||
|
||||
if (udf_is_dir(p_udf_dirent)) {
|
||||
|
||||
udf_dirent_t *p_udf_dirent2 = udf_opendir(p_udf_dirent);
|
||||
if (p_udf_dirent2) {
|
||||
const char *psz_dirname = udf_get_filename(p_udf_dirent);
|
||||
const unsigned int i_newlen=2 + strlen(psz_path) + strlen(psz_dirname);
|
||||
char *psz_newpath = calloc(1, sizeof(char)*i_newlen);
|
||||
|
||||
snprintf(psz_newpath, i_newlen, "%s%s/", psz_path, psz_dirname);
|
||||
list_files(p_udf, p_udf_dirent2, psz_newpath);
|
||||
free(psz_newpath);
|
||||
}
|
||||
} else {
|
||||
print_file_info(p_udf_dirent, NULL);
|
||||
}
|
||||
}
|
||||
return p_udf_dirent;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
udf_t *p_udf;
|
||||
char const *psz_udf_image;
|
||||
|
||||
if (argc > 1)
|
||||
psz_udf_image = argv[1];
|
||||
else
|
||||
psz_udf_image = UDF_IMAGE;
|
||||
|
||||
p_udf = udf_open (psz_udf_image);
|
||||
|
||||
if (NULL == p_udf) {
|
||||
fprintf(stderr, "Sorry, couldn't open %s as something using UDF\n",
|
||||
psz_udf_image);
|
||||
return 1;
|
||||
} else {
|
||||
udf_dirent_t *p_udf_root = udf_get_root(p_udf, true, 0);
|
||||
if (NULL == p_udf_root) {
|
||||
fprintf(stderr, "Sorry, couldn't find / in %s\n",
|
||||
psz_udf_image);
|
||||
return 1;
|
||||
}
|
||||
|
||||
{
|
||||
char vol_id[UDF_VOLID_SIZE] = "";
|
||||
char volset_id[UDF_VOLSET_ID_SIZE+1] = "";
|
||||
|
||||
if (0 < udf_get_volume_id(p_udf, vol_id, sizeof(vol_id)) )
|
||||
printf("volume id: %s\n", vol_id);
|
||||
|
||||
if (0 < udf_get_volume_id(p_udf, volset_id, sizeof(volset_id)) ) {
|
||||
volset_id[UDF_VOLSET_ID_SIZE]='\0';
|
||||
printf("volume set id: %s\n", volset_id);
|
||||
}
|
||||
|
||||
printf("partition number: %d\n", udf_get_part_number(p_udf));
|
||||
|
||||
|
||||
}
|
||||
|
||||
list_files(p_udf, p_udf_root, "");
|
||||
}
|
||||
|
||||
udf_close(p_udf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
134
example/udf2.c
Normal file
134
example/udf2.c
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
$Id: udf2.c,v 1.6 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 show using libudf to extract a file.
|
||||
|
||||
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 UDF image. */
|
||||
#define UDF_IMAGE_PATH "../"
|
||||
#define UDF_IMAGE "/src2/cd-images/udf/test2.iso"
|
||||
#define UDF_FILENAME "/parse/cue.L"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <cdio/cdio.h>
|
||||
#include <cdio/udf.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 CEILING(x, y) ((x+(y-1))/y)
|
||||
|
||||
#define udf_PATH_DELIMITERS "/\\"
|
||||
|
||||
static void
|
||||
print_file_info(const udf_dirent_t *p_udf_dirent, const char* psz_dirname)
|
||||
{
|
||||
time_t mod_time = udf_get_modification_time(p_udf_dirent);
|
||||
char psz_mode[11]="invalid";
|
||||
const char *psz_fname= psz_dirname
|
||||
? psz_dirname : udf_get_filename(p_udf_dirent);
|
||||
|
||||
/* Print directory attributes*/
|
||||
printf("%s ", udf_mode_string(udf_get_posix_filemode(p_udf_dirent),
|
||||
psz_mode));
|
||||
printf("%4d ", udf_get_link_count(p_udf_dirent));
|
||||
printf("%ld ", (long unsigned int) udf_get_file_length(p_udf_dirent));
|
||||
printf("%s %s\n", *psz_fname ? psz_fname : "/", ctime(&mod_time));
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
udf_t *p_udf;
|
||||
char const *psz_udf_image;
|
||||
char const *psz_udf_fname;
|
||||
|
||||
if (argc > 1)
|
||||
psz_udf_image = argv[1];
|
||||
else
|
||||
psz_udf_image = UDF_IMAGE;
|
||||
|
||||
if (argc > 2)
|
||||
psz_udf_fname = argv[2];
|
||||
else
|
||||
psz_udf_fname = UDF_FILENAME;
|
||||
|
||||
|
||||
p_udf = udf_open (psz_udf_image);
|
||||
|
||||
if (NULL == p_udf) {
|
||||
fprintf(stderr, "Sorry, couldn't open %s as something using UDF\n",
|
||||
psz_udf_image);
|
||||
return 1;
|
||||
} else {
|
||||
udf_dirent_t *p_udf_root = udf_get_root(p_udf, true, 0);
|
||||
udf_dirent_t *p_udf_file = NULL;
|
||||
if (NULL == p_udf_root) {
|
||||
fprintf(stderr, "Sorry, couldn't find / in %s\n",
|
||||
psz_udf_image);
|
||||
return 1;
|
||||
}
|
||||
|
||||
p_udf_file = udf_fopen(p_udf_root, psz_udf_fname);
|
||||
if (!p_udf_file) {
|
||||
fprintf(stderr, "Sorry, couldn't find %s in %s\n",
|
||||
psz_udf_fname, psz_udf_image);
|
||||
return 2;
|
||||
|
||||
}
|
||||
print_file_info(p_udf_file, udf_get_filename(p_udf_file));
|
||||
{
|
||||
long unsigned int i_file_length = udf_get_file_length(p_udf_file);
|
||||
char *p_buf;
|
||||
unsigned int i_blocks = CEILING(i_file_length, UDF_BLOCKSIZE);
|
||||
char fmt_string[100] = {'\0'};
|
||||
snprintf(fmt_string, sizeof(fmt_string), "%%%lus", i_file_length);
|
||||
|
||||
p_buf = (char *) calloc(sizeof(char), UDF_BLOCKSIZE*i_blocks);
|
||||
udf_read_block(p_udf_file, p_buf, i_blocks);
|
||||
printf(fmt_string, p_buf);
|
||||
free(p_buf);
|
||||
}
|
||||
udf_dirent_free(p_udf_file);
|
||||
udf_dirent_free(p_udf_root);
|
||||
}
|
||||
|
||||
udf_close(p_udf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
154
example/udffile.c
Normal file
154
example/udffile.c
Normal file
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
$Id: udffile.c,v 1.3 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 show using libudf to extract a file.
|
||||
|
||||
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 UDF image. */
|
||||
#define UDF_IMAGE_PATH "../"
|
||||
#define UDF_IMAGE "../test/udf102.iso"
|
||||
#define UDF_FILENAME "/COPYING"
|
||||
#define LOCAL_FILENAME "copying"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <cdio/cdio.h>
|
||||
#include <cdio/udf.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 udf_PATH_DELIMITERS "/\\"
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
udf_t *p_udf;
|
||||
FILE *p_outfd;
|
||||
char const *psz_udf_image;
|
||||
char const *psz_udf_fname;
|
||||
char const *psz_local_fname;
|
||||
|
||||
if (argc > 1)
|
||||
psz_udf_image = argv[1];
|
||||
else
|
||||
psz_udf_image = UDF_IMAGE;
|
||||
|
||||
if (argc > 2)
|
||||
psz_udf_fname = argv[2];
|
||||
else
|
||||
psz_udf_fname = UDF_FILENAME;
|
||||
|
||||
if (argc > 3)
|
||||
psz_local_fname = argv[3];
|
||||
else
|
||||
psz_local_fname = LOCAL_FILENAME;
|
||||
|
||||
|
||||
p_udf = udf_open (psz_udf_image);
|
||||
|
||||
if (NULL == p_udf) {
|
||||
fprintf(stderr, "Sorry, couldn't open %s as something using UDF\n",
|
||||
psz_udf_image);
|
||||
return 1;
|
||||
} else {
|
||||
udf_dirent_t *p_udf_root = udf_get_root(p_udf, true, 0);
|
||||
udf_dirent_t *p_udf_file = NULL;
|
||||
if (NULL == p_udf_root) {
|
||||
fprintf(stderr, "Sorry, couldn't find / in %s\n",
|
||||
psz_udf_image);
|
||||
return 1;
|
||||
}
|
||||
|
||||
p_udf_file = udf_fopen(p_udf_root, psz_udf_fname);
|
||||
if (!p_udf_file) {
|
||||
fprintf(stderr, "Sorry, couldn't find %s in %s\n",
|
||||
psz_udf_fname, psz_udf_image);
|
||||
return 2;
|
||||
|
||||
}
|
||||
|
||||
if (!(p_outfd = fopen (psz_local_fname, "wb")))
|
||||
{
|
||||
perror ("fopen()");
|
||||
return 3;
|
||||
}
|
||||
|
||||
{
|
||||
long unsigned int i_file_length = udf_get_file_length(p_udf_file);
|
||||
const unsigned int i_blocks = CEILING(i_file_length, UDF_BLOCKSIZE);
|
||||
unsigned int i;
|
||||
for (i = 0; i < i_blocks ; i++) {
|
||||
char buf[UDF_BLOCKSIZE] = {'\0',};
|
||||
ssize_t i_read = udf_read_block(p_udf_file, buf, 1);
|
||||
|
||||
if ( i_read < 0 ) {
|
||||
fprintf(stderr, "Error reading UDF file %s at block %u\n",
|
||||
psz_local_fname, i);
|
||||
return 4;
|
||||
}
|
||||
|
||||
fwrite (buf, i_read, 1, p_outfd);
|
||||
|
||||
if (ferror (p_outfd)) {
|
||||
perror ("fwrite()");
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
fflush (p_outfd);
|
||||
udf_dirent_free(p_udf_root);
|
||||
udf_close(p_udf);
|
||||
/* Make sure the file size has the exact same byte size. Without the
|
||||
truncate below, the file will a multiple of UDF_BLOCKSIZE.
|
||||
*/
|
||||
if (ftruncate (fileno (p_outfd), i_file_length))
|
||||
perror ("ftruncate()");
|
||||
|
||||
printf("Extraction of file '%s' from %s successful.\n",
|
||||
psz_local_fname, psz_udf_image);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user