EMILE/tools/iso9660_ls.c

78 lines
1.4 KiB
C
Raw Normal View History

2005-11-13 19:43:28 +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>
#include <sys/stat.h>
#include <fcntl.h>
2005-11-12 22:28:50 +00:00
#include <libiso9660.h>
2005-11-13 19:43:28 +00:00
#include "device.h"
2005-11-21 22:07:17 +00:00
static void list(iso9660_VOLUME *volume, char *path)
2005-11-12 22:28:50 +00:00
{
char name_buf[256];
iso9660_DIR *dir;
struct iso_directory_record *idr;
2005-11-21 22:07:17 +00:00
dir = iso9660_opendir(volume, path);
2005-11-12 22:28:50 +00:00
if (dir == NULL)
return;
while ((idr = iso9660_readdir(dir)) != NULL)
{
2005-11-21 22:07:17 +00:00
iso9660_name(volume->ucs_level, name_buf, idr);
2005-11-12 22:28:50 +00:00
if (iso9660_is_directory(idr)) {
printf("%s/\n", name_buf);
} else {
printf("%s\n", name_buf);
}
}
iso9660_closedir(dir);
}
int main(int argc, char **argv)
{
char *path;
2005-11-21 22:07:17 +00:00
device_io_t device;
iso9660_VOLUME *volume;
int arg = 1;
2005-11-12 22:28:50 +00:00
device_sector_size = 2048;
if (argc > 1)
device.data = (void*)device_open(argv[arg++], O_RDONLY);
else
device.data = (void*)device_open("/dev/cdrom", 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;
if (argc > arg)
path = argv[arg];
2005-11-12 22:28:50 +00:00
else
path = "/";
2005-11-21 22:07:17 +00:00
list(volume, path);
2005-11-12 22:28:50 +00:00
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);
}