Simplify code. Add usage.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
$Id: iso2.cpp,v 1.6 2005/11/10 11:22:55 rocky Exp $
|
$Id: iso2.cpp,v 1.7 2006/03/02 18:46:30 rocky Exp $
|
||||||
|
|
||||||
Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
|
Copyright (C) 2003, 2004, 2005, 2006 Rocky Bernstein <rocky@panix.com>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Simple program to show using libiso9660 to extract a file from a
|
/* Simple program to show using libiso9660 to extract a file from a
|
||||||
cue/bin CD-IMAGE.
|
CUE/BIN CD image.
|
||||||
|
|
||||||
If a single argument is given, it is used as the CUE file of a CD image
|
If a single argument is given, it is used as the CUE file of a CD image
|
||||||
to use. Otherwise a compiled-in default image name (that
|
to use. Otherwise a compiled-in default image name (that
|
||||||
@@ -69,6 +69,8 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define CEILING(x, y) ((x+(y-1))/y)
|
||||||
|
|
||||||
#define my_exit(rc) \
|
#define my_exit(rc) \
|
||||||
fclose (p_outfd); \
|
fclose (p_outfd); \
|
||||||
free(p_statbuf); \
|
free(p_statbuf); \
|
||||||
@@ -88,6 +90,12 @@ main(int argc, const char *argv[])
|
|||||||
char untranslated_name[256] = ISO9660_PATH;
|
char untranslated_name[256] = ISO9660_PATH;
|
||||||
CdIo_t *p_cdio;
|
CdIo_t *p_cdio;
|
||||||
|
|
||||||
|
if (argc > 3) {
|
||||||
|
printf("usage %s [CD-ROM-or-image [filename]]\n", argv[0]);
|
||||||
|
printf("Extracts filename from CD-ROM-or-image.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
psz_image = argv[1];
|
psz_image = argv[1];
|
||||||
else
|
else
|
||||||
@@ -128,18 +136,19 @@ main(int argc, const char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the blocks from the ISO-9660 filesystem to the local filesystem. */
|
/* Copy the blocks from the ISO-9660 filesystem to the local filesystem. */
|
||||||
for (i = 0; i < p_statbuf->size; i += ISO_BLOCKSIZE)
|
{
|
||||||
|
const unsigned int i_blocks = CEILING(p_statbuf->size, ISO_BLOCKSIZE);
|
||||||
|
for (i = 0; i < i_blocks; i ++)
|
||||||
{
|
{
|
||||||
char buf[ISO_BLOCKSIZE];
|
char buf[ISO_BLOCKSIZE];
|
||||||
|
const lsn_t lsn = p_statbuf->lsn + i;
|
||||||
|
|
||||||
memset (buf, 0, ISO_BLOCKSIZE);
|
memset (buf, 0, ISO_BLOCKSIZE);
|
||||||
|
|
||||||
if ( 0 != cdio_read_data_sectors (p_cdio, buf,
|
if ( 0 != cdio_read_data_sectors (p_cdio, buf, lsn, ISO_BLOCKSIZE, 1) )
|
||||||
p_statbuf->lsn + (i / ISO_BLOCKSIZE),
|
|
||||||
ISO_BLOCKSIZE, 1) )
|
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error reading ISO 9660 file at lsn %lu\n",
|
fprintf(stderr, "Error reading ISO 9660 file at lsn %lu\n",
|
||||||
(long unsigned int) p_statbuf->lsn + (i / ISO_BLOCKSIZE));
|
(long unsigned int) p_statbuf->lsn);
|
||||||
my_exit(4);
|
my_exit(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,6 +161,8 @@ main(int argc, const char *argv[])
|
|||||||
my_exit(5);
|
my_exit(5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fflush (p_outfd);
|
fflush (p_outfd);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
$Id: iso3.cpp,v 1.2 2005/11/10 11:22:55 rocky Exp $
|
$Id: iso3.cpp,v 1.3 2006/03/02 18:46:30 rocky Exp $
|
||||||
|
|
||||||
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
|
Copyright (C) 2004, 2006 Rocky Bernstein <rocky@panix.com>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -20,6 +20,10 @@
|
|||||||
|
|
||||||
/* Simple program to show using libiso9660 to extract a file from an
|
/* Simple program to show using libiso9660 to extract a file from an
|
||||||
ISO-9660 image.
|
ISO-9660 image.
|
||||||
|
|
||||||
|
If a single argument is given, it is used as the ISO 9660 image to
|
||||||
|
use in the extraction. Otherwise a compiled in default ISO 9660 image
|
||||||
|
name (that comes with the libcdio distribution) will be used.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* This is the ISO 9660 image. */
|
/* This is the ISO 9660 image. */
|
||||||
@@ -56,6 +60,8 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define CEILING(x, y) ((x+(y-1))/y)
|
||||||
|
|
||||||
#define my_exit(rc) \
|
#define my_exit(rc) \
|
||||||
fclose (p_outfd); \
|
fclose (p_outfd); \
|
||||||
free(p_statbuf); \
|
free(p_statbuf); \
|
||||||
@@ -67,34 +73,46 @@ main(int argc, const char *argv[])
|
|||||||
{
|
{
|
||||||
iso9660_stat_t *p_statbuf;
|
iso9660_stat_t *p_statbuf;
|
||||||
FILE *p_outfd;
|
FILE *p_outfd;
|
||||||
unsigned int i;
|
int i;
|
||||||
|
char const *psz_image;
|
||||||
char const *psz_fname;
|
char const *psz_fname;
|
||||||
iso9660_t *p_iso;
|
iso9660_t *p_iso;
|
||||||
|
|
||||||
if (argc > 1)
|
if (argc > 3) {
|
||||||
psz_fname = argv[1];
|
printf("usage %s [ISO9660-image.ISO [filename]]\n", argv[0]);
|
||||||
else
|
printf("Extracts filename from ISO-9660-image.ISO.\n");
|
||||||
psz_fname = ISO9660_IMAGE;
|
|
||||||
|
|
||||||
p_iso = iso9660_open (psz_fname);
|
|
||||||
|
|
||||||
if (NULL == p_iso) {
|
|
||||||
fprintf(stderr, "Sorry, couldn't open ISO 9660 image %s\n", ISO9660_IMAGE);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
p_statbuf = iso9660_ifs_stat_translate (p_iso, LOCAL_FILENAME);
|
if (argc > 1)
|
||||||
|
psz_image = argv[1];
|
||||||
|
else
|
||||||
|
psz_image = ISO9660_IMAGE;
|
||||||
|
|
||||||
|
if (argc > 2)
|
||||||
|
psz_fname = argv[2];
|
||||||
|
else
|
||||||
|
psz_fname = LOCAL_FILENAME;
|
||||||
|
|
||||||
|
p_iso = iso9660_open (psz_image);
|
||||||
|
|
||||||
|
if (NULL == p_iso) {
|
||||||
|
fprintf(stderr, "Sorry, couldn't open ISO 9660 image %s\n", psz_image);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
p_statbuf = iso9660_ifs_stat_translate (p_iso, psz_fname);
|
||||||
|
|
||||||
if (NULL == p_statbuf)
|
if (NULL == p_statbuf)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Could not get ISO-9660 file information for file %s\n",
|
"Could not get ISO-9660 file information for file %s\n",
|
||||||
LOCAL_FILENAME);
|
psz_fname);
|
||||||
iso9660_close(p_iso);
|
iso9660_close(p_iso);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(p_outfd = fopen (LOCAL_FILENAME, "wb")))
|
if (!(p_outfd = fopen (psz_fname, "wb")))
|
||||||
{
|
{
|
||||||
perror ("fopen()");
|
perror ("fopen()");
|
||||||
free(p_statbuf);
|
free(p_statbuf);
|
||||||
@@ -103,22 +121,22 @@ main(int argc, const char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the blocks from the ISO-9660 filesystem to the local filesystem. */
|
/* Copy the blocks from the ISO-9660 filesystem to the local filesystem. */
|
||||||
for (i = 0; i < p_statbuf->size; i += ISO_BLOCKSIZE)
|
{
|
||||||
|
const unsigned int i_blocks = CEILING(p_statbuf->size, ISO_BLOCKSIZE);
|
||||||
|
for (i = 0; i < i_blocks ; i++)
|
||||||
{
|
{
|
||||||
char buf[ISO_BLOCKSIZE];
|
char buf[ISO_BLOCKSIZE];
|
||||||
|
const lsn_t lsn = p_statbuf->lsn + i;
|
||||||
|
|
||||||
memset (buf, 0, ISO_BLOCKSIZE);
|
memset (buf, 0, ISO_BLOCKSIZE);
|
||||||
|
|
||||||
if ( ISO_BLOCKSIZE != iso9660_iso_seek_read (p_iso, buf, p_statbuf->lsn
|
if ( ISO_BLOCKSIZE != iso9660_iso_seek_read (p_iso, buf, lsn, 1) )
|
||||||
+ (i / ISO_BLOCKSIZE),
|
|
||||||
1) )
|
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error reading ISO 9660 file at lsn %lu\n",
|
fprintf(stderr, "Error reading ISO 9660 file %s at LSN %lu\n",
|
||||||
(long unsigned int) p_statbuf->lsn + (i / ISO_BLOCKSIZE));
|
psz_fname, (long unsigned int) lsn);
|
||||||
my_exit(4);
|
my_exit(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fwrite (buf, ISO_BLOCKSIZE, 1, p_outfd);
|
fwrite (buf, ISO_BLOCKSIZE, 1, p_outfd);
|
||||||
|
|
||||||
if (ferror (p_outfd))
|
if (ferror (p_outfd))
|
||||||
@@ -127,6 +145,7 @@ main(int argc, const char *argv[])
|
|||||||
my_exit(5);
|
my_exit(5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fflush (p_outfd);
|
fflush (p_outfd);
|
||||||
|
|
||||||
@@ -136,7 +155,8 @@ main(int argc, const char *argv[])
|
|||||||
if (ftruncate (fileno (p_outfd), p_statbuf->size))
|
if (ftruncate (fileno (p_outfd), p_statbuf->size))
|
||||||
perror ("ftruncate()");
|
perror ("ftruncate()");
|
||||||
|
|
||||||
printf("Extraction of file 'copying' from %s successful.\n", ISO9660_IMAGE);
|
printf("Extraction of file '%s' from %s successful.\n",
|
||||||
|
psz_fname, psz_image);
|
||||||
|
|
||||||
my_exit(0);
|
my_exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
$Id: iso2.c,v 1.10 2005/11/07 07:44:00 rocky Exp $
|
$Id: iso2.c,v 1.11 2006/03/02 18:46:30 rocky Exp $
|
||||||
|
|
||||||
Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
|
Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
|
||||||
|
|
||||||
@@ -69,6 +69,8 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define CEILING(x, y) ((x+(y-1))/y)
|
||||||
|
|
||||||
#define my_exit(rc) \
|
#define my_exit(rc) \
|
||||||
fclose (p_outfd); \
|
fclose (p_outfd); \
|
||||||
free(p_statbuf); \
|
free(p_statbuf); \
|
||||||
@@ -88,6 +90,12 @@ main(int argc, const char *argv[])
|
|||||||
char untranslated_name[256] = ISO9660_PATH;
|
char untranslated_name[256] = ISO9660_PATH;
|
||||||
CdIo_t *p_cdio;
|
CdIo_t *p_cdio;
|
||||||
|
|
||||||
|
if (argc > 3) {
|
||||||
|
printf("usage %s [CD-ROM-or-image [filename]]\n", argv[0]);
|
||||||
|
printf("Extracts filename from CD-ROM-or-image.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
psz_image = argv[1];
|
psz_image = argv[1];
|
||||||
else
|
else
|
||||||
@@ -128,18 +136,19 @@ main(int argc, const char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the blocks from the ISO-9660 filesystem to the local filesystem. */
|
/* Copy the blocks from the ISO-9660 filesystem to the local filesystem. */
|
||||||
for (i = 0; i < p_statbuf->size; i += ISO_BLOCKSIZE)
|
{
|
||||||
|
const unsigned int i_blocks = CEILING(p_statbuf->size, ISO_BLOCKSIZE);
|
||||||
|
for (i = 0; i < i_blocks; i ++)
|
||||||
{
|
{
|
||||||
char buf[ISO_BLOCKSIZE];
|
char buf[ISO_BLOCKSIZE];
|
||||||
|
const lsn_t lsn = p_statbuf->lsn + i;
|
||||||
|
|
||||||
memset (buf, 0, ISO_BLOCKSIZE);
|
memset (buf, 0, ISO_BLOCKSIZE);
|
||||||
|
|
||||||
if ( 0 != cdio_read_data_sectors (p_cdio, buf,
|
if ( 0 != cdio_read_data_sectors (p_cdio, buf, lsn, ISO_BLOCKSIZE, 1) )
|
||||||
p_statbuf->lsn + (i / ISO_BLOCKSIZE),
|
|
||||||
ISO_BLOCKSIZE, 1) )
|
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error reading ISO 9660 file at lsn %lu\n",
|
fprintf(stderr, "Error reading ISO 9660 file at lsn %lu\n",
|
||||||
(long unsigned int) p_statbuf->lsn + (i / ISO_BLOCKSIZE));
|
(long unsigned int) p_statbuf->lsn);
|
||||||
my_exit(4);
|
my_exit(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,6 +161,8 @@ main(int argc, const char *argv[])
|
|||||||
my_exit(5);
|
my_exit(5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fflush (p_outfd);
|
fflush (p_outfd);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
$Id: iso3.c,v 1.6 2006/03/02 01:28:58 rocky Exp $
|
$Id: iso3.c,v 1.7 2006/03/02 18:46:30 rocky Exp $
|
||||||
|
|
||||||
Copyright (C) 2004, 2005 Rocky Bernstein <rocky@panix.com>
|
Copyright (C) 2004, 2005, 2006 Rocky Bernstein <rocky@panix.com>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -74,33 +74,45 @@ main(int argc, const char *argv[])
|
|||||||
iso9660_stat_t *p_statbuf;
|
iso9660_stat_t *p_statbuf;
|
||||||
FILE *p_outfd;
|
FILE *p_outfd;
|
||||||
int i;
|
int i;
|
||||||
|
char const *psz_image;
|
||||||
char const *psz_fname;
|
char const *psz_fname;
|
||||||
iso9660_t *p_iso;
|
iso9660_t *p_iso;
|
||||||
|
|
||||||
if (argc > 1)
|
if (argc > 3) {
|
||||||
psz_fname = argv[1];
|
printf("usage %s [ISO9660-image.ISO [filename]]\n", argv[0]);
|
||||||
else
|
printf("Extracts filename from ISO-9660-image.ISO\n");
|
||||||
psz_fname = ISO9660_IMAGE;
|
|
||||||
|
|
||||||
p_iso = iso9660_open (psz_fname);
|
|
||||||
|
|
||||||
if (NULL == p_iso) {
|
|
||||||
fprintf(stderr, "Sorry, couldn't open ISO 9660 image %s\n", ISO9660_IMAGE);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
p_statbuf = iso9660_ifs_stat_translate (p_iso, LOCAL_FILENAME);
|
if (argc > 1)
|
||||||
|
psz_image = argv[1];
|
||||||
|
else
|
||||||
|
psz_image = ISO9660_IMAGE;
|
||||||
|
|
||||||
|
if (argc > 2)
|
||||||
|
psz_fname = argv[2];
|
||||||
|
else
|
||||||
|
psz_fname = LOCAL_FILENAME;
|
||||||
|
|
||||||
|
p_iso = iso9660_open (psz_image);
|
||||||
|
|
||||||
|
if (NULL == p_iso) {
|
||||||
|
fprintf(stderr, "Sorry, couldn't open ISO 9660 image %s\n", psz_image);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
p_statbuf = iso9660_ifs_stat_translate (p_iso, psz_fname);
|
||||||
|
|
||||||
if (NULL == p_statbuf)
|
if (NULL == p_statbuf)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Could not get ISO-9660 file information for file %s\n",
|
"Could not get ISO-9660 file information for file %s\n",
|
||||||
LOCAL_FILENAME);
|
psz_fname);
|
||||||
iso9660_close(p_iso);
|
iso9660_close(p_iso);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(p_outfd = fopen (LOCAL_FILENAME, "wb")))
|
if (!(p_outfd = fopen (psz_fname, "wb")))
|
||||||
{
|
{
|
||||||
perror ("fopen()");
|
perror ("fopen()");
|
||||||
free(p_statbuf);
|
free(p_statbuf);
|
||||||
@@ -121,7 +133,7 @@ main(int argc, const char *argv[])
|
|||||||
if ( ISO_BLOCKSIZE != iso9660_iso_seek_read (p_iso, buf, lsn, 1) )
|
if ( ISO_BLOCKSIZE != iso9660_iso_seek_read (p_iso, buf, lsn, 1) )
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error reading ISO 9660 file %s at LSN %lu\n",
|
fprintf(stderr, "Error reading ISO 9660 file %s at LSN %lu\n",
|
||||||
LOCAL_FILENAME, (long unsigned int) lsn);
|
psz_fname, (long unsigned int) lsn);
|
||||||
my_exit(4);
|
my_exit(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +156,7 @@ main(int argc, const char *argv[])
|
|||||||
perror ("ftruncate()");
|
perror ("ftruncate()");
|
||||||
|
|
||||||
printf("Extraction of file '%s' from %s successful.\n",
|
printf("Extraction of file '%s' from %s successful.\n",
|
||||||
LOCAL_FILENAME, ISO9660_IMAGE);
|
psz_fname, psz_image);
|
||||||
|
|
||||||
my_exit(0);
|
my_exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user