You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
187 lines
4.0 KiB
187 lines
4.0 KiB
/* |
|
Little test program for libisoburn. |
|
It grows an iso filesystem on a disc. |
|
|
|
Copyright 2007 Vreixo Formoso Lopes <metalpain2002@yahoo.es> |
|
*/ |
|
|
|
|
|
#include <stdlib.h> |
|
#include <stdio.h> |
|
#include <unistd.h> |
|
#include <getopt.h> |
|
#include <err.h> |
|
|
|
#include <libisofs/libisofs.h> |
|
#include <libburn/libburn.h> |
|
#include "../src/libisoburn.h" |
|
|
|
const char * const optstring = "JRh"; |
|
extern char *optarg; |
|
extern int optind; |
|
|
|
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 iso_tree_node_dir *root; |
|
struct burn_disc *disc; |
|
enum burn_disc_status state; |
|
struct isoburn_read_opts ropts; |
|
int c; |
|
struct iso_tree_radd_dir_behavior behav = {0,0,0}; |
|
int flags=0; |
|
int ret=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 '?': |
|
usage(); |
|
exit(1); |
|
break; |
|
} |
|
} |
|
|
|
if (argc < optind + 1) { |
|
printf("Please supply device name\n"); |
|
usage(); |
|
return 1; |
|
} |
|
if (argc < optind + 2) { |
|
printf("Please supply directory to add to disc\n"); |
|
usage(); |
|
return 1; |
|
} |
|
|
|
|
|
if (!isoburn_initialize()) { |
|
err(1, "Can't init libisoburn"); |
|
} |
|
|
|
// TODO change this. maybe we can add wrapp in libisoburn |
|
iso_msgs_set_severities("NEVER", "DEBUG", "libisofs : "); |
|
burn_msgs_set_severities("NEVER", "DEBUG", "libburn : "); |
|
|
|
printf("Growing drive %s\n", argv[optind]); |
|
|
|
if (isoburn_drive_scan_and_grab(&drives, argv[optind], 0) <= 0) { |
|
err(1, "Can't open device. Are you sure it is a valid drive?\n"); |
|
} |
|
drive = drives[0].drive; |
|
|
|
/* check for invalid state */ |
|
state = isoburn_disc_get_status(drive); |
|
if (state != BURN_DISC_BLANK && state != BURN_DISC_APPENDABLE) { |
|
printf("Unsuitable disc status"); |
|
goto exit_cleanup; |
|
} |
|
|
|
/* fill read opts */ |
|
ropts.norock = 0; |
|
ropts.nojoliet = 0; |
|
ropts.preferjoliet = 0; |
|
ropts.uid = 0; |
|
ropts.gid = 0; |
|
ropts.mode = 0555; |
|
|
|
if (isoburn_read_volset(drive, &ropts, &volset) <= 0) { |
|
printf("Can't read volset\n"); |
|
goto exit_cleanup; |
|
} |
|
printf("Volset read\n"); |
|
fflush(stdout); |
|
|
|
if (!volset) { |
|
// TODO this piece of code should be inside libisoburn |
|
struct iso_volume *volume; |
|
|
|
root = iso_tree_new_root(); |
|
volume = iso_volume_new_with_root("NEW DISC", "", "LIBISOBURN", root); |
|
volset = iso_volset_new( volume, "VOLSETID" ); |
|
} |
|
root = iso_volume_get_root(iso_volset_get_volume(volset, 0)); |
|
|
|
/* add a new dir */ |
|
iso_tree_radd_dir(root, argv[optind+1], &behav); |
|
|
|
if (isoburn_prepare_disc(drive, &disc) <= 0) { |
|
printf("Can't prepare disc"); |
|
goto volset_cleanup; |
|
} |
|
|
|
/* a. write the new image */ |
|
printf("Adding new data...\n"); |
|
{ |
|
struct burn_write_opts *burn_options; |
|
struct burn_progress progress; |
|
char reasons[BURN_REASONS_LEN]; |
|
|
|
burn_options = burn_write_opts_new(drive); |
|
burn_drive_set_speed(drive, 0, 0); |
|
burn_write_opts_set_underrun_proof(burn_options, 1); |
|
|
|
if (burn_write_opts_auto_write_type(burn_options, disc, |
|
reasons, 0) == BURN_WRITE_NONE) { |
|
printf("Failed to find a suitable write mode:\n%s\n", reasons); |
|
ret = 1; |
|
goto volset_cleanup; |
|
} |
|
|
|
/* 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) |
|
usleep(1002); |
|
|
|
while (burn_drive_get_status(drive, &progress) != BURN_DRIVE_IDLE) { |
|
printf("Writing: sector %d of %d\n", progress.sector, progress.sectors); |
|
sleep(1); |
|
} |
|
} |
|
|
|
/* b. write the new vol desc */ |
|
printf("Writing the new vol desc...\n"); |
|
if (isoburn_activate_session(drive) <= 0) { |
|
printf("Ups, new vol desc write failed\n"); |
|
} |
|
|
|
volset_cleanup:; |
|
iso_volset_free(volset); |
|
|
|
exit_cleanup:; |
|
isoburn_drive_release(drive, 0); |
|
isoburn_finish(); |
|
|
|
exit(ret); |
|
} |
|
|
|
|