From 9aa7430439e034653ace1bfa18bef734b52156a5 Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Fri, 8 Sep 2006 22:57:36 +0000 Subject: [PATCH] allow to read image file instead of /dev/cdrom --- tools/device.c | 9 +++++---- tools/device.h | 2 +- tools/iso9660_cat.c | 13 ++++++++++--- tools/iso9660_ls.c | 10 +++++++--- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/tools/device.c b/tools/device.c index 31f937f..080fa44 100644 --- a/tools/device.c +++ b/tools/device.c @@ -13,8 +13,6 @@ #define SECTOR_SIZE (2048) #define ISO_BLOCKS(X) (((X) / SECTOR_SIZE) + (((X)%SECTOR_SIZE)?1:0)) -static const char *filename = "/dev/cdrom"; - int device_read_sector(void *data,off_t offset, void* buffer, size_t size) { FILE* file = (FILE*)data; @@ -30,11 +28,14 @@ void device_close(void *data) fclose(file); } -FILE *device_open(void) +FILE *device_open(char *device) { FILE* file; - file = fopen(filename, "rb"); + if (device == NULL) + return NULL; + + file = fopen(device, "rb"); if (file == NULL) return NULL; diff --git a/tools/device.h b/tools/device.h index 68cb57a..6a09e9f 100644 --- a/tools/device.h +++ b/tools/device.h @@ -10,6 +10,6 @@ #include -extern FILE *device_open(void); +extern FILE *device_open(char *device); extern void device_close(void *data); extern int device_read_sector(void *data, off_t offset, void* buffer, size_t size); diff --git a/tools/iso9660_cat.c b/tools/iso9660_cat.c index 2526383..3bce2d1 100644 --- a/tools/iso9660_cat.c +++ b/tools/iso9660_cat.c @@ -25,8 +25,15 @@ int main(int argc, char **argv) iso9660_VOLUME *volume; char buffer[512]; size_t size; + int arg = 1; + char *devname; - device.data = device_open(); + if (argc > 2) + devname = argv[arg++]; + else + devname = "/dev/cdrom"; + + device.data = device_open(devname); device.read_sector = (stream_read_sector_t)device_read_sector; device.close = (stream_close_t)device_close; @@ -34,8 +41,8 @@ int main(int argc, char **argv) if (volume == NULL) return 1; - if (argc > 1) - path = argv[1]; + if (argc > arg) + path = argv[arg++]; else path = "/"; diff --git a/tools/iso9660_ls.c b/tools/iso9660_ls.c index 9add73c..9672839 100644 --- a/tools/iso9660_ls.c +++ b/tools/iso9660_ls.c @@ -44,8 +44,12 @@ int main(int argc, char **argv) char *path; device_io_t device; iso9660_VOLUME *volume; + int arg = 1; - device.data = device_open(); + if (argc > 1) + device.data = device_open(argv[arg++]); + else + device.data = device_open("/dev/cdrom"); device.read_sector = (stream_read_sector_t)device_read_sector; device.close = (stream_close_t)device_close; @@ -53,8 +57,8 @@ int main(int argc, char **argv) if (volume == NULL) return -1; - if (argc > 1) - path = argv[1]; + if (argc > arg) + path = argv[arg]; else path = "/";