libisofs-legacy/test/iso.c

135 lines
2.8 KiB
C
Raw Normal View History

2006-08-15 20:37:04 +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
2006-08-24 19:23:37 +00:00
#include "libisofs.h"
2006-08-24 20:46:12 +00:00
#include "libburn/libburn.h"
2006-08-15 20:37:04 +00:00
#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>
2006-08-24 19:23:37 +00:00
#include <err.h>
2006-08-15 20:37:04 +00:00
#define SECSIZE 2048
2007-06-05 22:01:26 +00:00
const char * const optstring = "JRL:b:h";
2006-08-15 20:37:04 +00:00
extern char *optarg;
extern int optind;
void usage()
{
printf("test [OPTIONS] DIRECTORY OUTPUT\n");
}
void help()
{
printf(
"Options:\n"
" -J Add Joliet support\n"
" -R Add Rock Ridge support\n"
" -L <num> Set the ISO level (1 or 2)\n"
2007-06-05 22:01:26 +00:00
" -b file Specifies a boot image to add to image\n"
2006-08-15 20:37:04 +00:00
" -h Print this message\n"
);
}
int main(int argc, char **argv)
{
struct iso_volset *volset;
struct iso_volume *volume;
struct iso_tree_node_dir *root;
2006-08-15 20:37:04 +00:00
struct burn_source *src;
unsigned char buf[2048];
FILE *fd;
int c;
struct iso_tree_radd_dir_behavior behav = {0,0,0};
2006-08-15 20:37:04 +00:00
int level=1, flags=0;
2007-06-05 22:01:26 +00:00
char *boot_img = NULL;
2006-08-15 20:37:04 +00:00
while ((c = getopt(argc, argv, optstring)) != -1) {
switch(c) {
case 'h':
usage();
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;
2006-08-15 20:37:04 +00:00
case '?':
usage();
exit(1);
break;
}
}
if (argc < 2) {
2006-12-03 11:14:07 +00:00
printf ("Please pass directory from which to build ISO\n");
2006-08-15 20:37:04 +00:00
usage();
return 1;
}
if (argc < 3) {
2006-12-03 11:14:07 +00:00
printf ("Please supply output file\n");
2006-08-15 20:37:04 +00:00
usage();
return 1;
}
fd = fopen(argv[optind+1], "w");
if (!fd) {
2006-08-24 19:23:37 +00:00
err(1, "error opening output file");
2006-08-15 20:37:04 +00:00
}
root = iso_tree_new_root();
iso_tree_radd_dir(root, argv[optind], &behav);
2006-08-24 19:23:37 +00:00
if (!root) {
err(1, "error opening input directory");
2006-08-15 20:37:04 +00:00
}
2006-08-24 19:23:37 +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 */
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");
}
struct el_torito_boot_image *bootimg =
iso_volume_create_boot_catalog(volume, img, ELTORITO_NO_EMUL,
boot, "boot.cat");
el_torito_set_load_size(bootimg, 4);
el_torito_set_write_boot_info(bootimg);
}
2006-08-24 19:23:37 +00:00
volset = iso_volset_new( volume, "VOLSETID" );
2007-06-05 22:01:26 +00:00
/* some tests */
iso_volume_set_application_id(volume, "Libburnia");
iso_volume_set_copyright_file_id(volume, "LICENSE");
2006-08-15 20:37:04 +00:00
src = iso_source_new_ecma119(volset, 0, level, flags);
while (src->read(src, buf, 2048) == 2048) {
fwrite(buf, 1, 2048, fd);
}
fclose(fd);
return 0;
}