diff --git a/tools/Makefile b/tools/Makefile index 553fd90..63d42c7 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -10,15 +10,19 @@ LD=$(CROSS_COMPILE)ld AR=$(CROSS_COMPILE)ar PROGRAMS = emile-set-cmdline emile-first-tune emile-install \ - emile-set-output emile emile-map-set + emile-set-output emile emile-map-set iso9660_ls \ + iso9660_cat DISTFILES = emile-set-cmdline.c Makefile emile-first-tune.c \ emile-install.c emile-set-output.c emile.c \ - emile_scanbus.c emile-map-set.c + emile_scanbus.c emile-map-set.c iso9660_ls.c \ + iso9660_cat.c -CPPFLAGS = $(CROSS_COMPILE_CPPFLAGS) -DSIGNATURE="\"$(SIGNATURE)\"" -DPREFIX=\"$(PREFIX)\" -I../libemile +CPPFLAGS = $(CROSS_COMPILE_CPPFLAGS) -DSIGNATURE="\"$(SIGNATURE)\"" -DPREFIX=\"$(PREFIX)\" \ + -I../libemile -I../libiso9660 CFLAGS = -Wall -g -LDLIBS = $(CROSS_COMPILE_LDFLAGS) -L../libemile -lemile +LDLIBS = $(CROSS_COMPILE_LDFLAGS) -L../libemile -lemile -L../libiso9660/native -liso9660 + all: $(PROGRAMS) @@ -26,6 +30,10 @@ emile: emile.o emile_scanbus.o emile-map-set: emile-map-set.o emile_scanbus.o +iso9660_ls: iso9660_ls.o device.o + +iso9660_cat: iso9660_cat.o device.o + install: install -d $(DESTDIR)/$(PREFIX)/sbin/ install emile-set-cmdline $(DESTDIR)/$(PREFIX)/sbin/emile-set-cmdline diff --git a/tools/device.c b/tools/device.c new file mode 100644 index 0000000..7d84185 --- /dev/null +++ b/tools/device.c @@ -0,0 +1,29 @@ +#include +#include +#include + +#define SECTOR_SIZE (2048) +#define ISO_BLOCKS(X) (((X) / SECTOR_SIZE) + (((X)%SECTOR_SIZE)?1:0)) + +static const char *filename = "/dev/cdrom"; +static FILE *infile = NULL; + +int iso9660_device_open(void) +{ + infile = fopen(filename, "rb"); + if (infile == NULL) + return -1; + return 0; +} + +void iso9660_device_close(void) +{ + if (infile) + fclose(infile); +} + +void iso9660_device_read(off_t offset, void* buffer, size_t size) +{ + lseek(fileno(infile), offset << 11, SEEK_SET); + read(fileno(infile), buffer, ISO_BLOCKS(size) << 11); +} diff --git a/tools/iso9660_cat.c b/tools/iso9660_cat.c new file mode 100644 index 0000000..aec4760 --- /dev/null +++ b/tools/iso9660_cat.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include +#include + +#include + +int main(int argc, char **argv) +{ + char *path; + iso9660_FILE* file; + char buffer[512]; + size_t size; + + if (iso9660_mount(NULL) != 0) + return 1; + + if (argc > 1) + path = argv[1]; + else + path = "/"; + + file = iso9660_open(path); + if (file == NULL) + { + fprintf(stderr, "%s not found\n", path); + return -1; + } + + while((size = iso9660_read(file, buffer, 512)) > 0) + write(STDOUT_FILENO, buffer, size); + iso9660_close(file); + + iso9660_umount(); + + return 0; +} diff --git a/tools/iso9660_ls.c b/tools/iso9660_ls.c new file mode 100644 index 0000000..63503e6 --- /dev/null +++ b/tools/iso9660_ls.c @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include +#include +#include + +#include + +static void list(char *path) +{ + char name_buf[256]; + iso9660_DIR *dir; + struct iso_directory_record *idr; + + dir = iso9660_opendir(path); + if (dir == NULL) + return; + + while ((idr = iso9660_readdir(dir)) != NULL) + { + iso9660_name(name_buf, idr); + + 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; + + if (iso9660_mount(NULL) != 0) + return -1; + + if (argc > 1) + path = argv[1]; + else + path = "/"; + + list(path); + + iso9660_umount(); + + return (0); +}