2003-08-31 06:59:23 +00:00
|
|
|
|
/*
|
2004-01-10 03:03:08 +00:00
|
|
|
|
$Id: iso9660_fs.c,v 1.14 2004/01/10 03:03:08 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
|
2003-08-31 06:59:23 +00:00
|
|
|
|
#include <string.h>
|
2003-08-31 09:11:25 +00:00
|
|
|
|
#endif
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
|
|
|
|
|
#include <cdio/cdio.h>
|
|
|
|
|
|
#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"
|
|
|
|
|
|
#include "bytesex.h"
|
|
|
|
|
|
#include "ds.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>
|
|
|
|
|
|
|
2004-01-10 03:03:08 +00:00
|
|
|
|
static const char _rcsid[] = "$Id: iso9660_fs.c,v 1.14 2004/01/10 03:03:08 rocky Exp $";
|
|
|
|
|
|
|
|
|
|
|
|
/* Implementation of iso9660_t type */
|
|
|
|
|
|
struct _iso9660 {
|
|
|
|
|
|
CdioDataSource *stream; /* Stream pointer */
|
|
|
|
|
|
void *env; /* environment. */
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Open an ISO 9660 image for reading. Maybe in the future we will have
|
|
|
|
|
|
flags and mode. NULL is returned on error.
|
|
|
|
|
|
*/
|
|
|
|
|
|
iso9660_t *
|
|
|
|
|
|
iso9660_open (const char *pathname /*flags, mode */)
|
|
|
|
|
|
{
|
|
|
|
|
|
iso9660_t *iso = (iso9660_t *) _cdio_malloc(sizeof(struct _iso9660)) ;
|
|
|
|
|
|
|
|
|
|
|
|
if (NULL == iso) return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
iso->stream = cdio_stdio_new( pathname );
|
|
|
|
|
|
if (NULL == iso->stream) {
|
|
|
|
|
|
free(iso);
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return iso;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Close previously opened ISO 9660 image.
|
|
|
|
|
|
True is unconditionally returned. If there was an error false would
|
|
|
|
|
|
be returned.
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool
|
|
|
|
|
|
iso9660_close (iso9660_t *iso)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (NULL != iso) {
|
|
|
|
|
|
cdio_stream_destroy(iso->stream);
|
|
|
|
|
|
free(iso);
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
Seek to a position and then read n blocks. Size read is returned.
|
|
|
|
|
|
*/
|
|
|
|
|
|
long int
|
|
|
|
|
|
iso9660_iso_seek_read (iso9660_t *iso, void *ptr, lsn_t start, long int size)
|
|
|
|
|
|
{
|
|
|
|
|
|
long int ret;
|
|
|
|
|
|
if (NULL == iso) return 0;
|
|
|
|
|
|
ret = cdio_stream_seek (iso->stream, start * ISO_BLOCKSIZE, SEEK_SET);
|
|
|
|
|
|
if (ret!=0) return 0;
|
|
|
|
|
|
return cdio_stream_read (iso->stream, ptr, ISO_BLOCKSIZE, size);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
static iso9660_stat_t *
|
|
|
|
|
|
_iso9660_dir_to_statbuf (const iso9660_dir_t *iso9660_dir, bool is_mode2)
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
|
|
|
|
|
iso9660_xa_t *xa_data = NULL;
|
2003-11-10 04:01:16 +00:00
|
|
|
|
uint8_t dir_len= iso9660_get_dir_len(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
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
filename_len = from_711(iso9660_dir->filename_len);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
/* .. string in statbuf is one longer than in iso9660_dir's listing '\1' */
|
|
|
|
|
|
stat_len = sizeof(iso9660_stat_t)+filename_len+2;
|
|
|
|
|
|
|
|
|
|
|
|
stat = _cdio_malloc(stat_len);
|
2003-11-10 04:01:16 +00:00
|
|
|
|
stat->type = (iso9660_dir->file_flags & ISO_DIRECTORY)
|
|
|
|
|
|
? _STAT_DIR : _STAT_FILE;
|
|
|
|
|
|
stat->lsn = from_733 (iso9660_dir->extent);
|
|
|
|
|
|
stat->size = from_733 (iso9660_dir->size);
|
2003-09-07 18:15:26 +00:00
|
|
|
|
stat->secsize = _cdio_len2blocks (stat->size, ISO_BLOCKSIZE);
|
|
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
if (iso9660_dir->filename[0] == '\0')
|
|
|
|
|
|
strcpy (stat->filename, ".");
|
|
|
|
|
|
else if (iso9660_dir->filename[0] == '\1')
|
|
|
|
|
|
strcpy (stat->filename, "..");
|
|
|
|
|
|
else
|
|
|
|
|
|
strncpy (stat->filename, iso9660_dir->filename, filename_len);
|
|
|
|
|
|
|
2003-11-10 04:01:16 +00:00
|
|
|
|
iso9660_get_dtime(&(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
|
|
|
|
|
2003-08-31 15:52:56 +00:00
|
|
|
|
if (is_mode2) {
|
2003-11-10 04:01:16 +00:00
|
|
|
|
int su_length = iso9660_get_dir_len(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
|
|
|
|
|
2003-11-10 04:01:16 +00:00
|
|
|
|
xa_data = (void *) (((char *) iso9660_dir)
|
|
|
|
|
|
+ (iso9660_get_dir_len(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)",
|
|
|
|
|
|
iso9660_get_dir_len(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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
static iso9660_stat_t *
|
|
|
|
|
|
_fs_stat_root (const CdIo *cdio, bool is_mode2)
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
|
|
|
|
|
char block[ISO_BLOCKSIZE] = { 0, };
|
|
|
|
|
|
const iso9660_pvd_t *pvd = (void *) █
|
2003-11-10 04:01:16 +00:00
|
|
|
|
const iso9660_dir_t *iso9660_dir = (void *) pvd->root_directory_record;
|
2003-11-16 19:30:45 +00:00
|
|
|
|
iso9660_stat_t *stat;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-08-31 14:26:06 +00:00
|
|
|
|
if (is_mode2) {
|
2003-09-05 22:48:16 +00:00
|
|
|
|
if (cdio_read_mode2_sector (cdio, &block, ISO_PVD_SECTOR, false))
|
2003-08-31 14:26:06 +00:00
|
|
|
|
cdio_assert_not_reached ();
|
|
|
|
|
|
} else {
|
2003-09-05 22:48:16 +00:00
|
|
|
|
if (cdio_read_mode1_sector (cdio, &block, ISO_PVD_SECTOR, false))
|
2003-08-31 14:26:06 +00:00
|
|
|
|
cdio_assert_not_reached ();
|
|
|
|
|
|
}
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
stat = _iso9660_dir_to_statbuf (iso9660_dir, is_mode2);
|
|
|
|
|
|
return stat;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-01-10 03:03:08 +00:00
|
|
|
|
static iso9660_stat_t *
|
|
|
|
|
|
_fs_stat_iso_root (iso9660_t *iso)
|
|
|
|
|
|
{
|
|
|
|
|
|
char block[ISO_BLOCKSIZE] = { 0, };
|
|
|
|
|
|
const iso9660_pvd_t *pvd = (void *) █
|
|
|
|
|
|
const iso9660_dir_t *iso9660_dir = (void *) pvd->root_directory_record;
|
|
|
|
|
|
iso9660_stat_t *stat;
|
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
|
|
ret = iso9660_iso_seek_read (iso, block, ISO_PVD_SECTOR, 1);
|
|
|
|
|
|
if (ret!=ISO_BLOCKSIZE) return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
stat = _iso9660_dir_to_statbuf (iso9660_dir, true);
|
|
|
|
|
|
return stat;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
static iso9660_stat_t *
|
2003-09-05 22:48:16 +00:00
|
|
|
|
_fs_stat_traverse (const CdIo *cdio, const iso9660_stat_t *_root,
|
2003-11-16 19:30:45 +00:00
|
|
|
|
char **splitpath, bool is_mode2)
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
|
|
|
|
|
unsigned offset = 0;
|
|
|
|
|
|
uint8_t *_dirbuf = NULL;
|
2003-11-16 19:30:45 +00:00
|
|
|
|
iso9660_stat_t *stat;
|
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;
|
|
|
|
|
|
stat = _cdio_malloc(len);
|
|
|
|
|
|
memcpy(stat, _root, len);
|
|
|
|
|
|
return 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);
|
|
|
|
|
|
|
2003-08-31 15:52:56 +00:00
|
|
|
|
if (is_mode2) {
|
2003-09-05 22:48:16 +00:00
|
|
|
|
if (cdio_read_mode2_sectors (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 {
|
2003-09-05 22:48:16 +00:00
|
|
|
|
if (cdio_read_mode1_sectors (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))
|
|
|
|
|
|
{
|
2003-11-10 04:01:16 +00:00
|
|
|
|
const iso9660_dir_t *iso9660_dir = (void *) &_dirbuf[offset];
|
2003-11-16 19:30:45 +00:00
|
|
|
|
iso9660_stat_t *stat;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-11-10 04:01:16 +00:00
|
|
|
|
if (!iso9660_get_dir_len(iso9660_dir))
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
|
|
|
|
|
offset++;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
stat = _iso9660_dir_to_statbuf (iso9660_dir, is_mode2);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
if (!strcmp (splitpath[0], stat->filename))
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
2003-11-16 19:30:45 +00:00
|
|
|
|
iso9660_stat_t *ret_stat
|
|
|
|
|
|
= _fs_stat_traverse (cdio, stat, &splitpath[1], is_mode2);
|
|
|
|
|
|
free(stat);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
free (_dirbuf);
|
2003-11-16 19:30:45 +00:00
|
|
|
|
return ret_stat;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
free(stat);
|
|
|
|
|
|
|
2003-11-10 04:01:16 +00:00
|
|
|
|
offset += iso9660_get_dir_len(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 *
|
|
|
|
|
|
_fs_iso_stat_traverse (iso9660_t *iso, const iso9660_stat_t *_root,
|
|
|
|
|
|
char **splitpath)
|
|
|
|
|
|
{
|
|
|
|
|
|
unsigned offset = 0;
|
|
|
|
|
|
uint8_t *_dirbuf = NULL;
|
|
|
|
|
|
iso9660_stat_t *stat;
|
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
|
|
if (!splitpath[0])
|
|
|
|
|
|
{
|
|
|
|
|
|
unsigned int len=sizeof(iso9660_stat_t) + strlen(_root->filename)+1;
|
|
|
|
|
|
stat = _cdio_malloc(len);
|
|
|
|
|
|
memcpy(stat, _root, len);
|
|
|
|
|
|
return stat;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
ret = iso9660_iso_seek_read (iso, _dirbuf, _root->lsn, _root->secsize);
|
|
|
|
|
|
if (ret!=ISO_BLOCKSIZE*_root->secsize) return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
while (offset < (_root->secsize * ISO_BLOCKSIZE))
|
|
|
|
|
|
{
|
|
|
|
|
|
const iso9660_dir_t *iso9660_dir = (void *) &_dirbuf[offset];
|
|
|
|
|
|
iso9660_stat_t *stat;
|
|
|
|
|
|
|
|
|
|
|
|
if (!iso9660_get_dir_len(iso9660_dir))
|
|
|
|
|
|
{
|
|
|
|
|
|
offset++;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stat = _iso9660_dir_to_statbuf (iso9660_dir, true);
|
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp (splitpath[0], stat->filename))
|
|
|
|
|
|
{
|
|
|
|
|
|
iso9660_stat_t *ret_stat
|
|
|
|
|
|
= _fs_iso_stat_traverse (iso, stat, &splitpath[1]);
|
|
|
|
|
|
free(stat);
|
|
|
|
|
|
free (_dirbuf);
|
|
|
|
|
|
return ret_stat;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
free(stat);
|
|
|
|
|
|
|
|
|
|
|
|
offset += iso9660_get_dir_len(iso9660_dir);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 *
|
|
|
|
|
|
iso9660_fs_stat (const CdIo *cdio, const char pathname[], bool is_mode2)
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
2003-11-16 19:30:45 +00:00
|
|
|
|
iso9660_stat_t *root;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
char **splitpath;
|
2003-11-16 19:30:45 +00:00
|
|
|
|
iso9660_stat_t *stat;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2004-01-10 03:03:08 +00:00
|
|
|
|
if (cdio == NULL) return NULL;
|
|
|
|
|
|
if (pathname == NULL) return NULL;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
root = _fs_stat_root (cdio, is_mode2);
|
|
|
|
|
|
if (NULL == root) return NULL;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
|
|
|
|
|
splitpath = _cdio_strsplit (pathname, '/');
|
2003-11-16 19:30:45 +00:00
|
|
|
|
stat = _fs_stat_traverse (cdio, root, splitpath, is_mode2);
|
|
|
|
|
|
free(root);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
_cdio_strfreev (splitpath);
|
|
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
return 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.
|
|
|
|
|
|
*/
|
|
|
|
|
|
void *
|
|
|
|
|
|
iso9660_ifs_stat (iso9660_t *iso, const char pathname[])
|
|
|
|
|
|
{
|
|
|
|
|
|
iso9660_stat_t *root;
|
|
|
|
|
|
char **splitpath;
|
|
|
|
|
|
iso9660_stat_t *stat;
|
|
|
|
|
|
|
|
|
|
|
|
if (iso == NULL) return NULL;
|
|
|
|
|
|
if (pathname == NULL) return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
root = _fs_stat_iso_root (iso);
|
|
|
|
|
|
if (NULL == root) return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
splitpath = _cdio_strsplit (pathname, '/');
|
|
|
|
|
|
stat = _fs_iso_stat_traverse (iso, root, splitpath);
|
|
|
|
|
|
free(root);
|
|
|
|
|
|
_cdio_strfreev (splitpath);
|
|
|
|
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
|
void *
|
2003-09-05 22:48:16 +00:00
|
|
|
|
iso9660_fs_readdir (const CdIo *cdio, const char pathname[], bool is_mode2)
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
2003-11-16 19:30:45 +00:00
|
|
|
|
iso9660_stat_t *stat;
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-09-05 22:48:16 +00:00
|
|
|
|
cdio_assert (cdio != NULL);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
cdio_assert (pathname != NULL);
|
|
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
stat = iso9660_fs_stat (cdio, pathname, is_mode2);
|
|
|
|
|
|
if (NULL == stat)
|
2003-08-31 06:59:23 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
if (stat->type != _STAT_DIR) {
|
|
|
|
|
|
free(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 ();
|
|
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
if (stat->size != ISO_BLOCKSIZE * 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)!",
|
2003-11-16 19:30:45 +00:00
|
|
|
|
(unsigned) stat->size,
|
|
|
|
|
|
(unsigned long int) ISO_BLOCKSIZE * stat->secsize);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
_dirbuf = _cdio_malloc (stat->secsize * ISO_BLOCKSIZE);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-08-31 14:26:06 +00:00
|
|
|
|
if (is_mode2) {
|
2003-11-16 19:30:45 +00:00
|
|
|
|
if (cdio_read_mode2_sectors (cdio, _dirbuf, stat->lsn, false,
|
|
|
|
|
|
stat->secsize))
|
2003-08-31 14:26:06 +00:00
|
|
|
|
cdio_assert_not_reached ();
|
|
|
|
|
|
} else {
|
2003-11-16 19:30:45 +00:00
|
|
|
|
if (cdio_read_mode1_sectors (cdio, _dirbuf, stat->lsn, false,
|
|
|
|
|
|
stat->secsize))
|
2003-08-31 14:26:06 +00:00
|
|
|
|
cdio_assert_not_reached ();
|
|
|
|
|
|
}
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
while (offset < (stat->secsize * ISO_BLOCKSIZE))
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
2003-11-16 19:30:45 +00:00
|
|
|
|
const iso9660_dir_t *iso9660_dir = (void *) &_dirbuf[offset];
|
|
|
|
|
|
iso9660_stat_t *iso9660_stat;
|
|
|
|
|
|
|
|
|
|
|
|
if (!iso9660_get_dir_len(iso9660_dir))
|
2003-08-31 06:59:23 +00:00
|
|
|
|
{
|
|
|
|
|
|
offset++;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
iso9660_stat = _iso9660_dir_to_statbuf(iso9660_dir, is_mode2);
|
|
|
|
|
|
_cdio_list_append (retval, iso9660_stat);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
offset += iso9660_get_dir_len(iso9660_dir);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
cdio_assert (offset == (stat->secsize * ISO_BLOCKSIZE));
|
2003-08-31 06:59:23 +00:00
|
|
|
|
|
|
|
|
|
|
free (_dirbuf);
|
2003-11-16 19:30:45 +00:00
|
|
|
|
free (stat);
|
2003-08-31 06:59:23 +00:00
|
|
|
|
return retval;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-11-16 19:30:45 +00:00
|
|
|
|
static iso9660_stat_t *
|
|
|
|
|
|
find_fs_lsn_recurse (const CdIo *cdio, const char pathname[], lsn_t lsn)
|
2003-09-05 22:48:16 +00:00
|
|
|
|
{
|
|
|
|
|
|
CdioList *entlist = iso9660_fs_readdir (cdio, pathname, true);
|
|
|
|
|
|
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);
|
2003-11-16 19:30:45 +00:00
|
|
|
|
iso9660_stat_t *ret_stat = find_fs_lsn_recurse (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 *
|
|
|
|
|
|
iso9660_find_fs_lsn(const CdIo *cdio, lsn_t lsn)
|
2003-09-05 22:48:16 +00:00
|
|
|
|
{
|
2003-11-16 19:30:45 +00:00
|
|
|
|
return find_fs_lsn_recurse (cdio, "/", lsn);
|
2003-09-05 22:48:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|