Add iso9660_name_translate() to remove ISO-name cruft.

Document iso9660_fs_stat().
This commit is contained in:
rocky
2003-09-06 14:50:50 +00:00
parent 2418f7ba45
commit c850bd6b04
5 changed files with 96 additions and 36 deletions

View File

@@ -1,5 +1,5 @@
/*
$Id: iso9660.h,v 1.17 2003/09/05 22:48:16 rocky Exp $
$Id: iso9660.h,v 1.18 2003/09/06 14:50:50 rocky Exp $
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2003 Rocky Bernstein <rocky@panix.com>
@@ -184,6 +184,16 @@ bool iso9660_isdchar (int c);
*/
bool iso9660_isachar (int c);
/*!
Convert ISO-9660 file name that stored in a directory entry into
what's usually listed as the file name in a listing.
Lowercase name, and drop deal with trailing ;1's or .;1's or
; version numbers.
The length of the translated string is returned.
*/
int iso9660_name_translate(const char *old, char *new);
/*!
Pad string src with spaces to size len and copy this to dst. If
len is less than the length of src, dst will be truncated to the
@@ -263,13 +273,15 @@ iso9660_dir_calc_record_size (unsigned int namelen, unsigned int su_len);
Returns true if we found an entry with the lsn and false if not.
*/
bool
iso9660_find_fs_lsn(const CdIo *cdio, lsn_t lsn, /*out*/ iso9660_stat_t *stat);
bool iso9660_find_fs_lsn(const CdIo *cdio, lsn_t lsn,
/*out*/ iso9660_stat_t *stat);
int
iso9660_fs_stat (const CdIo *obj, const char pathname[], iso9660_stat_t *buf,
bool is_mode2);
/*!
Get file status for pathname into stat. As with libc's stat, 0 is returned
if no error and -1 on error.
*/
int iso9660_fs_stat (const CdIo *obj, const char pathname[],
/*out*/ iso9660_stat_t *stat, bool is_mode2);
void * /* list of char* -- caller must free it */
iso9660_fs_readdir (const CdIo *obj, const char pathname[], bool mode2);

View File

@@ -1,5 +1,5 @@
/*
$Id: iso9660.c,v 1.7 2003/09/01 15:10:43 rocky Exp $
$Id: iso9660.c,v 1.8 2003/09/06 14:50:50 rocky Exp $
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2003 Rocky Bernstein <rocky@panix.com>
@@ -19,9 +19,14 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
/* Private headers */
#include "iso9660_private.h"
#include "cdio_assert.h"
#include "bytesex.h"
/* Public headers */
#include <cdio/iso9660.h>
#include <cdio/util.h>
#include <time.h>
#include <ctype.h>
@@ -32,16 +37,7 @@
#include <stdio.h>
#endif
/* Public headers */
#include <cdio/iso9660.h>
#include <cdio/util.h>
/* Private headers */
#include "iso9660_private.h"
#include "cdio_assert.h"
#include "bytesex.h"
static const char _rcsid[] = "$Id: iso9660.c,v 1.7 2003/09/01 15:10:43 rocky Exp $";
static const char _rcsid[] = "$Id: iso9660.c,v 1.8 2003/09/06 14:50:50 rocky Exp $";
/* some parameters... */
#define SYSTEM_ID "CD-RTOS CD-BRIDGE"
@@ -86,6 +82,46 @@ _pvd_set_time (char _pvd_date[], const struct tm *_tm)
_pvd_date[16] = (int8_t) 0; /* tz */
}
/*!
Convert ISO-9660 file name that stored in a directory entry into
what's usually listed as the file name in a listing.
Lowercase name, and trailing ;1's or .;1's and turn the
other ;'s into version numbers.
The length of the translated string is returned.
*/
int
iso9660_name_translate(const char *old, char *new)
{
int len = strlen(old);
int i;
for (i = 0; i < len; i++) {
unsigned char c = old[i];
if (!c)
break;
/* lower case */
if (isupper(c)) c = tolower(c);
/* Drop trailing '.;1' (ISO 9660:1988 7.5.1 requires period) */
if (c == '.' && i == len - 3 && old[i + 1] == ';' && old[i + 2] == '1')
break;
/* Drop trailing ';1' */
if (c == ';' && i == len - 2 && old[i + 1] == '1')
break;
/* Convert remaining ';' to '.' */
if (c == ';')
c = '.';
new[i] = c;
}
new[i] = '\0';
return i;
}
/*!
Pad string src with spaces to size len and copy this to dst. If
len is less than the length of src, dst will be truncated to the

View File

@@ -1,5 +1,5 @@
/*
$Id: iso9660_fs.c,v 1.6 2003/09/05 22:48:16 rocky Exp $
$Id: iso9660_fs.c,v 1.7 2003/09/06 14:50:50 rocky Exp $
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2003 Rocky Bernstein <rocky@panix.com>
@@ -38,7 +38,7 @@
#include <stdio.h>
static const char _rcsid[] = "$Id: iso9660_fs.c,v 1.6 2003/09/05 22:48:16 rocky Exp $";
static const char _rcsid[] = "$Id: iso9660_fs.c,v 1.7 2003/09/06 14:50:50 rocky Exp $";
static void
_idr2statbuf (const iso9660_dir_t *idr, iso9660_stat_t *buf, bool is_mode2)
@@ -201,9 +201,13 @@ _fs_stat_traverse (const CdIo *cdio, const iso9660_stat_t *_root,
return -1;
}
/*!
Get file status for pathname into stat. As with libc's stat, 0 is returned
if no error and -1 on error.
*/
int
iso9660_fs_stat (const CdIo *cdio, const char pathname[], iso9660_stat_t *buf,
bool is_mode2)
iso9660_fs_stat (const CdIo *cdio, const char pathname[],
/*out*/ iso9660_stat_t *stat, bool is_mode2)
{
iso9660_stat_t _root;
int retval;
@@ -211,12 +215,12 @@ iso9660_fs_stat (const CdIo *cdio, const char pathname[], iso9660_stat_t *buf,
cdio_assert (cdio != NULL);
cdio_assert (pathname != NULL);
cdio_assert (buf != NULL);
cdio_assert (stat != NULL);
_fs_stat_root (cdio, &_root, is_mode2);
splitpath = _cdio_strsplit (pathname, '/');
retval = _fs_stat_traverse (cdio, &_root, splitpath, buf, is_mode2);
retval = _fs_stat_traverse (cdio, &_root, splitpath, stat, is_mode2);
_cdio_strfreev (splitpath);
return retval;

View File

@@ -1,5 +1,5 @@
/*
$Id: iso9660_private.h,v 1.5 2003/09/01 02:08:59 rocky Exp $
$Id: iso9660_private.h,v 1.6 2003/09/06 14:50:50 rocky Exp $
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2003 Rocky Bernstein <rocky@panix.com>
@@ -27,6 +27,10 @@
#ifndef __CDIO_ISO9660_PRIVATE_H__
#define __CDIO_ISO9660_PRIVATE_H__
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <cdio/types.h>
#define ISO_VERSION 1

View File

@@ -1,5 +1,5 @@
/*
$Id: cd-info.c,v 1.31 2003/09/01 22:31:46 rocky Exp $
$Id: cd-info.c,v 1.32 2003/09/06 14:50:50 rocky Exp $
Copyright (C) 2003 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1996,1997,1998 Gerd Knorr <kraxel@bytesex.org>
@@ -612,15 +612,19 @@ print_iso9660_recurse (CdIo *cdio, const char pathname[], cdio_fs_anal_t fs,
cdio_assert (entlist != NULL);
/* just iterate */
/* Iterate over files in this directory */
_CDIO_LIST_FOREACH (entnode, entlist)
{
char *_name = _cdio_list_node_data (entnode);
char *iso_name = _cdio_list_node_data (entnode);
char _fullname[4096] = { 0, };
iso9660_stat_t statbuf;
char translated_name[MAX_ISONAME+1];
snprintf (_fullname, sizeof (_fullname), "%s%s", pathname, _name);
iso9660_name_translate(iso_name, translated_name);
snprintf (_fullname, sizeof (_fullname), "%s%s", pathname,
iso_name);
if (iso9660_fs_stat (cdio, _fullname, &statbuf, is_mode2))
cdio_assert_not_reached ();
@@ -628,8 +632,8 @@ print_iso9660_recurse (CdIo *cdio, const char pathname[], cdio_fs_anal_t fs,
strncat (_fullname, "/", sizeof (_fullname));
if (statbuf.type == _STAT_DIR
&& strcmp (_name, ".")
&& strcmp (_name, ".."))
&& strcmp (iso_name, ".")
&& strcmp (iso_name, ".."))
_cdio_list_append (dirlist, strdup (_fullname));
if (fs & CDIO_FS_ANAL_XA) {
@@ -649,14 +653,14 @@ print_iso9660_recurse (CdIo *cdio, const char pathname[], cdio_fs_anal_t fs,
printf ("%9d", statbuf.size);
}
}
printf (" %s\n", _name);
printf (" %s\n", translated_name);
}
_cdio_list_free (entlist, true);
printf ("\n");
/* now recurse */
/* Now wecurse over the directories. */
_CDIO_LIST_FOREACH (entnode, dirlist)
{