2007-09-22 15:19:05 +00:00
|
|
|
/*
|
|
|
|
Little test program for libisoburn.
|
|
|
|
It grows an iso filesystem on a disc.
|
|
|
|
|
|
|
|
Copyright 2007 Vreixo Formoso Lopes <metalpain2002@yahoo.es>
|
2007-10-02 21:36:44 +00:00
|
|
|
and Thomas Schmitt <scdbackup@gmx.net>
|
2007-09-22 15:19:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <err.h>
|
2007-10-02 21:36:44 +00:00
|
|
|
#include <string.h>
|
2007-10-08 20:41:42 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/stat.h>
|
2007-10-02 21:36:44 +00:00
|
|
|
|
2007-09-22 15:19:05 +00:00
|
|
|
|
|
|
|
#include <libisofs/libisofs.h>
|
|
|
|
#include <libburn/libburn.h>
|
|
|
|
#include "../src/libisoburn.h"
|
|
|
|
|
|
|
|
const char * const optstring = "JRh";
|
|
|
|
extern char *optarg;
|
|
|
|
extern int optind;
|
|
|
|
|
2007-10-02 21:36:44 +00:00
|
|
|
|
|
|
|
/** Activates the usage of function graft_point() rather than
|
|
|
|
plain iso_tree_radd_dir() from libisofs
|
|
|
|
*/
|
|
|
|
#define With_graft_poinT 1
|
|
|
|
|
|
|
|
|
2007-10-08 20:41:42 +00:00
|
|
|
static int graft_point(struct iso_volume *volume, const char *disk_path,
|
2007-10-02 21:36:44 +00:00
|
|
|
const char *img_path, struct iso_tree_radd_dir_behavior *behav)
|
|
|
|
{
|
|
|
|
char path[4096], *apt, *npt;
|
|
|
|
struct iso_tree_node_dir *dir;
|
|
|
|
struct iso_tree_node *node;
|
2007-10-08 20:41:42 +00:00
|
|
|
int done= 0, is_dir= 0;
|
|
|
|
struct stat stbuf;
|
2007-10-02 21:36:44 +00:00
|
|
|
|
|
|
|
strncpy(path, img_path, sizeof(path)-1);
|
|
|
|
path[sizeof(path)-1]= 0;
|
|
|
|
apt= npt= path;
|
|
|
|
|
2007-10-08 20:41:42 +00:00
|
|
|
if(lstat(disk_path, &stbuf) == -1) {
|
|
|
|
fprintf(stderr, "Cannot determine attributes of '%s' : %s (%d)\n",
|
|
|
|
disk_path, (errno > 0 ? strerror(errno) : "unknown error"), errno);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
if(S_ISDIR(stbuf.st_mode))
|
|
|
|
is_dir= 1;
|
|
|
|
else if(!(S_ISREG(stbuf.st_mode) || S_ISLNK(stbuf.st_mode))) {
|
|
|
|
fprintf(stderr, "File object '%s' is of non-supported file type\n",
|
|
|
|
disk_path);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2007-10-02 21:36:44 +00:00
|
|
|
dir= iso_volume_get_root(volume);
|
|
|
|
if(dir==NULL) {
|
|
|
|
fprintf(stderr, "While grafting '%s' : no root node available\n", img_path);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
for(npt= apt; !done; apt= npt+1) {
|
|
|
|
npt= strchr(apt, '/');
|
|
|
|
if(npt==NULL) {
|
|
|
|
npt= apt+strlen(apt);
|
|
|
|
done= 1;
|
|
|
|
} else
|
|
|
|
*npt= 0;
|
|
|
|
if(*apt==0) {
|
|
|
|
*apt= '/';
|
|
|
|
apt++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
node= iso_tree_volume_path_to_node(volume,path);
|
|
|
|
if(node!=NULL) {
|
|
|
|
if(iso_tree_node_get_type(node)!=LIBISO_NODE_DIR) {
|
|
|
|
fprintf(stderr, "While grafting '%s' : '%s' is not a directory\n",
|
|
|
|
img_path, path);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
dir= (struct iso_tree_node_dir *) node;
|
|
|
|
} else {
|
|
|
|
dir= iso_tree_add_dir(dir, apt);
|
|
|
|
if(dir==NULL) {
|
|
|
|
fprintf(stderr, "While grafting '%s' : could not insert '%s'\n",
|
|
|
|
img_path, path);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
2007-10-08 20:41:42 +00:00
|
|
|
if(done) {
|
|
|
|
if(is_dir) {
|
|
|
|
iso_tree_radd_dir(dir, disk_path, behav);
|
|
|
|
} else {
|
|
|
|
node= iso_tree_add_node(dir, disk_path);
|
|
|
|
if(node == NULL) {
|
|
|
|
fprintf(stderr, "While grafting '%s'='%s' : libisofs_errno = %d\n",
|
|
|
|
img_path, disk_path, libisofs_errno);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
2007-10-02 21:36:44 +00:00
|
|
|
*npt= '/';
|
|
|
|
}
|
2007-10-08 20:41:42 +00:00
|
|
|
fprintf(stderr, "NOTE: added %s '%s'='%s'\n", (is_dir ? "directory" : "node"),
|
|
|
|
img_path, disk_path);
|
2007-10-02 21:36:44 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-22 15:19:05 +00:00
|
|
|
static
|
|
|
|
void usage()
|
|
|
|
{
|
|
|
|
printf("test [OPTIONS] DRIVE DIRECTORY\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void help()
|
|
|
|
{
|
|
|
|
printf(
|
|
|
|
"Options:\n"
|
|
|
|
" -J Add Joliet support\n"
|
|
|
|
" -R Add Rock Ridge support\n"
|
|
|
|
" -h Print this message\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct burn_drive_info *drives;
|
|
|
|
struct iso_volset *volset;
|
|
|
|
struct burn_drive *drive;
|
|
|
|
struct burn_disc *disc;
|
|
|
|
enum burn_disc_status state;
|
|
|
|
struct isoburn_read_opts ropts;
|
2007-09-28 16:10:48 +00:00
|
|
|
struct isoburn_source_opts sopts;
|
2007-09-22 15:19:05 +00:00
|
|
|
int c;
|
|
|
|
struct iso_tree_radd_dir_behavior behav = {0,0,0};
|
|
|
|
int flags=0;
|
2007-10-08 20:41:42 +00:00
|
|
|
int ret=0, i;
|
|
|
|
int size, free_bytes;
|
|
|
|
char *status_text;
|
2007-09-22 15:19:05 +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 '?':
|
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc < optind + 1) {
|
2007-10-02 21:36:44 +00:00
|
|
|
fprintf(stderr, "Please supply device name\n");
|
2007-09-22 15:19:05 +00:00
|
|
|
usage();
|
2007-10-02 21:36:44 +00:00
|
|
|
exit(1);
|
2007-09-22 15:19:05 +00:00
|
|
|
}
|
|
|
|
if (argc < optind + 2) {
|
2007-10-02 21:36:44 +00:00
|
|
|
fprintf(stderr, "Please supply directory to add to disc\n");
|
2007-09-22 15:19:05 +00:00
|
|
|
usage();
|
2007-10-02 21:36:44 +00:00
|
|
|
exit(1);
|
2007-09-22 15:19:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!isoburn_initialize()) {
|
2007-10-02 21:36:44 +00:00
|
|
|
fprintf(stderr, "Can't init libisoburn\n");
|
|
|
|
exit(1);
|
2007-09-22 15:19:05 +00:00
|
|
|
}
|
|
|
|
|
2007-10-02 21:36:44 +00:00
|
|
|
/* TODO change this. maybe we can add wrapp in libisoburn */
|
2007-09-22 15:19:05 +00:00
|
|
|
iso_msgs_set_severities("NEVER", "DEBUG", "libisofs : ");
|
|
|
|
burn_msgs_set_severities("NEVER", "DEBUG", "libburn : ");
|
2007-10-02 21:36:44 +00:00
|
|
|
burn_set_signal_handling("libisoburn/test/test : ", NULL, 0);
|
2007-09-22 15:19:05 +00:00
|
|
|
|
|
|
|
printf("Growing drive %s\n", argv[optind]);
|
|
|
|
|
2007-10-02 21:36:44 +00:00
|
|
|
if (isoburn_drive_scan_and_grab(&drives, argv[optind], 1) <= 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Can't open device. Are you sure it is a valid drive?\n");
|
|
|
|
exit(1);
|
2007-09-22 15:19:05 +00:00
|
|
|
}
|
|
|
|
drive = drives[0].drive;
|
|
|
|
|
|
|
|
/* check for invalid state */
|
|
|
|
state = isoburn_disc_get_status(drive);
|
|
|
|
if (state != BURN_DISC_BLANK && state != BURN_DISC_APPENDABLE) {
|
2007-10-02 21:36:44 +00:00
|
|
|
fprintf(stderr, "Unsuitable disc status\n");
|
2007-09-22 15:19:05 +00:00
|
|
|
goto exit_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill read opts */
|
2007-11-14 14:26:32 +00:00
|
|
|
memset(&ropts, sizeof(ropts), 0);
|
2007-09-22 15:19:05 +00:00
|
|
|
ropts.norock = 0;
|
|
|
|
ropts.nojoliet = 0;
|
|
|
|
ropts.preferjoliet = 0;
|
|
|
|
ropts.uid = 0;
|
|
|
|
ropts.gid = 0;
|
|
|
|
ropts.mode = 0555;
|
2007-11-14 14:26:32 +00:00
|
|
|
ropts.pretend_blank= 0;
|
2007-09-22 15:19:05 +00:00
|
|
|
|
|
|
|
if (isoburn_read_volset(drive, &ropts, &volset) <= 0) {
|
2007-10-02 21:36:44 +00:00
|
|
|
fprintf(stderr, "Can't read volset\n");
|
|
|
|
goto exit_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef With_graft_poinT
|
2007-10-08 20:41:42 +00:00
|
|
|
for (i = optind + 1; i < argc; i++) {
|
|
|
|
if (graft_point(iso_volset_get_volume(volset, 0),
|
|
|
|
argv[i], argv[i], &behav) <= 0) {
|
|
|
|
fprintf(stderr, "Canot graft '%s'\n", argv[optind+1]);
|
|
|
|
goto exit_cleanup;
|
|
|
|
}
|
2007-09-22 15:19:05 +00:00
|
|
|
}
|
|
|
|
|
2007-10-02 21:36:44 +00:00
|
|
|
#else
|
2007-10-18 22:19:00 +00:00
|
|
|
struct iso_tree_node_dir *root;
|
2007-10-02 21:36:44 +00:00
|
|
|
root = iso_volume_get_root(iso_volset_get_volume(volset, 0));
|
2007-09-22 15:19:05 +00:00
|
|
|
/* add a new dir */
|
|
|
|
iso_tree_radd_dir(root, argv[optind+1], &behav);
|
2007-10-02 21:36:44 +00:00
|
|
|
#endif /* ! With_graft_poinT */
|
2007-09-28 16:10:48 +00:00
|
|
|
|
2007-09-22 15:19:05 +00:00
|
|
|
|
2007-09-28 16:10:48 +00:00
|
|
|
sopts.level = 2;
|
|
|
|
sopts.flags = flags;
|
|
|
|
sopts.relaxed_constraints = 0;
|
|
|
|
sopts.copy_eltorito = 1;
|
|
|
|
sopts.no_cache_inodes = 0;
|
|
|
|
sopts.sort_files = 1;
|
|
|
|
sopts.default_mode = 0;
|
|
|
|
sopts.replace_dir_mode = 0;
|
|
|
|
sopts.replace_file_mode = 0;
|
|
|
|
sopts.replace_uid = 0;
|
|
|
|
sopts.replace_gid = 0;
|
|
|
|
sopts.dir_mode = 0555;
|
|
|
|
sopts.file_mode = 0444;
|
|
|
|
sopts.gid = 0;
|
|
|
|
sopts.uid = 0;
|
|
|
|
sopts.input_charset = NULL;
|
|
|
|
sopts.ouput_charset = NULL;
|
|
|
|
|
|
|
|
if (isoburn_prepare_disc(drive, &disc, &sopts) <= 0) {
|
2007-10-02 21:36:44 +00:00
|
|
|
fprintf(stderr, "Can't prepare disc\n");
|
2007-09-22 15:19:05 +00:00
|
|
|
goto volset_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* a. write the new image */
|
|
|
|
printf("Adding new data...\n");
|
|
|
|
{
|
|
|
|
struct burn_write_opts *burn_options;
|
|
|
|
struct burn_progress progress;
|
|
|
|
|
|
|
|
burn_options = burn_write_opts_new(drive);
|
|
|
|
burn_drive_set_speed(drive, 0, 0);
|
|
|
|
burn_write_opts_set_underrun_proof(burn_options, 1);
|
2007-10-08 20:41:42 +00:00
|
|
|
|
2007-09-22 15:19:05 +00:00
|
|
|
/* ok, write the new track */
|
|
|
|
isoburn_disc_write(burn_options, disc);
|
|
|
|
burn_write_opts_free(burn_options);
|
|
|
|
|
|
|
|
while (burn_drive_get_status(drive, NULL) == BURN_DRIVE_SPAWNING)
|
2007-10-02 21:36:44 +00:00
|
|
|
usleep(100002);
|
2007-09-22 15:19:05 +00:00
|
|
|
|
2007-10-08 20:41:42 +00:00
|
|
|
while (burn_drive_get_status(drive, &progress)
|
|
|
|
!= BURN_DRIVE_IDLE) {
|
|
|
|
|
|
|
|
printf("Writing: sector %d of %d",
|
|
|
|
progress.sector, progress.sectors);
|
|
|
|
ret = isoburn_get_fifo_status(drive, &size,
|
|
|
|
&free_bytes, &status_text);
|
|
|
|
if (ret > 0 )
|
|
|
|
printf(" [fifo %s, %2d%% fill]", status_text,
|
|
|
|
(int) (100.0 - 100.0 *
|
|
|
|
((double) free_bytes) /
|
|
|
|
(double) size));
|
|
|
|
printf("\n");
|
2007-09-22 15:19:05 +00:00
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* b. write the new vol desc */
|
|
|
|
printf("Writing the new vol desc...\n");
|
|
|
|
if (isoburn_activate_session(drive) <= 0) {
|
2007-10-02 21:36:44 +00:00
|
|
|
fprintf(stderr, "Ups, new vol desc write failed\n");
|
2007-09-22 15:19:05 +00:00
|
|
|
}
|
2007-10-08 20:41:42 +00:00
|
|
|
|
|
|
|
ret= 0;
|
2007-09-22 15:19:05 +00:00
|
|
|
volset_cleanup:;
|
2007-10-02 21:36:44 +00:00
|
|
|
/*
|
2007-09-22 15:19:05 +00:00
|
|
|
iso_volset_free(volset);
|
2007-10-02 21:36:44 +00:00
|
|
|
*/
|
2007-09-22 15:19:05 +00:00
|
|
|
|
|
|
|
exit_cleanup:;
|
|
|
|
isoburn_drive_release(drive, 0);
|
|
|
|
isoburn_finish();
|
|
|
|
|
|
|
|
exit(ret);
|
|
|
|
}
|
|
|
|
|