2008-01-04 22:54:31 +00:00
|
|
|
/*
|
|
|
|
* Little program to show how to create a multisession iso image.
|
|
|
|
*/
|
|
|
|
|
2009-02-18 09:29:26 +00:00
|
|
|
#define LIBISOFS_WITHOUT_LIBBURN yes
|
2008-01-04 22:54:31 +00:00
|
|
|
#include "libisofs.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <err.h>
|
|
|
|
|
|
|
|
void usage(char **argv)
|
|
|
|
{
|
|
|
|
printf("%s LSS NWA DISC DIRECTORY OUTPUT\n", argv[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
IsoImage *image;
|
|
|
|
IsoDataSource *src;
|
|
|
|
struct burn_source *burn_src;
|
|
|
|
unsigned char buf[2048];
|
|
|
|
FILE *fd;
|
2008-01-26 12:04:16 +00:00
|
|
|
IsoWriteOpts *opts;
|
2008-01-26 13:00:46 +00:00
|
|
|
IsoReadOpts *ropts;
|
2008-01-26 12:04:16 +00:00
|
|
|
uint32_t ms_block;
|
2008-01-04 22:54:31 +00:00
|
|
|
|
|
|
|
if (argc < 6) {
|
|
|
|
usage(argv);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = fopen(argv[5], "w");
|
|
|
|
if (!fd) {
|
|
|
|
err(1, "error opening output file");
|
|
|
|
}
|
2008-01-19 01:48:12 +00:00
|
|
|
|
|
|
|
iso_init();
|
|
|
|
iso_set_msgs_severities("NEVER", "ALL", "");
|
2008-01-04 22:54:31 +00:00
|
|
|
|
|
|
|
/* create the data source to accesss previous image */
|
|
|
|
result = iso_data_source_new_from_file(argv[3], &src);
|
|
|
|
if (result < 0) {
|
|
|
|
printf ("Error creating data source\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create the image context */
|
|
|
|
result = iso_image_new("volume_id", &image);
|
|
|
|
if (result < 0) {
|
|
|
|
printf ("Error creating image\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
iso_tree_set_follow_symlinks(image, 0);
|
|
|
|
iso_tree_set_ignore_hidden(image, 0);
|
|
|
|
|
|
|
|
/* import previous image */
|
2008-01-26 13:00:46 +00:00
|
|
|
result = iso_read_opts_new(&ropts, 0);
|
|
|
|
if (result < 0) {
|
|
|
|
fprintf(stderr, "Error creating read options\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
iso_read_opts_set_start_block(ropts, atoi(argv[1]));
|
|
|
|
result = iso_image_import(image, src, ropts, NULL);
|
|
|
|
iso_read_opts_free(ropts);
|
2008-01-04 22:54:31 +00:00
|
|
|
iso_data_source_unref(src);
|
|
|
|
if (result < 0) {
|
|
|
|
printf ("Error importing previous session %d\n", result);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add new dir */
|
|
|
|
result = iso_tree_add_dir_rec(image, iso_image_get_root(image), argv[4]);
|
|
|
|
if (result < 0) {
|
|
|
|
printf ("Error adding directory %d\n", result);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* generate a multisession image with new contents */
|
2008-01-26 12:04:16 +00:00
|
|
|
result = iso_write_opts_new(&opts, 1);
|
|
|
|
if (result < 0) {
|
|
|
|
printf("Cant create write opts, error %d\n", result);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* round up to 32kb aligment = 16 block */
|
|
|
|
ms_block = atoi(argv[2]);
|
|
|
|
iso_write_opts_set_ms_block(opts, ms_block);
|
|
|
|
iso_write_opts_set_appendable(opts, 1);
|
|
|
|
|
|
|
|
result = iso_image_create_burn_source(image, opts, &burn_src);
|
2008-01-04 22:54:31 +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-04 22:54:31 +00:00
|
|
|
|
2008-01-22 23:34:27 +00:00
|
|
|
while (burn_src->read_xt(burn_src, buf, 2048) == 2048) {
|
2008-01-04 22:54:31 +00:00
|
|
|
fwrite(buf, 1, 2048, fd);
|
|
|
|
}
|
|
|
|
fclose(fd);
|
|
|
|
burn_src->free_data(burn_src);
|
|
|
|
free(burn_src);
|
|
|
|
|
|
|
|
iso_image_unref(image);
|
2008-01-19 01:48:12 +00:00
|
|
|
iso_finish();
|
2008-01-04 22:54:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|