Add iso9660_fs_find_lsn_with_path and iso9660_ifs_find_lsn_with_path to report the full filename path of lsn.

This commit is contained in:
rocky
2007-08-11 16:26:14 +00:00
parent bba9e0eb8b
commit de2c6a18ae
5 changed files with 127 additions and 31 deletions

View File

@@ -1,8 +1,8 @@
/*
$Id: iso9660.h,v 1.95 2006/10/27 10:38:41 rocky Exp $
$Id: iso9660.h,v 1.96 2007/08/11 16:26:14 rocky Exp $
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2003, 2004, 2005, 2006 Rocky Bernstein <rocky@gnu.org>
Copyright (C) 2003, 2004, 2005, 2006, 2007 Rocky Bernstein <rocky@gnu.org>
See also iso9660.h by Eric Youngdale (1993).
@@ -835,6 +835,16 @@ iso9660_dir_calc_record_size (unsigned int namelen, unsigned int su_len);
iso9660_stat_t *iso9660_fs_find_lsn(CdIo_t *p_cdio, lsn_t i_lsn);
/*!
Given a directory pointer, find the filesystem entry that contains
lsn and return information about it.
@return stat_t of entry if we found lsn, or NULL otherwise.
Caller must free return value.
*/
iso9660_stat_t *iso9660_fs_find_lsn_with_path(CdIo_t *p_cdio, lsn_t i_lsn,
/*out*/ char **ppsz_path);
/*!
Given a directory pointer, find the filesystem entry that contains
lsn and return information about it.
@@ -845,6 +855,25 @@ iso9660_stat_t *iso9660_fs_find_lsn(CdIo_t *p_cdio, lsn_t i_lsn);
iso9660_stat_t *iso9660_ifs_find_lsn(iso9660_t *p_iso, lsn_t i_lsn);
/*!
Given a directory pointer, find the filesystem entry that contains
lsn and return information about it.
@param p_iso pointer to iso_t
@param i_lsn LSN to find
@param ppsz_path full path of lsn filename. On entry *ppsz_path should be
NULL. On return it will be allocated an point to the full path of the
file at lsn or NULL if the lsn is not found. You should deallocate
*ppsz_path when you are done using it.
@return stat_t of entry if we found lsn, or NULL otherwise.
Caller must free return value.
*/
iso9660_stat_t *iso9660_ifs_find_lsn_with_path(iso9660_t *p_iso,
lsn_t i_lsn,
/*out*/ char **ppsz_path);
/*!
Return file status for psz_path. NULL is returned on error.

View File

@@ -1,4 +1,4 @@
# $Id: Makefile.am,v 1.12 2006/10/11 12:38:18 rocky Exp $
# $Id: Makefile.am,v 1.13 2007/08/11 16:26:14 rocky Exp $
#
# Copyright (C) 2003, 2004, 2005, 2006 Rocky Bernstein <rocky@panix.com>
#
@@ -43,9 +43,9 @@
# public release, then set AGE to 0. A changed interface means an
# incompatibility with previous versions.
libiso9660_la_CURRENT := 5
libiso9660_la_REVISION := 1
libiso9660_la_AGE := 0
libiso9660_la_CURRENT := 6
libiso9660_la_REVISION := 0
libiso9660_la_AGE := 1
EXTRA_DIST = libiso9660.sym

View File

@@ -1,8 +1,8 @@
/*
$Id: iso9660_fs.c,v 1.38 2006/12/20 09:26:35 rocky Exp $
$Id: iso9660_fs.c,v 1.39 2007/08/11 16:26:14 rocky Exp $
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2003, 2004, 2005, 2006 Rocky Bernstein <rocky@panix.com>
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
@@ -50,7 +50,7 @@
#include <stdio.h>
static const char _rcsid[] = "$Id: iso9660_fs.c,v 1.38 2006/12/20 09:26:35 rocky Exp $";
static const char _rcsid[] = "$Id: iso9660_fs.c,v 1.39 2007/08/11 16:26:14 rocky Exp $";
/* Implementation of iso9660_t type */
struct _iso9660_s {
@@ -1375,7 +1375,8 @@ iso9660_ifs_readdir (iso9660_t *p_iso, const char psz_path[])
}
static iso9660_stat_t *
find_fs_lsn_recurse (CdIo_t *p_cdio, const char psz_path[], lsn_t lsn)
find_fs_lsn_recurse (CdIo_t *p_cdio, const char psz_path[], lsn_t lsn,
/*out*/ char **ppsz_full_filename)
{
CdioList_t *entlist = iso9660_fs_readdir (p_cdio, psz_path, true);
CdioList_t *dirlist = _cdio_list_new ();
@@ -1388,15 +1389,17 @@ find_fs_lsn_recurse (CdIo_t *p_cdio, const char psz_path[], lsn_t lsn)
_CDIO_LIST_FOREACH (entnode, entlist)
{
iso9660_stat_t *statbuf = _cdio_list_node_data (entnode);
char _fullname[4096] = { 0, };
char *filename = (char *) statbuf->filename;
const char *psz_filename = (char *) statbuf->filename;
const unsigned int len = strlen(psz_path) + strlen(psz_filename)+2;
snprintf (_fullname, sizeof (_fullname), "%s%s/", psz_path, filename);
if (*ppsz_full_filename != NULL) free(*ppsz_full_filename);
*ppsz_full_filename = calloc(1, len);
snprintf (*ppsz_full_filename, len, "%s%s/", psz_path, psz_filename);
if (statbuf->type == _STAT_DIR
&& strcmp ((char *) statbuf->filename, ".")
&& strcmp ((char *) statbuf->filename, ".."))
_cdio_list_append (dirlist, strdup (_fullname));
_cdio_list_append (dirlist, strdup(*ppsz_full_filename));
if (statbuf->lsn == lsn) {
unsigned int len=sizeof(iso9660_stat_t)+strlen(statbuf->filename)+1;
@@ -1415,8 +1418,11 @@ find_fs_lsn_recurse (CdIo_t *p_cdio, const char psz_path[], lsn_t lsn)
_CDIO_LIST_FOREACH (entnode, dirlist)
{
char *_fullname = _cdio_list_node_data (entnode);
iso9660_stat_t *ret_stat = find_fs_lsn_recurse (p_cdio, _fullname, lsn);
char *psz_path_prefix = _cdio_list_node_data (entnode);
iso9660_stat_t *ret_stat;
free(ppsz_full_filename);
ret_stat = find_fs_lsn_recurse (p_cdio, psz_path_prefix, lsn,
ppsz_full_filename);
if (NULL != ret_stat) {
_cdio_list_free (dirlist, true);
@@ -1424,12 +1430,15 @@ find_fs_lsn_recurse (CdIo_t *p_cdio, const char psz_path[], lsn_t lsn)
}
}
free(ppsz_full_filename);
*ppsz_full_filename = NULL;
_cdio_list_free (dirlist, true);
return NULL;
}
static iso9660_stat_t *
find_ifs_lsn_recurse (iso9660_t *p_iso, const char psz_path[], lsn_t lsn)
find_ifs_lsn_recurse (iso9660_t *p_iso, const char psz_path[], lsn_t lsn,
/*out*/ char **ppsz_full_filename)
{
CdioList_t *entlist = iso9660_ifs_readdir (p_iso, psz_path);
CdioList_t *dirlist = _cdio_list_new ();
@@ -1442,15 +1451,18 @@ find_ifs_lsn_recurse (iso9660_t *p_iso, const char psz_path[], lsn_t lsn)
_CDIO_LIST_FOREACH (entnode, entlist)
{
iso9660_stat_t *statbuf = _cdio_list_node_data (entnode);
char _fullname[4096] = { 0, };
char *filename = (char *) statbuf->filename;
snprintf (_fullname, sizeof (_fullname), "%s%s/", psz_path, filename);
const char *psz_filename = (char *) statbuf->filename;
const unsigned int len = strlen(psz_path) + strlen(psz_filename)+2;
if (*ppsz_full_filename != NULL) free(*ppsz_full_filename);
*ppsz_full_filename = calloc(1, len);
snprintf (*ppsz_full_filename, len, "%s%s/", psz_path, psz_filename);
if (statbuf->type == _STAT_DIR
&& strcmp ((char *) statbuf->filename, ".")
&& strcmp ((char *) statbuf->filename, ".."))
_cdio_list_append (dirlist, strdup (_fullname));
&& strcmp ((char *) statbuf->filename, "..")) {
_cdio_list_append (dirlist, strdup(*ppsz_full_filename));
}
if (statbuf->lsn == lsn) {
unsigned int len=sizeof(iso9660_stat_t)+strlen(statbuf->filename)+1;
@@ -1469,8 +1481,11 @@ find_ifs_lsn_recurse (iso9660_t *p_iso, const char psz_path[], lsn_t lsn)
_CDIO_LIST_FOREACH (entnode, dirlist)
{
char *_fullname = _cdio_list_node_data (entnode);
iso9660_stat_t *ret_stat = find_ifs_lsn_recurse (p_iso, _fullname, lsn);
char *psz_path_prefix = _cdio_list_node_data (entnode);
iso9660_stat_t *ret_stat;
free(ppsz_full_filename);
ret_stat = find_ifs_lsn_recurse (p_iso, psz_path_prefix, lsn,
ppsz_full_filename);
if (NULL != ret_stat) {
_cdio_list_free (dirlist, true);
@@ -1478,6 +1493,8 @@ find_ifs_lsn_recurse (iso9660_t *p_iso, const char psz_path[], lsn_t lsn)
}
}
free(ppsz_full_filename);
*ppsz_full_filename = NULL;
_cdio_list_free (dirlist, true);
return NULL;
}
@@ -1491,7 +1508,21 @@ find_ifs_lsn_recurse (iso9660_t *p_iso, const char psz_path[], lsn_t lsn)
iso9660_stat_t *
iso9660_fs_find_lsn(CdIo_t *p_cdio, lsn_t i_lsn)
{
return find_fs_lsn_recurse (p_cdio, "/", i_lsn);
char *psz_full_filename = NULL;
return find_fs_lsn_recurse (p_cdio, "/", i_lsn, &psz_full_filename);
}
/*!
Given a directory pointer, find the filesystem entry that contains
lsn and return information about it.
Returns stat_t of entry if we found lsn, or NULL otherwise.
*/
iso9660_stat_t *
iso9660_fs_find_lsn_with_path(CdIo_t *p_cdio, lsn_t i_lsn,
/*out*/ char **ppsz_full_filename)
{
return find_fs_lsn_recurse (p_cdio, "/", i_lsn, ppsz_full_filename);
}
/*!
@@ -1503,7 +1534,21 @@ iso9660_fs_find_lsn(CdIo_t *p_cdio, lsn_t i_lsn)
iso9660_stat_t *
iso9660_ifs_find_lsn(iso9660_t *p_iso, lsn_t i_lsn)
{
return find_ifs_lsn_recurse (p_iso, "/", i_lsn);
char *psz_full_filename = NULL;
return find_ifs_lsn_recurse (p_iso, "/", i_lsn, &psz_full_filename);
}
/*!
Given a directory pointer, find the filesystem entry that contains
lsn and return information about it.
Returns stat_t of entry if we found lsn, or NULL otherwise.
*/
iso9660_stat_t *
iso9660_ifs_find_lsn_with_path(iso9660_t *p_iso, lsn_t i_lsn,
/*out*/ char **ppsz_full_filename)
{
return find_ifs_lsn_recurse (p_iso, "/", i_lsn, ppsz_full_filename);
}
/*!

View File

@@ -15,6 +15,7 @@ iso9660_dir_to_name
iso9660_dirname_valid_p
iso9660_find_fs_lsn
iso9660_fs_find_lsn
iso9660_fs_find_lsn_with_path
iso9660_fs_read_pvd
iso9660_fs_read_superblock
iso9660_fs_readdir
@@ -41,6 +42,7 @@ iso9660_get_volume_id
iso9660_get_volumeset_id
iso9660_get_xa_attr_str
iso9660_ifs_find_lsn
iso9660_ifs_find_lsn_with_path
iso9660_ifs_fuzzy_read_superblock
iso9660_ifs_get_application_id
iso9660_ifs_get_joliet_level

View File

@@ -1,7 +1,7 @@
/* $Id: testisocd.c,v 1.3 2006/03/28 03:26:16 rocky Exp $
/* $Id: testisocd.c,v 1.4 2007/08/11 16:26:14 rocky Exp $
Copyright (C) 2003, 2004, 2005, 2006 Rocky Bernstein
<rockyb@users.sourceforge.net>
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
@@ -101,8 +101,11 @@ main(int argc, const char *argv[])
} 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_fs_find_lsn (p_cdio, i_lsn);
const iso9660_stat_t *p_statbuf3 =
iso9660_fs_find_lsn_with_path (p_cdio, i_lsn, &psz_path);
/* Compare the two statbufs. */
if (0 != memcmp(p_statbuf, p_statbuf2, sizeof(iso9660_stat_t))) {
@@ -110,6 +113,23 @@ main(int argc, const char *argv[])
"fs_find_lsn isn't the same\n");
exit(3);
}
if (0 != memcmp(p_statbuf3, p_statbuf2, sizeof(iso9660_stat_t))) {
fprintf(stderr, "File stat information between fs_find_lsn and "
"fs_find_lsn_with_path isn't the same\n");
exit(4);
}
if (psz_path != NULL) {
if (0 != strncmp("/./", psz_path, strlen("/./"))) {
fprintf(stderr, "Path returned for fs_find_lsn_with_path "
"is not correct should be /./, is %s\n", psz_path);
exit(5);
}
} 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);
@@ -117,7 +137,7 @@ main(int argc, const char *argv[])
{
fprintf(stderr, "Error reading ISO 9660 file at lsn %lu\n",
(long unsigned int) p_statbuf->lsn);
exit(4);
exit(7);
}
exit(0);
}