libisofs/demo/iso.c

100 lines
2.3 KiB
C
Raw Normal View History

/*
* Little program to show how to create an iso image from a local
* directory.
*/
#include "libisofs.h"
#include "libburn/libburn.h"
#include <stdio.h>
2007-12-28 21:45:56 +00:00
#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 [OPTIONS] DIRECTORY OUTPUT\n", argv[0]);
}
int main(int argc, char **argv)
{
2007-12-27 09:43:06 +00:00
int result;
IsoImage *image;
struct burn_source *burn_src;
unsigned char buf[2048];
FILE *fd;
Ecma119WriteOpts opts = {
1, /* level */
2007-12-27 09:43:06 +00:00
1, /* rockridge */
2008-01-08 15:10:25 +00:00
1, /* joliet */
2007-12-27 09:43:06 +00:00
0, /* omit_version_numbers */
0, /* allow_deep_paths */
2008-01-08 15:10:25 +00:00
0, /* joliet_longer_paths */
0, /* sort files */
0, /* replace_dir_mode */
0, /* replace_file_mode */
0, /* replace_uid */
0, /* replace_gid */
0, /* dir_mode */
0, /* file_mode */
0, /* uid */
0, /* gid */
NULL, /* output charset */
0, /* appendable */
0, /* ms_block */
NULL /* overwrite */
};
2007-12-27 09:43:06 +00:00
if (argc < 2) {
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");
}
result = iso_image_new("volume_id", &image);
if (result < 0) {
printf ("Error creating image\n");
return 1;
}
2007-12-27 09:43:06 +00:00
iso_image_set_msgs_severities(image, "NEVER", "ALL", "");
iso_tree_set_follow_symlinks(image, 0);
iso_tree_set_ignore_hidden(image, 0);
iso_tree_set_stop_on_error(image, 0);
result = iso_tree_add_dir_rec(image, iso_image_get_root(image), argv[1]);
if (result < 0) {
printf ("Error adding directory %d\n", result);
return 1;
}
2008-01-04 23:42:32 +00:00
result = iso_image_create_burn_source(image, &opts, &burn_src);
if (result < 0) {
printf ("Cant create image, error %d\n", result);
return 1;
}
while (burn_src->read(burn_src, buf, 2048) == 2048) {
fwrite(buf, 1, 2048, fd);
}
fclose(fd);
burn_src->free_data(burn_src);
2007-12-28 21:45:56 +00:00
free(burn_src);
iso_image_unref(image);
return 0;
}