2003-08-31 06:59:23 +00:00
|
|
|
|
/*
|
2005-01-02 22:43:41 +00:00
|
|
|
|
$Id: iso9660_fs.c,v 1.2 2005/01/02 22:43:41 rocky Exp $
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
|
|
|
|
|
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
|
2004-01-10 03:03:08 +00:00
|
|
|
|
Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
|
# include "config.h"
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2003-08-31 09:11:25 +00:00
|
|
|
|
#ifdef HAVE_STRING_H
|
2004-10-23 20:55:08 +00:00
|
|
|
|
# include <string.h>
|
2003-08-31 09:11:25 +00:00
|
|
|
|
#endif
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
#ifdef HAVE_ERRNO_H
|
|
|
|
|
|
# include <errno.h>
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2004-10-24 12:26:28 +00:00
|
|
|
|
#ifdef HAVE_ICONV
|
2004-10-23 20:55:08 +00:00
|
|
|
|
# include <iconv.h>
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2004-10-31 13:58:44 +00:00
|
|
|
|
#ifdef HAVE_LANGINFO_CODESET
|
2004-10-23 20:55:08 +00:00
|
|
|
|
#include <langinfo.h>
|
2004-10-30 02:55:17 +00:00
|
|
|
|
#endif
|
2004-10-23 20:55:08 +00:00
|
|
|
|
|
2003-08-31 06:59:23 +00:00
|
|
|
|
#include <cdio/cdio.h>
|
2004-10-22 01:13:38 +00:00
|
|
|
|
#include <cdio/bytesex.h>
|
2003-08-31 06:59:23 +00:00
|
|
|
|
#include <cdio/iso9660.h>
|
2003-08-31 08:32:40 +00:00
|
|
|
|
#include <cdio/util.h>
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
|
|
|
|
|
/* Private headers */
|
2003-08-31 08:32:40 +00:00
|
|
|
|
#include "cdio_assert.h"
|
2004-01-10 03:03:08 +00:00
|
|
|
|
#include "_cdio_stdio.h"
|
|
|
|
|
|
#include "cdio_private.h"
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-09-05 22:48:16 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
2005-01-02 22:43:41 +00:00
|
|
|
|
static const char _rcsid[] = "$Id: iso9660_fs.c,v 1.2 2005/01/02 22:43:41 rocky Exp $";
|
2004-01-10 03:03:08 +00:00
|
|
|
|
|
|
|
|
|
|
/* Implementation of iso9660_t type */
|
|
|
|
|
|
struct _iso9660 {
|
|
|
|
|
|
CdioDataSource *stream; /* Stream pointer */
|
2004-10-22 01:13:38 +00:00
|
|
|
|
bool b_xa; /* true if has XA attributes. */
|
2004-10-23 20:55:08 +00:00
|
|
|
|
uint8_t i_joliet_level;/* 0 = no Joliet extensions.
|
|
|
|
|
|
1-3: Joliet level. */
|
2004-10-24 03:29:31 +00:00
|
|
|
|
iso9660_pvd_t pvd;
|
|
|
|
|
|
iso9660_svd_t svd;
|
2004-10-23 20:55:08 +00:00
|
|
|
|
iso_extension_mask_t iso_extension_mask; /* What extensions we
|
|
|
|
|
|
tolerate. */
|
2004-01-10 03:03:08 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Open an ISO 9660 image for reading. Maybe in the future we will have
|
2004-10-23 20:55:08 +00:00
|
|
|
|
a mode. NULL is returned on error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
iso9660_t *
|
|
|
|
|
|
iso9660_open (const char *pathname /*, mode*/)
|
|
|
|
|
|
{
|
|
|
|
|
|
return iso9660_open_ext(pathname, ISO_EXTENSION_NONE);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Open an ISO 9660 image for reading. Maybe in the future we will have
|
|
|
|
|
|
a mode. NULL is returned on error.
|
2004-01-10 03:03:08 +00:00
|
|
|
|
*/
|
|
|
|
|
|
iso9660_t *
|
2004-10-23 20:55:08 +00:00
|
|
|
|
iso9660_open_ext (const char *pathname,
|
|
|
|
|
|
iso_extension_mask_t iso_extension_mask)
|
2004-01-10 03:03:08 +00:00
|
|
|
|
{
|
2004-10-22 01:13:38 +00:00
|
|
|
|
iso9660_t *p_iso = (iso9660_t *) _cdio_malloc(sizeof(struct _iso9660)) ;
|
2004-01-10 03:03:08 +00:00
|
|
|
|
|
2004-10-22 01:13:38 +00:00
|
|
|
|
if (NULL == p_iso) return NULL;
|
2004-01-10 03:03:08 +00:00
|
|
|
|
|
2004-10-22 01:13:38 +00:00
|
|
|
|
p_iso->stream = cdio_stdio_new( pathname );
|
|
|
|
|
|
if (NULL == p_iso->stream)
|
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
2004-10-24 23:42:39 +00:00
|
|
|
|
if ( !iso9660_ifs_read_superblock(p_iso, iso_extension_mask) )
|
2004-10-22 01:13:38 +00:00
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
|
|
/* Determine if image has XA attributes. */
|
2004-01-10 03:03:08 +00:00
|
|
|
|
|
2004-10-24 03:29:31 +00:00
|
|
|
|
p_iso->b_xa = !strncmp ((char *) &(p_iso->pvd) + ISO_XA_MARKER_OFFSET,
|
2004-10-22 01:13:38 +00:00
|
|
|
|
ISO_XA_MARKER_STRING,
|
|
|
|
|
|
strlen (ISO_XA_MARKER_STRING));
|
2004-10-23 20:55:08 +00:00
|
|
|
|
p_iso->iso_extension_mask = iso_extension_mask;
|
2004-10-22 01:13:38 +00:00
|
|
|
|
return p_iso;
|
|
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
|
free(p_iso);
|
|
|
|
|
|
return NULL;
|
2004-01-10 03:03:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Close previously opened ISO 9660 image.
|
|
|
|
|
|
True is unconditionally returned. If there was an error false would
|
|
|
|
|
|
be returned.
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool
|
2004-06-19 00:10:23 +00:00
|
|
|
|
iso9660_close (iso9660_t *p_iso)
|
2004-01-10 03:03:08 +00:00
|
|
|
|
{
|
2004-06-19 00:10:23 +00:00
|
|
|
|
if (NULL != p_iso) {
|
|
|
|
|
|
cdio_stdio_destroy(p_iso->stream);
|
|
|
|
|
|
free(p_iso);
|
2004-01-10 03:03:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-06-19 02:27:19 +00:00
|
|
|
|
static bool
|
|
|
|
|
|
check_pvd (const iso9660_pvd_t *p_pvd)
|
2004-06-19 00:10:23 +00:00
|
|
|
|
{
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if ( ISO_VD_PRIMARY != from_711(p_pvd->type) ) {
|
2004-06-19 00:10:23 +00:00
|
|
|
|
cdio_warn ("unexpected PVD type %d", p_pvd->type);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (strncmp (p_pvd->id, ISO_STANDARD_ID, strlen (ISO_STANDARD_ID)))
|
|
|
|
|
|
{
|
|
|
|
|
|
cdio_warn ("unexpected ID encountered (expected `"
|
|
|
|
|
|
ISO_STANDARD_ID "', got `%.5s'", p_pvd->id);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2004-01-10 03:03:08 +00:00
|
|
|
|
|
2004-10-29 02:11:48 +00:00
|
|
|
|
#ifdef HAVE_JOLIET
|
2004-10-23 20:55:08 +00:00
|
|
|
|
static bool
|
2004-10-28 11:13:40 +00:00
|
|
|
|
ucs2be_to_locale(ICONV_CONST char *psz_ucs2be, size_t i_inlen,
|
2004-10-23 20:55:08 +00:00
|
|
|
|
char **p_psz_out, size_t i_outlen)
|
|
|
|
|
|
{
|
2004-11-06 17:50:05 +00:00
|
|
|
|
|
|
|
|
|
|
iconv_t ic =
|
2004-10-31 13:58:44 +00:00
|
|
|
|
#if defined(HAVE_LANGINFO_CODESET)
|
2004-11-06 17:50:05 +00:00
|
|
|
|
iconv_open(nl_langinfo(CODESET), "UCS-2BE");
|
2004-10-30 02:55:17 +00:00
|
|
|
|
#else
|
2004-11-06 17:50:05 +00:00
|
|
|
|
iconv_open("ASCII", "UCS-2BE");
|
2004-10-30 02:55:17 +00:00
|
|
|
|
#endif
|
2004-11-06 17:50:05 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
int rc;
|
|
|
|
|
|
char *psz_buf = NULL;
|
|
|
|
|
|
char *psz_buf2;
|
2004-10-28 11:13:40 +00:00
|
|
|
|
int i_outlen_max = i_outlen;
|
|
|
|
|
|
int i_outlen_actual;
|
2004-10-24 03:29:31 +00:00
|
|
|
|
|
2004-10-26 10:00:27 +00:00
|
|
|
|
if (-1 == (size_t) ic) {
|
2004-11-06 17:50:05 +00:00
|
|
|
|
#if defined(HAVE_LANGINFO_CODESET)
|
2004-10-26 09:56:53 +00:00
|
|
|
|
cdio_info("Failed to get conversion table for locale, trying ASCII");
|
2004-10-24 03:29:31 +00:00
|
|
|
|
ic = iconv_open("ASCII", "UCS-2BE");
|
2004-10-26 10:00:27 +00:00
|
|
|
|
if (-1 == (size_t) ic) {
|
2004-10-26 09:56:53 +00:00
|
|
|
|
cdio_info("Failed to get conversion table for ASCII too");
|
2004-10-24 03:29:31 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2004-11-06 17:50:05 +00:00
|
|
|
|
#else
|
|
|
|
|
|
cdio_info("Failed to get conversion table for locale");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
#endif
|
2004-10-24 03:29:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
psz_buf = (char *) realloc(psz_buf, i_outlen);
|
|
|
|
|
|
psz_buf2 = psz_buf;
|
|
|
|
|
|
if (!psz_buf) {
|
|
|
|
|
|
/* XXX: report out of memory error */
|
|
|
|
|
|
goto error;
|
|
|
|
|
|
}
|
|
|
|
|
|
rc = iconv(ic, &psz_ucs2be, &i_inlen, &psz_buf2, &i_outlen);
|
|
|
|
|
|
iconv_close(ic);
|
|
|
|
|
|
if ((rc == -1) && (errno != E2BIG)) {
|
|
|
|
|
|
/* conversion failed */
|
|
|
|
|
|
goto error;
|
|
|
|
|
|
}
|
2004-10-28 11:13:40 +00:00
|
|
|
|
i_outlen_actual = i_outlen_max - i_outlen;
|
|
|
|
|
|
*p_psz_out = malloc(i_outlen_actual + 1);
|
|
|
|
|
|
memcpy(*p_psz_out, psz_buf, i_outlen_actual);
|
|
|
|
|
|
*(*p_psz_out + i_outlen_actual) = '\0';
|
2004-10-23 20:55:08 +00:00
|
|
|
|
free(psz_buf);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
error:
|
|
|
|
|
|
free(psz_buf);
|
|
|
|
|
|
*p_psz_out = NULL;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2004-10-29 02:11:48 +00:00
|
|
|
|
#endif /*HAVE_JOLIET*/
|
2004-10-23 20:55:08 +00:00
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the application ID. NULL is returned in psz_app_id if there
|
|
|
|
|
|
is some problem in getting this.
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool
|
|
|
|
|
|
iso9660_ifs_get_application_id(iso9660_t *p_iso,
|
|
|
|
|
|
/*out*/ char **p_psz_app_id)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!p_iso) {
|
|
|
|
|
|
*p_psz_app_id = NULL;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2004-10-29 02:11:48 +00:00
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_JOLIET
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (p_iso->i_joliet_level) {
|
|
|
|
|
|
/* TODO: check that we haven't reached the maximum size.
|
|
|
|
|
|
If we have, perhaps we've truncated and if we can get
|
|
|
|
|
|
longer results *and* have the same character using
|
|
|
|
|
|
the PVD, do that.
|
|
|
|
|
|
*/
|
2004-10-24 03:29:31 +00:00
|
|
|
|
if ( ucs2be_to_locale(p_iso->svd.application_id,
|
|
|
|
|
|
ISO_MAX_APPLICATION_ID,
|
|
|
|
|
|
p_psz_app_id,
|
|
|
|
|
|
ISO_MAX_APPLICATION_ID))
|
|
|
|
|
|
return true;
|
2004-10-29 02:11:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
#endif /*HAVE_JOLIET*/
|
2004-10-24 03:29:31 +00:00
|
|
|
|
*p_psz_app_id = iso9660_get_application_id( &(p_iso->pvd) );
|
|
|
|
|
|
return *p_psz_app_id != NULL && strlen(*p_psz_app_id);
|
2004-10-23 20:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return the Joliet level recognaized for p_iso.
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint8_t iso9660_ifs_get_joliet_level(iso9660_t *p_iso)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!p_iso) return 0;
|
|
|
|
|
|
return p_iso->i_joliet_level;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return a string containing the preparer id with trailing
|
|
|
|
|
|
blanks removed.
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool
|
|
|
|
|
|
iso9660_ifs_get_preparer_id(iso9660_t *p_iso,
|
|
|
|
|
|
/*out*/ char **p_psz_preparer_id)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!p_iso) {
|
|
|
|
|
|
*p_psz_preparer_id = NULL;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2004-10-29 02:11:48 +00:00
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_JOLIET
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (p_iso->i_joliet_level) {
|
|
|
|
|
|
/* TODO: check that we haven't reached the maximum size.
|
|
|
|
|
|
If we have, perhaps we've truncated and if we can get
|
|
|
|
|
|
longer results *and* have the same character using
|
|
|
|
|
|
the PVD, do that.
|
|
|
|
|
|
*/
|
2004-10-24 03:29:31 +00:00
|
|
|
|
if ( ucs2be_to_locale(p_iso->svd.preparer_id, ISO_MAX_PREPARER_ID,
|
|
|
|
|
|
p_psz_preparer_id, ISO_MAX_PREPARER_ID) )
|
|
|
|
|
|
return true;
|
2004-10-29 02:11:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
#endif /*HAVE_JOLIET*/
|
2004-10-24 03:29:31 +00:00
|
|
|
|
*p_psz_preparer_id = iso9660_get_preparer_id( &(p_iso->pvd) );
|
|
|
|
|
|
return *p_psz_preparer_id != NULL && strlen(*p_psz_preparer_id);
|
2004-10-23 20:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return a string containing the PVD's publisher id with trailing
|
|
|
|
|
|
blanks removed.
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool iso9660_ifs_get_publisher_id(iso9660_t *p_iso,
|
|
|
|
|
|
/*out*/ char **p_psz_publisher_id)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!p_iso) {
|
|
|
|
|
|
*p_psz_publisher_id = NULL;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2004-10-29 02:11:48 +00:00
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_JOLIET
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (p_iso->i_joliet_level) {
|
|
|
|
|
|
/* TODO: check that we haven't reached the maximum size.
|
|
|
|
|
|
If we have, perhaps we've truncated and if we can get
|
|
|
|
|
|
longer results *and* have the same character using
|
|
|
|
|
|
the PVD, do that.
|
|
|
|
|
|
*/
|
2004-10-24 03:29:31 +00:00
|
|
|
|
if( ucs2be_to_locale(p_iso->svd.publisher_id, ISO_MAX_PUBLISHER_ID,
|
|
|
|
|
|
p_psz_publisher_id, ISO_MAX_PUBLISHER_ID) )
|
|
|
|
|
|
return true;
|
2004-10-29 02:11:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
#endif /*HAVE_JOLIET*/
|
2004-10-24 03:29:31 +00:00
|
|
|
|
*p_psz_publisher_id = iso9660_get_publisher_id( &(p_iso->pvd) );
|
|
|
|
|
|
return *p_psz_publisher_id != NULL && strlen(*p_psz_publisher_id);
|
2004-10-23 20:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return a string containing the PVD's publisher id with trailing
|
|
|
|
|
|
blanks removed.
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool iso9660_ifs_get_system_id(iso9660_t *p_iso,
|
|
|
|
|
|
/*out*/ char **p_psz_system_id)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!p_iso) {
|
|
|
|
|
|
*p_psz_system_id = NULL;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2004-10-29 02:11:48 +00:00
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_JOLIET
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (p_iso->i_joliet_level) {
|
|
|
|
|
|
/* TODO: check that we haven't reached the maximum size.
|
|
|
|
|
|
If we have, perhaps we've truncated and if we can get
|
|
|
|
|
|
longer results *and* have the same character using
|
|
|
|
|
|
the PVD, do that.
|
|
|
|
|
|
*/
|
2004-10-24 03:29:31 +00:00
|
|
|
|
if ( ucs2be_to_locale(p_iso->svd.system_id, ISO_MAX_SYSTEM_ID,
|
|
|
|
|
|
p_psz_system_id, ISO_MAX_SYSTEM_ID) )
|
|
|
|
|
|
return true;
|
2004-10-23 20:55:08 +00:00
|
|
|
|
}
|
2004-10-29 02:11:48 +00:00
|
|
|
|
#endif /*HAVE_JOLIET*/
|
2004-10-24 03:29:31 +00:00
|
|
|
|
*p_psz_system_id = iso9660_get_system_id( &(p_iso->pvd) );
|
|
|
|
|
|
return *p_psz_system_id != NULL && strlen(*p_psz_system_id);
|
2004-10-23 20:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return a string containing the PVD's publisher id with trailing
|
|
|
|
|
|
blanks removed.
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool iso9660_ifs_get_volume_id(iso9660_t *p_iso,
|
|
|
|
|
|
/*out*/ char **p_psz_volume_id)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!p_iso) {
|
|
|
|
|
|
*p_psz_volume_id = NULL;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2004-10-29 02:11:48 +00:00
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_JOLIET
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (p_iso->i_joliet_level) {
|
|
|
|
|
|
/* TODO: check that we haven't reached the maximum size.
|
|
|
|
|
|
If we have, perhaps we've truncated and if we can get
|
|
|
|
|
|
longer results *and* have the same character using
|
|
|
|
|
|
the PVD, do that.
|
|
|
|
|
|
*/
|
2004-10-24 03:29:31 +00:00
|
|
|
|
if ( ucs2be_to_locale(p_iso->svd.volume_id, ISO_MAX_VOLUME_ID,
|
|
|
|
|
|
p_psz_volume_id, ISO_MAX_VOLUME_ID) )
|
|
|
|
|
|
return true;
|
2004-10-29 02:11:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
#endif /* HAVE_JOLIET */
|
2004-10-24 03:29:31 +00:00
|
|
|
|
*p_psz_volume_id = iso9660_get_volume_id( &(p_iso->pvd) );
|
|
|
|
|
|
return *p_psz_volume_id != NULL && strlen(*p_psz_volume_id);
|
2004-10-23 20:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Return a string containing the PVD's publisher id with trailing
|
|
|
|
|
|
blanks removed.
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool iso9660_ifs_get_volumeset_id(iso9660_t *p_iso,
|
|
|
|
|
|
/*out*/ char **p_psz_volumeset_id)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!p_iso) {
|
|
|
|
|
|
*p_psz_volumeset_id = NULL;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2004-10-29 02:11:48 +00:00
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_JOLIET
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (p_iso->i_joliet_level) {
|
|
|
|
|
|
/* TODO: check that we haven't reached the maximum size.
|
|
|
|
|
|
If we have, perhaps we've truncated and if we can get
|
|
|
|
|
|
longer results *and* have the same character using
|
|
|
|
|
|
the PVD, do that.
|
|
|
|
|
|
*/
|
2004-10-24 03:29:31 +00:00
|
|
|
|
if ( ucs2be_to_locale(p_iso->svd.volume_set_id,
|
|
|
|
|
|
ISO_MAX_VOLUMESET_ID,
|
|
|
|
|
|
p_psz_volumeset_id,
|
|
|
|
|
|
ISO_MAX_VOLUMESET_ID) )
|
|
|
|
|
|
return true;
|
2004-10-23 20:55:08 +00:00
|
|
|
|
}
|
2004-10-29 02:11:48 +00:00
|
|
|
|
#endif /*HAVE_JOLIET*/
|
2004-10-24 03:29:31 +00:00
|
|
|
|
*p_psz_volumeset_id = iso9660_get_volume_id( &(p_iso->pvd) );
|
|
|
|
|
|
return *p_psz_volumeset_id != NULL && strlen(*p_psz_volumeset_id);
|
2004-10-23 20:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-06-19 02:27:19 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Read the Primary Volume Descriptor for an ISO 9660 image.
|
2004-10-23 20:55:08 +00:00
|
|
|
|
True is returned if read, and false if there was an error.
|
2004-06-19 02:27:19 +00:00
|
|
|
|
*/
|
|
|
|
|
|
bool
|
|
|
|
|
|
iso9660_ifs_read_pvd (const iso9660_t *p_iso, /*out*/ iso9660_pvd_t *p_pvd)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (0 == iso9660_iso_seek_read (p_iso, p_pvd, ISO_PVD_SECTOR, 1)) {
|
|
|
|
|
|
cdio_warn ("error reading PVD sector (%d)", ISO_PVD_SECTOR);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return check_pvd(p_pvd);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
/*!
|
2004-10-24 23:42:39 +00:00
|
|
|
|
Read the Super block of an ISO 9660 image. This is the
|
2004-10-24 03:29:31 +00:00
|
|
|
|
Primary Volume Descriptor (PVD) and perhaps a Supplemental Volume
|
2004-10-23 20:55:08 +00:00
|
|
|
|
Descriptor if (Joliet) extensions are acceptable.
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool
|
2004-10-24 23:42:39 +00:00
|
|
|
|
iso9660_ifs_read_superblock (iso9660_t *p_iso,
|
|
|
|
|
|
iso_extension_mask_t iso_extension_mask)
|
2004-10-23 20:55:08 +00:00
|
|
|
|
{
|
2004-10-24 03:29:31 +00:00
|
|
|
|
iso9660_svd_t *p_svd; /* Secondary volume descriptor. */
|
2004-10-23 20:55:08 +00:00
|
|
|
|
|
2004-10-24 03:29:31 +00:00
|
|
|
|
if (!p_iso || !iso9660_ifs_read_pvd(p_iso, &(p_iso->pvd)))
|
2004-10-23 20:55:08 +00:00
|
|
|
|
return false;
|
2004-10-24 03:29:31 +00:00
|
|
|
|
|
|
|
|
|
|
p_svd = &(p_iso->svd);
|
2004-10-23 20:55:08 +00:00
|
|
|
|
p_iso->i_joliet_level = 0;
|
|
|
|
|
|
|
2004-10-24 03:29:31 +00:00
|
|
|
|
if (0 != iso9660_iso_seek_read (p_iso, p_svd, ISO_PVD_SECTOR+1, 1)) {
|
|
|
|
|
|
if ( ISO_VD_SUPPLEMENTARY == from_711(p_svd->type) ) {
|
|
|
|
|
|
if (p_svd->escape_sequences[0] == 0x25
|
|
|
|
|
|
&& p_svd->escape_sequences[1] == 0x2f) {
|
|
|
|
|
|
switch (p_svd->escape_sequences[2]) {
|
2004-10-23 20:55:08 +00:00
|
|
|
|
case 0x40:
|
|
|
|
|
|
if (iso_extension_mask & ISO_EXTENSION_JOLIET_LEVEL1)
|
|
|
|
|
|
p_iso->i_joliet_level = 1;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 0x43:
|
|
|
|
|
|
if (iso_extension_mask & ISO_EXTENSION_JOLIET_LEVEL2)
|
|
|
|
|
|
p_iso->i_joliet_level = 2;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 0x45:
|
|
|
|
|
|
if (iso_extension_mask & ISO_EXTENSION_JOLIET_LEVEL3)
|
|
|
|
|
|
p_iso->i_joliet_level = 3;
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
cdio_info("Supplementary Volume Descriptor found, but not Joliet");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (p_iso->i_joliet_level > 0) {
|
|
|
|
|
|
cdio_info("Found Extension: Joliet Level %d", p_iso->i_joliet_level);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-06-19 02:27:19 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Read the Primary Volume Descriptor for of CD.
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool
|
2005-01-02 22:43:41 +00:00
|
|
|
|
iso9660_fs_read_pvd(const CdIo_t *p_cdio, /*out*/ iso9660_pvd_t *p_pvd)
|
2004-06-19 02:27:19 +00:00
|
|
|
|
{
|
2004-10-24 23:42:39 +00:00
|
|
|
|
/* A bit of a hack, we'll assume track 1 contains ISO_PVD_SECTOR.*/
|
2004-10-26 01:21:05 +00:00
|
|
|
|
bool b_mode2;
|
2004-10-24 23:42:39 +00:00
|
|
|
|
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
|
|
|
|
|
|
int i_rc;
|
|
|
|
|
|
|
2004-10-26 01:21:05 +00:00
|
|
|
|
switch(cdio_get_track_format(p_cdio, 1)) {
|
|
|
|
|
|
case TRACK_FORMAT_CDI:
|
|
|
|
|
|
case TRACK_FORMAT_XA:
|
|
|
|
|
|
b_mode2 = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case TRACK_FORMAT_DATA:
|
|
|
|
|
|
b_mode2 = false;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case TRACK_FORMAT_AUDIO:
|
|
|
|
|
|
case TRACK_FORMAT_PSX:
|
|
|
|
|
|
case TRACK_FORMAT_ERROR:
|
|
|
|
|
|
default:
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-10-24 23:42:39 +00:00
|
|
|
|
i_rc = b_mode2
|
|
|
|
|
|
? cdio_read_mode2_sector (p_cdio, buf, ISO_PVD_SECTOR, false)
|
|
|
|
|
|
: cdio_read_mode1_sector (p_cdio, buf, ISO_PVD_SECTOR, false);
|
|
|
|
|
|
|
|
|
|
|
|
if (i_rc) {
|
2004-06-19 02:27:19 +00:00
|
|
|
|
cdio_warn ("error reading PVD sector (%d)", ISO_PVD_SECTOR);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2004-10-24 23:42:39 +00:00
|
|
|
|
|
|
|
|
|
|
/* The size of a PVD or SVD is smaller than a sector. So we
|
|
|
|
|
|
allocated a bigger block above (buf) and now we'll copy just
|
|
|
|
|
|
the part we need to save.
|
|
|
|
|
|
*/
|
|
|
|
|
|
cdio_assert (sizeof(buf) >= sizeof (iso9660_pvd_t));
|
|
|
|
|
|
memcpy(p_pvd, buf, sizeof(iso9660_pvd_t));
|
2004-06-19 02:27:19 +00:00
|
|
|
|
|
|
|
|
|
|
return check_pvd(p_pvd);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-10-24 23:42:39 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Read the Super block of an ISO 9660 image. This is the
|
|
|
|
|
|
Primary Volume Descriptor (PVD) and perhaps a Supplemental Volume
|
|
|
|
|
|
Descriptor if (Joliet) extensions are acceptable.
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool
|
2005-01-02 22:43:41 +00:00
|
|
|
|
iso9660_fs_read_superblock (CdIo_t *p_cdio,
|
2004-10-24 23:42:39 +00:00
|
|
|
|
iso_extension_mask_t iso_extension_mask)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!p_cdio) return false;
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
generic_img_private_t *p_env = (generic_img_private_t *) p_cdio->env;
|
|
|
|
|
|
iso9660_pvd_t *p_pvd = &(p_env->pvd);
|
|
|
|
|
|
iso9660_svd_t *p_svd = &(p_env->svd);
|
|
|
|
|
|
char buf[CDIO_CD_FRAMESIZE_RAW] = { 0, };
|
2004-10-26 01:21:05 +00:00
|
|
|
|
bool b_mode2;
|
2004-10-24 23:42:39 +00:00
|
|
|
|
int i_rc;
|
|
|
|
|
|
|
2004-10-26 01:21:05 +00:00
|
|
|
|
/* A bit of a hack, we'll assume track 1 contains ISO_PVD_SECTOR.*/
|
|
|
|
|
|
switch(cdio_get_track_format(p_cdio, 1)) {
|
|
|
|
|
|
case TRACK_FORMAT_CDI:
|
|
|
|
|
|
case TRACK_FORMAT_XA:
|
|
|
|
|
|
b_mode2 = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case TRACK_FORMAT_DATA:
|
|
|
|
|
|
b_mode2 = false;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case TRACK_FORMAT_AUDIO:
|
|
|
|
|
|
case TRACK_FORMAT_PSX:
|
|
|
|
|
|
case TRACK_FORMAT_ERROR:
|
|
|
|
|
|
default:
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-10-24 23:42:39 +00:00
|
|
|
|
if ( !iso9660_fs_read_pvd(p_cdio, p_pvd) )
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
p_env->i_joliet_level = 0;
|
|
|
|
|
|
|
|
|
|
|
|
i_rc = (b_mode2)
|
|
|
|
|
|
? cdio_read_mode2_sector (p_cdio, buf, ISO_PVD_SECTOR+1, false)
|
|
|
|
|
|
: cdio_read_mode1_sector (p_cdio, buf, ISO_PVD_SECTOR+1, false);
|
|
|
|
|
|
|
2004-10-26 01:21:05 +00:00
|
|
|
|
if (0 == i_rc) {
|
2004-10-24 23:42:39 +00:00
|
|
|
|
/* The size of a PVD or SVD is smaller than a sector. So we
|
|
|
|
|
|
allocated a bigger block above (buf) and now we'll copy just
|
|
|
|
|
|
the part we need to save.
|
|
|
|
|
|
*/
|
|
|
|
|
|
cdio_assert (sizeof(buf) >= sizeof (iso9660_svd_t));
|
|
|
|
|
|
memcpy(p_svd, buf, sizeof(iso9660_svd_t));
|
|
|
|
|
|
|
|
|
|
|
|
if ( ISO_VD_SUPPLEMENTARY == from_711(p_svd->type) ) {
|
|
|
|
|
|
if (p_svd->escape_sequences[0] == 0x25
|
|
|
|
|
|
&& p_svd->escape_sequences[1] == 0x2f) {
|
|
|
|
|
|
switch (p_svd->escape_sequences[2]) {
|
|
|
|
|
|
case 0x40:
|
|
|
|
|
|
if (iso_extension_mask & ISO_EXTENSION_JOLIET_LEVEL1)
|
|
|
|
|
|
p_env->i_joliet_level = 1;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 0x43:
|
|
|
|
|
|
if (iso_extension_mask & ISO_EXTENSION_JOLIET_LEVEL2)
|
|
|
|
|
|
p_env->i_joliet_level = 2;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 0x45:
|
|
|
|
|
|
if (iso_extension_mask & ISO_EXTENSION_JOLIET_LEVEL3)
|
|
|
|
|
|
p_env->i_joliet_level = 3;
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
cdio_info("Supplementary Volume Descriptor found, but not Joliet");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (p_env->i_joliet_level > 0) {
|
|
|
|
|
|
cdio_info("Found Extension: Joliet Level %d",
|
|
|
|
|
|
p_env->i_joliet_level);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-01-10 03:03:08 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Seek to a position and then read n blocks. Size read is returned.
|
|
|
|
|
|
*/
|
|
|
|
|
|
long int
|
2004-06-19 02:27:19 +00:00
|
|
|
|
iso9660_iso_seek_read (const iso9660_t *p_iso, void *ptr, lsn_t start,
|
|
|
|
|
|
long int size)
|
2004-01-10 03:03:08 +00:00
|
|
|
|
{
|
|
|
|
|
|
long int ret;
|
2004-06-19 00:10:23 +00:00
|
|
|
|
if (NULL == p_iso) return 0;
|
|
|
|
|
|
ret = cdio_stream_seek (p_iso->stream, start * ISO_BLOCKSIZE, SEEK_SET);
|
2004-01-10 03:03:08 +00:00
|
|
|
|
if (ret!=0) return 0;
|
2004-06-19 00:10:23 +00:00
|
|
|
|
return cdio_stream_read (p_iso->stream, ptr, ISO_BLOCKSIZE, size);
|
2004-01-10 03:03:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
static iso9660_stat_t *
|
2004-10-23 20:55:08 +00:00
|
|
|
|
_iso9660_dir_to_statbuf (iso9660_dir_t *p_iso9660_dir,
|
|
|
|
|
|
bool b_mode2, uint8_t i_joliet_level)
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
|
|
|
|
|
iso9660_xa_t *xa_data = NULL;
|
2004-10-23 20:55:08 +00:00
|
|
|
|
uint8_t dir_len= iso9660_get_dir_len(p_iso9660_dir);
|
2003-11-16 19:30:45 +00:00
|
|
|
|
unsigned int filename_len;
|
|
|
|
|
|
unsigned int stat_len;
|
|
|
|
|
|
iso9660_stat_t *stat;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
if (!dir_len) return NULL;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
filename_len = from_711(p_iso9660_dir->filename_len);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
/* .. string in statbuf is one longer than in p_iso9660_dir's listing '\1' */
|
2003-11-16 19:30:45 +00:00
|
|
|
|
stat_len = sizeof(iso9660_stat_t)+filename_len+2;
|
|
|
|
|
|
|
|
|
|
|
|
stat = _cdio_malloc(stat_len);
|
2004-10-23 20:55:08 +00:00
|
|
|
|
stat->type = (p_iso9660_dir->file_flags & ISO_DIRECTORY)
|
2003-11-10 04:01:16 +00:00
|
|
|
|
? _STAT_DIR : _STAT_FILE;
|
2004-10-23 20:55:08 +00:00
|
|
|
|
stat->lsn = from_733 (p_iso9660_dir->extent);
|
|
|
|
|
|
stat->size = from_733 (p_iso9660_dir->size);
|
2003-09-07 18:15:26 +00:00
|
|
|
|
stat->secsize = _cdio_len2blocks (stat->size, ISO_BLOCKSIZE);
|
|
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if ('\0' == p_iso9660_dir->filename[0] && 1 == filename_len)
|
2003-11-16 19:30:45 +00:00
|
|
|
|
strcpy (stat->filename, ".");
|
2004-10-23 20:55:08 +00:00
|
|
|
|
else if ('\1' == p_iso9660_dir->filename[0] && 1 == filename_len)
|
2003-11-16 19:30:45 +00:00
|
|
|
|
strcpy (stat->filename, "..");
|
2004-10-23 20:55:08 +00:00
|
|
|
|
else {
|
2004-10-29 02:11:48 +00:00
|
|
|
|
#ifdef HAVE_JOLIET
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (i_joliet_level) {
|
|
|
|
|
|
int i_inlen = filename_len;
|
|
|
|
|
|
int i_outlen = (i_inlen / 2);
|
|
|
|
|
|
char *p_psz_out = NULL;
|
|
|
|
|
|
ucs2be_to_locale(p_iso9660_dir->filename, i_inlen,
|
|
|
|
|
|
&p_psz_out, i_outlen);
|
|
|
|
|
|
strncpy(stat->filename, p_psz_out, filename_len);
|
|
|
|
|
|
free(p_psz_out);
|
|
|
|
|
|
} else
|
2004-10-29 02:11:48 +00:00
|
|
|
|
#endif /*HAVE_JOLIET*/
|
2004-10-23 20:55:08 +00:00
|
|
|
|
strncpy (stat->filename, p_iso9660_dir->filename, filename_len);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
iso9660_get_dtime(&(p_iso9660_dir->recording_time), true, &(stat->tm));
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-08-31 15:52:56 +00:00
|
|
|
|
cdio_assert (dir_len >= sizeof (iso9660_dir_t));
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (b_mode2) {
|
|
|
|
|
|
int su_length = iso9660_get_dir_len(p_iso9660_dir)
|
|
|
|
|
|
- sizeof (iso9660_dir_t);
|
2003-11-16 19:30:45 +00:00
|
|
|
|
su_length -= filename_len;
|
2003-08-31 15:52:56 +00:00
|
|
|
|
|
|
|
|
|
|
if (su_length % 2)
|
|
|
|
|
|
su_length--;
|
|
|
|
|
|
|
|
|
|
|
|
if (su_length < 0 || su_length < sizeof (iso9660_xa_t))
|
2003-11-16 19:30:45 +00:00
|
|
|
|
return stat;
|
2003-08-31 15:52:56 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
xa_data = (void *) (((char *) p_iso9660_dir)
|
|
|
|
|
|
+ (iso9660_get_dir_len(p_iso9660_dir) - su_length));
|
2003-08-31 15:52:56 +00:00
|
|
|
|
|
|
|
|
|
|
if (xa_data->signature[0] != 'X'
|
|
|
|
|
|
|| xa_data->signature[1] != 'A')
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
|
|
|
|
|
cdio_warn ("XA signature not found in ISO9660's system use area;"
|
2003-08-31 15:52:56 +00:00
|
|
|
|
" ignoring XA attributes for this file entry.");
|
2003-11-10 04:01:16 +00:00
|
|
|
|
cdio_debug ("%d %d %d, '%c%c' (%d, %d)",
|
2004-10-23 20:55:08 +00:00
|
|
|
|
iso9660_get_dir_len(p_iso9660_dir),
|
2003-11-16 19:30:45 +00:00
|
|
|
|
filename_len,
|
2003-08-31 06:59:23 +00:00
|
|
|
|
su_length,
|
|
|
|
|
|
xa_data->signature[0], xa_data->signature[1],
|
|
|
|
|
|
xa_data->signature[0], xa_data->signature[1]);
|
2003-11-16 19:30:45 +00:00
|
|
|
|
return stat;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
}
|
2003-09-07 18:15:26 +00:00
|
|
|
|
stat->xa = *xa_data;
|
2003-08-31 15:52:56 +00:00
|
|
|
|
}
|
2003-11-16 19:30:45 +00:00
|
|
|
|
return stat;
|
2003-08-31 15:52:56 +00:00
|
|
|
|
|
2003-08-31 06:59:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-11-10 04:01:16 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Return the directory name stored in the iso9660_dir_t
|
|
|
|
|
|
|
|
|
|
|
|
A string is allocated: the caller must deallocate.
|
|
|
|
|
|
*/
|
|
|
|
|
|
char *
|
|
|
|
|
|
iso9660_dir_to_name (const iso9660_dir_t *iso9660_dir)
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
|
|
|
|
|
char namebuf[256] = { 0, };
|
2003-11-10 04:01:16 +00:00
|
|
|
|
uint8_t len=iso9660_get_dir_len(iso9660_dir);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-09-14 06:35:59 +00:00
|
|
|
|
if (!len) return NULL;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-09-14 06:35:59 +00:00
|
|
|
|
cdio_assert (len >= sizeof (iso9660_dir_t));
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-11-10 04:01:16 +00:00
|
|
|
|
/* (iso9660_dir->file_flags & ISO_DIRECTORY) */
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-11-10 04:01:16 +00:00
|
|
|
|
if (iso9660_dir->filename[0] == '\0')
|
2003-08-31 06:59:23 +00:00
|
|
|
|
strcpy (namebuf, ".");
|
2003-11-10 04:01:16 +00:00
|
|
|
|
else if (iso9660_dir->filename[0] == '\1')
|
2003-08-31 06:59:23 +00:00
|
|
|
|
strcpy (namebuf, "..");
|
|
|
|
|
|
else
|
2003-11-10 04:01:16 +00:00
|
|
|
|
strncpy (namebuf, iso9660_dir->filename, iso9660_dir->filename_len);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
|
|
|
|
|
return strdup (namebuf);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-06-21 16:18:08 +00:00
|
|
|
|
/*
|
|
|
|
|
|
Return a pointer to a ISO 9660 stat buffer or NULL if there's an error
|
|
|
|
|
|
*/
|
2003-11-16 19:30:45 +00:00
|
|
|
|
static iso9660_stat_t *
|
2005-01-02 22:43:41 +00:00
|
|
|
|
_fs_stat_root (CdIo_t *p_cdio)
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
2004-10-26 09:35:47 +00:00
|
|
|
|
if (!p_cdio) return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
iso_extension_mask_t iso_extension_mask = ISO_EXTENSION_ALL;
|
|
|
|
|
|
generic_img_private_t *p_env = (generic_img_private_t *) p_cdio->env;
|
|
|
|
|
|
bool b_mode2 = cdio_get_track_green(p_cdio, 1);
|
|
|
|
|
|
iso9660_dir_t *p_iso9660_dir;
|
|
|
|
|
|
iso9660_stat_t *p_stat;
|
2004-10-24 23:42:39 +00:00
|
|
|
|
|
2004-10-26 09:35:47 +00:00
|
|
|
|
if (!p_env->i_joliet_level)
|
|
|
|
|
|
iso_extension_mask &= ~ISO_EXTENSION_JOLIET;
|
|
|
|
|
|
|
|
|
|
|
|
/* FIXME try also with Joliet.*/
|
|
|
|
|
|
if ( !iso9660_fs_read_superblock (p_cdio, iso_extension_mask) ) {
|
|
|
|
|
|
cdio_warn("Could not read ISO-9660 Superblock.");
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
2004-10-31 04:55:57 +00:00
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_JOLIET
|
2004-10-26 09:35:47 +00:00
|
|
|
|
p_iso9660_dir = p_env->i_joliet_level
|
|
|
|
|
|
? &(p_env->svd.root_directory_record)
|
|
|
|
|
|
: &(p_env->pvd.root_directory_record) ;
|
2004-10-31 04:55:57 +00:00
|
|
|
|
#else
|
|
|
|
|
|
p_iso9660_dir = &(p_env->pvd.root_directory_record) ;
|
|
|
|
|
|
#endif
|
2004-10-26 09:35:47 +00:00
|
|
|
|
|
|
|
|
|
|
p_stat = _iso9660_dir_to_statbuf (p_iso9660_dir, b_mode2,
|
|
|
|
|
|
p_env->i_joliet_level);
|
|
|
|
|
|
return p_stat;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-08-31 06:59:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-01-10 03:03:08 +00:00
|
|
|
|
static iso9660_stat_t *
|
2004-10-23 20:55:08 +00:00
|
|
|
|
_fs_stat_iso_root (iso9660_t *p_iso)
|
2004-01-10 03:03:08 +00:00
|
|
|
|
{
|
2004-10-23 20:55:08 +00:00
|
|
|
|
iso9660_stat_t *p_stat;
|
2004-10-24 03:29:31 +00:00
|
|
|
|
iso9660_dir_t *p_iso9660_dir;
|
2004-01-10 03:03:08 +00:00
|
|
|
|
|
2004-10-31 04:55:57 +00:00
|
|
|
|
#ifdef HAVE_JOLIET
|
2004-10-24 03:29:31 +00:00
|
|
|
|
p_iso9660_dir = p_iso->i_joliet_level
|
2004-10-24 23:42:39 +00:00
|
|
|
|
? &(p_iso->svd.root_directory_record)
|
|
|
|
|
|
: &(p_iso->pvd.root_directory_record) ;
|
2004-10-31 04:55:57 +00:00
|
|
|
|
#else
|
|
|
|
|
|
p_iso9660_dir = &(p_iso->pvd.root_directory_record) ;
|
|
|
|
|
|
#endif
|
2004-10-24 23:42:39 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
p_stat = _iso9660_dir_to_statbuf (p_iso9660_dir, true,
|
|
|
|
|
|
p_iso->i_joliet_level);
|
|
|
|
|
|
return p_stat;
|
2004-01-10 03:03:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
static iso9660_stat_t *
|
2005-01-02 22:43:41 +00:00
|
|
|
|
_fs_stat_traverse (const CdIo_t *p_cdio, const iso9660_stat_t *_root,
|
2004-10-23 20:55:08 +00:00
|
|
|
|
char **splitpath, bool b_mode2, bool translate)
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
|
|
|
|
|
unsigned offset = 0;
|
|
|
|
|
|
uint8_t *_dirbuf = NULL;
|
2004-10-26 01:21:05 +00:00
|
|
|
|
iso9660_stat_t *p_stat;
|
|
|
|
|
|
generic_img_private_t *p_env = (generic_img_private_t *) p_cdio->env;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
|
|
|
|
|
if (!splitpath[0])
|
|
|
|
|
|
{
|
2003-11-16 19:30:45 +00:00
|
|
|
|
unsigned int len=sizeof(iso9660_stat_t) + strlen(_root->filename)+1;
|
2004-10-26 01:21:05 +00:00
|
|
|
|
p_stat = _cdio_malloc(len);
|
|
|
|
|
|
memcpy(p_stat, _root, len);
|
|
|
|
|
|
return p_stat;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_root->type == _STAT_FILE)
|
2003-11-16 19:30:45 +00:00
|
|
|
|
return NULL;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
|
|
|
|
|
cdio_assert (_root->type == _STAT_DIR);
|
|
|
|
|
|
|
|
|
|
|
|
if (_root->size != ISO_BLOCKSIZE * _root->secsize)
|
|
|
|
|
|
{
|
2003-09-14 06:35:59 +00:00
|
|
|
|
cdio_warn ("bad size for ISO9660 directory (%ud) should be (%lu)!",
|
|
|
|
|
|
(unsigned) _root->size,
|
|
|
|
|
|
(unsigned long int) ISO_BLOCKSIZE * _root->secsize);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_dirbuf = _cdio_malloc (_root->secsize * ISO_BLOCKSIZE);
|
|
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (b_mode2) {
|
2004-10-26 01:21:05 +00:00
|
|
|
|
if (cdio_read_mode2_sectors (p_cdio, _dirbuf, _root->lsn, false,
|
2003-08-31 15:52:56 +00:00
|
|
|
|
_root->secsize))
|
2004-01-10 03:03:08 +00:00
|
|
|
|
return NULL;
|
2003-08-31 15:52:56 +00:00
|
|
|
|
} else {
|
2004-10-26 01:21:05 +00:00
|
|
|
|
if (cdio_read_mode1_sectors (p_cdio, _dirbuf, _root->lsn, false,
|
2003-08-31 15:52:56 +00:00
|
|
|
|
_root->secsize))
|
2004-01-10 03:03:08 +00:00
|
|
|
|
return NULL;
|
2003-08-31 15:52:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-08-31 06:59:23 +00:00
|
|
|
|
while (offset < (_root->secsize * ISO_BLOCKSIZE))
|
|
|
|
|
|
{
|
2004-10-23 20:55:08 +00:00
|
|
|
|
iso9660_dir_t *p_iso9660_dir = (void *) &_dirbuf[offset];
|
2004-10-26 01:21:05 +00:00
|
|
|
|
iso9660_stat_t *p_stat;
|
2004-02-26 00:13:24 +00:00
|
|
|
|
int cmp;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (!iso9660_get_dir_len(p_iso9660_dir))
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
|
|
|
|
|
offset++;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-10-26 01:21:05 +00:00
|
|
|
|
p_stat = _iso9660_dir_to_statbuf (p_iso9660_dir, b_mode2,
|
|
|
|
|
|
p_env->i_joliet_level);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2004-02-26 00:13:24 +00:00
|
|
|
|
if (translate) {
|
2004-10-26 01:21:05 +00:00
|
|
|
|
char *trans_fname = malloc(strlen(p_stat->filename));
|
2004-02-26 00:13:24 +00:00
|
|
|
|
int trans_len;
|
|
|
|
|
|
|
|
|
|
|
|
if (trans_fname == NULL) {
|
2004-02-26 01:33:01 +00:00
|
|
|
|
cdio_warn("can't allocate %lu bytes",
|
2004-10-26 01:21:05 +00:00
|
|
|
|
(long unsigned int) strlen(p_stat->filename));
|
2004-02-26 00:13:24 +00:00
|
|
|
|
return NULL;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
}
|
2004-10-26 01:21:05 +00:00
|
|
|
|
trans_len = iso9660_name_translate_ext(p_stat->filename, trans_fname,
|
|
|
|
|
|
p_env->i_joliet_level);
|
2004-02-26 00:13:24 +00:00
|
|
|
|
cmp = strcmp(splitpath[0], trans_fname);
|
|
|
|
|
|
free(trans_fname);
|
|
|
|
|
|
} else {
|
2004-10-26 01:21:05 +00:00
|
|
|
|
cmp = strcmp(splitpath[0], p_stat->filename);
|
2004-02-26 00:13:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!cmp) {
|
|
|
|
|
|
iso9660_stat_t *ret_stat
|
2004-10-26 01:21:05 +00:00
|
|
|
|
= _fs_stat_traverse (p_cdio, p_stat, &splitpath[1], b_mode2,
|
2004-02-26 00:13:24 +00:00
|
|
|
|
translate);
|
2004-10-26 01:21:05 +00:00
|
|
|
|
free(p_stat);
|
2004-02-26 00:13:24 +00:00
|
|
|
|
free (_dirbuf);
|
|
|
|
|
|
return ret_stat;
|
|
|
|
|
|
}
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2004-10-26 01:21:05 +00:00
|
|
|
|
free(p_stat);
|
2003-11-16 19:30:45 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
offset += iso9660_get_dir_len(p_iso9660_dir);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cdio_assert (offset == (_root->secsize * ISO_BLOCKSIZE));
|
|
|
|
|
|
|
|
|
|
|
|
/* not found */
|
|
|
|
|
|
free (_dirbuf);
|
2003-11-16 19:30:45 +00:00
|
|
|
|
return NULL;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-01-10 03:03:08 +00:00
|
|
|
|
static iso9660_stat_t *
|
2004-10-23 20:55:08 +00:00
|
|
|
|
_fs_iso_stat_traverse (iso9660_t *p_iso, const iso9660_stat_t *_root,
|
2004-02-26 00:13:24 +00:00
|
|
|
|
char **splitpath, bool translate)
|
2004-01-10 03:03:08 +00:00
|
|
|
|
{
|
|
|
|
|
|
unsigned offset = 0;
|
|
|
|
|
|
uint8_t *_dirbuf = NULL;
|
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
|
|
if (!splitpath[0])
|
|
|
|
|
|
{
|
2004-10-23 20:55:08 +00:00
|
|
|
|
iso9660_stat_t *p_stat;
|
2004-01-10 03:03:08 +00:00
|
|
|
|
unsigned int len=sizeof(iso9660_stat_t) + strlen(_root->filename)+1;
|
2004-10-23 20:55:08 +00:00
|
|
|
|
p_stat = _cdio_malloc(len);
|
|
|
|
|
|
memcpy(p_stat, _root, len);
|
|
|
|
|
|
return p_stat;
|
2004-01-10 03:03:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_root->type == _STAT_FILE)
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
cdio_assert (_root->type == _STAT_DIR);
|
|
|
|
|
|
|
|
|
|
|
|
if (_root->size != ISO_BLOCKSIZE * _root->secsize)
|
|
|
|
|
|
{
|
|
|
|
|
|
cdio_warn ("bad size for ISO9660 directory (%ud) should be (%lu)!",
|
|
|
|
|
|
(unsigned) _root->size,
|
|
|
|
|
|
(unsigned long int) ISO_BLOCKSIZE * _root->secsize);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_dirbuf = _cdio_malloc (_root->secsize * ISO_BLOCKSIZE);
|
|
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
ret = iso9660_iso_seek_read (p_iso, _dirbuf, _root->lsn, _root->secsize);
|
2004-01-10 03:03:08 +00:00
|
|
|
|
if (ret!=ISO_BLOCKSIZE*_root->secsize) return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
while (offset < (_root->secsize * ISO_BLOCKSIZE))
|
|
|
|
|
|
{
|
2004-10-23 20:55:08 +00:00
|
|
|
|
iso9660_dir_t *p_iso9660_dir = (void *) &_dirbuf[offset];
|
|
|
|
|
|
iso9660_stat_t *p_stat;
|
2004-02-26 00:13:24 +00:00
|
|
|
|
int cmp;
|
2004-01-10 03:03:08 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (!iso9660_get_dir_len(p_iso9660_dir))
|
2004-01-10 03:03:08 +00:00
|
|
|
|
{
|
|
|
|
|
|
offset++;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
p_stat = _iso9660_dir_to_statbuf (p_iso9660_dir, true,
|
|
|
|
|
|
p_iso->i_joliet_level);
|
2004-01-10 03:03:08 +00:00
|
|
|
|
|
2004-02-26 00:13:24 +00:00
|
|
|
|
if (translate) {
|
2004-10-23 20:55:08 +00:00
|
|
|
|
char *trans_fname = malloc(strlen(p_stat->filename)+1);
|
2004-02-26 00:13:24 +00:00
|
|
|
|
int trans_len;
|
|
|
|
|
|
|
|
|
|
|
|
if (trans_fname == NULL) {
|
2004-02-26 01:33:01 +00:00
|
|
|
|
cdio_warn("can't allocate %lu bytes",
|
2004-10-23 20:55:08 +00:00
|
|
|
|
(long unsigned int) strlen(p_stat->filename));
|
2004-02-26 00:13:24 +00:00
|
|
|
|
return NULL;
|
2004-01-10 03:03:08 +00:00
|
|
|
|
}
|
2004-10-23 20:55:08 +00:00
|
|
|
|
trans_len = iso9660_name_translate_ext(p_stat->filename, trans_fname,
|
|
|
|
|
|
p_iso->i_joliet_level);
|
2004-02-26 00:13:24 +00:00
|
|
|
|
cmp = strcmp(splitpath[0], trans_fname);
|
|
|
|
|
|
free(trans_fname);
|
|
|
|
|
|
} else {
|
2004-10-23 20:55:08 +00:00
|
|
|
|
cmp = strcmp(splitpath[0], p_stat->filename);
|
2004-02-26 00:13:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!cmp) {
|
|
|
|
|
|
iso9660_stat_t *ret_stat
|
2004-10-23 20:55:08 +00:00
|
|
|
|
= _fs_iso_stat_traverse (p_iso, p_stat, &splitpath[1], translate);
|
|
|
|
|
|
free(p_stat);
|
2004-02-26 00:13:24 +00:00
|
|
|
|
free (_dirbuf);
|
|
|
|
|
|
return ret_stat;
|
|
|
|
|
|
}
|
2004-01-10 03:03:08 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
free(p_stat);
|
2004-01-10 03:03:08 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
offset += iso9660_get_dir_len(p_iso9660_dir);
|
2004-01-10 03:03:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cdio_assert (offset == (_root->secsize * ISO_BLOCKSIZE));
|
|
|
|
|
|
|
|
|
|
|
|
/* not found */
|
|
|
|
|
|
free (_dirbuf);
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-09-06 14:50:50 +00:00
|
|
|
|
/*!
|
2003-11-16 19:30:45 +00:00
|
|
|
|
Get file status for pathname into stat. NULL is returned on error.
|
2003-09-06 14:50:50 +00:00
|
|
|
|
*/
|
2003-11-16 19:30:45 +00:00
|
|
|
|
iso9660_stat_t *
|
2005-01-02 22:43:41 +00:00
|
|
|
|
iso9660_fs_stat (CdIo_t *p_cdio, const char pathname[])
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
2004-10-24 23:42:39 +00:00
|
|
|
|
iso9660_stat_t *p_root;
|
|
|
|
|
|
char **p_psz_splitpath;
|
|
|
|
|
|
iso9660_stat_t *p_stat;
|
|
|
|
|
|
/* A bit of a hack, we'll assume track 1 contains ISO_PVD_SECTOR.*/
|
|
|
|
|
|
bool b_mode2;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2004-10-24 23:42:39 +00:00
|
|
|
|
if (!p_cdio) return NULL;
|
|
|
|
|
|
if (!pathname) return NULL;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2004-10-24 23:42:39 +00:00
|
|
|
|
p_root = _fs_stat_root (p_cdio);
|
|
|
|
|
|
if (!p_root) return NULL;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2004-10-24 23:42:39 +00:00
|
|
|
|
b_mode2 = cdio_get_track_green(p_cdio, 1);
|
|
|
|
|
|
p_psz_splitpath = _cdio_strsplit (pathname, '/');
|
|
|
|
|
|
p_stat = _fs_stat_traverse (p_cdio, p_root, p_psz_splitpath, b_mode2, false);
|
|
|
|
|
|
free(p_root);
|
|
|
|
|
|
_cdio_strfreev (p_psz_splitpath);
|
2004-02-26 00:13:24 +00:00
|
|
|
|
|
2004-10-24 23:42:39 +00:00
|
|
|
|
return p_stat;
|
2004-02-26 00:13:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Get file status for pathname 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 *
|
2005-01-02 22:43:41 +00:00
|
|
|
|
iso9660_fs_stat_translate (CdIo_t *p_cdio, const char pathname[],
|
2004-10-23 20:55:08 +00:00
|
|
|
|
bool b_mode2)
|
2004-02-26 00:13:24 +00:00
|
|
|
|
{
|
2004-10-24 23:42:39 +00:00
|
|
|
|
iso9660_stat_t *p_root;
|
|
|
|
|
|
char **p_psz_splitpath;
|
|
|
|
|
|
iso9660_stat_t *p_stat;
|
2004-02-26 00:13:24 +00:00
|
|
|
|
|
2004-10-24 23:42:39 +00:00
|
|
|
|
if (!p_cdio) return NULL;
|
|
|
|
|
|
if (pathname) return NULL;
|
2004-02-26 00:13:24 +00:00
|
|
|
|
|
2004-10-24 23:42:39 +00:00
|
|
|
|
p_root = _fs_stat_root (p_cdio);
|
|
|
|
|
|
if (!p_root) return NULL;
|
2004-02-26 00:13:24 +00:00
|
|
|
|
|
2004-10-24 23:42:39 +00:00
|
|
|
|
p_psz_splitpath = _cdio_strsplit (pathname, '/');
|
|
|
|
|
|
p_stat = _fs_stat_traverse (p_cdio, p_root, p_psz_splitpath, b_mode2, true);
|
|
|
|
|
|
free(p_root);
|
|
|
|
|
|
_cdio_strfreev (p_psz_splitpath);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2004-10-24 23:42:39 +00:00
|
|
|
|
return p_stat;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-01-10 03:03:08 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Get file status for pathname into stat. NULL is returned on error.
|
|
|
|
|
|
*/
|
2004-10-09 23:20:52 +00:00
|
|
|
|
iso9660_stat_t *
|
2004-10-23 20:55:08 +00:00
|
|
|
|
iso9660_ifs_stat (iso9660_t *p_iso, const char pathname[])
|
2004-01-10 03:03:08 +00:00
|
|
|
|
{
|
2004-10-23 20:55:08 +00:00
|
|
|
|
iso9660_stat_t *p_root;
|
2004-01-10 03:03:08 +00:00
|
|
|
|
char **splitpath;
|
|
|
|
|
|
iso9660_stat_t *stat;
|
|
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (!p_iso) return NULL;
|
|
|
|
|
|
if (!pathname) return NULL;
|
2004-01-10 03:03:08 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
p_root = _fs_stat_iso_root (p_iso);
|
|
|
|
|
|
if (!p_root) return NULL;
|
2004-01-10 03:03:08 +00:00
|
|
|
|
|
|
|
|
|
|
splitpath = _cdio_strsplit (pathname, '/');
|
2004-10-23 20:55:08 +00:00
|
|
|
|
stat = _fs_iso_stat_traverse (p_iso, p_root, splitpath, false);
|
|
|
|
|
|
free(p_root);
|
|
|
|
|
|
/*** FIXME _cdio_strfreev (splitpath); ***/
|
2004-01-10 03:03:08 +00:00
|
|
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-02-26 00:13:24 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Get file status for pathname 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.
|
|
|
|
|
|
*/
|
2004-10-09 23:20:52 +00:00
|
|
|
|
iso9660_stat_t *
|
2004-10-24 23:42:39 +00:00
|
|
|
|
iso9660_ifs_stat_translate (iso9660_t *p_iso, const char pathname[])
|
2004-02-26 00:13:24 +00:00
|
|
|
|
{
|
2004-10-23 20:55:08 +00:00
|
|
|
|
iso9660_stat_t *p_root;
|
2004-10-24 23:42:39 +00:00
|
|
|
|
char **p_psz_splitpath;
|
|
|
|
|
|
iso9660_stat_t *p_stat;
|
2004-02-26 00:13:24 +00:00
|
|
|
|
|
2004-10-24 23:42:39 +00:00
|
|
|
|
if (!p_iso) return NULL;
|
|
|
|
|
|
if (!pathname) return NULL;
|
2004-02-26 00:13:24 +00:00
|
|
|
|
|
2004-10-24 23:42:39 +00:00
|
|
|
|
p_root = _fs_stat_iso_root (p_iso);
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (NULL == p_root) return NULL;
|
2004-02-26 00:13:24 +00:00
|
|
|
|
|
2004-10-24 23:42:39 +00:00
|
|
|
|
p_psz_splitpath = _cdio_strsplit (pathname, '/');
|
|
|
|
|
|
p_stat = _fs_iso_stat_traverse (p_iso, p_root, p_psz_splitpath, true);
|
2004-10-23 20:55:08 +00:00
|
|
|
|
free(p_root);
|
2004-10-24 23:42:39 +00:00
|
|
|
|
_cdio_strfreev (p_psz_splitpath);
|
2004-02-26 00:13:24 +00:00
|
|
|
|
|
2004-10-24 23:42:39 +00:00
|
|
|
|
return p_stat;
|
2004-02-26 00:13:24 +00:00
|
|
|
|
}
|
2003-11-10 04:01:16 +00:00
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Read pathname (a directory) and return a list of iso9660_stat_t
|
|
|
|
|
|
of the files inside that. The caller must free the returned result.
|
2003-11-10 04:01:16 +00:00
|
|
|
|
*/
|
2004-10-09 23:20:52 +00:00
|
|
|
|
CdioList *
|
2005-01-02 22:43:41 +00:00
|
|
|
|
iso9660_fs_readdir (CdIo_t *p_cdio, const char pathname[], bool b_mode2)
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
2004-10-23 20:55:08 +00:00
|
|
|
|
iso9660_stat_t *p_stat;
|
2004-10-26 01:21:05 +00:00
|
|
|
|
generic_img_private_t *p_env = (generic_img_private_t *) p_cdio->env;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2004-10-24 23:42:39 +00:00
|
|
|
|
if (!p_cdio) return NULL;
|
|
|
|
|
|
if (!pathname) return NULL;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2004-10-24 23:42:39 +00:00
|
|
|
|
p_stat = iso9660_fs_stat (p_cdio, pathname);
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (!p_stat) return NULL;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (p_stat->type != _STAT_DIR) {
|
|
|
|
|
|
free(p_stat);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
return NULL;
|
2003-11-16 19:30:45 +00:00
|
|
|
|
}
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
unsigned offset = 0;
|
|
|
|
|
|
uint8_t *_dirbuf = NULL;
|
|
|
|
|
|
CdioList *retval = _cdio_list_new ();
|
|
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (p_stat->size != ISO_BLOCKSIZE * p_stat->secsize)
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
2003-09-14 06:35:59 +00:00
|
|
|
|
cdio_warn ("bad size for ISO9660 directory (%ud) should be (%lu)!",
|
2004-10-23 20:55:08 +00:00
|
|
|
|
(unsigned) p_stat->size,
|
|
|
|
|
|
(unsigned long int) ISO_BLOCKSIZE * p_stat->secsize);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
_dirbuf = _cdio_malloc (p_stat->secsize * ISO_BLOCKSIZE);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (b_mode2) {
|
2004-10-24 23:42:39 +00:00
|
|
|
|
if (cdio_read_mode2_sectors (p_cdio, _dirbuf, p_stat->lsn, false,
|
2004-10-23 20:55:08 +00:00
|
|
|
|
p_stat->secsize))
|
2003-08-31 14:26:06 +00:00
|
|
|
|
cdio_assert_not_reached ();
|
|
|
|
|
|
} else {
|
2004-10-24 23:42:39 +00:00
|
|
|
|
if (cdio_read_mode1_sectors (p_cdio, _dirbuf, p_stat->lsn, false,
|
2004-10-23 20:55:08 +00:00
|
|
|
|
p_stat->secsize))
|
2003-08-31 14:26:06 +00:00
|
|
|
|
cdio_assert_not_reached ();
|
|
|
|
|
|
}
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
while (offset < (p_stat->secsize * ISO_BLOCKSIZE))
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
2004-10-23 20:55:08 +00:00
|
|
|
|
iso9660_dir_t *p_iso9660_dir = (void *) &_dirbuf[offset];
|
|
|
|
|
|
iso9660_stat_t *p_iso9660_stat;
|
2003-11-16 19:30:45 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (!iso9660_get_dir_len(p_iso9660_dir))
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
|
|
|
|
|
offset++;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-10-26 01:21:05 +00:00
|
|
|
|
p_iso9660_stat = _iso9660_dir_to_statbuf(p_iso9660_dir, b_mode2,
|
|
|
|
|
|
p_env->i_joliet_level);
|
2004-10-23 20:55:08 +00:00
|
|
|
|
_cdio_list_append (retval, p_iso9660_stat);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
offset += iso9660_get_dir_len(p_iso9660_dir);
|
2004-01-10 03:21:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
cdio_assert (offset == (p_stat->secsize * ISO_BLOCKSIZE));
|
2004-01-10 03:21:50 +00:00
|
|
|
|
|
|
|
|
|
|
free (_dirbuf);
|
2004-10-23 20:55:08 +00:00
|
|
|
|
free (p_stat);
|
2004-01-10 03:21:50 +00:00
|
|
|
|
return retval;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Read pathname (a directory) and return a list of iso9660_stat_t
|
|
|
|
|
|
of the files inside that. The caller must free the returned result.
|
|
|
|
|
|
*/
|
2004-10-09 23:20:52 +00:00
|
|
|
|
CdioList *
|
2004-10-23 20:55:08 +00:00
|
|
|
|
iso9660_ifs_readdir (iso9660_t *p_iso, const char pathname[])
|
2004-01-10 03:21:50 +00:00
|
|
|
|
{
|
2004-10-23 20:55:08 +00:00
|
|
|
|
iso9660_stat_t *p_stat;
|
2004-01-10 03:21:50 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (!p_iso) return NULL;
|
|
|
|
|
|
if (!pathname) return NULL;
|
2004-01-10 03:21:50 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
p_stat = iso9660_ifs_stat (p_iso, pathname);
|
|
|
|
|
|
if (!p_stat) return NULL;
|
2004-01-10 03:21:50 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (p_stat->type != _STAT_DIR) {
|
|
|
|
|
|
free(p_stat);
|
2004-01-10 03:21:50 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
long int ret;
|
|
|
|
|
|
unsigned offset = 0;
|
|
|
|
|
|
uint8_t *_dirbuf = NULL;
|
|
|
|
|
|
CdioList *retval = _cdio_list_new ();
|
|
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (p_stat->size != ISO_BLOCKSIZE * p_stat->secsize)
|
2004-01-10 03:21:50 +00:00
|
|
|
|
{
|
|
|
|
|
|
cdio_warn ("bad size for ISO9660 directory (%ud) should be (%lu)!",
|
2004-10-23 20:55:08 +00:00
|
|
|
|
(unsigned int) p_stat->size,
|
|
|
|
|
|
(unsigned long int) ISO_BLOCKSIZE * p_stat->secsize);
|
2004-01-10 03:21:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
_dirbuf = _cdio_malloc (p_stat->secsize * ISO_BLOCKSIZE);
|
2004-01-10 03:21:50 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
ret = iso9660_iso_seek_read (p_iso, _dirbuf, p_stat->lsn, p_stat->secsize);
|
|
|
|
|
|
if (ret != ISO_BLOCKSIZE*p_stat->secsize) return NULL;
|
2004-01-10 03:21:50 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
while (offset < (p_stat->secsize * ISO_BLOCKSIZE))
|
2004-01-10 03:21:50 +00:00
|
|
|
|
{
|
2004-10-23 20:55:08 +00:00
|
|
|
|
iso9660_dir_t *p_iso9660_dir = (void *) &_dirbuf[offset];
|
|
|
|
|
|
iso9660_stat_t *p_iso9660_stat;
|
2004-01-10 03:21:50 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
if (!iso9660_get_dir_len(p_iso9660_dir))
|
2004-01-10 03:21:50 +00:00
|
|
|
|
{
|
|
|
|
|
|
offset++;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
p_iso9660_stat = _iso9660_dir_to_statbuf(p_iso9660_dir, true,
|
|
|
|
|
|
p_iso->i_joliet_level);
|
|
|
|
|
|
_cdio_list_append (retval, p_iso9660_stat);
|
2004-01-10 03:21:50 +00:00
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
offset += iso9660_get_dir_len(p_iso9660_dir);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-10-23 20:55:08 +00:00
|
|
|
|
cdio_assert (offset == (p_stat->secsize * ISO_BLOCKSIZE));
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
|
|
|
|
|
free (_dirbuf);
|
2004-10-23 20:55:08 +00:00
|
|
|
|
free (p_stat);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
return retval;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
static iso9660_stat_t *
|
2005-01-02 22:43:41 +00:00
|
|
|
|
find_fs_lsn_recurse (CdIo_t *p_cdio, const char pathname[], lsn_t lsn)
|
2003-09-05 22:48:16 +00:00
|
|
|
|
{
|
2004-10-24 23:42:39 +00:00
|
|
|
|
CdioList *entlist = iso9660_fs_readdir (p_cdio, pathname, true);
|
2003-09-05 22:48:16 +00:00
|
|
|
|
CdioList *dirlist = _cdio_list_new ();
|
|
|
|
|
|
CdioListNode *entnode;
|
|
|
|
|
|
|
|
|
|
|
|
cdio_assert (entlist != NULL);
|
|
|
|
|
|
|
|
|
|
|
|
/* iterate over each entry in the directory */
|
|
|
|
|
|
|
|
|
|
|
|
_CDIO_LIST_FOREACH (entnode, entlist)
|
|
|
|
|
|
{
|
2003-11-16 19:30:45 +00:00
|
|
|
|
iso9660_stat_t *statbuf = _cdio_list_node_data (entnode);
|
2003-09-05 22:48:16 +00:00
|
|
|
|
char _fullname[4096] = { 0, };
|
2003-11-16 19:30:45 +00:00
|
|
|
|
char *filename = (char *) statbuf->filename;
|
2003-09-05 22:48:16 +00:00
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
snprintf (_fullname, sizeof (_fullname), "%s%s", pathname, filename);
|
2003-09-05 22:48:16 +00:00
|
|
|
|
|
|
|
|
|
|
strncat (_fullname, "/", sizeof (_fullname));
|
|
|
|
|
|
|
|
|
|
|
|
if (statbuf->type == _STAT_DIR
|
2003-11-16 19:30:45 +00:00
|
|
|
|
&& strcmp ((char *) statbuf->filename, ".")
|
|
|
|
|
|
&& strcmp ((char *) statbuf->filename, ".."))
|
2003-09-05 22:48:16 +00:00
|
|
|
|
_cdio_list_append (dirlist, strdup (_fullname));
|
|
|
|
|
|
|
|
|
|
|
|
if (statbuf->lsn == lsn) {
|
2003-11-16 19:30:45 +00:00
|
|
|
|
unsigned int len=sizeof(iso9660_stat_t)+strlen(statbuf->filename)+1;
|
|
|
|
|
|
iso9660_stat_t *ret_stat = _cdio_malloc(len);
|
|
|
|
|
|
memcpy(ret_stat, statbuf, len);
|
2003-09-05 22:48:16 +00:00
|
|
|
|
_cdio_list_free (entlist, true);
|
|
|
|
|
|
_cdio_list_free (dirlist, true);
|
2003-11-16 19:30:45 +00:00
|
|
|
|
return ret_stat;
|
2003-09-05 22:48:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_cdio_list_free (entlist, true);
|
|
|
|
|
|
|
|
|
|
|
|
/* now recurse/descend over directories encountered */
|
|
|
|
|
|
|
|
|
|
|
|
_CDIO_LIST_FOREACH (entnode, dirlist)
|
|
|
|
|
|
{
|
|
|
|
|
|
char *_fullname = _cdio_list_node_data (entnode);
|
2004-10-24 23:42:39 +00:00
|
|
|
|
iso9660_stat_t *ret_stat = find_fs_lsn_recurse (p_cdio, _fullname, lsn);
|
2003-09-05 22:48:16 +00:00
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
if (NULL != ret_stat) {
|
2003-09-05 22:48:16 +00:00
|
|
|
|
_cdio_list_free (dirlist, true);
|
2003-11-16 19:30:45 +00:00
|
|
|
|
return ret_stat;
|
2003-09-05 22:48:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_cdio_list_free (dirlist, true);
|
2003-11-16 19:30:45 +00:00
|
|
|
|
return NULL;
|
2003-09-05 22:48:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Given a directory pointer, find the filesystem entry that contains
|
2003-11-16 19:30:45 +00:00
|
|
|
|
lsn and return information about it.
|
2003-09-05 22:48:16 +00:00
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
Returns stat_t of entry if we found lsn, or NULL otherwise.
|
2003-09-05 22:48:16 +00:00
|
|
|
|
*/
|
2003-11-16 19:30:45 +00:00
|
|
|
|
iso9660_stat_t *
|
2005-01-02 22:43:41 +00:00
|
|
|
|
iso9660_find_fs_lsn(CdIo_t *p_cdio, lsn_t i_lsn)
|
2003-09-05 22:48:16 +00:00
|
|
|
|
{
|
2004-10-24 23:42:39 +00:00
|
|
|
|
return find_fs_lsn_recurse (p_cdio, "/", i_lsn);
|
2003-09-05 22:48:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-10-22 01:13:38 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
Return true if ISO 9660 image has extended attrributes (XA).
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool
|
|
|
|
|
|
iso9660_ifs_is_xa (const iso9660_t * p_iso)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!p_iso) return false;
|
|
|
|
|
|
return p_iso->b_xa;
|
|
|
|
|
|
}
|