From de3c4e4962a426d5b564c0f7b7a266653090601f Mon Sep 17 00:00:00 2001 From: Vreixo Formoso Date: Sat, 22 Dec 2007 17:09:49 +0100 Subject: [PATCH] Little demo program to test image generation. --- .bzrignore | 1 + Makefile.am | 7 ++++- demo/iso.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 demo/iso.c diff --git a/.bzrignore b/.bzrignore index 582b34e..20b3250 100644 --- a/.bzrignore +++ b/.bzrignore @@ -28,3 +28,4 @@ demo/lsl demo/cat demo/tree demo/ecma119tree +demo/iso diff --git a/Makefile.am b/Makefile.am index 402b6f1..3cd45a5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -47,7 +47,8 @@ noinst_PROGRAMS = \ demo/lsl \ demo/cat \ demo/tree \ - demo/ecma119tree + demo/ecma119tree \ + demo/iso demo_lsl_CPPFLAGS = -Isrc demo_lsl_LDADD = $(src_libisofs_la_OBJECTS) $(THREAD_LIBS) @@ -65,6 +66,10 @@ demo_ecma119tree_CPPFLAGS = -Isrc demo_ecma119tree_LDADD = $(src_libisofs_la_OBJECTS) $(THREAD_LIBS) demo_ecma119tree_SOURCES = demo/ecma119_tree.c +demo_iso_CPPFLAGS = -Isrc +demo_iso_LDADD = $(src_libisofs_la_OBJECTS) $(THREAD_LIBS) +demo_iso_SOURCES = demo/iso.c + ## Build unit test diff --git a/demo/iso.c b/demo/iso.c new file mode 100644 index 0000000..2588765 --- /dev/null +++ b/demo/iso.c @@ -0,0 +1,78 @@ +/* + * Little program to show how to create an iso image from a local + * directory. + */ + +#include "libisofs.h" +#include "libburn/libburn.h" + +#include +#include +#include +#include +#include +#include +#include + +void usage(char **argv) +{ + printf("%s [OPTIONS] DIRECTORY OUTPUT\n", argv[0]); +} + +int main(int argc, char **argv) +{ + int result; + IsoImage *image; + struct burn_source *burn_src; + unsigned char buf[2048]; + FILE *fd; + Ecma119WriteOpts opts = { + 1, /* level */ + 0, /* flags */ + 0 /* sort files */ + }; + + if (argc < 2) { + printf ("Please pass directory from which to build ISO\n"); + usage(argv); + return 1; + } + if (argc < 3) { + printf ("Please supply output file\n"); + usage(argv); + return 1; + } + + fd = fopen(argv[optind+1], "w"); + if (!fd) { + err(1, "error opening output file"); + } + + result = iso_image_new("volume_id", &image); + if (result < 0) { + printf ("Error creating image\n"); + return 1; + } + iso_image_set_msgs_severities(image, "NEVER", "ALL", ""); + + result = iso_tree_add_dir_rec(image, iso_image_get_root(image), argv[1]); + if (result < 0) { + printf ("Error adding directory %d\n", result); + return 1; + } + + result = iso_image_create(image, &opts, &burn_src); + if (result < 0) { + printf ("Cant create image, error %d\n", result); + return 1; + } + + while (burn_src->read(burn_src, buf, 2048) == 2048) { + fwrite(buf, 1, 2048, fd); + } + fclose(fd); + burn_src->free_data(burn_src); + + iso_image_unref(image); + return 0; +}