iso9660_fs.c: remove some (but not all) of the redundancy
testisocd2.c.in: a test of working with an ISO 9660 image.
This commit is contained in:
@@ -19,7 +19,7 @@ define(RELEASE_NUM, 79cvs)
|
||||
define(CDIO_VERSION_STR, 0.$1)
|
||||
|
||||
AC_PREREQ(2.52)
|
||||
AC_REVISION([$Id: configure.ac,v 1.211 2007/08/09 02:19:40 flameeyes Exp $])dnl
|
||||
AC_REVISION([$Id: configure.ac,v 1.212 2007/08/12 12:41:10 rocky Exp $])dnl
|
||||
AC_INIT(libcdio, CDIO_VERSION_STR(RELEASE_NUM))
|
||||
AC_CONFIG_SRCDIR(src/cd-info.c)
|
||||
|
||||
@@ -676,6 +676,7 @@ AC_CONFIG_FILES([ \
|
||||
src/cd-paranoia/doc/ja/Makefile \
|
||||
src/Makefile \
|
||||
test/testbincue.c \
|
||||
test/testisocd2.c \
|
||||
test/check_common_fn \
|
||||
test/Makefile \
|
||||
])
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
$Id: iso9660_fs.c,v 1.40 2007/08/12 00:56:10 rocky Exp $
|
||||
$Id: iso9660_fs.c,v 1.41 2007/08/12 12:41:10 rocky Exp $
|
||||
|
||||
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
|
||||
Copyright (C) 2003, 2004, 2005, 2006, 2007 Rocky Bernstein <rocky@gnu.org>
|
||||
@@ -50,7 +50,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char _rcsid[] = "$Id: iso9660_fs.c,v 1.40 2007/08/12 00:56:10 rocky Exp $";
|
||||
static const char _rcsid[] = "$Id: iso9660_fs.c,v 1.41 2007/08/12 12:41:10 rocky Exp $";
|
||||
|
||||
/* Implementation of iso9660_t type */
|
||||
struct _iso9660_s {
|
||||
@@ -958,6 +958,9 @@ _fs_stat_traverse (const CdIo_t *p_cdio, const iso9660_stat_t *_root,
|
||||
unsigned int len=sizeof(iso9660_stat_t) + strlen(_root->filename)+1;
|
||||
p_stat = calloc(1, len);
|
||||
memcpy(p_stat, _root, len);
|
||||
p_stat->rr.psz_symlink = calloc(1, p_stat->rr.i_symlink_max);
|
||||
memcpy(p_stat->rr.psz_symlink, _root->rr.psz_symlink,
|
||||
p_stat->rr.i_symlink_max);
|
||||
return p_stat;
|
||||
}
|
||||
|
||||
@@ -996,7 +999,8 @@ _fs_stat_traverse (const CdIo_t *p_cdio, const iso9660_stat_t *_root,
|
||||
|
||||
cmp = strcmp(splitpath[0], p_stat->filename);
|
||||
|
||||
if ( 0 != cmp && 0 == p_env->i_joliet_level && yep != p_stat->rr.b3_rock ) {
|
||||
if ( 0 != cmp && 0 == p_env->i_joliet_level
|
||||
&& yep != p_stat->rr.b3_rock ) {
|
||||
char *trans_fname = NULL;
|
||||
unsigned int i_trans_fname=strlen(p_stat->filename);
|
||||
int trans_len;
|
||||
@@ -1052,7 +1056,8 @@ _fs_iso_stat_traverse (iso9660_t *p_iso, const iso9660_stat_t *_root,
|
||||
p_stat = calloc(1, len);
|
||||
memcpy(p_stat, _root, len);
|
||||
p_stat->rr.psz_symlink = calloc(1, p_stat->rr.i_symlink_max);
|
||||
memcpy(p_stat->rr.psz_symlink, _root->rr.psz_symlink, p_stat->rr.i_symlink_max);
|
||||
memcpy(p_stat->rr.psz_symlink, _root->rr.psz_symlink,
|
||||
p_stat->rr.i_symlink_max);
|
||||
return p_stat;
|
||||
}
|
||||
|
||||
@@ -1092,7 +1097,8 @@ _fs_iso_stat_traverse (iso9660_t *p_iso, const iso9660_stat_t *_root,
|
||||
|
||||
if ( 0 != cmp && 0 == p_iso->i_joliet_level
|
||||
&& yep != p_stat->rr.b3_rock ) {
|
||||
char *trans_fname = malloc(strlen(p_stat->filename)+1);
|
||||
char *trans_fname = NULL;
|
||||
unsigned int i_trans_fname=strlen(p_stat->filename);
|
||||
int trans_len;
|
||||
|
||||
if (trans_fname == NULL) {
|
||||
@@ -1100,11 +1106,19 @@ _fs_iso_stat_traverse (iso9660_t *p_iso, const iso9660_stat_t *_root,
|
||||
(long unsigned int) strlen(p_stat->filename));
|
||||
return NULL;
|
||||
}
|
||||
if (i_trans_fname) {
|
||||
trans_fname = calloc(1, i_trans_fname+1);
|
||||
if (!trans_fname) {
|
||||
cdio_warn("can't allocate %lu bytes",
|
||||
(long unsigned int) strlen(p_stat->filename));
|
||||
return NULL;
|
||||
}
|
||||
trans_len = iso9660_name_translate_ext(p_stat->filename, trans_fname,
|
||||
p_iso->i_joliet_level);
|
||||
cmp = strcmp(splitpath[0], trans_fname);
|
||||
free(trans_fname);
|
||||
}
|
||||
}
|
||||
|
||||
if (!cmp) {
|
||||
iso9660_stat_t *ret_stat
|
||||
@@ -1153,6 +1167,48 @@ iso9660_fs_stat (CdIo_t *p_cdio, const char psz_path[])
|
||||
return p_stat;
|
||||
}
|
||||
|
||||
typedef iso9660_stat_t * (stat_root_t) (void *p_image);
|
||||
typedef iso9660_stat_t * (stat_traverse_t)
|
||||
(const void *p_image, const iso9660_stat_t *_root, char **splitpath);
|
||||
|
||||
/*!
|
||||
Get file status for psz_path into stat. NULL is returned on error.
|
||||
pathname version numbers in the ISO 9660
|
||||
name are dropped, i.e. ;1 is removed and if level 1 ISO-9660 names
|
||||
are lowercased.
|
||||
*/
|
||||
static iso9660_stat_t *
|
||||
fs_stat_translate (void *p_image, stat_root_t stat_root,
|
||||
stat_traverse_t stat_traverse,
|
||||
const char psz_path[])
|
||||
{
|
||||
iso9660_stat_t *p_root;
|
||||
char **p_psz_splitpath;
|
||||
iso9660_stat_t *p_stat;
|
||||
|
||||
if (!p_image) return NULL;
|
||||
if (psz_path) return NULL;
|
||||
|
||||
p_root = stat_root (p_image);
|
||||
if (!p_root) return NULL;
|
||||
|
||||
p_psz_splitpath = _cdio_strsplit (psz_path, '/');
|
||||
p_stat = _fs_stat_traverse (p_image, p_root, p_psz_splitpath);
|
||||
free(p_root);
|
||||
_cdio_strfreev (p_psz_splitpath);
|
||||
|
||||
return p_stat;
|
||||
}
|
||||
|
||||
iso9660_stat_t *
|
||||
iso9660_fs_stat_translate (CdIo_t *p_cdio, const char psz_path[],
|
||||
bool b_mode2)
|
||||
{
|
||||
return fs_stat_translate(p_cdio, (stat_root_t *) _fs_stat_root,
|
||||
(stat_traverse_t *) _fs_stat_traverse,
|
||||
psz_path);
|
||||
}
|
||||
|
||||
/*!
|
||||
Get file status for psz_path into stat. NULL is returned on error.
|
||||
pathname version numbers in the ISO 9660
|
||||
@@ -1160,27 +1216,14 @@ iso9660_fs_stat (CdIo_t *p_cdio, const char psz_path[])
|
||||
are lowercased.
|
||||
*/
|
||||
iso9660_stat_t *
|
||||
iso9660_fs_stat_translate (CdIo_t *p_cdio, const char psz_path[],
|
||||
bool b_mode2)
|
||||
iso9660_ifs_stat_translate (iso9660_t *p_iso, const char psz_path[])
|
||||
{
|
||||
iso9660_stat_t *p_root;
|
||||
char **p_psz_splitpath;
|
||||
iso9660_stat_t *p_stat;
|
||||
|
||||
if (!p_cdio) return NULL;
|
||||
if (psz_path) return NULL;
|
||||
|
||||
p_root = _fs_stat_root (p_cdio);
|
||||
if (!p_root) return NULL;
|
||||
|
||||
p_psz_splitpath = _cdio_strsplit (psz_path, '/');
|
||||
p_stat = _fs_stat_traverse (p_cdio, p_root, p_psz_splitpath);
|
||||
free(p_root);
|
||||
_cdio_strfreev (p_psz_splitpath);
|
||||
|
||||
return p_stat;
|
||||
return fs_stat_translate(p_iso, (stat_root_t *) _ifs_stat_root,
|
||||
(stat_traverse_t *) _fs_iso_stat_traverse,
|
||||
psz_path);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
Get file status for psz_path into stat. NULL is returned on error.
|
||||
*/
|
||||
@@ -1205,33 +1248,6 @@ iso9660_ifs_stat (iso9660_t *p_iso, const char psz_path[])
|
||||
return stat;
|
||||
}
|
||||
|
||||
/*!
|
||||
Get file status for psz_path into stat. NULL is returned on error.
|
||||
pathname version numbers in the ISO 9660
|
||||
name are dropped, i.e. ;1 is removed and if level 1 ISO-9660 names
|
||||
are lowercased.
|
||||
*/
|
||||
iso9660_stat_t *
|
||||
iso9660_ifs_stat_translate (iso9660_t *p_iso, const char psz_path[])
|
||||
{
|
||||
iso9660_stat_t *p_root;
|
||||
char **p_psz_splitpath;
|
||||
iso9660_stat_t *p_stat;
|
||||
|
||||
if (!p_iso) return NULL;
|
||||
if (!psz_path) return NULL;
|
||||
|
||||
p_root = _ifs_stat_root (p_iso);
|
||||
if (NULL == p_root) return NULL;
|
||||
|
||||
p_psz_splitpath = _cdio_strsplit (psz_path, '/');
|
||||
p_stat = _fs_iso_stat_traverse (p_iso, p_root, p_psz_splitpath);
|
||||
free(p_root);
|
||||
_cdio_strfreev (p_psz_splitpath);
|
||||
|
||||
return p_stat;
|
||||
}
|
||||
|
||||
/*!
|
||||
Read psz_path (a directory) and return a list of iso9660_stat_t
|
||||
of the files inside that. The caller must free the returned result.
|
||||
|
||||
@@ -23,6 +23,8 @@ testdefault
|
||||
testischar
|
||||
testiso9660
|
||||
testisocd
|
||||
testisocd2
|
||||
testisocd2.c
|
||||
testparanoia
|
||||
testtoc
|
||||
*.dump
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# $Id: Makefile.am,v 1.56 2006/11/16 15:07:07 rocky Exp $
|
||||
# $Id: Makefile.am,v 1.57 2007/08/12 12:41:10 rocky Exp $
|
||||
#
|
||||
# Copyright (C) 2003, 2004, 2005, 2006 Rocky Bernstein
|
||||
# <rocky@cpan.org>
|
||||
@@ -31,7 +31,7 @@ testparanoia_LDADD = $(LIBCDIO_PARANOIA_LIBS) $(LIBCDIO_CDDA_LIBS) $(LIBCDIO_LIB
|
||||
endif
|
||||
|
||||
hack = check_sizeof testassert testbincue testischar \
|
||||
testisocd testiso9660 \
|
||||
testisocd testisocd2 testiso9660 \
|
||||
$(testparanoia) testtoc
|
||||
|
||||
noinst_PROGRAMS = $(hack) testdefault
|
||||
@@ -45,6 +45,7 @@ testischar_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV)
|
||||
testiso9660_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV)
|
||||
|
||||
testisocd_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV)
|
||||
testisocd2_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV)
|
||||
|
||||
testtoc_LDADD = $(LIBCDIO_LIBS)
|
||||
testtoc_CFLAGS = -DTEST_DIR=\"$(srcdir)\"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: testisocd.c,v 1.4 2007/08/11 16:26:14 rocky Exp $
|
||||
/* $Id: testisocd.c,v 1.5 2007/08/12 12:41:10 rocky Exp $
|
||||
|
||||
Copyright (C) 2003, 2004, 2005, 2006, 2007 Rocky Bernstein
|
||||
<rocky@gnu.org>
|
||||
@@ -108,7 +108,13 @@ main(int argc, const char *argv[])
|
||||
iso9660_fs_find_lsn_with_path (p_cdio, i_lsn, &psz_path);
|
||||
|
||||
/* Compare the two statbufs. */
|
||||
#if 0
|
||||
if (0 != memcmp(p_statbuf, p_statbuf2, sizeof(iso9660_stat_t))) {
|
||||
#else
|
||||
if (p_statbuf->lsn != p_statbuf2->lsn ||
|
||||
p_statbuf->size != p_statbuf2->size ||
|
||||
p_statbuf->type != p_statbuf2->type) {
|
||||
#endif
|
||||
fprintf(stderr, "File stat information between fs_stat and "
|
||||
"fs_find_lsn isn't the same\n");
|
||||
exit(3);
|
||||
@@ -125,6 +131,7 @@ main(int argc, const char *argv[])
|
||||
fprintf(stderr, "Path returned for fs_find_lsn_with_path "
|
||||
"is not correct should be /./, is %s\n", psz_path);
|
||||
exit(5);
|
||||
free(psz_path);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Path returned for fs_find_lsn_with_path is NULL\n");
|
||||
|
||||
135
test/testisocd2.c.in
Normal file
135
test/testisocd2.c.in
Normal file
@@ -0,0 +1,135 @@
|
||||
/* $Id: testisocd2.c.in,v 1.1 2007/08/12 12:41:10 rocky Exp $
|
||||
|
||||
Copyright (C) 2003, 2004, 2005, 2006, 2007 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 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
|
||||
*/
|
||||
|
||||
/* Tests reading ISO 9660 info from an ISO 9660 image. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "portable.h"
|
||||
|
||||
#include <cdio/cdio.h>
|
||||
#include <cdio/iso9660.h>
|
||||
#include <cdio/cd_types.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
|
||||
|
||||
/* Set up a CD-DA image to test on which is in the libcdio distribution. */
|
||||
#define ISO9660_IMAGE_PATH "@srcdir@/"
|
||||
#define ISO9660_IMAGE ISO9660_IMAGE_PATH "copying.iso"
|
||||
|
||||
#define SKIP_TEST_RC 77
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
iso9660_t *p_iso;
|
||||
|
||||
p_iso = iso9660_open (ISO9660_IMAGE);
|
||||
if (!p_iso) {
|
||||
fprintf(stderr, "Sorry, couldn't open ISO9660 image %s\n",
|
||||
ISO9660_IMAGE);
|
||||
return 1;
|
||||
} else {
|
||||
/* You make get different results looking up "/" versus "/." and the
|
||||
latter may give more complete information. "/" will take information
|
||||
from the PVD only, whereas "/." will force a directory read of "/" and
|
||||
find "." and in that Rock-Ridge information might be found which fills
|
||||
in more stat information that iso9660_fs_find_lsn also will find.
|
||||
. Ideally iso9660_fs_stat should be fixed. */
|
||||
iso9660_stat_t *p_statbuf = iso9660_ifs_stat (p_iso, "/.");
|
||||
|
||||
if (NULL == p_statbuf) {
|
||||
fprintf(stderr,
|
||||
"Could not get ISO-9660 file information for file /.\n");
|
||||
iso9660_close(p_iso);
|
||||
exit(2);
|
||||
} else {
|
||||
/* Now try getting the statbuf another way */
|
||||
char buf[ISO_BLOCKSIZE];
|
||||
char *psz_path = NULL;
|
||||
const lsn_t i_lsn = p_statbuf->lsn;
|
||||
const iso9660_stat_t *p_statbuf2 = iso9660_ifs_find_lsn (p_iso, i_lsn);
|
||||
const iso9660_stat_t *p_statbuf3 =
|
||||
iso9660_ifs_find_lsn_with_path (p_iso, i_lsn, &psz_path);
|
||||
|
||||
/* Compare the two statbufs. */
|
||||
if (p_statbuf->lsn != p_statbuf2->lsn ||
|
||||
p_statbuf->size != p_statbuf2->size ||
|
||||
p_statbuf->type != p_statbuf2->type) {
|
||||
|
||||
fprintf(stderr, "File stat information between fs_stat and "
|
||||
"iso9660_ifs_find_lsn isn't the same\n");
|
||||
exit(3);
|
||||
}
|
||||
|
||||
if (p_statbuf3->lsn != p_statbuf2->lsn ||
|
||||
p_statbuf3->size != p_statbuf2->size ||
|
||||
p_statbuf3->type != p_statbuf2->type) {
|
||||
exit(4);
|
||||
}
|
||||
|
||||
if (psz_path != NULL) {
|
||||
if (0 != strncmp("/./", psz_path, strlen("/./"))) {
|
||||
fprintf(stderr, "Path returned for ifs_find_lsn_with_path "
|
||||
"is not correct should be /./, is %s\n", psz_path);
|
||||
exit(5);
|
||||
}
|
||||
free(psz_path);
|
||||
} else {
|
||||
fprintf(stderr, "Path returned for fs_find_lsn_with_path is NULL\n");
|
||||
exit(6);
|
||||
}
|
||||
|
||||
/* Try reading from the directory. */
|
||||
memset (buf, 0, ISO_BLOCKSIZE);
|
||||
if ( ISO_BLOCKSIZE != iso9660_iso_seek_read (p_iso, buf, i_lsn, 1) )
|
||||
{
|
||||
fprintf(stderr, "Error reading ISO 9660 file at lsn %lu\n",
|
||||
(long unsigned int) p_statbuf->lsn);
|
||||
exit(7);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
Reference in New Issue
Block a user