2007-03-20 09:41:05 +00:00
|
|
|
/* -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 8; -*- */
|
|
|
|
/* vim: set ts=8 sts=8 sw=8 noet : */
|
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
|
|
|
|
#include "libisofs.h"
|
|
|
|
#include "libburn/libburn.h"
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <err.h>
|
|
|
|
|
|
|
|
#define SECSIZE 2048
|
|
|
|
|
2007-09-06 15:15:09 +00:00
|
|
|
const char * const optstring = "JRL:b:hV:";
|
2007-03-20 09:41:05 +00:00
|
|
|
extern char *optarg;
|
|
|
|
extern int optind;
|
|
|
|
|
2007-09-14 04:03:42 +00:00
|
|
|
void usage(char **argv)
|
2007-03-20 09:41:05 +00:00
|
|
|
{
|
2007-09-14 04:03:42 +00:00
|
|
|
printf("%s [OPTIONS] DIRECTORY OUTPUT\n", argv[0]);
|
|
|
|
help();
|
2007-03-20 09:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void help()
|
|
|
|
{
|
|
|
|
printf(
|
|
|
|
"Options:\n"
|
2007-09-06 15:15:09 +00:00
|
|
|
" -J Add Joliet support\n"
|
|
|
|
" -R Add Rock Ridge support\n"
|
|
|
|
" -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"
|
2007-03-20 09:41:05 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2007-08-10 09:35:10 +00:00
|
|
|
struct ecma119_source_opts opts;
|
2007-03-20 09:41:05 +00:00
|
|
|
struct iso_volset *volset;
|
|
|
|
struct iso_volume *volume;
|
2007-05-31 04:25:39 +00:00
|
|
|
struct iso_tree_node_dir *root;
|
2007-03-20 09:41:05 +00:00
|
|
|
struct burn_source *src;
|
|
|
|
unsigned char buf[2048];
|
|
|
|
FILE *fd;
|
|
|
|
int c;
|
2007-08-10 09:35:10 +00:00
|
|
|
int constraints;
|
2007-05-31 04:25:39 +00:00
|
|
|
struct iso_tree_radd_dir_behavior behav = {0,0,0};
|
2007-03-20 09:41:05 +00:00
|
|
|
int level=1, flags=0;
|
2007-06-05 22:01:26 +00:00
|
|
|
char *boot_img = NULL;
|
2007-09-06 15:15:09 +00:00
|
|
|
char *volid = "VOLID";
|
2007-03-20 09:41:05 +00:00
|
|
|
|
|
|
|
while ((c = getopt(argc, argv, optstring)) != -1) {
|
|
|
|
switch(c) {
|
|
|
|
case 'h':
|
2007-09-14 04:03:42 +00:00
|
|
|
usage(argv);
|
2007-03-20 09:41:05 +00:00
|
|
|
help();
|
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
case 'J':
|
|
|
|
flags |= ECMA119_JOLIET;
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
flags |= ECMA119_ROCKRIDGE;
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
level = atoi(optarg);
|
|
|
|
break;
|
2007-06-05 22:01:26 +00:00
|
|
|
case 'b':
|
|
|
|
boot_img = optarg;
|
|
|
|
break;
|
2007-09-06 15:15:09 +00:00
|
|
|
case 'V':
|
|
|
|
volid = optarg;
|
|
|
|
break;
|
2007-03-20 09:41:05 +00:00
|
|
|
case '?':
|
2007-09-14 04:03:42 +00:00
|
|
|
usage(argv);
|
2007-03-20 09:41:05 +00:00
|
|
|
exit(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
printf ("Please pass directory from which to build ISO\n");
|
2007-09-14 04:03:42 +00:00
|
|
|
usage(argv);
|
2007-03-20 09:41:05 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (argc < 3) {
|
|
|
|
printf ("Please supply output file\n");
|
2007-09-14 04:03:42 +00:00
|
|
|
usage(argv);
|
2007-03-20 09:41:05 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2007-08-27 22:51:48 +00:00
|
|
|
|
|
|
|
if (!iso_init()) {
|
|
|
|
err(1, "Can't init libisofs");
|
|
|
|
}
|
|
|
|
iso_msgs_set_severities("NEVER", "ALL", "");
|
|
|
|
|
2007-03-20 09:41:05 +00:00
|
|
|
fd = fopen(argv[optind+1], "w");
|
|
|
|
if (!fd) {
|
|
|
|
err(1, "error opening output file");
|
|
|
|
}
|
|
|
|
|
2007-05-31 04:25:39 +00:00
|
|
|
root = iso_tree_new_root();
|
|
|
|
iso_tree_radd_dir(root, argv[optind], &behav);
|
2007-03-20 09:41:05 +00:00
|
|
|
if (!root) {
|
|
|
|
err(1, "error opening input directory");
|
|
|
|
}
|
2007-09-06 15:15:09 +00:00
|
|
|
volume = iso_volume_new_with_root(volid, "PUBID", "PREPID", root);
|
2007-06-05 22:01:26 +00:00
|
|
|
|
|
|
|
if ( boot_img ) {
|
|
|
|
/* adds El-Torito boot info. Tunned for isolinux */
|
2007-08-10 09:35:10 +00:00
|
|
|
struct el_torito_boot_image *bootimg;
|
2007-06-05 22:01:26 +00:00
|
|
|
struct iso_tree_node_dir *boot = (struct iso_tree_node_dir *)
|
|
|
|
iso_tree_volume_path_to_node(volume, "isolinux");
|
|
|
|
struct iso_tree_node *img = iso_tree_volume_path_to_node(volume, boot_img);
|
|
|
|
if (!img) {
|
|
|
|
err(1, "boot image patch is not valid");
|
|
|
|
}
|
2007-09-01 20:35:53 +00:00
|
|
|
bootimg = iso_volume_set_boot_image(volume, img, ELTORITO_NO_EMUL,
|
2007-08-10 09:35:10 +00:00
|
|
|
boot, "boot.cat");
|
2007-06-05 22:01:26 +00:00
|
|
|
el_torito_set_load_size(bootimg, 4);
|
2007-09-01 20:35:53 +00:00
|
|
|
el_torito_patch_isolinux_image(bootimg);
|
|
|
|
|
|
|
|
/* Or just this for hidden img
|
|
|
|
* iso_volume_set_boot_image_hidden(volume, boot_img, ELTORITO_NO_EMUL);
|
|
|
|
*/
|
2007-06-05 22:01:26 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 09:41:05 +00:00
|
|
|
volset = iso_volset_new( volume, "VOLSETID" );
|
2007-05-12 00:30:04 +00:00
|
|
|
|
2007-06-05 22:01:26 +00:00
|
|
|
/* some tests */
|
2007-05-12 00:30:04 +00:00
|
|
|
iso_volume_set_application_id(volume, "Libburnia");
|
|
|
|
iso_volume_set_copyright_file_id(volume, "LICENSE");
|
2007-03-20 09:41:05 +00:00
|
|
|
|
2007-08-10 09:35:10 +00:00
|
|
|
constraints = ECMA119_OMIT_VERSION_NUMBERS |
|
2007-06-21 11:19:11 +00:00
|
|
|
ECMA119_37_CHAR_FILENAMES | ECMA119_NO_DIR_REALOCATION |
|
|
|
|
ECMA119_RELAXED_FILENAMES;
|
|
|
|
|
2007-08-10 09:35:10 +00:00
|
|
|
memset(&opts, 0, sizeof(struct ecma119_source_opts));
|
|
|
|
opts.level = level;
|
|
|
|
opts.flags = flags;
|
2007-09-01 20:35:53 +00:00
|
|
|
opts.relaxed_constraints = 0;
|
|
|
|
opts.input_charset = NULL;
|
2007-08-10 09:35:10 +00:00
|
|
|
opts.ouput_charset = "UTF-8";
|
2007-06-21 11:19:11 +00:00
|
|
|
|
|
|
|
src = iso_source_new_ecma119(volset, &opts);
|
2007-03-20 09:41:05 +00:00
|
|
|
|
|
|
|
while (src->read(src, buf, 2048) == 2048) {
|
|
|
|
fwrite(buf, 1, 2048, fd);
|
|
|
|
}
|
|
|
|
fclose(fd);
|
|
|
|
|
2007-08-27 22:51:48 +00:00
|
|
|
iso_finish();
|
2007-03-20 09:41:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|