From b1594201cbc4faff9834745f0a8eb88c54224d64 Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Sat, 12 Apr 2008 21:19:32 +0000 Subject: [PATCH] Add tools for ext2 --- tools/Makefile | 14 +++++++--- tools/ext2_cat.c | 69 +++++++++++++++++++++++++++++++++++++++++++++ tools/ext2_ls.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 4 deletions(-) create mode 100644 tools/ext2_cat.c create mode 100644 tools/ext2_ls.c diff --git a/tools/Makefile b/tools/Makefile index 1001239..6d72cb0 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -8,13 +8,14 @@ TOP=$(shell pwd) PROGRAMS = emile-set-cmdline emile-first-tune emile-install \ emile-set-output emile emile-map-set iso9660_ls \ - iso9660_cat minigzip read_vmlinuz emile-mkisofs + iso9660_cat minigzip read_vmlinuz emile-mkisofs \ + ext2_ls ext2_cat SOURCES = 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 iso9660_ls.c \ iso9660_cat.c minigzip.c read_vmlinuz.c device.c gzio.c \ - emile-mkisofs.c emile_config.c + emile-mkisofs.c emile_config.c ext2_ls.c ext2_cat.c HEADERS = device.h emile_config.h @@ -23,10 +24,11 @@ DISTFILES =$(HEADERS) $(SOURCES) Makefile CPPFLAGS = $(CROSS_COMPILE_CPPFLAGS) -DSIGNATURE="\"$(SIGNATURE)\"" -DPREFIX=\"$(PREFIX)\" \ -I../libemile -I../libiso9660 -I../libgzip -I../libstream \ -I../libcontainer -I../libmacos -DFATFREE -DNO_GZCOMPRESS \ - -I../libconfig -I../libmap + -I../libconfig -I../libmap -I../libext2 CFLAGS = -Wall -Werror -g -LDLIBS = $(CROSS_COMPILE_LDFLAGS) -L../libemile -lemile -L../libiso9660/native -liso9660 -L../libgzip/native -lgzip -L../libconfig/native -lconfig -L../libmap/native -lmap +LDLIBS = $(CROSS_COMPILE_LDFLAGS) -L../libemile -lemile -L../libiso9660/native -liso9660 -L../libgzip/native -lgzip -L../libconfig/native -lconfig -L../libmap/native -lmap \ +-L../libext2/native -lext2 all: $(PROGRAMS) @@ -40,6 +42,10 @@ iso9660_ls: iso9660_ls.o device.o iso9660_cat: iso9660_cat.o device.o +ext2_ls: ext2_ls.o device.o + +ext2_cat: ext2_cat.o device.o + minigzip: minigzip.c gzio.c read_vmlinuz: read_vmlinuz.o gzio.o diff --git a/tools/ext2_cat.c b/tools/ext2_cat.c new file mode 100644 index 0000000..35c998f --- /dev/null +++ b/tools/ext2_cat.c @@ -0,0 +1,69 @@ +/* + * + * (c) 2005 Laurent Vivier + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include +#include + +#include "device.h" + +int main(int argc, char **argv) +{ + char *path; + device_io_t device; + ext2_FILE* file; + ext2_VOLUME *volume; + char buffer[512]; + ssize_t size; + int arg = 1; + char *devname; + + if (argc <= arg) + return 1; + devname = argv[arg++]; + + if (argc > arg) + path = argv[arg++]; + else + path = "/"; + + device_sector_size = 512; + device.data = (void*)device_open(devname, O_RDONLY); + device.read_sector = (stream_read_sector_t)device_read_sector; + device.close = (stream_close_t)device_close; + device.get_blocksize = (stream_get_blocksize_t)device_get_blocksize; + + volume = ext2_mount(&device); + if (volume == NULL) + return 1; + + file = ext2_open(volume, path); + if (file == NULL) + { + fprintf(stderr, "%s not found\n", path); + return -1; + } + + while((size = ext2_read(file, buffer, 512)) > 0) + write(STDOUT_FILENO, buffer, size); + ext2_close(file); + + ext2_umount(volume); + + device_close(device.data); + + return 0; +} diff --git a/tools/ext2_ls.c b/tools/ext2_ls.c new file mode 100644 index 0000000..ebec167 --- /dev/null +++ b/tools/ext2_ls.c @@ -0,0 +1,73 @@ +/* + * + * (c) 2005 Laurent Vivier + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include + +#include "device.h" + +static void list(ext2_VOLUME *volume, char *path) +{ + ext2_DIR *dir; + struct ext2_dir_entry_2 *entry; + + dir = ext2_opendir(volume, path); + if (dir == NULL) + return; + while ((entry = ext2_readdir(dir)) != NULL) + { + if (entry->file_type == EXT2_FT_DIR) + printf("%s/\n", entry->name); + else + printf("%s\n", entry->name); + } + ext2_closedir(dir); +} + +int main(int argc, char **argv) +{ + char *path; + device_io_t device; + ext2_VOLUME *volume; + int arg = 1; + + device_sector_size = 512; + if (argc <= 1) { + fprintf(stderr, "You must specify a device to open\n"); + exit(1); + } + device.data = (void*)device_open(argv[arg++], O_RDONLY); + device.read_sector = (stream_read_sector_t)device_read_sector; + device.close = (stream_close_t)device_close; + device.get_blocksize = (stream_get_blocksize_t)device_get_blocksize; + + volume = ext2_mount(&device); + if (volume == NULL) + return -1; + + if (argc > arg) + path = argv[arg]; + else + path = "/"; + + list(volume, path); + + ext2_umount(volume); + + device_close(device.data); + + return (0); +}