2005-11-13 19:43:28 +00:00
|
|
|
/*
|
|
|
|
*
|
2006-09-15 14:55:39 +00:00
|
|
|
* (c) 2005 Laurent Vivier <Laurent@lvivier.info>
|
2005-11-13 19:43:28 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-11-12 22:28:50 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
2007-10-09 19:21:14 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2005-11-12 22:28:50 +00:00
|
|
|
|
|
|
|
#include <libiso9660.h>
|
2005-11-21 22:07:17 +00:00
|
|
|
#include <libstream.h>
|
2005-11-12 22:28:50 +00:00
|
|
|
|
2005-11-13 19:43:28 +00:00
|
|
|
#include "device.h"
|
|
|
|
|
2005-11-12 22:28:50 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *path;
|
2005-11-21 22:07:17 +00:00
|
|
|
device_io_t device;
|
2008-04-20 16:35:55 +00:00
|
|
|
stream_FILE* file;
|
|
|
|
stream_VOLUME *volume;
|
2005-11-12 22:28:50 +00:00
|
|
|
char buffer[512];
|
|
|
|
size_t size;
|
2006-09-09 21:25:35 +00:00
|
|
|
int get_info = 0;
|
2006-09-08 22:57:36 +00:00
|
|
|
int arg = 1;
|
|
|
|
char *devname;
|
2005-11-12 22:28:50 +00:00
|
|
|
|
2006-09-09 21:25:35 +00:00
|
|
|
if ((argc > arg) && (strcmp(argv[arg], "-i") == 0)) {
|
|
|
|
arg++;
|
|
|
|
get_info = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > arg)
|
2006-09-08 22:57:36 +00:00
|
|
|
devname = argv[arg++];
|
|
|
|
else
|
|
|
|
devname = "/dev/cdrom";
|
|
|
|
|
2006-09-09 21:25:35 +00:00
|
|
|
if (argc > arg)
|
|
|
|
path = argv[arg++];
|
|
|
|
else
|
|
|
|
path = "/";
|
|
|
|
|
2007-10-09 19:21:14 +00:00
|
|
|
device_sector_size = 2048;
|
|
|
|
device.data = (void*)device_open(devname, O_RDONLY);
|
2005-11-21 22:07:17 +00:00
|
|
|
device.read_sector = (stream_read_sector_t)device_read_sector;
|
|
|
|
device.close = (stream_close_t)device_close;
|
2007-10-10 16:47:03 +00:00
|
|
|
device.get_blocksize = (stream_get_blocksize_t)device_get_blocksize;
|
2005-11-13 19:43:28 +00:00
|
|
|
|
2005-11-21 22:07:17 +00:00
|
|
|
volume = iso9660_mount(&device);
|
|
|
|
if (volume == NULL)
|
2005-11-12 22:28:50 +00:00
|
|
|
return 1;
|
|
|
|
|
2005-11-21 22:07:17 +00:00
|
|
|
file = iso9660_open(volume, path);
|
2005-11-12 22:28:50 +00:00
|
|
|
if (file == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s not found\n", path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-09-09 21:25:35 +00:00
|
|
|
if (get_info) {
|
2008-04-20 16:35:55 +00:00
|
|
|
struct stream_stat st;
|
|
|
|
iso9660_fstat(file, &st);
|
2008-07-08 21:58:50 +00:00
|
|
|
printf("%ld %ld\n", st.st_base * 4, st.st_size);
|
2006-09-09 21:25:35 +00:00
|
|
|
} else {
|
|
|
|
while((size = iso9660_read(file, buffer, 512)) > 0)
|
|
|
|
write(STDOUT_FILENO, buffer, size);
|
|
|
|
}
|
2005-11-12 22:28:50 +00:00
|
|
|
iso9660_close(file);
|
|
|
|
|
2005-11-21 22:07:17 +00:00
|
|
|
iso9660_umount(volume);
|
2005-11-12 22:28:50 +00:00
|
|
|
|
2005-11-21 22:07:17 +00:00
|
|
|
device_close(device.data);
|
2005-11-13 19:43:28 +00:00
|
|
|
|
2005-11-12 22:28:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|