Get first libiso9660++ OO program (iso3) working.

This commit is contained in:
rocky
2006-03-06 01:34:22 +00:00
parent 129e141493
commit 5e2d4f6bdf
6 changed files with 329 additions and 34 deletions

View File

@@ -19,7 +19,7 @@ define(RELEASE_NUM, 77)
define(CDIO_VERSION_STR, 0.$1cvs)
AC_PREREQ(2.52)
AC_REVISION([$Id: configure.ac,v 1.185 2006/02/12 04:26:44 rocky Exp $])dnl
AC_REVISION([$Id: configure.ac,v 1.186 2006/03/06 01:34:22 rocky Exp $])dnl
AC_INIT(libcdio, CDIO_VERSION_STR(RELEASE_NUM))
AC_CONFIG_SRCDIR(src/cd-info.c)
@@ -358,6 +358,7 @@ LIBCDIO_CFLAGS='-I$(top_srcdir)/lib/driver -I$(top_srcdir)/include/'
LIBCDIO_LIBS='$(top_builddir)/lib/driver/libcdio.la'
LIBCDIO_DEPS="$LIBCDIO_LIBS"
LIBCDIOPP_LIBS='$(top_builddir)/lib/cdio++/libcdio++.la'
LIBISO9660PP_LIBS='$(top_builddir)/lib/cdio++/libiso9660++.la'
LIBCDIO_PARANOIA_LIBS='$(top_builddir)/lib/paranoia/libcdio_paranoia.la'
LIBISO9660_CFLAGS='-I$(top_srcdir)/lib/iso9660/'
LIBISO9660_LIBS='$(top_builddir)/lib/iso9660/libiso9660.la'
@@ -366,6 +367,7 @@ LIBUDF_LIBS='$(top_builddir)/lib/udf/libudf.la'
AC_SUBST(LIBCDIO_CDDA_LIBS)
AC_SUBST(LIBCDIO_CFLAGS)
AC_SUBST(LIBISO9660_CFLAGS)
AC_SUBST(LIBCDISO9660PP_LIBS)
AC_SUBST(LIBCDIO_LIBS)
AC_SUBST(LIBCDIOPP_LIBS)
AC_SUBST(LIBCDIO_DEPS)

View File

@@ -4,9 +4,11 @@ Makefile
Makefile.am
Makefile.in
cdtext
copying
device
drives
eject
iso3
mmc1
mmc2
tracks

View File

@@ -1,4 +1,4 @@
# $Id: Makefile.am,v 1.3 2006/01/25 06:30:22 rocky Exp $
# $Id: Makefile.am,v 1.4 2006/03/06 01:34:22 rocky Exp $
#
# Copyright (C) 2005, 2006 Rocky Bernstein <rocky@panix.com>
#
@@ -20,9 +20,9 @@
# Sample C++ programs using libcdio++ (with C++ OO wrapper)
############################################################
#
noinst_PROGRAMS = cdtext device drives eject mmc1 mmc2 tracks
noinst_PROGRAMS = cdtext device drives eject iso3 mmc1 mmc2 tracks
INCLUDES = -I$(top_srcdir)/include
INCLUDES = -I$(top_srcdir)/include $(LIBCDIO_CFLAGS)
cdtext_SOURCES = cdtext.cpp
cdtext_DEPENDENCIES = $(LIBCDIO_DEPS)
@@ -40,6 +40,10 @@ eject_SOURCES = eject.cpp
eject_DEPENDENCIES = $(LIBCDIO_DEPS)
eject_LDADD = $(LIBCDIOPP_LIBS) $(LIBCDIO_LIBS)
iso3_SOURCES = iso3.cpp
iso3_LDADD = $(LIBISO966PP0_LIBS) $(LIBISO9660_LIBS) \
$(LIBCDIOPP_LIBS) $(LIBICONV)
mmc1_SOURCES = mmc1.cpp
mmc1_DEPENDENCIES = $(LIBCDIO_DEPS)
mmc1_LDADD = $(LIBCDIOPP_LIBS) $(LIBCDIO_LIBS)

155
example/C++/OO/iso3.cpp Normal file
View File

@@ -0,0 +1,155 @@
/*
$Id: iso3.cpp,v 1.1 2006/03/06 01:34:22 rocky Exp $
Copyright (C) 2006 Rocky Bernstein <rocky@panix.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Simple program to show 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); \
return rc; \
int
main(int argc, const char *argv[])
{
ISO9660::Stat *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;
}
stat = p_iso->stat(psz_fname, true);
if (!stat)
{
fprintf(stderr,
"Could not get ISO-9660 file information for file %s\n",
psz_fname);
p_iso->close();
return 2;
}
if (!(p_outfd = fopen (psz_fname, "wb")))
{
perror ("fopen()");
return 3;
}
/* Copy the blocks from the ISO-9660 filesystem to the local filesystem. */
{
const unsigned int i_blocks = CEILING(stat->p_stat->size, ISO_BLOCKSIZE);
for (i = 0; i < i_blocks ; i++)
{
char buf[ISO_BLOCKSIZE];
const lsn_t lsn = 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), stat->p_stat->size))
perror ("ftruncate()");
printf("Extraction of file '%s' from %s successful.\n",
psz_fname, psz_image);
my_exit(0);
}

View File

@@ -1,5 +1,5 @@
/* -*- C++ -*-
$Id: iso9660.hpp,v 1.2 2006/03/05 08:31:03 rocky Exp $
$Id: iso9660.hpp,v 1.3 2006/03/06 01:34:22 rocky Exp $
Copyright (C) 2006 Rocky Bernstein <rocky@panix.com>
@@ -29,6 +29,7 @@
#include <cdio/iso9660.h>
#include <string.h>
#include <list> // list class library
/** ISO 9660 class.
*/
@@ -37,27 +38,139 @@ class ISO9660
public:
class PVD
{
PVD(iso9660_pvd_t *p_new_pvd)
{
p_pvd = p_new_pvd;
};
private:
iso9660_pvd_t *p_pvd;
};
class Stat
{
public:
iso9660_stat_t *p_stat; // Make private?
Stat(iso9660_stat_t *p_new_stat)
{
p_stat = p_new_stat;
};
private:
iso9660_stat_t * p_stat;
Stat(const Stat& copy_in)
{
free(p_stat);
p_stat = (iso9660_stat_t *)
calloc( 1, sizeof(iso9660_stat_t)
+ strlen(copy_in.p_stat->filename)+1 );
p_stat = copy_in.p_stat;
}
const Stat& operator= (const Stat& right)
{
free(p_stat);
this->p_stat = right.p_stat;
}
~Stat()
{
free(p_stat);
p_stat = NULL;
}
};
class PVD
{
public:
iso9660_pvd_t pvd; // Make private?
PVD(iso9660_pvd_t *p_new_pvd)
{
memcpy(&pvd, p_new_pvd, sizeof(pvd));
};
/*!
Return the PVD's application ID.
NULL is returned if there is some problem in getting this.
*/
char * get_application_id()
{
return iso9660_get_application_id(&pvd);
};
int get_pvd_block_size()
{
return iso9660_get_pvd_block_size(&pvd);
}
/*!
Return the PVD's preparer ID.
NULL is returned if there is some problem in getting this.
*/
char * get_preparer_id()
{
return iso9660_get_preparer_id(&pvd);
};
/*!
Return the PVD's publisher ID.
NULL is returned if there is some problem in getting this.
*/
char * get_publisher_id()
{
return iso9660_get_publisher_id(&pvd);
};
const char *get_pvd_id()
{
return iso9660_get_pvd_id(&pvd);
};
int get_pvd_space_size()
{
return iso9660_get_pvd_space_size(&pvd);
};
uint8_t get_pvd_type() {
return iso9660_get_pvd_type(&pvd);
};
/*! Return the primary volume id version number (of pvd).
If there is an error 0 is returned.
*/
int get_pvd_version()
{
return iso9660_get_pvd_version(&pvd);
}
/*! Return the LSN of the root directory for pvd.
If there is an error CDIO_INVALID_LSN is returned.
*/
lsn_t get_root_lsn()
{
return iso9660_get_root_lsn(&pvd);
}
/*!
Return the PVD's system ID.
NULL is returned if there is some problem in getting this.
*/
char * get_system_id()
{
return iso9660_get_system_id(&pvd);
};
/*!
Return the PVD's volume ID.
NULL is returned if there is some problem in getting this.
*/
char * get_volume_id()
{
return iso9660_get_volume_id(&pvd);
};
/*!
Return the PVD's volumeset ID.
NULL is returned if there is some problem in getting this.
*/
char * get_volumeset_id()
{
return iso9660_get_volumeset_id(&pvd);
};
};
class IFS
@@ -97,9 +210,7 @@ public:
*/
Stat *find_lsn(lsn_t i_lsn)
{
iso9660_stat_t *p_stat = iso9660_find_ifs_lsn(p_iso9660, i_lsn);
if (!p_stat) return (Stat *) NULL;
return new Stat(p_stat);
return new Stat(iso9660_find_ifs_lsn(p_iso9660, i_lsn));
};
/*!
@@ -215,6 +326,19 @@ public:
return true;
};
/*! Read the Primary Volume Descriptor for an ISO 9660 image. A
PVD object is returned if read, and NULL if there was an error.
*/
PVD *read_pvd ()
{
iso9660_pvd_t pvd;
bool b_okay = iso9660_ifs_read_pvd (p_iso9660, &pvd);
if (b_okay) {
return new PVD(&pvd);
}
return (PVD *) NULL;
}
/*!
Read the Super block of an ISO 9660 image but determine framesize
and datastart and a possible additional offset. Generally here we are
@@ -229,7 +353,6 @@ public:
uint16_t i_fuzz=20)
{
return iso9660_ifs_read_superblock (p_iso9660, iso_extension_mask);
};
/*!
@@ -250,6 +373,19 @@ public:
};
#if 0
/*! Read psz_path (a directory) and return a list of iso9660_stat_t
pointers for the files inside that directory. The caller must free
the returned result.
*/
list<Stat>::readdir (const char psz_path[])
{
CdioList_t *p_stat_list = iso9660_ifs_readdir (p_iso9660, psz_path);
list<Stat> stat_list;
}
#endif
/*!
Seek to a position and then read n bytes. Size read is returned.
*/
@@ -263,14 +399,10 @@ public:
*/
Stat *stat (const char psz_path[], bool b_translate=false)
{
iso9660_stat_t *p_stat;
if (b_translate)
p_stat = iso9660_ifs_stat_translate (p_iso9660, psz_path);
return new Stat(iso9660_ifs_stat_translate (p_iso9660, psz_path));
else
p_stat = iso9660_ifs_stat (p_iso9660, psz_path);
if (!p_stat) return (Stat *) NULL;
return new Stat(p_stat);
return new Stat(iso9660_ifs_stat (p_iso9660, psz_path));
}
private:

View File

@@ -1,4 +1,4 @@
# $Id: Makefile.am,v 1.2 2006/03/05 06:52:15 rocky Exp $
# $Id: Makefile.am,v 1.3 2006/03/06 01:34:22 rocky Exp $
#
# Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
#
@@ -42,7 +42,7 @@
# public release, then set AGE to 0. A changed interface means an
# incompatibility with previous versions.
lib_LTLIBRARIES = libiso9660pp.la libcdio++.la
lib_LTLIBRARIES = libiso9660++.la libcdio++.la
libcdiopp_la_CURRENT := 0
libcdiopp_la_REVISION := 0
@@ -59,7 +59,7 @@ libiso9660pp_la_AGE := 0
libiso9660pp_sources = iso9660_stub.cpp
libiso9660pp_la_SOURCES = $(libiso9660pp_sources)
libiso9660pp_la_ldflags = -version-info $(libiso9660pp_la_CURRENT):$(libiso9660pp_la_REVISION):$(libiso9660pp_la_AGE)
libiso9660___la_SOURCES = $(libiso9660pp_sources)
libiso9660___la_ldflags = -version-info $(libiso9660pp_la_CURRENT):$(libiso9660pp_la_REVISION):$(libiso9660pp_la_AGE)
INCLUDES = -I$(top_srcdir)/include/