mirror of
https://github.com/vivier/EMILE.git
synced 2025-02-01 19:30:36 +00:00
Add iso9660 tools
This commit is contained in:
parent
f8dc89b20b
commit
e421b248fc
@ -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
|
||||
|
29
tools/device.c
Normal file
29
tools/device.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#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);
|
||||
}
|
40
tools/iso9660_cat.c
Normal file
40
tools/iso9660_cat.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <libiso9660.h>
|
||||
|
||||
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;
|
||||
}
|
51
tools/iso9660_ls.c
Normal file
51
tools/iso9660_ls.c
Normal file
@ -0,0 +1,51 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <libiso9660.h>
|
||||
|
||||
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);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user