2007-12-22 16:09:49 +00:00
|
|
|
/*
|
|
|
|
* Little program to show how to create an iso image from a local
|
|
|
|
* directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libisofs.h"
|
|
|
|
#include "libburn/libburn.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2008-01-10 18:41:38 +00:00
|
|
|
#include <getopt.h>
|
2007-12-28 21:45:56 +00:00
|
|
|
#include <stdlib.h>
|
2007-12-22 16:09:49 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <err.h>
|
|
|
|
|
2008-01-16 20:51:41 +00:00
|
|
|
const char * const optstring = "JRIL:b:hV:";
|
2008-01-10 18:41:38 +00:00
|
|
|
extern char *optarg;
|
|
|
|
extern int optind;
|
|
|
|
|
2007-12-22 16:09:49 +00:00
|
|
|
void usage(char **argv)
|
|
|
|
{
|
|
|
|
printf("%s [OPTIONS] DIRECTORY OUTPUT\n", argv[0]);
|
|
|
|
}
|
|
|
|
|
2008-01-10 18:41:38 +00:00
|
|
|
void help()
|
|
|
|
{
|
|
|
|
printf(
|
|
|
|
"Options:\n"
|
|
|
|
" -J Add Joliet support\n"
|
|
|
|
" -R Add Rock Ridge support\n"
|
2008-01-16 20:51:41 +00:00
|
|
|
" -I Add ISO 9660:1999 support\n"
|
2008-01-10 18:41:38 +00:00
|
|
|
" -V label Volume Label\n"
|
|
|
|
" -L <num> Set the ISO level (1 or 2)\n"
|
|
|
|
" -b file Specifies a boot image to add to image\n"
|
|
|
|
" -h Print this message\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-01-23 19:46:38 +00:00
|
|
|
int callback(IsoFileSource *src)
|
|
|
|
{
|
|
|
|
char *path = iso_file_source_get_path(src);
|
|
|
|
printf("CALLBACK: %s\n", path);
|
|
|
|
free(path);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-12-22 16:09:49 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2007-12-27 09:43:06 +00:00
|
|
|
int result;
|
2008-01-10 18:41:38 +00:00
|
|
|
int c;
|
2007-12-22 16:09:49 +00:00
|
|
|
IsoImage *image;
|
|
|
|
struct burn_source *burn_src;
|
|
|
|
unsigned char buf[2048];
|
|
|
|
FILE *fd;
|
2008-01-26 12:04:16 +00:00
|
|
|
IsoWriteOpts *opts;
|
2008-01-10 18:41:38 +00:00
|
|
|
char *volid = "VOLID";
|
|
|
|
char *boot_img = NULL;
|
2008-01-26 12:04:16 +00:00
|
|
|
int rr = 0, j = 0, iso1999 = 0, level = 1;
|
2008-01-10 18:41:38 +00:00
|
|
|
|
|
|
|
while ((c = getopt(argc, argv, optstring)) != -1) {
|
|
|
|
switch(c) {
|
|
|
|
case 'h':
|
|
|
|
usage(argv);
|
|
|
|
help();
|
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
case 'J':
|
2008-01-26 12:04:16 +00:00
|
|
|
j = 1;
|
2008-01-10 18:41:38 +00:00
|
|
|
break;
|
|
|
|
case 'R':
|
2008-01-26 12:04:16 +00:00
|
|
|
rr = 1;
|
2008-01-10 18:41:38 +00:00
|
|
|
break;
|
2008-01-16 20:51:41 +00:00
|
|
|
case 'I':
|
2008-01-26 12:04:16 +00:00
|
|
|
iso1999 = 1;
|
2008-01-16 20:51:41 +00:00
|
|
|
break;
|
2008-01-10 18:41:38 +00:00
|
|
|
case 'L':
|
2008-01-26 12:04:16 +00:00
|
|
|
level = atoi(optarg);
|
2008-01-10 18:41:38 +00:00
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
boot_img = optarg;
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
volid = optarg;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
usage(argv);
|
|
|
|
exit(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-12-22 16:09:49 +00:00
|
|
|
|
2007-12-27 09:43:06 +00:00
|
|
|
if (argc < 2) {
|
2007-12-22 16:09:49 +00:00
|
|
|
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");
|
|
|
|
}
|
2008-01-19 01:48:12 +00:00
|
|
|
|
|
|
|
result = iso_init();
|
|
|
|
if (result < 0) {
|
|
|
|
printf ("Can't initialize libisofs\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
iso_set_msgs_severities("NEVER", "ALL", "");
|
2007-12-22 16:09:49 +00:00
|
|
|
|
2008-01-10 18:41:38 +00:00
|
|
|
result = iso_image_new(volid, &image);
|
2007-12-22 16:09:49 +00:00
|
|
|
if (result < 0) {
|
|
|
|
printf ("Error creating image\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2007-12-29 16:15:24 +00:00
|
|
|
iso_tree_set_follow_symlinks(image, 0);
|
|
|
|
iso_tree_set_ignore_hidden(image, 0);
|
2008-01-15 16:23:34 +00:00
|
|
|
iso_tree_set_ignore_special(image, 0);
|
2008-01-22 21:24:33 +00:00
|
|
|
iso_set_abort_severity("SORRY");
|
2008-01-26 15:10:23 +00:00
|
|
|
/*iso_tree_set_report_callback(image, callback);*/
|
2007-12-29 16:15:24 +00:00
|
|
|
|
2008-01-10 18:41:38 +00:00
|
|
|
result = iso_tree_add_dir_rec(image, iso_image_get_root(image), argv[optind]);
|
2007-12-22 16:09:49 +00:00
|
|
|
if (result < 0) {
|
|
|
|
printf ("Error adding directory %d\n", result);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-01-10 18:41:38 +00:00
|
|
|
if (boot_img) {
|
|
|
|
/* adds El-Torito boot info. Tunned for isolinux */
|
|
|
|
ElToritoBootImage *bootimg;
|
|
|
|
result = iso_image_set_boot_image(image, boot_img, ELTORITO_NO_EMUL,
|
|
|
|
"/isolinux/boot.cat", &bootimg);
|
|
|
|
if (result < 0) {
|
|
|
|
printf ("Error adding boot image %d\n", result);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
el_torito_set_load_size(bootimg, 4);
|
|
|
|
el_torito_patch_isolinux_image(bootimg);
|
|
|
|
}
|
2008-01-26 12:04:16 +00:00
|
|
|
|
|
|
|
result = iso_write_opts_new(&opts, 0);
|
|
|
|
if (result < 0) {
|
|
|
|
printf ("Cant create write opts, error %d\n", result);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
iso_write_opts_set_iso_level(opts, level);
|
|
|
|
iso_write_opts_set_rockridge(opts, rr);
|
|
|
|
iso_write_opts_set_joliet(opts, j);
|
|
|
|
iso_write_opts_set_iso1999(opts, iso1999);
|
2008-01-10 18:41:38 +00:00
|
|
|
|
2008-01-26 12:04:16 +00:00
|
|
|
result = iso_image_create_burn_source(image, opts, &burn_src);
|
2007-12-22 16:09:49 +00:00
|
|
|
if (result < 0) {
|
|
|
|
printf ("Cant create image, error %d\n", result);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-01-26 12:04:16 +00:00
|
|
|
iso_write_opts_free(opts);
|
|
|
|
|
2008-01-22 23:34:27 +00:00
|
|
|
while (burn_src->read_xt(burn_src, buf, 2048) == 2048) {
|
2007-12-22 16:09:49 +00:00
|
|
|
fwrite(buf, 1, 2048, fd);
|
|
|
|
}
|
|
|
|
fclose(fd);
|
|
|
|
burn_src->free_data(burn_src);
|
2007-12-28 21:45:56 +00:00
|
|
|
free(burn_src);
|
2007-12-22 16:09:49 +00:00
|
|
|
|
|
|
|
iso_image_unref(image);
|
2008-01-19 01:48:12 +00:00
|
|
|
iso_finish();
|
2007-12-22 16:09:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|