legacy/libisofs/attic/test/iso_add.c

158 lines
3.0 KiB
C
Raw Normal View History

2007-08-10 09:37:39 +00:00
/* -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 8; -*- */
/* vim: set ts=8 sts=8 sw=8 noet : */
/*
* Little program that appends a dir to an existing image
*/
#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
const char * const optstring = "JRL:h";
extern char *optarg;
extern int optind;
void usage()
{
printf("test [OPTIONS] IMAGE 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"
" -h Print this message\n"
);
}
int main(int argc, char **argv)
{
struct ecma119_source_opts wopts;
struct ecma119_read_opts ropts;
struct data_source *rsrc;
struct iso_volset *volset;
struct iso_tree_node_dir *root;
struct burn_source *wsrc;
unsigned char buf[2048];
FILE *fd;
int c;
int constraints;
struct iso_tree_radd_dir_behavior behav = {0,0,0};
int level=1, flags=0;
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;
case '?':
usage();
exit(1);
break;
}
}
if (argc < optind + 1) {
printf ("Please supply old image file\n");
usage();
return 1;
}
if (argc < optind + 2) {
printf ("Please supply directory to add to image\n");
usage();
return 1;
}
if (argc < optind + 3) {
printf ("Please supply output file\n");
usage();
return 1;
}
if (!iso_init()) {
err(1, "Can't init libisofs");
}
iso_msgs_set_severities("NEVER", "ALL", "");
2007-08-10 09:37:39 +00:00
rsrc = data_source_from_file(argv[optind]);
if (rsrc == NULL) {
printf ("Can't open device\n");
return 1;
}
fd = fopen(argv[optind+2], "w");
if (!fd) {
err(1, "error opening output file");
}
ropts.block = 0;
ropts.norock = 0;
ropts.nojoliet = 0;
ropts.preferjoliet = 0;
ropts.mode = 0555;
ropts.uid = 0;
ropts.gid = 0;
2007-08-10 09:37:39 +00:00
volset = iso_volset_read(rsrc, &ropts);
if (volset == NULL) {
printf ("Error reading image\n");
return 1;
}
root = iso_volume_get_root(iso_volset_get_volume(volset, 0));
iso_tree_radd_dir(root, argv[optind+1], &behav);
constraints = ECMA119_OMIT_VERSION_NUMBERS |
ECMA119_37_CHAR_FILENAMES | ECMA119_NO_DIR_REALOCATION |
ECMA119_RELAXED_FILENAMES;
memset(&wopts, 0, sizeof(struct ecma119_source_opts));
wopts.level = level;
wopts.flags = flags;
wopts.relaxed_constraints = 0;//constraints;
wopts.input_charset = "UTF-8";
wopts.ouput_charset = "UTF-8";
wopts.ms_block = 0;
wopts.src = rsrc;
wsrc = iso_source_new_ecma119(volset, &wopts);
while (wsrc->read(wsrc, buf, 2048) == 2048) {
fwrite(buf, 1, 2048, fd);
}
fclose(fd);
iso_finish();
2007-08-10 09:37:39 +00:00
return 0;
}