Integrated functionality of test/devices.c into test/burniso.c

This commit is contained in:
Thomas Schmitt 2006-08-28 20:26:02 +00:00
parent 29ce7967dc
commit a21c112fc5

View File

@ -12,12 +12,31 @@
#define Burniso_try_to_simulatE 1
/** Overview
Before you can do anything, you have to initialize libburn by
as it is done in main() at the end of this file. Then you aquire a
drive in an appropriate way conforming to the API. The two main
approaches are shown here in application functions:
burn_app_aquire_by_adr() demonstrates usage as of cdrecord traditions
burn_app_aquire_by_driveno() demonstrates a scan-and-choose approach
With that aquired drive you can burn to CD-R or blank CD-RW.
This is demonstrated in:
When everything is done, main() shuts down libburn by
/* test/burniso.c , API illustration of burning a single data track to CD
Copyright (C) ???? - 2006 Derek Foreman
Copyright (C) 2005 - 2006 Thomas Schmitt
This is provided under GPL only. Don't ask for anything else for now.
Read. Try. Think. Play. Write yourself some code. Be free of our copyright.
Be also invited to study the code of cdrskin/cdrskin.c et al.
@ -55,6 +74,7 @@ static unsigned int n_drives;
static int simulate_burn = Burniso_try_to_simulatE ;
/** You need to aquire a drive before burning. The API offers this as one
compact call and alternatively as application controllable gestures of
whitelisting, scanning for drives and finally grabbing one of them.
@ -109,7 +129,7 @@ int burn_app_aquire_by_adr(char *drive_adr)
int burn_app_aquire_by_driveno(int driveno)
int ret;
int ret, i;
printf("Scanning for devices ...\n");
while (!burn_drive_scan(&drives, &n_drives)) ;
@ -118,13 +138,6 @@ int burn_app_aquire_by_driveno(int driveno)
return 0;
if (n_drives <= driveno) {
"Found only %d drives. Number %d not available.\n",
return 0;
/* Interactive programs may choose the drive number at this moment.
@ -139,6 +152,29 @@ int burn_app_aquire_by_driveno(int driveno)
easy to fix. Please report them but also strive for
workarounds on application level.
printf("\nOverview of accessible drives (%d found) :\n",
for (i = 0; i < n_drives; i++) {
if (burn_drive_get_adr(&(drives[i]), adr) <=0)
strcpy(adr, "-get_adr_failed-");
printf("%d --drive '%s' : '%s' '%s'\n",
if (driveno < 0) {
printf("Pseudo-drive \"-\" given : bus scanning done.\n");
return 2; /* only return 1 will cause a burn */
/* We already made our choice via command line. (default is 0) */
if (n_drives <= driveno || driveno < 0) {
"Found only %d drives. Number %d not available.\n",
return 0;
/* Now save yourself from sysadmins' revenge */
@ -176,7 +212,14 @@ int burn_app_aquire_by_driveno(int driveno)
/** Brings the preformatted image (ISO 9660 or whatever) onto media.
/** Brings the preformatted image (ISO 9660, afio, ext2, whatever) onto media.
To make sure your image is readable on any Linux machine, you should
add at least 300 kB of padding. This program will not do this for you.
For a file on disk, do:
dd if=/dev/zero bs=1K count=300 >>my_image_file
For on-the-fly streams it suffices to add the 300 kB to the argument for
--stdin_size (which is then needed due to lack of TAO mode).
Without a signal handler it is quite dangerous to abort the process
while this function is active. See cdrskin/cdrskin.c and its usage
@ -194,7 +237,7 @@ int burn_app_aquire_by_driveno(int driveno)
i believe. But cdrecord had long years of time to complete itself.
We are still practicing. Help us with that. :))
void burn_iso(struct burn_drive *drive, const char *path, off_t size)
void burn_app_payload(struct burn_drive *drive, const char *path, off_t size)
struct burn_source *src;
struct burn_disc *disc;
@ -259,21 +302,28 @@ void burn_iso(struct burn_drive *drive, const char *path, off_t size)
#ifdef Burniso_raw_mode_which_i_do_not_likE
/* This yields higher CD capacity but hampers my IDE controller
with burning on one drive and reading on another simultaneously */
with burning on one drive and reading on another simultaneously.
My burner does not obey the order --try_to_simulate in this mode.
burn_write_opts_set_write_type(o, BURN_WRITE_RAW, BURN_BLOCK_RAW96R);
/* This is by what cdrskin competes with cdrecord -sao which
i understand is the mode preferrably advised by Joerg Schilling */
burn_write_opts_set_write_type(o, BURN_WRITE_SAO, BURN_BLOCK_SAO);
printf("\n*** Will TRY to SIMULATE burning ***\n\n");
burn_write_opts_set_simulate(o, simulate_burn);
burn_drive_set_speed(drive, 0, 0);
burn_disc_write(o, disc);
burn_write_opts_set_underrun_proof(o, 1);
printf("Burning starts. Expect up to a minute of zero progress.\n");
burn_disc_write(o, disc);
while (burn_drive_get_status(drive, NULL) == BURN_DRIVE_SPAWNING) ;
while (burn_drive_get_status(drive, &p)) {
printf("S: %d/%d ", p.session, p.sessions);
@ -307,6 +357,9 @@ void parse_args(int argc, char **argv, char **drive_adr, int *driveno,
if (i >= argc) {
printf("--drive requires an argument\n");
} else if (strcmp(argv[i], "-") == 0) {
*drive_adr = no_drive_adr;
*driveno = -1;
} else if (isdigit(argv[i][0])) {
*drive_adr = no_drive_adr;
*driveno = atoi(argv[i]);
@ -336,18 +389,35 @@ void parse_args(int argc, char **argv, char **drive_adr, int *driveno,
} else
*iso = argv[i];
if (help || !*iso) {
if (help || ( (!*iso) && *driveno >= 0) ) {
printf("Usage: %s\n", argv[0]);
printf(" [--drive <address>|<driveno>] [--stdin_size <bytes>] [--verbose <level>]\n");
printf(" [--drive <address>|<driveno>|\"-\"]\n");
printf(" [--stdin_size <bytes>] [--verbose <level>]\n");
printf(" [--burn_for_real|--try_to_simulate] <imagefile>|\"-\"\n");
printf("A bus scan (needs rw-permissions to see a drive):\n");
printf(" %s --drive -\n",argv[0]);
printf("Burn a file to drive chosen by number:\n");
printf(" %s --drive 0 --burn_for_real my_image_file\n",
printf("Burn a file to drive chosen by persistent address:\n");
printf(" %s --drive /dev/hdc --burn_for_real my_image_file\n",
printf("Burn a compressed afio archive on-the-fly, pad up to 700 MB:\n");
printf(" ( cd my_directory ; find . -print | afio -oZ - ) | \\\n");
printf(" %s --drive /dev/hdc --burn_for_real --stdin_size 734003200 -\n",
printf("To be read from *not mounted* CD via:\n");
printf(" afio -tvZ /dev/hdc\n");
printf("Program tar would need a clean EOF which our padded CD cannot deliver.\n");
int main(int argc, char **argv)
int driveno = 0;
int driveno = 0, ret;
char *iso = NULL, *drive_adr= NULL;
off_t stdin_size= 650*1024*1024;
@ -362,12 +432,13 @@ int main(int argc, char **argv)
return 1;
if (burn_app_aquire_drive(drive_adr,driveno)<=0) {
ret= burn_app_aquire_drive(drive_adr,driveno);
if (ret<=0) {
fprintf(stderr,"\nFATAL: Failed to aquire drive.\n");
return 2;
burn_iso(drives[driveno].drive, iso, stdin_size);
if (ret == 1)
burn_app_payload(drives[driveno].drive, iso, stdin_size);