Function graft_point(),some general polishing, call of iso_volset_free disabled

This commit is contained in:
Thomas Schmitt 2007-10-02 21:36:44 +00:00
parent 5818ce44f5
commit 3d59d26849

View File

@ -3,6 +3,7 @@
It grows an iso filesystem on a disc. It grows an iso filesystem on a disc.
Copyright 2007 Vreixo Formoso Lopes <metalpain2002@yahoo.es> Copyright 2007 Vreixo Formoso Lopes <metalpain2002@yahoo.es>
and Thomas Schmitt <scdbackup@gmx.net>
*/ */
@ -11,6 +12,8 @@
#include <unistd.h> #include <unistd.h>
#include <getopt.h> #include <getopt.h>
#include <err.h> #include <err.h>
#include <string.h>
#include <libisofs/libisofs.h> #include <libisofs/libisofs.h>
#include <libburn/libburn.h> #include <libburn/libburn.h>
@ -20,6 +23,67 @@ const char * const optstring = "JRh";
extern char *optarg; extern char *optarg;
extern int optind; extern int optind;
/** Activates the usage of function graft_point() rather than
plain iso_tree_radd_dir() from libisofs
*/
#define With_graft_poinT 1
static int graft_point(struct iso_volume *volume, const char *disc_path,
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;
int done= 0;
strncpy(path, img_path, sizeof(path)-1);
path[sizeof(path)-1]= 0;
apt= npt= path;
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);
}
}
if(done)
iso_tree_radd_dir(dir, path, behav);
else
*npt= '/';
}
return(1);
}
static static
void usage() void usage()
{ {
@ -73,36 +137,40 @@ int main(int argc, char **argv)
} }
if (argc < optind + 1) { if (argc < optind + 1) {
printf("Please supply device name\n"); fprintf(stderr, "Please supply device name\n");
usage(); usage();
return 1; exit(1);
} }
if (argc < optind + 2) { if (argc < optind + 2) {
printf("Please supply directory to add to disc\n"); fprintf(stderr, "Please supply directory to add to disc\n");
usage(); usage();
return 1; exit(1);
} }
if (!isoburn_initialize()) { if (!isoburn_initialize()) {
err(1, "Can't init libisoburn"); fprintf(stderr, "Can't init libisoburn\n");
exit(1);
} }
// TODO change this. maybe we can add wrapp in libisoburn /* TODO change this. maybe we can add wrapp in libisoburn */
iso_msgs_set_severities("NEVER", "DEBUG", "libisofs : "); iso_msgs_set_severities("NEVER", "DEBUG", "libisofs : ");
burn_msgs_set_severities("NEVER", "DEBUG", "libburn : "); burn_msgs_set_severities("NEVER", "DEBUG", "libburn : ");
burn_set_signal_handling("libisoburn/test/test : ", NULL, 0);
printf("Growing drive %s\n", argv[optind]); printf("Growing drive %s\n", argv[optind]);
if (isoburn_drive_scan_and_grab(&drives, argv[optind], 0) <= 0) { if (isoburn_drive_scan_and_grab(&drives, argv[optind], 1) <= 0) {
err(1, "Can't open device. Are you sure it is a valid drive?\n"); fprintf(stderr,
"Can't open device. Are you sure it is a valid drive?\n");
exit(1);
} }
drive = drives[0].drive; drive = drives[0].drive;
/* check for invalid state */ /* check for invalid state */
state = isoburn_disc_get_status(drive); state = isoburn_disc_get_status(drive);
if (state != BURN_DISC_BLANK && state != BURN_DISC_APPENDABLE) { if (state != BURN_DISC_BLANK && state != BURN_DISC_APPENDABLE) {
printf("Unsuitable disc status"); fprintf(stderr, "Unsuitable disc status\n");
goto exit_cleanup; goto exit_cleanup;
} }
@ -115,13 +183,23 @@ int main(int argc, char **argv)
ropts.mode = 0555; ropts.mode = 0555;
if (isoburn_read_volset(drive, &ropts, &volset) <= 0) { if (isoburn_read_volset(drive, &ropts, &volset) <= 0) {
printf("Can't read volset\n"); fprintf(stderr, "Can't read volset\n");
goto exit_cleanup; goto exit_cleanup;
} }
root = iso_volume_get_root(iso_volset_get_volume(volset, 0));
#ifdef With_graft_poinT
if (graft_point(iso_volset_get_volume(volset, 0),
argv[optind+1], argv[optind+1], &behav) <= 0) {
fprintf(stderr, "Canot graft '%s'\n", argv[optind+1]);
goto exit_cleanup;
}
#else
root = iso_volume_get_root(iso_volset_get_volume(volset, 0));
/* add a new dir */ /* add a new dir */
iso_tree_radd_dir(root, argv[optind+1], &behav); iso_tree_radd_dir(root, argv[optind+1], &behav);
#endif /* ! With_graft_poinT */
sopts.level = 2; sopts.level = 2;
@ -143,7 +221,7 @@ int main(int argc, char **argv)
sopts.ouput_charset = NULL; sopts.ouput_charset = NULL;
if (isoburn_prepare_disc(drive, &disc, &sopts) <= 0) { if (isoburn_prepare_disc(drive, &disc, &sopts) <= 0) {
printf("Can't prepare disc"); fprintf(stderr, "Can't prepare disc\n");
goto volset_cleanup; goto volset_cleanup;
} }
@ -160,7 +238,8 @@ int main(int argc, char **argv)
if (burn_write_opts_auto_write_type(burn_options, disc, if (burn_write_opts_auto_write_type(burn_options, disc,
reasons, 0) == BURN_WRITE_NONE) { reasons, 0) == BURN_WRITE_NONE) {
printf("Failed to find a suitable write mode:\n%s\n", reasons); fprintf(stderr,
"Failed to find a suitable write mode:\n%s\n", reasons);
ret = 1; ret = 1;
goto volset_cleanup; goto volset_cleanup;
} }
@ -170,7 +249,7 @@ int main(int argc, char **argv)
burn_write_opts_free(burn_options); burn_write_opts_free(burn_options);
while (burn_drive_get_status(drive, NULL) == BURN_DRIVE_SPAWNING) while (burn_drive_get_status(drive, NULL) == BURN_DRIVE_SPAWNING)
usleep(1002); usleep(100002);
while (burn_drive_get_status(drive, &progress) != BURN_DRIVE_IDLE) { while (burn_drive_get_status(drive, &progress) != BURN_DRIVE_IDLE) {
printf("Writing: sector %d of %d\n", progress.sector, progress.sectors); printf("Writing: sector %d of %d\n", progress.sector, progress.sectors);
@ -181,11 +260,13 @@ int main(int argc, char **argv)
/* b. write the new vol desc */ /* b. write the new vol desc */
printf("Writing the new vol desc...\n"); printf("Writing the new vol desc...\n");
if (isoburn_activate_session(drive) <= 0) { if (isoburn_activate_session(drive) <= 0) {
printf("Ups, new vol desc write failed\n"); fprintf(stderr, "Ups, new vol desc write failed\n");
} }
volset_cleanup:; volset_cleanup:;
/*
iso_volset_free(volset); iso_volset_free(volset);
*/
exit_cleanup:; exit_cleanup:;
isoburn_drive_release(drive, 0); isoburn_drive_release(drive, 0);