allow to read image file instead of /dev/cdrom

This commit is contained in:
Laurent Vivier 2006-09-08 22:57:36 +00:00
parent a472cae367
commit 9aa7430439
4 changed files with 23 additions and 11 deletions

View File

@ -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;

View File

@ -10,6 +10,6 @@
#include <libstream.h>
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);

View File

@ -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 = "/";

View File

@ -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 = "/";