iso9660*.{c,h}: Add PVD read for ISO 9660 images.

iso-info now shows this info.
This commit is contained in:
rocky
2004-06-19 00:10:23 +00:00
parent b2f2e45d8c
commit f126d236aa
3 changed files with 61 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
/*
$Id: iso9660.h,v 1.41 2004/06/18 23:00:05 rocky Exp $
$Id: iso9660.h,v 1.42 2004/06/19 00:10:23 rocky Exp $
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
@@ -284,15 +284,21 @@ typedef struct _iso9660 iso9660_t;
True is unconditionally returned. If there was an error false would
be returned.
*/
bool iso9660_close (iso9660_t * iso);
bool iso9660_close (iso9660_t * p_iso);
/*!
Seek to a position and then read n bytes. Size read is returned.
*/
long int iso9660_iso_seek_read (iso9660_t *iso, void *ptr, lsn_t start,
long int iso9660_iso_seek_read (iso9660_t *p_iso, void *ptr, lsn_t start,
long int size);
/*!
Read the Primary Volume Descriptor for an ISO 9660 image.
True is returned if read, and false if there was an error.
*/
bool iso9660_iso_read_pvd (iso9660_t *p_iso, iso9660_pvd_t *p_pvd);
/*====================================================
Time conversion
====================================================*/
@@ -307,7 +313,7 @@ typedef struct _iso9660 iso9660_t;
Set "long" time in format used in ISO 9660 primary volume descriptor
from a Unix time structure. */
void iso9660_set_ltime (const struct tm *_tm,
/*out*/ iso9660_ltime_t *pvd_date);
/*out*/ iso9660_ltime_t *p_pvd_date);
/*!
Get Unix time structure from format use in an ISO 9660 directory index
@@ -490,7 +496,7 @@ void * iso9660_ifs_readdir (iso9660_t *iso, const char pathname[]);
Return the PVD's application ID.
NULL is returned if there is some problem in getting this.
*/
const char * iso9660_get_application_id(const iso9660_pvd_t *pvd);
const char * iso9660_get_application_id(const iso9660_pvd_t *p_pvd);
uint8_t iso9660_get_dir_len(const iso9660_dir_t *idr);

View File

@@ -1,5 +1,5 @@
/*
$Id: iso9660_fs.c,v 1.19 2004/03/21 00:51:49 rocky Exp $
$Id: iso9660_fs.c,v 1.20 2004/06/19 00:10:23 rocky Exp $
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
@@ -40,7 +40,7 @@
#include <stdio.h>
static const char _rcsid[] = "$Id: iso9660_fs.c,v 1.19 2004/03/21 00:51:49 rocky Exp $";
static const char _rcsid[] = "$Id: iso9660_fs.c,v 1.20 2004/06/19 00:10:23 rocky Exp $";
/* Implementation of iso9660_t type */
struct _iso9660 {
@@ -76,28 +76,50 @@ iso9660_open (const char *pathname /*flags, mode */)
be returned.
*/
bool
iso9660_close (iso9660_t *iso)
iso9660_close (iso9660_t *p_iso)
{
if (NULL != iso) {
cdio_stdio_destroy(iso->stream);
free(iso);
if (NULL != p_iso) {
cdio_stdio_destroy(p_iso->stream);
free(p_iso);
}
return true;
}
/*!
Read the Primary Volume Descriptor for an ISO 9660 image.
*/
bool iso9660_iso_read_pvd (iso9660_t *p_iso, 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;
}
if (p_pvd->type != ISO_VD_PRIMARY) {
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;
}
/*!
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)
iso9660_iso_seek_read (iso9660_t *p_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 (NULL == p_iso) return 0;
ret = cdio_stream_seek (p_iso->stream, start * ISO_BLOCKSIZE, SEEK_SET);
if (ret!=0) return 0;
return cdio_stream_read (iso->stream, ptr, ISO_BLOCKSIZE, size);
return cdio_stream_read (p_iso->stream, ptr, ISO_BLOCKSIZE, size);
}

View File

@@ -1,5 +1,5 @@
/*
$Id: iso-info.c,v 1.5 2004/03/13 03:31:47 rocky Exp $
$Id: iso-info.c,v 1.6 2004/06/19 00:10:23 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
@@ -25,7 +25,7 @@
#define err_exit(fmt, args...) \
fprintf(stderr, "%s: "fmt, program_name, ##args); \
iso9660_close(iso); \
iso9660_close(p_iso); \
return(EXIT_FAILURE);
#ifdef HAVE_CONFIG_H
@@ -252,7 +252,7 @@ int
main(int argc, const char *argv[])
{
iso9660_t *iso=NULL;
iso9660_t *p_iso=NULL;
init();
@@ -272,24 +272,33 @@ main(int argc, const char *argv[])
err_exit("%s: No input device given/found\n", program_name);
}
iso = iso9660_open (source_name);
p_iso = iso9660_open (source_name);
if (iso==NULL) {
if (p_iso==NULL) {
free(source_name);
err_exit("%s: Error in opening device driver\n", program_name);
}
if (opts.silent == 0) {
printf("ISO 9660 image: %s\n", source_name);
iso9660_pvd_t pvd;
printf(STRONG "ISO 9660 image: %s\n", source_name);
if (iso9660_iso_read_pvd(p_iso, &pvd)) {
printf("Application ID: %s\n", iso9660_get_application_id(&pvd));
printf("System ID : %s\n", iso9660_get_system_id(&pvd));
printf("Volume ID : %s\n", iso9660_get_volume_id(&pvd));
printf("Volume Set ID : %s\n", iso9660_get_volumeset_id(&pvd));
}
}
if (!opts.no_analysis) {
printf(STRONG "ISO-9660 Information\n" NORMAL);
print_iso9660_fs(iso);
print_iso9660_fs(p_iso);
}
free(source_name);
iso9660_close(iso);
iso9660_close(p_iso);
/* Not reached:*/
free(program_name);
return(EXIT_SUCCESS);