Branching for libburn release 0.8.8
This commit is contained in:
4
libburn/branches/ZeroEightEight/test/Makefile
Normal file
4
libburn/branches/ZeroEightEight/test/Makefile
Normal file
@ -0,0 +1,4 @@
|
||||
all clean:
|
||||
$(MAKE) -C .. -$(MAKEFLAGS) $@
|
||||
|
||||
.PHONY: all clean
|
216
libburn/branches/ZeroEightEight/test/dewav.c
Normal file
216
libburn/branches/ZeroEightEight/test/dewav.c
Normal file
@ -0,0 +1,216 @@
|
||||
|
||||
/* dewav
|
||||
Demo of libburn extension libdax_audioxtr
|
||||
Audio track data extraction facility of libdax and libburn.
|
||||
Copyright (C) 2006 Thomas Schmitt <scdbackup@gmx.net>, provided under GPL
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
/* libdax_audioxtr is quite independent of libburn. It only needs
|
||||
the messaging facility libdax_msgs. So we got two build variations:
|
||||
*/
|
||||
#ifdef Dewav_without_libburN
|
||||
|
||||
/* This build environment is standalone relying only on libdax components */
|
||||
#include "../libburn/libdax_msgs.h"
|
||||
struct libdax_msgs *libdax_messenger= NULL;
|
||||
|
||||
/* The API for .wav extraction */
|
||||
#define LIBDAX_AUDIOXTR_H_PUBLIC 1
|
||||
#include "../libburn/libdax_audioxtr.h"
|
||||
|
||||
#else /* Dewav_without_libburN */
|
||||
|
||||
/* This build environment uses libdax_msgs and libdax_audioxtr via libburn */
|
||||
/* Thus the API header of libburn */
|
||||
#include "../libburn/libburn.h"
|
||||
|
||||
#endif /* ! Dewav_without_libburN */
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/* This program acts as filter from in_path to out_path */
|
||||
char *in_path= "", *out_path= "-";
|
||||
|
||||
/* The read-and-extract object for use with in_path */
|
||||
struct libdax_audioxtr *xtr= NULL;
|
||||
/* The file descriptor eventually detached from xtr */
|
||||
int xtr_fd= -2;
|
||||
|
||||
/* Default output is stdout */
|
||||
int out_fd= 1;
|
||||
|
||||
/* Inquired source parameters */
|
||||
char *fmt, *fmt_info;
|
||||
int num_channels, sample_rate, bits_per_sample, msb_first;
|
||||
off_t data_size;
|
||||
|
||||
/* Auxiliary variables */
|
||||
int ret, i, be_strict= 1, buf_count, detach_fd= 0, extract_all= 0;
|
||||
char buf[2048];
|
||||
|
||||
if(argc < 2)
|
||||
goto help;
|
||||
for(i= 1; i<argc; i++) {
|
||||
if(strcmp(argv[i],"-o")==0) {
|
||||
if(i>=argc-1) {
|
||||
fprintf(stderr,"%s: option -o needs a file address as argument.\n",
|
||||
argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
i++;
|
||||
out_path= argv[i];
|
||||
} else if(strcmp(argv[i],"--lax")==0) {
|
||||
be_strict= 0;
|
||||
} else if(strcmp(argv[i],"--strict")==0) {
|
||||
be_strict= 1;
|
||||
} else if(strcmp(argv[i],"--detach_fd")==0) {
|
||||
/* Test the dirty detach method. Always --extract_all */
|
||||
detach_fd= 1;
|
||||
} else if(strcmp(argv[i],"--extract_all")==0) {
|
||||
/* Dirty : read all available bytes regardless of data_size */
|
||||
extract_all= 1;
|
||||
} else if(strcmp(argv[i],"--help")==0) {
|
||||
help:;
|
||||
fprintf(stderr,
|
||||
"usage: %s [-o output_path|\"-\"] [--lax|--strict] [source_path|\"-\"]\n",
|
||||
argv[0]);
|
||||
exit(0);
|
||||
} else {
|
||||
if(in_path[0]!=0) {
|
||||
fprintf(stderr,"%s: only one input file is allowed.\n", argv[0]);
|
||||
exit(2);
|
||||
}
|
||||
in_path= argv[i];
|
||||
}
|
||||
}
|
||||
if(in_path[0] == 0)
|
||||
in_path= "-";
|
||||
|
||||
|
||||
/* Depending on wether this was built standalone or with full libburn :
|
||||
*/
|
||||
#ifdef Dewav_without_libburN
|
||||
|
||||
/* Initialize and set up libdax messaging system */
|
||||
ret= libdax_msgs_new(&libdax_messenger,0);
|
||||
if(ret<=0) {
|
||||
fprintf(stderr,"Failed to create libdax_messenger object.\n");
|
||||
exit(3);
|
||||
}
|
||||
libdax_msgs_set_severities(libdax_messenger, LIBDAX_MSGS_SEV_NEVER,
|
||||
LIBDAX_MSGS_SEV_NOTE, "", 0);
|
||||
fprintf(stderr, "dewav on libdax\n");
|
||||
|
||||
#else /* Dewav_without_libburN */
|
||||
|
||||
/* Initialize libburn and set up its messaging system */
|
||||
if(burn_initialize() == 0) {
|
||||
fprintf(stderr,"Failed to initialize libburn.\n");
|
||||
exit(3);
|
||||
}
|
||||
/* Print messages of severity NOTE or more directly to stderr */
|
||||
burn_msgs_set_severities("NEVER", "NOTE", "");
|
||||
fprintf(stderr, "dewav on libburn\n");
|
||||
|
||||
#endif /* ! Dewav_without_libburN */
|
||||
|
||||
|
||||
/* Open audio source and create extractor object */
|
||||
ret= libdax_audioxtr_new(&xtr, in_path, 0);
|
||||
if(ret<=0)
|
||||
exit(4);
|
||||
if(strcmp(out_path,"-")!=0) {
|
||||
out_fd= open(out_path, O_WRONLY | O_CREAT | O_TRUNC,
|
||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
if(out_fd == -1) {
|
||||
fprintf(stderr, "Cannot open file: %s\n", out_path);
|
||||
fprintf(stderr, "Error reported: '%s' (%d)\n",strerror(errno), errno);
|
||||
exit(5);
|
||||
}
|
||||
}
|
||||
/* Obtain and print parameters of audio source */
|
||||
libdax_audioxtr_get_id(xtr, &fmt, &fmt_info,
|
||||
&num_channels, &sample_rate, &bits_per_sample, &msb_first, 0);
|
||||
fprintf(stderr, "Detected format: %s\n", fmt_info);
|
||||
libdax_audioxtr_get_size(xtr, &data_size, 0);
|
||||
fprintf(stderr, "Data size : %.f bytes\n", (double) data_size);
|
||||
if((strcmp(fmt,".wav")!=0 && strcmp(fmt,".au")!=0) ||
|
||||
num_channels!=2 || sample_rate!=44100 || bits_per_sample!=16) {
|
||||
fprintf(stderr,
|
||||
"%sAudio source parameters do not comply to cdrskin/README specs\n",
|
||||
(be_strict ? "" : "WARNING: "));
|
||||
if(be_strict)
|
||||
exit(6);
|
||||
}
|
||||
if(msb_first==0)
|
||||
fprintf(stderr,
|
||||
"NOTE: Extracted data to be written with cdrskin option -swab\n");
|
||||
|
||||
if(detach_fd) {
|
||||
/* Take over fd from xtr */;
|
||||
ret= libdax_audioxtr_detach_fd(xtr, &xtr_fd, 0);
|
||||
if(ret<=0) {
|
||||
fprintf(stderr, "Cannot detach file descriptor from extractor\n");
|
||||
exit(8);
|
||||
}
|
||||
/* not needed any more */
|
||||
libdax_audioxtr_destroy(&xtr, 0);
|
||||
fprintf(stderr, "Note: detached fd and freed extractor object.\n");
|
||||
}
|
||||
|
||||
/* Extract and put out raw audio data */;
|
||||
while(1) {
|
||||
if(detach_fd) {
|
||||
buf_count= read(xtr_fd, buf, sizeof(buf));
|
||||
if(buf_count==-1)
|
||||
fprintf(stderr,"Error while reading from detached fd\n(%d) '%s'\n",
|
||||
errno, strerror(errno));
|
||||
} else {
|
||||
buf_count= libdax_audioxtr_read(xtr, buf, sizeof(buf), !!extract_all);
|
||||
}
|
||||
if(buf_count < 0)
|
||||
exit(7);
|
||||
if(buf_count == 0)
|
||||
break;
|
||||
|
||||
ret= write(out_fd, buf, buf_count);
|
||||
if(ret == -1) {
|
||||
fprintf(stderr, "Failed to write buffer of %d bytes to: %s\n",
|
||||
buf_count, out_path);
|
||||
fprintf(stderr, "Error reported: '%s' (%d)\n", strerror(errno), errno);
|
||||
exit(5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Shutdown */
|
||||
if(out_fd>2)
|
||||
close(out_fd);
|
||||
/* ( It is permissible to do this with xtr==NULL ) */
|
||||
libdax_audioxtr_destroy(&xtr, 0);
|
||||
|
||||
#ifdef Dewav_without_libburN
|
||||
|
||||
libdax_msgs_destroy(&libdax_messenger,0);
|
||||
|
||||
#else /* Dewav_without_libburN */
|
||||
|
||||
burn_finish();
|
||||
|
||||
#endif /* ! Dewav_without_libburN */
|
||||
|
||||
exit(0);
|
||||
}
|
164
libburn/branches/ZeroEightEight/test/fake_au.c
Normal file
164
libburn/branches/ZeroEightEight/test/fake_au.c
Normal file
@ -0,0 +1,164 @@
|
||||
|
||||
/* fake_au
|
||||
Fakes a file in SUN .au format from a raw little-endian PCM audio file
|
||||
(e.g. a file extracted from .wav by test/dewav). The input data are assumed
|
||||
to be 16 bit, stereo, 44100 Hz.
|
||||
Copyright (C) 2006 Thomas Schmitt <scdbackup@gmx.net>, provided under GPL
|
||||
|
||||
Info used: http://www.opengroup.org/public/pubs/external/auformat.html
|
||||
*/
|
||||
|
||||
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
int fake_write(unsigned char *buf, size_t size, FILE *fp)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret= fwrite(buf,size,1,fp);
|
||||
if(ret==1)
|
||||
return(1);
|
||||
fprintf(stderr,"Error %d while writing: '%s'\n",errno,strerror(errno));
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret, i;
|
||||
unsigned data_size= 0,byte_count,exit_value= 0;
|
||||
FILE *fp_out= stdout,*fp_in= stdin;
|
||||
unsigned char buf[4];
|
||||
char out_path[4096],in_path[4096];
|
||||
struct stat stbuf;
|
||||
|
||||
strcpy(out_path,"-");
|
||||
strcpy(in_path,"");
|
||||
if(argc < 2) {
|
||||
exit_value= 1;
|
||||
goto help;
|
||||
}
|
||||
for(i= 1; i<argc; i++) {
|
||||
if(strcmp(argv[i],"-o")==0) {
|
||||
if(i>=argc-1) {
|
||||
fprintf(stderr,"%s: option -o needs a file address as argument.\n",
|
||||
argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
i++;
|
||||
strcpy(out_path, argv[i]);
|
||||
} else if(strcmp(argv[i],"--stdin_size")==0) {
|
||||
if(i>=argc-1) {
|
||||
fprintf(stderr,"%s: option --stdin_size needs a number as argument.\n",
|
||||
argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
i++;
|
||||
sscanf(argv[i],"%u",&data_size);
|
||||
} else if(strcmp(argv[i],"--help")==0) {
|
||||
exit_value= 0;
|
||||
help:;
|
||||
fprintf(stderr,"usage: %s \\\n", argv[0]);
|
||||
fprintf(stderr," [-o output_path|\"-\"] [source_path | --stdin_size size]\n");
|
||||
fprintf(stderr,
|
||||
"Disguises an extracted .wav stream as .au stereo, 16bit, 44100Hz\n");
|
||||
fprintf(stderr,
|
||||
"stdin gets byte-swapped and appended up to the announced data_size.\n");
|
||||
exit(exit_value);
|
||||
} else {
|
||||
if(in_path[0]!=0) {
|
||||
fprintf(stderr,"%s: only one input file is allowed.\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
strcpy(in_path, argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if(strcmp(in_path,"-")==0 || in_path[0]==0) {
|
||||
if(data_size==0) {
|
||||
fprintf(stderr,"%s: input from stdin needs option --stdin_size.\n",
|
||||
argv[0]);
|
||||
exit(6);
|
||||
}
|
||||
fp_in= stdin;
|
||||
} else {
|
||||
fp_in= fopen(in_path,"r");
|
||||
if(stat(in_path,&stbuf)!=-1)
|
||||
data_size= stbuf.st_size;
|
||||
}
|
||||
if(fp_in==NULL) {
|
||||
fprintf(stderr,"Error %d while fopen(\"%s\",\"r\") : '%s'\n",
|
||||
errno,in_path,strerror(errno));
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if(strcmp(out_path,"-")==0) {
|
||||
fp_out= stdout;
|
||||
} else {
|
||||
if(stat(out_path,&stbuf)!=-1) {
|
||||
fprintf(stderr,"%s: file '%s' already existing\n",argv[0],out_path);
|
||||
exit(4);
|
||||
}
|
||||
fp_out= fopen(out_path,"w");
|
||||
}
|
||||
if(fp_out==NULL) {
|
||||
fprintf(stderr,"Error %d while fopen(\"%s\",\"w\") : '%s'\n",
|
||||
errno,out_path,strerror(errno));
|
||||
exit(2);
|
||||
}
|
||||
|
||||
fake_write((unsigned char *) ".snd",4,fp_out); /* magic number */
|
||||
buf[0]= buf[1]= buf[2]= 0;
|
||||
buf[3]= 32;
|
||||
fake_write(buf,4,fp_out); /* data_location */
|
||||
buf[0]= (data_size>>24)&0xff;
|
||||
buf[1]= (data_size>>16)&0xff;
|
||||
buf[2]= (data_size>>8)&0xff;
|
||||
buf[3]= (data_size)&0xff;
|
||||
fake_write(buf,4,fp_out); /* data_size */
|
||||
buf[0]= buf[1]= buf[2]= 0;
|
||||
buf[3]= 3;
|
||||
fake_write(buf,4,fp_out); /* encoding 16 Bit PCM */
|
||||
buf[0]= buf[1]= 0;
|
||||
buf[2]= 172;
|
||||
buf[3]= 68;
|
||||
fake_write(buf,4,fp_out); /* sample rate 44100 Hz */
|
||||
buf[0]= buf[1]= buf[2]= 0;
|
||||
buf[3]= 2;
|
||||
fake_write(buf,4,fp_out); /* number of channels */
|
||||
buf[0]= buf[1]= buf[2]= buf[3]= 0;
|
||||
fake_write(buf,4,fp_out); /* padding */
|
||||
fake_write(buf,4,fp_out); /* padding */
|
||||
|
||||
for(byte_count= 0; byte_count<data_size; byte_count+=2) {
|
||||
ret= fread(buf,2,1,fp_in);
|
||||
if(ret<=0) {
|
||||
fprintf(stderr,"Premature end end of input\n");
|
||||
exit_value= 5;
|
||||
break;
|
||||
}
|
||||
buf[3]= buf[0];
|
||||
buf[2]= buf[1];
|
||||
ret= fake_write(buf+2,2,fp_out);
|
||||
if(ret<=0) {
|
||||
exit_value= 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(fp_out!=stdout)
|
||||
fclose(fp_out);
|
||||
if(fp_in!=stdin)
|
||||
fclose(fp_in);
|
||||
fprintf(stderr, "Swapped and appended: %u stdin bytes\n",byte_count);
|
||||
exit(exit_value);
|
||||
}
|
||||
|
825
libburn/branches/ZeroEightEight/test/libburner.c
Normal file
825
libburn/branches/ZeroEightEight/test/libburner.c
Normal file
@ -0,0 +1,825 @@
|
||||
|
||||
/* test/libburner.c , API illustration of burning data or audio tracks to CD */
|
||||
/* Copyright (C) 2005 - 2010 Thomas Schmitt <scdbackup@gmx.net> */
|
||||
/* Provided under GPL, see also "License and copyright aspects" at file end */
|
||||
|
||||
|
||||
/** Overview
|
||||
|
||||
libburner is a minimal demo application for the library libburn as provided
|
||||
on http://libburnia-project.org . It can list the available devices, can
|
||||
blank a CD-RW or DVD-RW, can format DVD-RW and BD, can burn to CD-R,
|
||||
CD-RW, DVD-R, DVD+R, DVD+R/DL, DVD+RW, DVD-RW, DVD-RAM, BD-R, BD-RE.
|
||||
Not supported yet: DVD-R/DL.
|
||||
|
||||
It's main purpose, nevertheless, is to show you how to use libburn and also
|
||||
to serve the libburnia team as reference application. libburner.c does indeed
|
||||
define the standard way how above three gestures can be implemented and
|
||||
stay upward compatible for a good while.
|
||||
|
||||
Before you can do anything, you have to initialize libburn by
|
||||
burn_initialize()
|
||||
and provide some signal and abort handling, e.g. by the builtin handler, by
|
||||
burn_set_signal_handling("libburner : ", NULL, 0x0)
|
||||
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 twoi
|
||||
main approaches are shown here in application functions:
|
||||
libburner_aquire_by_adr() demonstrates usage as of cdrecord traditions
|
||||
libburner_aquire_by_driveno() demonstrates a scan-and-choose approach
|
||||
|
||||
With that aquired drive you can blank a CD-RW or DVD-RW as shown in
|
||||
libburner_blank_disc()
|
||||
or you can format a DVD-RW to profile "Restricted Overwrite" (needed once)
|
||||
or an unused BD to default size with spare blocks
|
||||
libburner_format()
|
||||
With the aquired drive you can burn to CD, DVD, BD. See
|
||||
libburner_payload()
|
||||
|
||||
These three functions switch temporarily to a non-fatal signal handler
|
||||
while they are waiting for the drive to become idle again:
|
||||
burn_set_signal_handling("libburner : ", NULL, 0x30)
|
||||
After the waiting loop ended, they check for eventual abort events by
|
||||
burn_is_aborting(0)
|
||||
The 0x30 handler will eventually execute
|
||||
burn_abort()
|
||||
but not wait for the drive to become idle and not call exit().
|
||||
This is needed because the worker threads might block as long as the signal
|
||||
handler has not returned. The 0x0 handler would wait for them to finish.
|
||||
Take this into respect when implementing own signal handlers.
|
||||
|
||||
When everything is done, main() releases the drive and shuts down libburn:
|
||||
burn_drive_release();
|
||||
burn_finish()
|
||||
|
||||
Applications must use 64 bit off_t. E.g. by defining
|
||||
#define _LARGEFILE_SOURCE
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
or take special precautions to interface with the library by 64 bit integers
|
||||
where libburn/libburn.h prescribes off_t.
|
||||
This program gets fed with appropriate settings externally by libburn's
|
||||
autotools generated build system.
|
||||
*/
|
||||
|
||||
|
||||
/** See this for the decisive API specs . libburn.h is The Original */
|
||||
/* For using the installed header file : #include <libburn/libburn.h> */
|
||||
/* This program insists in the own headerfile. */
|
||||
#include "../libburn/libburn.h"
|
||||
|
||||
/* libburn works on Linux systems with kernel 2.4 or 2.6, FreeBSD, Solaris */
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
/** For simplicity i use global variables to represent the drives.
|
||||
Drives are systemwide global, so we do not give away much of good style.
|
||||
*/
|
||||
|
||||
/** This list will hold the drives known to libburn. This might be all CD
|
||||
drives of the system and thus might impose severe impact on the system.
|
||||
*/
|
||||
static struct burn_drive_info *drive_list;
|
||||
|
||||
/** If you start a long lasting operation with drive_count > 1 then you are
|
||||
not friendly to the users of other drives on those systems. Beware. */
|
||||
static unsigned int drive_count;
|
||||
|
||||
/** This variable indicates wether the drive is grabbed and must be
|
||||
finally released */
|
||||
static int drive_is_grabbed = 0;
|
||||
|
||||
/** A number and a text describing the type of media in aquired drive */
|
||||
static int current_profile= -1;
|
||||
static char current_profile_name[80]= {""};
|
||||
|
||||
|
||||
/* Some in-advance definitions to allow a more comprehensive ordering
|
||||
of the functions and their explanations in here */
|
||||
int libburner_aquire_by_adr(char *drive_adr);
|
||||
int libburner_aquire_by_driveno(int *drive_no);
|
||||
|
||||
|
||||
/* ------------------------------- API gestures ---------------------------- */
|
||||
|
||||
/** 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.
|
||||
|
||||
If you have a persistent address of the drive, then the compact call is
|
||||
to prefer because it only touches one drive. On modern Linux kernels,
|
||||
there should be no fatal disturbance of ongoing burns of other libburn
|
||||
instances with any of our approaches. We use open(O_EXCL) by default.
|
||||
On /dev/hdX it should cooperate with growisofs and some cdrecord variants.
|
||||
On /dev/sgN versus /dev/scdM expect it not to respect other programs.
|
||||
*/
|
||||
int libburner_aquire_drive(char *drive_adr, int *driveno)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if(drive_adr != NULL && drive_adr[0] != 0)
|
||||
ret = libburner_aquire_by_adr(drive_adr);
|
||||
else
|
||||
ret = libburner_aquire_by_driveno(driveno);
|
||||
if (ret <= 0 || *driveno <= 0)
|
||||
return ret;
|
||||
burn_disc_get_profile(drive_list[0].drive, ¤t_profile,
|
||||
current_profile_name);
|
||||
if (current_profile_name[0])
|
||||
printf("Detected media type: %s\n", current_profile_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/** If the persistent drive address is known, then this approach is much
|
||||
more un-obtrusive to the systemwide livestock of drives. Only the
|
||||
given drive device will be opened during this procedure.
|
||||
*/
|
||||
int libburner_aquire_by_adr(char *drive_adr)
|
||||
{
|
||||
int ret;
|
||||
char libburn_drive_adr[BURN_DRIVE_ADR_LEN];
|
||||
|
||||
/* Some not-so-harmless drive addresses get blocked in this demo */
|
||||
if (strncmp(drive_adr, "stdio:/dev/fd/", 14) == 0 ||
|
||||
strcmp(drive_adr, "stdio:-") == 0) {
|
||||
fprintf(stderr, "Will not work with pseudo-drive '%s'\n",
|
||||
drive_adr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This tries to resolve links or alternative device files */
|
||||
ret = burn_drive_convert_fs_adr(drive_adr, libburn_drive_adr);
|
||||
if (ret<=0) {
|
||||
fprintf(stderr, "Address does not lead to a CD burner: '%s'\n",
|
||||
drive_adr);
|
||||
return 0;
|
||||
}
|
||||
fprintf(stderr,"Aquiring drive '%s' ...\n", libburn_drive_adr);
|
||||
ret = burn_drive_scan_and_grab(&drive_list, libburn_drive_adr, 1);
|
||||
if (ret <= 0) {
|
||||
fprintf(stderr,"FAILURE with persistent drive address '%s'\n",
|
||||
libburn_drive_adr);
|
||||
} else {
|
||||
fprintf(stderr,"Done\n");
|
||||
drive_is_grabbed = 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/** This method demonstrates how to use libburn without knowing a persistent
|
||||
drive address in advance. It has to make sure that after assessing the list
|
||||
of available drives, all unwanted drives get closed again. As long as they
|
||||
are open, no other libburn instance can see them. This is an intended
|
||||
locking feature. The application is responsible for giving up the locks
|
||||
by either burn_drive_release() (only after burn_drive_grab() !),
|
||||
burn_drive_info_forget(), burn_drive_info_free(), or burn_finish().
|
||||
@param driveno the index number in libburn's drive list. This will get
|
||||
set to 0 on success and will then be the drive index to
|
||||
use in the further dourse of processing.
|
||||
@return 1 success , <= 0 failure
|
||||
*/
|
||||
int libburner_aquire_by_driveno(int *driveno)
|
||||
{
|
||||
char adr[BURN_DRIVE_ADR_LEN];
|
||||
int ret, i;
|
||||
|
||||
printf("Beginning to scan for devices ...\n");
|
||||
while (!burn_drive_scan(&drive_list, &drive_count))
|
||||
usleep(100002);
|
||||
if (drive_count <= 0 && *driveno >= 0) {
|
||||
printf("FAILED (no drives found)\n");
|
||||
return 0;
|
||||
}
|
||||
printf("Done\n");
|
||||
|
||||
/*
|
||||
Interactive programs may choose the drive number at this moment.
|
||||
|
||||
drive[0] to drive[drive_count-1] are struct burn_drive_info
|
||||
as defined in libburn/libburn.h . This structure is part of API
|
||||
and thus will strive for future compatibility on source level.
|
||||
Have a look at the info offered.
|
||||
Caution: do not take .location for drive address. Always use
|
||||
burn_drive_get_adr() or you might become incompatible
|
||||
in future.
|
||||
Note: bugs with struct burn_drive_info - if any - will not be
|
||||
easy to fix. Please report them but also strive for
|
||||
workarounds on application level.
|
||||
*/
|
||||
printf("\nOverview of accessible drives (%d found) :\n",
|
||||
drive_count);
|
||||
printf("-----------------------------------------------------------------------------\n");
|
||||
for (i = 0; i < drive_count; i++) {
|
||||
if (burn_drive_get_adr(&(drive_list[i]), adr) <=0)
|
||||
strcpy(adr, "-get_adr_failed-");
|
||||
printf("%d --drive '%s' : '%s' '%s'\n",
|
||||
i,adr,drive_list[i].vendor,drive_list[i].product);
|
||||
}
|
||||
printf("-----------------------------------------------------------------------------\n\n");
|
||||
|
||||
/*
|
||||
On multi-drive systems save yourself from sysadmins' revenge.
|
||||
|
||||
Be aware that you hold reserved all available drives at this point.
|
||||
So either make your choice quick enough not to annoy other system
|
||||
users, or set free the drives for a while.
|
||||
|
||||
The tested way of setting free all drives is to shutdown the library
|
||||
and to restart when the choice has been made. The list of selectable
|
||||
drives should also hold persistent drive addresses as obtained
|
||||
above by burn_drive_get_adr(). By such an address one may use
|
||||
burn_drive_scan_and_grab() to finally aquire exactly one drive.
|
||||
|
||||
A not yet tested shortcut should be to call burn_drive_info_free()
|
||||
and to call either burn_drive_scan() or burn_drive_scan_and_grab()
|
||||
before accessing any drives again.
|
||||
|
||||
In both cases you have to be aware that the desired drive might get
|
||||
aquired in the meantime by another user resp. libburn process.
|
||||
*/
|
||||
|
||||
/* We already made our choice via command line. (default is 0)
|
||||
So we just have to keep our desired drive and drop all others.
|
||||
No other libburn instance will have a chance to steal our drive.
|
||||
*/
|
||||
if (*driveno < 0) {
|
||||
printf("Pseudo-drive \"-\" given : bus scanning done.\n");
|
||||
return 2; /* the program will end after this */
|
||||
}
|
||||
if (drive_count <= *driveno) {
|
||||
fprintf(stderr,
|
||||
"Found only %d drives. Number %d not available.\n",
|
||||
drive_count, *driveno);
|
||||
return 0; /* the program will end after this */
|
||||
}
|
||||
|
||||
/* Drop all drives which we do not want to use */
|
||||
for (i = 0; i < drive_count; i++) {
|
||||
if (i == *driveno) /* the one drive we want to keep */
|
||||
continue;
|
||||
ret = burn_drive_info_forget(&(drive_list[i]),0);
|
||||
if (ret != 1)
|
||||
fprintf(stderr, "Cannot drop drive %d. Please report \"ret=%d\" to libburn-hackers@pykix.org\n",
|
||||
i, ret);
|
||||
else
|
||||
printf("Dropped unwanted drive %d\n",i);
|
||||
}
|
||||
/* Make the one we want ready for blanking or burning */
|
||||
ret= burn_drive_grab(drive_list[*driveno].drive, 1);
|
||||
if (ret != 1)
|
||||
return 0;
|
||||
drive_is_grabbed = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/** Makes a previously used CD-RW or unformatted DVD-RW ready for thorough
|
||||
re-usal.
|
||||
|
||||
To our knowledge it is hardly possible to abort an ongoing blank operation
|
||||
because after start it is entirely handled by the drive.
|
||||
So expect signal handling to wait the normal blanking timespan until it
|
||||
can allow the process to end. External kill -9 will not help the drive.
|
||||
*/
|
||||
int libburner_blank_disc(struct burn_drive *drive, int blank_fast)
|
||||
{
|
||||
enum burn_disc_status disc_state;
|
||||
struct burn_progress p;
|
||||
double percent = 1.0;
|
||||
|
||||
disc_state = burn_disc_get_status(drive);
|
||||
printf(
|
||||
"Drive media status: %d (see libburn/libburn.h BURN_DISC_*)\n",
|
||||
disc_state);
|
||||
if (current_profile == 0x13) {
|
||||
; /* formatted DVD-RW will get blanked to sequential state */
|
||||
} else if (disc_state == BURN_DISC_BLANK) {
|
||||
fprintf(stderr,
|
||||
"IDLE: Blank media detected. Will leave it untouched\n");
|
||||
return 2;
|
||||
} else if (disc_state == BURN_DISC_FULL ||
|
||||
disc_state == BURN_DISC_APPENDABLE) {
|
||||
; /* this is what libburner is willing to blank */
|
||||
} else if (disc_state == BURN_DISC_EMPTY) {
|
||||
fprintf(stderr,"FATAL: No media detected in drive\n");
|
||||
return 0;
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"FATAL: Unsuitable drive and media state\n");
|
||||
return 0;
|
||||
}
|
||||
if(!burn_disc_erasable(drive)) {
|
||||
fprintf(stderr,
|
||||
"FATAL : Media is not of erasable type\n");
|
||||
return 0;
|
||||
}
|
||||
/* Switch to asynchronous signal handling for the time of waiting */
|
||||
burn_set_signal_handling("libburner : ", NULL, 0x30);
|
||||
|
||||
printf("Beginning to %s-blank media.\n", (blank_fast?"fast":"full"));
|
||||
burn_disc_erase(drive, blank_fast);
|
||||
|
||||
sleep(1);
|
||||
while (burn_drive_get_status(drive, &p) != BURN_DRIVE_IDLE) {
|
||||
if(p.sectors>0 && p.sector>=0) /* display 1 to 99 percent */
|
||||
percent = 1.0 + ((double) p.sector+1.0)
|
||||
/ ((double) p.sectors) * 98.0;
|
||||
printf("Blanking ( %.1f%% done )\n", percent);
|
||||
sleep(1);
|
||||
}
|
||||
if (burn_is_aborting(0) > 0)
|
||||
return -1;
|
||||
/* Back to synchronous handling */
|
||||
burn_set_signal_handling("libburner : ", NULL, 0x0);
|
||||
printf("Done\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/** Formats unformatted DVD-RW to profile 0013h "Restricted Overwrite"
|
||||
which needs no blanking for re-use but is not capable of multi-session.
|
||||
Expect a behavior similar to blanking with unusual noises from the drive.
|
||||
|
||||
Formats unformatted BD-RE to default size. This will allocate some
|
||||
reserve space, test for bad blocks and make the media ready for writing.
|
||||
Expect a very long run time.
|
||||
|
||||
Formats unformatted blank BD-R to hold a default amount of spare blocks
|
||||
for eventual mishaps during writing. If BD-R get written without being
|
||||
formatted, then they get no such reserve and will burn at full speed.
|
||||
*/
|
||||
int libburner_format(struct burn_drive *drive)
|
||||
{
|
||||
struct burn_progress p;
|
||||
double percent = 1.0;
|
||||
int ret, status, num_formats, format_flag= 0;
|
||||
off_t size = 0;
|
||||
unsigned dummy;
|
||||
enum burn_disc_status disc_state;
|
||||
|
||||
if (current_profile == 0x13) {
|
||||
fprintf(stderr, "IDLE: DVD-RW media is already formatted\n");
|
||||
return 2;
|
||||
} else if (current_profile == 0x41 || current_profile == 0x43) {
|
||||
disc_state = burn_disc_get_status(drive);
|
||||
if (disc_state != BURN_DISC_BLANK && current_profile == 0x41) {
|
||||
fprintf(stderr,
|
||||
"FATAL: BD-R is not blank. Cannot format.\n");
|
||||
return 0;
|
||||
}
|
||||
ret = burn_disc_get_formats(drive, &status, &size, &dummy,
|
||||
&num_formats);
|
||||
if (ret > 0 && status != BURN_FORMAT_IS_UNFORMATTED) {
|
||||
fprintf(stderr,
|
||||
"IDLE: BD media is already formatted\n");
|
||||
return 2;
|
||||
}
|
||||
size = 0; /* does not really matter */
|
||||
format_flag = 3<<1; /* format to default size, no quick */
|
||||
} else if (current_profile == 0x14) { /* sequential DVD-RW */
|
||||
size = 128 * 1024 * 1024;
|
||||
format_flag = 1; /* write initial 128 MiB */
|
||||
} else {
|
||||
fprintf(stderr, "FATAL: Can only format DVD-RW or BD\n");
|
||||
return 0;
|
||||
}
|
||||
burn_set_signal_handling("libburner : ", NULL, 0x30);
|
||||
|
||||
printf("Beginning to format media.\n");
|
||||
burn_disc_format(drive, size, format_flag);
|
||||
|
||||
sleep(1);
|
||||
while (burn_drive_get_status(drive, &p) != BURN_DRIVE_IDLE) {
|
||||
if(p.sectors>0 && p.sector>=0) /* display 1 to 99 percent */
|
||||
percent = 1.0 + ((double) p.sector+1.0)
|
||||
/ ((double) p.sectors) * 98.0;
|
||||
printf("Formatting ( %.1f%% done )\n", percent);
|
||||
sleep(1);
|
||||
}
|
||||
if (burn_is_aborting(0) > 0)
|
||||
return -1;
|
||||
burn_set_signal_handling("libburner : ", NULL, 0x0);
|
||||
burn_disc_get_profile(drive_list[0].drive, ¤t_profile,
|
||||
current_profile_name);
|
||||
if (current_profile == 0x14 || current_profile == 0x13)
|
||||
printf("Media type now: %4.4xh \"%s\"\n",
|
||||
current_profile, current_profile_name);
|
||||
if (current_profile == 0x14) {
|
||||
fprintf(stderr,
|
||||
"FATAL: Failed to change media profile to desired value\n");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/** Brings preformatted track images (ISO 9660, audio, ...) onto media.
|
||||
To make sure a data image is fully readable on any Linux machine, this
|
||||
function adds 300 kiB of padding to the (usualy single) track.
|
||||
Audio tracks get padded to complete their last sector.
|
||||
A fifo of 4 MB is installed between each track and its data source.
|
||||
Each of the 4 MB buffers gets allocated automatically as soon as a track
|
||||
begins to be processed and it gets freed as soon as the track is done.
|
||||
The fifos do not wait for buffer fill but writing starts immediately.
|
||||
|
||||
In case of external signals expect abort handling of an ongoing burn to
|
||||
last up to a minute. Wait the normal burning timespan before any kill -9.
|
||||
|
||||
For simplicity, this function allows memory leaks in case of failure.
|
||||
In apps which do not abort immediately, one should clean up better.
|
||||
*/
|
||||
int libburner_payload(struct burn_drive *drive,
|
||||
char source_adr[][4096], int source_adr_count,
|
||||
int multi, int simulate_burn, int all_tracks_type)
|
||||
{
|
||||
struct burn_source *data_src, *fifo_src[99];
|
||||
struct burn_disc *target_disc;
|
||||
struct burn_session *session;
|
||||
struct burn_write_opts *burn_options;
|
||||
enum burn_disc_status disc_state;
|
||||
struct burn_track *track, *tracklist[99];
|
||||
struct burn_progress progress;
|
||||
time_t start_time;
|
||||
int last_sector = 0, padding = 0, trackno, unpredicted_size = 0, fd;
|
||||
int fifo_chunksize = 2352, fifo_chunks = 1783; /* ~ 4 MB fifo */
|
||||
off_t fixed_size;
|
||||
char *adr, reasons[BURN_REASONS_LEN];
|
||||
struct stat stbuf;
|
||||
|
||||
if (all_tracks_type != BURN_AUDIO) {
|
||||
all_tracks_type = BURN_MODE1;
|
||||
/* a padding of 300 kiB helps to avoid the read-ahead bug */
|
||||
padding = 300*1024;
|
||||
fifo_chunksize = 2048;
|
||||
fifo_chunks = 2048; /* 4 MB fifo */
|
||||
}
|
||||
|
||||
target_disc = burn_disc_create();
|
||||
session = burn_session_create();
|
||||
burn_disc_add_session(target_disc, session, BURN_POS_END);
|
||||
|
||||
for (trackno = 0 ; trackno < source_adr_count; trackno++) {
|
||||
tracklist[trackno] = track = burn_track_create();
|
||||
burn_track_define_data(track, 0, padding, 1, all_tracks_type);
|
||||
|
||||
/* Open file descriptor to source of track data */
|
||||
adr = source_adr[trackno];
|
||||
fixed_size = 0;
|
||||
if (adr[0] == '-' && adr[1] == 0) {
|
||||
fd = 0;
|
||||
} else {
|
||||
fd = open(adr, O_RDONLY);
|
||||
if (fd>=0)
|
||||
if (fstat(fd,&stbuf)!=-1)
|
||||
if((stbuf.st_mode&S_IFMT)==S_IFREG)
|
||||
fixed_size = stbuf.st_size;
|
||||
}
|
||||
if (fixed_size==0)
|
||||
unpredicted_size = 1;
|
||||
|
||||
/* Convert this filedescriptor into a burn_source object */
|
||||
data_src = NULL;
|
||||
if (fd>=0)
|
||||
data_src = burn_fd_source_new(fd, -1, fixed_size);
|
||||
if (data_src == NULL) {
|
||||
fprintf(stderr,
|
||||
"FATAL: Could not open data source '%s'.\n",adr);
|
||||
if(errno!=0)
|
||||
fprintf(stderr,"(Most recent system error: %s )\n",
|
||||
strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
/* Install a fifo object on top of that data source object */
|
||||
fifo_src[trackno] = burn_fifo_source_new(data_src,
|
||||
fifo_chunksize, fifo_chunks, 0);
|
||||
if (fifo_src[trackno] == NULL) {
|
||||
fprintf(stderr,
|
||||
"FATAL: Could not create fifo object of 4 MB\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Use the fifo object as data source for the track */
|
||||
if (burn_track_set_source(track, fifo_src[trackno])
|
||||
!= BURN_SOURCE_OK) {
|
||||
fprintf(stderr,
|
||||
"FATAL: Cannot attach source object to track object\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
burn_session_add_track(session, track, BURN_POS_END);
|
||||
printf("Track %d : source is '%s'\n", trackno+1, adr);
|
||||
|
||||
/* Give up local reference to the data burn_source object */
|
||||
burn_source_free(data_src);
|
||||
|
||||
} /* trackno loop end */
|
||||
|
||||
/* Evaluate drive and media */
|
||||
disc_state = burn_disc_get_status(drive);
|
||||
if (disc_state != BURN_DISC_BLANK &&
|
||||
disc_state != BURN_DISC_APPENDABLE) {
|
||||
if (disc_state == BURN_DISC_FULL) {
|
||||
fprintf(stderr, "FATAL: Closed media with data detected. Need blank or appendable media.\n");
|
||||
if (burn_disc_erasable(drive))
|
||||
fprintf(stderr, "HINT: Try --blank_fast\n\n");
|
||||
} else if (disc_state == BURN_DISC_EMPTY)
|
||||
fprintf(stderr,"FATAL: No media detected in drive\n");
|
||||
else
|
||||
fprintf(stderr,
|
||||
"FATAL: Cannot recognize state of drive and media\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
burn_options = burn_write_opts_new(drive);
|
||||
burn_write_opts_set_perform_opc(burn_options, 0);
|
||||
burn_write_opts_set_multi(burn_options, !!multi);
|
||||
if(simulate_burn)
|
||||
printf("\n*** Will TRY to SIMULATE burning ***\n\n");
|
||||
burn_write_opts_set_simulate(burn_options, simulate_burn);
|
||||
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, target_disc,
|
||||
reasons, 0) == BURN_WRITE_NONE) {
|
||||
fprintf(stderr, "FATAL: Failed to find a suitable write mode with this media.\n");
|
||||
fprintf(stderr, "Reasons given:\n%s\n", reasons);
|
||||
return 0;
|
||||
}
|
||||
burn_set_signal_handling("libburner : ", NULL, 0x30);
|
||||
|
||||
printf("Burning starts. With e.g. 4x media expect up to a minute of zero progress.\n");
|
||||
start_time = time(0);
|
||||
burn_disc_write(burn_options, target_disc);
|
||||
|
||||
burn_write_opts_free(burn_options);
|
||||
while (burn_drive_get_status(drive, NULL) == BURN_DRIVE_SPAWNING)
|
||||
usleep(100002);
|
||||
while (burn_drive_get_status(drive, &progress) != BURN_DRIVE_IDLE) {
|
||||
if (progress.sectors <= 0 ||
|
||||
(progress.sector >= progress.sectors - 1 &&
|
||||
!unpredicted_size) ||
|
||||
(unpredicted_size && progress.sector == last_sector))
|
||||
printf(
|
||||
"Thank you for being patient since %d seconds.",
|
||||
(int) (time(0) - start_time));
|
||||
else if(unpredicted_size)
|
||||
printf("Track %d : sector %d", progress.track+1,
|
||||
progress.sector);
|
||||
else
|
||||
printf("Track %d : sector %d of %d",progress.track+1,
|
||||
progress.sector, progress.sectors);
|
||||
last_sector = progress.sector;
|
||||
if (progress.track >= 0 && progress.track < source_adr_count) {
|
||||
int size, free_bytes, ret;
|
||||
char *status_text;
|
||||
|
||||
ret = burn_fifo_inquire_status(
|
||||
fifo_src[progress.track], &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");
|
||||
sleep(1);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
for (trackno = 0 ; trackno < source_adr_count; trackno++) {
|
||||
burn_source_free(fifo_src[trackno]);
|
||||
burn_track_free(tracklist[trackno]);
|
||||
}
|
||||
burn_session_free(session);
|
||||
burn_disc_free(target_disc);
|
||||
if (burn_is_aborting(0) > 0)
|
||||
return -1;
|
||||
if (multi && current_profile != 0x1a && current_profile != 0x13 &&
|
||||
current_profile != 0x12 && current_profile != 0x43)
|
||||
/* not with DVD+RW, formatted DVD-RW, DVD-RAM, BD-RE */
|
||||
printf("NOTE: Media left appendable.\n");
|
||||
if (simulate_burn)
|
||||
printf("\n*** Did TRY to SIMULATE burning ***\n\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/** The setup parameters of libburner */
|
||||
static char drive_adr[BURN_DRIVE_ADR_LEN] = {""};
|
||||
static int driveno = 0;
|
||||
static int do_blank = 0;
|
||||
static char source_adr[99][4096];
|
||||
static int source_adr_count = 0;
|
||||
static int do_multi = 0;
|
||||
static int simulate_burn = 0;
|
||||
static int all_tracks_type = BURN_MODE1;
|
||||
|
||||
|
||||
/** Converts command line arguments into above setup parameters.
|
||||
*/
|
||||
int libburner_setup(int argc, char **argv)
|
||||
{
|
||||
int i, insuffient_parameters = 0, print_help = 0;
|
||||
|
||||
for (i = 1; i < argc; ++i) {
|
||||
if (!strcmp(argv[i], "--audio")) {
|
||||
all_tracks_type = BURN_AUDIO;
|
||||
|
||||
} else if (!strcmp(argv[i], "--blank_fast")) {
|
||||
do_blank = 1;
|
||||
|
||||
} else if (!strcmp(argv[i], "--blank_full")) {
|
||||
do_blank = 2;
|
||||
|
||||
} else if (!strcmp(argv[i], "--burn_for_real")) {
|
||||
simulate_burn = 0;
|
||||
|
||||
} else if (!strcmp(argv[i], "--drive")) {
|
||||
++i;
|
||||
if (i >= argc) {
|
||||
fprintf(stderr,"--drive requires an argument\n");
|
||||
return 1;
|
||||
} else if (strcmp(argv[i], "-") == 0) {
|
||||
drive_adr[0] = 0;
|
||||
driveno = -1;
|
||||
} else if (isdigit(argv[i][0])) {
|
||||
drive_adr[0] = 0;
|
||||
driveno = atoi(argv[i]);
|
||||
} else {
|
||||
if(strlen(argv[i]) >= BURN_DRIVE_ADR_LEN) {
|
||||
fprintf(stderr,"--drive address too long (max. %d)\n",
|
||||
BURN_DRIVE_ADR_LEN-1);
|
||||
return 2;
|
||||
}
|
||||
strcpy(drive_adr, argv[i]);
|
||||
}
|
||||
} else if ((!strcmp(argv[i], "--format_overwrite")) ||
|
||||
(!strcmp(argv[i], "--format"))) {
|
||||
do_blank = 101;
|
||||
|
||||
} else if (!strcmp(argv[i], "--multi")) {
|
||||
do_multi = 1;
|
||||
|
||||
} else if (!strcmp(argv[i], "--stdin_size")) { /* obsoleted */
|
||||
i++;
|
||||
|
||||
} else if (!strcmp(argv[i], "--try_to_simulate")) {
|
||||
simulate_burn = 1;
|
||||
|
||||
} else if (!strcmp(argv[i], "--help")) {
|
||||
print_help = 1;
|
||||
|
||||
} else if (!strncmp(argv[i], "--",2)) {
|
||||
fprintf(stderr, "Unidentified option: %s\n", argv[i]);
|
||||
return 7;
|
||||
} else {
|
||||
if(strlen(argv[i]) >= 4096) {
|
||||
fprintf(stderr, "Source address too long (max. %d)\n", 4096-1);
|
||||
return 5;
|
||||
}
|
||||
if(source_adr_count >= 99) {
|
||||
fprintf(stderr, "Too many tracks (max. 99)\n");
|
||||
return 6;
|
||||
}
|
||||
strcpy(source_adr[source_adr_count], argv[i]);
|
||||
source_adr_count++;
|
||||
}
|
||||
}
|
||||
insuffient_parameters = 1;
|
||||
if (driveno < 0)
|
||||
insuffient_parameters = 0;
|
||||
if (source_adr_count > 0)
|
||||
insuffient_parameters = 0;
|
||||
if (do_blank)
|
||||
insuffient_parameters = 0;
|
||||
if (print_help || insuffient_parameters ) {
|
||||
printf("Usage: %s\n", argv[0]);
|
||||
printf(" [--drive <address>|<driveno>|\"-\"] [--audio]\n");
|
||||
printf(" [--blank_fast|--blank_full|--format] [--try_to_simulate]\n");
|
||||
printf(" [--multi] [<one or more imagefiles>|\"-\"]\n");
|
||||
printf("Examples\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, leave appendable:\n");
|
||||
printf(" %s --drive 0 --multi my_image_file\n", argv[0]);
|
||||
printf("Burn a file to drive chosen by persistent address, close:\n");
|
||||
printf(" %s --drive /dev/hdc my_image_file\n", argv[0]);
|
||||
printf("Blank a used CD-RW (is combinable with burning in one run):\n");
|
||||
printf(" %s --drive /dev/hdc --blank_fast\n",argv[0]);
|
||||
printf("Blank a used DVD-RW (is combinable with burning in one run):\n");
|
||||
printf(" %s --drive /dev/hdc --blank_full\n",argv[0]);
|
||||
printf("Format a DVD-RW, BD-RE or BD-R:\n");
|
||||
printf(" %s --drive /dev/hdc --format\n", argv[0]);
|
||||
printf("Burn two audio tracks (to CD only):\n");
|
||||
printf(" lame --decode -t /path/to/track1.mp3 track1.cd\n");
|
||||
printf(" test/dewav /path/to/track2.wav -o track2.cd\n");
|
||||
printf(" %s --drive /dev/hdc --audio track1.cd track2.cd\n", argv[0]);
|
||||
printf("Burn a compressed afio archive on-the-fly:\n");
|
||||
printf(" ( cd my_directory ; find . -print | afio -oZ - ) | \\\n");
|
||||
printf(" %s --drive /dev/hdc -\n", argv[0]);
|
||||
printf("To be read from *not mounted* media via: afio -tvZ /dev/hdc\n");
|
||||
if (insuffient_parameters)
|
||||
return 6;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* A warning to programmers who start their own projekt from here. */
|
||||
if (sizeof(off_t) != 8) {
|
||||
fprintf(stderr,
|
||||
"\nFATAL: Compile time misconfiguration. off_t is not 64 bit.\n\n");
|
||||
exit(39);
|
||||
}
|
||||
|
||||
ret = libburner_setup(argc, argv);
|
||||
if (ret)
|
||||
exit(ret);
|
||||
|
||||
printf("Initializing libburnia-project.org ...\n");
|
||||
if (burn_initialize())
|
||||
printf("Done\n");
|
||||
else {
|
||||
printf("FAILED\n");
|
||||
fprintf(stderr,"\nFATAL: Failed to initialize.\n");
|
||||
exit(33);
|
||||
}
|
||||
|
||||
/* Print messages of severity SORRY or more directly to stderr */
|
||||
burn_msgs_set_severities("NEVER", "SORRY", "libburner : ");
|
||||
|
||||
/* Activate the synchronous signal handler which eventually will try to
|
||||
properly shutdown drive and library on aborting events. */
|
||||
burn_set_signal_handling("libburner : ", NULL, 0x0);
|
||||
|
||||
/** Note: driveno might change its value in this call */
|
||||
ret = libburner_aquire_drive(drive_adr, &driveno);
|
||||
if (ret<=0) {
|
||||
fprintf(stderr,"\nFATAL: Failed to aquire drive.\n");
|
||||
{ ret = 34; goto finish_libburn; }
|
||||
}
|
||||
if (ret == 2)
|
||||
{ ret = 0; goto release_drive; }
|
||||
if (do_blank) {
|
||||
if (do_blank > 100)
|
||||
ret = libburner_format(drive_list[driveno].drive);
|
||||
else
|
||||
ret = libburner_blank_disc(drive_list[driveno].drive,
|
||||
do_blank == 1);
|
||||
if (ret<=0)
|
||||
{ ret = 36; goto release_drive; }
|
||||
}
|
||||
if (source_adr_count > 0) {
|
||||
ret = libburner_payload(drive_list[driveno].drive,
|
||||
source_adr, source_adr_count,
|
||||
do_multi, simulate_burn, all_tracks_type);
|
||||
if (ret<=0)
|
||||
{ ret = 38; goto release_drive; }
|
||||
}
|
||||
ret = 0;
|
||||
release_drive:;
|
||||
if (drive_is_grabbed)
|
||||
burn_drive_release(drive_list[driveno].drive, 0);
|
||||
|
||||
finish_libburn:;
|
||||
if (burn_is_aborting(0) > 0) {
|
||||
burn_abort(4400, burn_abort_pacifier, "libburner : ");
|
||||
fprintf(stderr,"\nlibburner run aborted\n");
|
||||
exit(1);
|
||||
}
|
||||
/* This app does not bother to know about exact scan state.
|
||||
Better to accept a memory leak here. We are done anyway. */
|
||||
/* burn_drive_info_free(drive_list); */
|
||||
burn_finish();
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
|
||||
/* License and copyright aspects:
|
||||
|
||||
This all is provided under GPL.
|
||||
Read. Try. Think. Play. Write yourself some code. Be free of my copyright.
|
||||
|
||||
Be also invited to study the code of cdrskin/cdrskin.c et al.
|
||||
|
||||
History:
|
||||
libburner is a compilation of my own contributions to test/burniso.c and
|
||||
fresh code which replaced the remaining parts under copyright of
|
||||
Derek Foreman.
|
||||
My respect and my thanks to Derek for providing me a start back in 2005.
|
||||
|
||||
*/
|
||||
|
134
libburn/branches/ZeroEightEight/test/offst_source.c
Normal file
134
libburn/branches/ZeroEightEight/test/offst_source.c
Normal file
@ -0,0 +1,134 @@
|
||||
|
||||
/*
|
||||
cc -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS -g -o test/offst_source test/offst_source.c -lburn
|
||||
*/
|
||||
|
||||
#include "../libburn/libburn.h"
|
||||
|
||||
/* Just everything from test/libburner.c */
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
static int create_original(struct burn_source **original, char *path, int flag)
|
||||
{
|
||||
printf("create_original: path='%s'\n", path);
|
||||
*original = burn_file_source_new(path, NULL);
|
||||
if (*original == NULL)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int set_up_offst_sources(struct burn_source *original,
|
||||
struct burn_source *offsetters[],
|
||||
int count, int flag)
|
||||
{
|
||||
int i;
|
||||
off_t start = 3, size = 10, gap = 7;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
offsetters[i] = burn_offst_source_new(original,
|
||||
i > 0 ? offsetters[i - 1] : NULL,
|
||||
start, size, 0);
|
||||
if (offsetters[i] == NULL)
|
||||
return 0;
|
||||
printf("set_up_offst_sources: idx=%d, start=%d\n",
|
||||
i, (int) start);
|
||||
start += size + gap;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int consume_source(struct burn_source *src, int flag)
|
||||
{
|
||||
int ret, count = 0;
|
||||
unsigned char buf[1];
|
||||
|
||||
while (1) {
|
||||
ret = src->read_xt(src, buf, 1);
|
||||
if (ret < 0) {
|
||||
printf("\n");
|
||||
fprintf(stderr, "consume_source: count=%d, ret=%d\n",
|
||||
count, ret);
|
||||
return 0;
|
||||
}
|
||||
if (ret == 0)
|
||||
break;
|
||||
printf("%u ", buf[0]);
|
||||
count++;
|
||||
}
|
||||
printf(" count=%d\n", count);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int consume_all_sources(struct burn_source *offsetters[],
|
||||
int count, int flag)
|
||||
{
|
||||
int i, ret;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
printf("consume_source: idx=%d\n", i);
|
||||
ret = consume_source(offsetters[i], 0);
|
||||
if (ret <= 0)
|
||||
return ret;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int free_all_sources(struct burn_source *original,
|
||||
struct burn_source *offsetters[],
|
||||
int count, int flag)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
burn_source_free(offsetters[i]);
|
||||
burn_source_free(original);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
char *path = "./COPYRIGHT";
|
||||
struct burn_source *original = NULL, *offsetters[4];
|
||||
|
||||
if (argc > 1)
|
||||
path = argv[1];
|
||||
|
||||
if (burn_initialize() == 0)
|
||||
exit(1);
|
||||
|
||||
ret = create_original(&original, path, 0);
|
||||
if (ret <= 0)
|
||||
exit(2);
|
||||
|
||||
ret = set_up_offst_sources(original, offsetters, 4, 0);
|
||||
if (ret <= 0)
|
||||
exit(3);
|
||||
|
||||
ret = consume_all_sources(offsetters, 4, 0);
|
||||
if (ret <= 0)
|
||||
exit(4);
|
||||
|
||||
ret = free_all_sources(original, offsetters, 4, 0);
|
||||
if (ret <= 0)
|
||||
exit(5);
|
||||
|
||||
burn_finish();
|
||||
exit(0);
|
||||
}
|
||||
|
133
libburn/branches/ZeroEightEight/test/open-cd-excl.c
Normal file
133
libburn/branches/ZeroEightEight/test/open-cd-excl.c
Normal file
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* open-cd-excl.c --- This program tries to open a block device
|
||||
* by various exclusive and non-exclusive gestures in order to explore
|
||||
* their impact on running CD/DVD recordings.
|
||||
*
|
||||
* Copyright 2007, by Theodore Ts'o.
|
||||
*
|
||||
* Detail modifications 2007, by Thomas Schmitt.
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the GNU Public
|
||||
* License.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE /* for O_LARGEFILE *//*ts A70417: or _LARGEFILE64_SOURCE */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
|
||||
const char *progname;
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-feirw] device\n", progname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* ts A70417: added parameter do_rdwr */
|
||||
static void init_flock(struct flock *fl, int do_rdwr)
|
||||
{
|
||||
memset(fl, 0, sizeof(struct flock));
|
||||
if (do_rdwr)
|
||||
fl->l_type = F_WRLCK;
|
||||
else
|
||||
fl->l_type = F_RDLCK;
|
||||
fl->l_whence = SEEK_SET;
|
||||
fl->l_start = 0;
|
||||
fl->l_len = 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct flock fl;
|
||||
char *device_name;
|
||||
int fd, c, f_opt = 0, do_rdwr = 0, end_immediately = 0;
|
||||
int flags = O_NONBLOCK|O_LARGEFILE;
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
/* ts A70417: added -w , -r , -i */
|
||||
while ((c = getopt (argc, argv, "feirw")) != EOF) {
|
||||
switch (c) {
|
||||
case 'e':
|
||||
flags |= O_EXCL;
|
||||
break;
|
||||
case 'f':
|
||||
f_opt++;
|
||||
break;
|
||||
case 'i':
|
||||
end_immediately = 1;
|
||||
break;
|
||||
case 'r':
|
||||
do_rdwr = 0;
|
||||
break;
|
||||
case 'w':
|
||||
do_rdwr = 1;
|
||||
break;
|
||||
case '?':
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind == argc)
|
||||
usage();
|
||||
device_name = argv[optind++];
|
||||
|
||||
/* ts A70417 : made read-write adjustable independently of f_opt */
|
||||
if (do_rdwr) {
|
||||
flags |= O_RDWR;
|
||||
printf("Using O_RDWR\n");
|
||||
} else {
|
||||
flags |= O_RDONLY;
|
||||
printf("Using O_RDONLY\n");
|
||||
}
|
||||
|
||||
if (flags & O_EXCL)
|
||||
printf("Trying to open %s with O_EXCL ...\n", device_name);
|
||||
fd = open(device_name, flags, 0);
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
printf("failed\n");
|
||||
exit(1);
|
||||
}
|
||||
if (flags & O_EXCL)
|
||||
printf("succeeded\n");
|
||||
|
||||
if (f_opt) {
|
||||
init_flock(&fl, do_rdwr);
|
||||
if (fcntl(fd, F_GETLK, &fl) < 0) {
|
||||
perror("fcntl: F_GETLK: ");
|
||||
exit(1);
|
||||
}
|
||||
printf("fcntl lock apparently %sLOCKED\n",
|
||||
(fl.l_type == F_UNLCK) ? "NOT " : "");
|
||||
|
||||
init_flock(&fl, do_rdwr);
|
||||
printf("Trying to grab fcntl lock...\n");
|
||||
if (fcntl(fd, F_SETLK, &fl) < 0) {
|
||||
perror("fcntl: F_SETLK: ");
|
||||
printf("failed\n");
|
||||
exit(1);
|
||||
}
|
||||
printf("succeeded\n");
|
||||
}
|
||||
|
||||
/* ts A70417: added end_immediately */
|
||||
printf("Holding %s open.\n", device_name);
|
||||
usleep(100000);
|
||||
if (end_immediately)
|
||||
exit(0);
|
||||
printf("Press ^C to exit.\n");
|
||||
while (1) {
|
||||
sleep(300);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
return 0;
|
||||
}
|
78
libburn/branches/ZeroEightEight/test/poll.c
Normal file
78
libburn/branches/ZeroEightEight/test/poll.c
Normal file
@ -0,0 +1,78 @@
|
||||
/* -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 8; -*- */
|
||||
|
||||
#include "libburn/libburn.h"
|
||||
#include "libburn/toc.h"
|
||||
#include "libburn/mmc.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <assert.h>
|
||||
|
||||
static struct burn_drive_info *drives;
|
||||
static unsigned int n_drives;
|
||||
int NEXT;
|
||||
|
||||
static void catch_int ()
|
||||
{
|
||||
NEXT = 1;
|
||||
}
|
||||
|
||||
static void poll_drive(int d)
|
||||
{
|
||||
enum burn_disc_status s;
|
||||
|
||||
fprintf(stderr, "polling disc in %s - %s:\n",
|
||||
drives[d].vendor, drives[d].product);
|
||||
|
||||
if (!burn_drive_grab(drives[d].drive, 1)) {
|
||||
fprintf(stderr, "Unable to open the drive!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
while (burn_drive_get_status(drives[d].drive, NULL))
|
||||
usleep(1000);
|
||||
|
||||
while ((s = burn_disc_get_status(drives[d].drive))
|
||||
== BURN_DISC_UNREADY)
|
||||
usleep(1000);
|
||||
|
||||
while (NEXT == 0) {
|
||||
sleep(2);
|
||||
mmc_get_event(drives[d].drive);
|
||||
}
|
||||
burn_drive_release(drives[d].drive, 0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
struct sigaction newact;
|
||||
struct sigaction oldact;
|
||||
fprintf(stderr, "Initializing library...");
|
||||
if (burn_initialize())
|
||||
fprintf(stderr, "Success\n");
|
||||
else {
|
||||
printf("Failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Scanning for devices...");
|
||||
while (!burn_drive_scan(&drives, &n_drives)) ;
|
||||
fprintf(stderr, "Done\n");
|
||||
if (!drives) {
|
||||
printf("No burner found\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
newact.sa_handler = catch_int;
|
||||
sigaction(SIGINT, &newact, &oldact);
|
||||
for (i = 0; i < n_drives; i++) {
|
||||
NEXT=0;
|
||||
poll_drive(i);
|
||||
}
|
||||
sigaction(SIGINT, &oldact, NULL);
|
||||
burn_drive_info_free(drives);
|
||||
burn_finish();
|
||||
return 0;
|
||||
}
|
48
libburn/branches/ZeroEightEight/test/structest.c
Normal file
48
libburn/branches/ZeroEightEight/test/structest.c
Normal file
@ -0,0 +1,48 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <libburn/libburn.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
const char *path;
|
||||
struct burn_track *track;
|
||||
struct burn_disc *disc;
|
||||
struct burn_session *session;
|
||||
struct burn_source *src;
|
||||
|
||||
disc = burn_disc_create();
|
||||
session = burn_session_create();
|
||||
burn_disc_add_session(disc, session, BURN_POS_END);
|
||||
|
||||
/* Define a source for all of the tracks */
|
||||
path = strdup("/etc/hosts");
|
||||
src = burn_file_source_new(path, NULL);
|
||||
|
||||
/* Add ten tracks to a session */
|
||||
for (i = 0; i < 10; i++) {
|
||||
track = burn_track_create();
|
||||
burn_session_add_track(session, track, 0);
|
||||
if (burn_track_set_source(track, src) != BURN_SOURCE_OK) {
|
||||
printf("problem with the source\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Add ten tracks to a session */
|
||||
for (i = 0; i < 10; i++) {
|
||||
track = burn_track_create();
|
||||
burn_session_add_track(session, track, 0);
|
||||
if (burn_track_set_source(track, src) != BURN_SOURCE_OK) {
|
||||
printf("problem with the source\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete a session */
|
||||
burn_session_remove_track(session, track);
|
||||
|
||||
burn_structure_print_disc(disc);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
921
libburn/branches/ZeroEightEight/test/telltoc.c
Normal file
921
libburn/branches/ZeroEightEight/test/telltoc.c
Normal file
@ -0,0 +1,921 @@
|
||||
|
||||
/* test/telltoc.c , API illustration of obtaining media status info */
|
||||
/* Copyright (C) 2006 - 2010 Thomas Schmitt <scdbackup@gmx.net>
|
||||
Provided under GPL */
|
||||
|
||||
/** Overview
|
||||
|
||||
telltoc is a minimal demo application for the library libburn as provided
|
||||
on http://libburnia-project.org . It can list the available devices, can
|
||||
display some drive properties, the type of media, eventual table of content
|
||||
and multisession info for mkisofs option -C .
|
||||
It's main purpose, nevertheless, is to show you how to use libburn and also
|
||||
to serve the libburn team as reference application. telltoc.c does indeed
|
||||
define the standard way how above gestures can be implemented and stay upward
|
||||
compatible for a good while.
|
||||
|
||||
Before you can do anything, you have to initialize libburn by
|
||||
burn_initialize()
|
||||
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:
|
||||
telltoc_aquire_by_adr() demonstrates usage as of cdrecord traditions
|
||||
telltoc_aquire_by_driveno() demonstrates a scan-and-choose approach
|
||||
With that aquired drive you can call
|
||||
telltoc_media() prints some information about the media in a drive
|
||||
telltoc_toc() prints a table of content (if there is content)
|
||||
telltoc_msinfo() prints parameters for mkisofs option -C
|
||||
telltoc_read_and_print() reads from data CD or from DVD and prints 7-bit
|
||||
to stdout (encodings 0,2) or 8-bit to file (encoding 1)
|
||||
When everything is done, main() releases the drive and shuts down libburn:
|
||||
burn_drive_release();
|
||||
burn_finish()
|
||||
|
||||
*/
|
||||
|
||||
/** See this for the decisive API specs . libburn.h is The Original */
|
||||
/* For using the installed header file : #include <libburn/libburn.h> */
|
||||
/* This program insists in the own headerfile. */
|
||||
#include "../libburn/libburn.h"
|
||||
|
||||
/* libburn is intended for Linux systems with kernel 2.4 or 2.6 for now */
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
/** For simplicity i use global variables to represent the drives.
|
||||
Drives are systemwide global, so we do not give away much of good style.
|
||||
*/
|
||||
|
||||
/** This list will hold the drives known to libburn. This might be all CD
|
||||
drives of the system and thus might impose severe impact on the system.
|
||||
*/
|
||||
static struct burn_drive_info *drive_list;
|
||||
|
||||
/** If you start a long lasting operation with drive_count > 1 then you are
|
||||
not friendly to the users of other drives on those systems. Beware. */
|
||||
static unsigned int drive_count;
|
||||
|
||||
/** This variable indicates wether the drive is grabbed and must be
|
||||
finally released */
|
||||
static int drive_is_grabbed = 0;
|
||||
|
||||
|
||||
/* Some in-advance definitions to allow a more comprehensive ordering
|
||||
of the functions and their explanations in here */
|
||||
int telltoc_aquire_by_adr(char *drive_adr);
|
||||
int telltoc_aquire_by_driveno(int *drive_no, int silent);
|
||||
|
||||
|
||||
/* A message from --toc to --read_and_print (CD tracksize is a bit tricky) */
|
||||
static int last_track_start = 0, last_track_size = -1;
|
||||
static int media_is_cd_profile = 0;
|
||||
|
||||
|
||||
/* ------------------------------- API gestures ---------------------------- */
|
||||
|
||||
/** 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.
|
||||
|
||||
If you have a persistent address of the drive, then the compact call is
|
||||
to prefer because it only touches one drive. On modern Linux kernels,
|
||||
there should be no fatal disturbance of ongoing burns of other libburn
|
||||
instances with any of our approaches. We use open(O_EXCL) by default.
|
||||
On /dev/hdX it should cooperate with growisofs and some cdrecord variants.
|
||||
On /dev/sgN versus /dev/scdM expect it not to respect other programs.
|
||||
*/
|
||||
int telltoc_aquire_drive(char *drive_adr, int *driveno, int silent_drive)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if(drive_adr != NULL && drive_adr[0] != 0)
|
||||
ret = telltoc_aquire_by_adr(drive_adr);
|
||||
else
|
||||
ret = telltoc_aquire_by_driveno(driveno, silent_drive);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/** If the persistent drive address is known, then this approach is much
|
||||
more un-obtrusive to the systemwide livestock of drives. Only the
|
||||
given drive device will be opened during this procedure.
|
||||
Special drive addresses stdio:<path> direct output to a hard disk file
|
||||
which will behave much like a DVD-RAM.
|
||||
*/
|
||||
int telltoc_aquire_by_adr(char *drive_adr)
|
||||
{
|
||||
int ret;
|
||||
char libburn_drive_adr[BURN_DRIVE_ADR_LEN];
|
||||
|
||||
/* <<< ts A70907 FOR TESTING ONLY !
|
||||
struct burn_drive_info *test_drive_list;
|
||||
*/
|
||||
|
||||
/* This tries to resolve links or alternative device files */
|
||||
ret = burn_drive_convert_fs_adr(drive_adr, libburn_drive_adr);
|
||||
if (ret<=0) {
|
||||
fprintf(stderr, "Address does not lead to a CD burner: '%s'\n",
|
||||
drive_adr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* <<< ts A70907 FOR TESTING ONLY !
|
||||
ret = burn_drive_scan_and_grab(&test_drive_list, "/dev/sg2", 1);
|
||||
*/
|
||||
|
||||
fprintf(stderr,"Aquiring drive '%s' ...\n", libburn_drive_adr);
|
||||
ret = burn_drive_scan_and_grab(&drive_list, libburn_drive_adr, 1);
|
||||
|
||||
if (ret <= 0) {
|
||||
fprintf(stderr,"FAILURE with persistent drive address '%s'\n",
|
||||
libburn_drive_adr);
|
||||
} else {
|
||||
fprintf(stderr,"Done\n");
|
||||
drive_is_grabbed = 1;
|
||||
}
|
||||
|
||||
/* <<< ts A70907 FOR TESTING ONLY !
|
||||
burn_drive_info_free(test_drive_list);
|
||||
*/
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/** This method demonstrates how to use libburn without knowing a persistent
|
||||
drive address in advance. It has to make sure that after assessing the list
|
||||
of available drives, all unwanted drives get closed again. As long as they
|
||||
are open, no other libburn instance can see them. This is an intended
|
||||
locking feature. The application is responsible for giving up the locks
|
||||
by either burn_drive_release() (only after burn_drive_grab() !),
|
||||
burn_drive_info_forget(), burn_drive_info_free(), or burn_finish().
|
||||
@param driveno the index number in libburn's drive list. This will get
|
||||
set to 0 on success and will then be the drive index to
|
||||
use in the further dourse of processing.
|
||||
@param silent_drive 1=do not print "Drive found :" line with *driveno >= 0
|
||||
@return 1 success , <= 0 failure
|
||||
*/
|
||||
int telltoc_aquire_by_driveno(int *driveno, int silent_drive)
|
||||
{
|
||||
char adr[BURN_DRIVE_ADR_LEN];
|
||||
int ret, i;
|
||||
|
||||
fprintf(stderr, "Beginning to scan for devices ...\n");
|
||||
while (!burn_drive_scan(&drive_list, &drive_count))
|
||||
usleep(100002);
|
||||
if (drive_count <= 0 && *driveno >= 0) {
|
||||
fprintf(stderr, "FAILED (no drives found)\n");
|
||||
return 0;
|
||||
}
|
||||
fprintf(stderr, "Done\n");
|
||||
|
||||
for (i = 0; i < drive_count; i++) {
|
||||
if (*driveno >= 0 && (silent_drive || *driveno != i))
|
||||
continue;
|
||||
if (burn_drive_get_adr(&(drive_list[i]), adr) <=0)
|
||||
strcpy(adr, "-get_adr_failed-");
|
||||
printf("Drive found : %d --drive '%s' : ", i,adr);
|
||||
printf("%-8s %-16s (%4s)\n",
|
||||
drive_list[i].vendor,drive_list[i].product,
|
||||
drive_list[i].revision);
|
||||
}
|
||||
if (*driveno < 0) {
|
||||
fprintf(stderr,
|
||||
"Pseudo-drive \"-\" given : bus scanning done.\n");
|
||||
return 2; /* the program will end after this */
|
||||
}
|
||||
|
||||
/* We already made our choice via command line. (default is 0)
|
||||
So we just have to keep our desired drive and drop all others.
|
||||
*/
|
||||
if (drive_count <= *driveno) {
|
||||
fprintf(stderr,
|
||||
"Found only %d drives. Number %d not available.\n",
|
||||
drive_count, *driveno);
|
||||
return 0; /* the program will end after this */
|
||||
}
|
||||
|
||||
/* Drop all drives which we do not want to use */
|
||||
for (i = 0; i < drive_count; i++) {
|
||||
if (i == *driveno) /* the one drive we want to keep */
|
||||
continue;
|
||||
ret = burn_drive_info_forget(&(drive_list[i]),0);
|
||||
if (ret != 1)
|
||||
fprintf(stderr, "Cannot drop drive %d. Please report \"ret=%d\" to libburn-hackers@pykix.org\n",
|
||||
i, ret);
|
||||
else
|
||||
fprintf(stderr, "Dropped unwanted drive %d\n",i);
|
||||
}
|
||||
/* Make the one we want ready for inquiry */
|
||||
ret= burn_drive_grab(drive_list[*driveno].drive, 1);
|
||||
if (ret != 1)
|
||||
return 0;
|
||||
drive_is_grabbed = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/** This gesture is necessary to get my NEC DVD_RW ND-4570A out of a state
|
||||
of noisy overexcitement after its tray was loaded and it then was inquired
|
||||
for Next Writeable Address.
|
||||
The noise then still lasts 20 seconds. Same with cdrecord -toc, btw.
|
||||
This opens a small gap for losing the drive to another libburn instance.
|
||||
Not a problem in telltoc. This is done as very last drive operation.
|
||||
Eventually the other libburn instance will have the same sanitizing effect.
|
||||
*/
|
||||
int telltoc_regrab(struct burn_drive *drive) {
|
||||
int ret;
|
||||
|
||||
if (drive_is_grabbed)
|
||||
burn_drive_release(drive, 0);
|
||||
drive_is_grabbed = 0;
|
||||
ret = burn_drive_grab(drive, 0);
|
||||
if (ret != 0) {
|
||||
drive_is_grabbed = 1;
|
||||
}
|
||||
return !!ret;
|
||||
}
|
||||
|
||||
|
||||
int telltoc_media(struct burn_drive *drive)
|
||||
{
|
||||
int ret, media_found = 0, profile_no = -1;
|
||||
double max_speed = 0.0, min_speed = 0.0, speed_conv;
|
||||
off_t available = 0;
|
||||
enum burn_disc_status s;
|
||||
char profile_name[80], speed_unit[40];
|
||||
struct burn_multi_caps *caps;
|
||||
struct burn_write_opts *o = NULL;
|
||||
|
||||
printf("Media current: ");
|
||||
ret = burn_disc_get_profile(drive, &profile_no, profile_name);
|
||||
if (profile_no > 0 && ret > 0) {
|
||||
if (profile_name[0])
|
||||
printf("%s\n", profile_name);
|
||||
else
|
||||
printf("%4.4Xh\n", profile_no);
|
||||
} else
|
||||
printf("is not recognizable\n");
|
||||
|
||||
speed_conv = 176.4;
|
||||
strcpy(speed_unit,"176.4 kB/s (CD, data speed 150 KiB/s)");
|
||||
if (strstr(profile_name, "DVD") == profile_name) {
|
||||
speed_conv = 1385.0;
|
||||
strcpy(speed_unit,"1385.0 kB/s (DVD)");
|
||||
}
|
||||
|
||||
/* >>> libburn does not obtain full profile list yet */
|
||||
|
||||
printf("Media status : ");
|
||||
s = burn_disc_get_status(drive);
|
||||
if (s == BURN_DISC_FULL) {
|
||||
printf("is written , is closed\n");
|
||||
media_found = 1;
|
||||
} else if (s == BURN_DISC_APPENDABLE) {
|
||||
printf("is written , is appendable\n");
|
||||
media_found = 1;
|
||||
} else if (s == BURN_DISC_BLANK) {
|
||||
printf("is blank\n");
|
||||
media_found = 1;
|
||||
} else if (s == BURN_DISC_EMPTY)
|
||||
printf("is not present\n");
|
||||
else
|
||||
printf("is not recognizable\n");
|
||||
|
||||
printf("Media reuse : ");
|
||||
if (media_found) {
|
||||
if (burn_disc_erasable(drive))
|
||||
printf("is erasable\n");
|
||||
else
|
||||
printf("is not erasable\n");
|
||||
} else
|
||||
printf("is not recognizable\n");
|
||||
|
||||
ret = burn_disc_get_multi_caps(drive, BURN_WRITE_NONE, &caps, 0);
|
||||
if (ret > 0) {
|
||||
/* Media appears writeable */
|
||||
printf("Write multi : ");
|
||||
printf("%s multi-session , ",
|
||||
caps->multi_session == 1 ? "allows" : "prohibits");
|
||||
if (caps->multi_track)
|
||||
printf("allows multiple tracks\n");
|
||||
else
|
||||
printf("enforces single track\n");
|
||||
printf("Write start : ");
|
||||
if (caps->start_adr == 1)
|
||||
printf(
|
||||
"allows addresses [%.f , %.f]s , alignment=%.fs\n",
|
||||
(double) caps->start_range_low / 2048 ,
|
||||
(double) caps->start_range_high / 2048 ,
|
||||
(double) caps->start_alignment / 2048 );
|
||||
else
|
||||
printf("prohibits write start addressing\n");
|
||||
printf("Write modes : ");
|
||||
if (caps->might_do_tao)
|
||||
printf("TAO%s",
|
||||
caps->advised_write_mode == BURN_WRITE_TAO ?
|
||||
" (advised)" : "");
|
||||
if (caps->might_do_sao)
|
||||
printf("%sSAO%s",
|
||||
caps->might_do_tao ? " , " : "",
|
||||
caps->advised_write_mode == BURN_WRITE_SAO ?
|
||||
" (advised)" : "");
|
||||
if (caps->might_do_raw)
|
||||
printf("%sRAW%s",
|
||||
caps->might_do_tao | caps->might_do_sao ?
|
||||
" , " : "",
|
||||
caps->advised_write_mode == BURN_WRITE_RAW ?
|
||||
" (advised)" : "");
|
||||
printf("\n");
|
||||
printf("Write dummy : ");
|
||||
if (caps->might_simulate)
|
||||
printf("supposed to work with non-RAW modes\n");
|
||||
else
|
||||
printf("will not work\n");
|
||||
o= burn_write_opts_new(drive);
|
||||
if (o != NULL) {
|
||||
burn_write_opts_set_perform_opc(o, 0);
|
||||
if(caps->advised_write_mode == BURN_WRITE_TAO)
|
||||
burn_write_opts_set_write_type(o,
|
||||
BURN_WRITE_TAO, BURN_BLOCK_MODE1);
|
||||
else if (caps->advised_write_mode == BURN_WRITE_SAO)
|
||||
burn_write_opts_set_write_type(o,
|
||||
BURN_WRITE_SAO, BURN_BLOCK_SAO);
|
||||
else {
|
||||
burn_write_opts_free(o);
|
||||
o = NULL;
|
||||
}
|
||||
}
|
||||
available = burn_disc_available_space(drive, o);
|
||||
printf("Write space : %.1f MiB (%.fs)\n",
|
||||
((double) available) / 1024.0 / 1024.0,
|
||||
((double) available) / 2048.0);
|
||||
burn_disc_free_multi_caps(&caps);
|
||||
if (o != NULL)
|
||||
burn_write_opts_free(o);
|
||||
}
|
||||
|
||||
ret = burn_drive_get_write_speed(drive);
|
||||
max_speed = ((double ) ret) / speed_conv;
|
||||
ret = burn_drive_get_min_write_speed(drive);
|
||||
min_speed = ((double ) ret) / speed_conv;
|
||||
if (!media_found)
|
||||
printf("Drive speed : max=%.1f , min=%.1f\n",
|
||||
max_speed, min_speed);
|
||||
else
|
||||
printf("Avail. speed : max=%.1f , min=%.1f\n",
|
||||
max_speed, min_speed);
|
||||
|
||||
ret = 0;
|
||||
if (media_found)
|
||||
ret = burn_disc_read_atip(drive);
|
||||
if(ret>0) {
|
||||
ret = burn_drive_get_min_write_speed(drive);
|
||||
min_speed = ((double ) ret) / speed_conv;
|
||||
ret = burn_drive_get_write_speed(drive);
|
||||
max_speed = ((double ) ret) / speed_conv;
|
||||
printf("Media speed : max=%.1f , min=%.1f\n",
|
||||
max_speed, min_speed);
|
||||
}
|
||||
printf("Speed unit 1x: %s\n", speed_unit);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int telltoc_speedlist(struct burn_drive *drive)
|
||||
{
|
||||
int ret, has_modern_entries = 0;
|
||||
struct burn_speed_descriptor *speed_list, *sd;
|
||||
|
||||
ret = burn_drive_get_speedlist(drive, &speed_list);
|
||||
if (ret <= 0) {
|
||||
fprintf(stderr, "SORRY: Cannot obtain speed list info\n");
|
||||
return 2;
|
||||
}
|
||||
for (sd = speed_list; sd != NULL; sd = sd->next)
|
||||
if (sd->source == 2)
|
||||
has_modern_entries = 1;
|
||||
for (sd = speed_list; sd != NULL; sd = sd->next) {
|
||||
if (has_modern_entries && sd->source < 2)
|
||||
continue;
|
||||
if (sd->write_speed <= 0)
|
||||
continue;
|
||||
printf("Speed descr. : %d kB/s", sd->write_speed);
|
||||
if (sd->end_lba >= 0)
|
||||
printf(", %.1f MiB", ((double) sd->end_lba) / 512.0);
|
||||
if (sd->profile_name[0])
|
||||
printf(", %s", sd->profile_name);
|
||||
printf("\n");
|
||||
}
|
||||
burn_drive_free_speedlist(&speed_list);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int telltoc_formatlist(struct burn_drive *drive)
|
||||
{
|
||||
int ret, i, status, num_formats, profile_no, type;
|
||||
off_t size;
|
||||
unsigned dummy;
|
||||
char status_text[80], profile_name[90];
|
||||
|
||||
ret = burn_disc_get_formats(drive, &status, &size, &dummy,
|
||||
&num_formats);
|
||||
if (ret <= 0) {
|
||||
fprintf(stderr, "SORRY: Cannot obtain format list info\n");
|
||||
return 2;
|
||||
}
|
||||
if (status == BURN_FORMAT_IS_UNFORMATTED)
|
||||
sprintf(status_text, "unformatted, up to %.1f MiB",
|
||||
((double) size) / 1024.0 / 1024.0);
|
||||
else if(status == BURN_FORMAT_IS_FORMATTED)
|
||||
sprintf(status_text, "formatted, with %.1f MiB",
|
||||
((double) size) / 1024.0 / 1024.0);
|
||||
else if(status == BURN_FORMAT_IS_UNKNOWN) {
|
||||
burn_disc_get_profile(drive, &profile_no, profile_name);
|
||||
if (profile_no > 0)
|
||||
sprintf(status_text, "intermediate or unknown");
|
||||
else
|
||||
sprintf(status_text, "no media or unknown media");
|
||||
} else
|
||||
sprintf(status_text, "illegal status according to MMC-5");
|
||||
printf("Format status: %s\n", status_text);
|
||||
|
||||
for (i = 0; i < num_formats; i++) {
|
||||
ret = burn_disc_get_format_descr(drive, i,
|
||||
&type, &size, &dummy);
|
||||
if (ret <= 0)
|
||||
continue;
|
||||
printf("Format descr.: %2.2Xh , %.1f MiB (%.fs)\n",
|
||||
type, ((double) size) / 1024.0 / 1024.0,
|
||||
((double) size) / 2048.0);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int telltoc_toc(struct burn_drive *drive)
|
||||
{
|
||||
int num_sessions = 0 , num_tracks = 0 , lba = 0, pmin, psec, pframe;
|
||||
int track_count = 0, pno;
|
||||
int session_no, track_no;
|
||||
char profile_name[80];
|
||||
struct burn_disc *disc= NULL;
|
||||
struct burn_session **sessions;
|
||||
struct burn_track **tracks;
|
||||
struct burn_toc_entry toc_entry;
|
||||
|
||||
disc = burn_drive_get_disc(drive);
|
||||
if (disc==NULL) {
|
||||
fprintf(stderr, "SORRY: Cannot obtain Table Of Content\n");
|
||||
return 2;
|
||||
}
|
||||
sessions = burn_disc_get_sessions(disc, &num_sessions);
|
||||
for (session_no = 0; session_no<num_sessions; session_no++) {
|
||||
tracks = burn_session_get_tracks(sessions[session_no],
|
||||
&num_tracks);
|
||||
if (tracks==NULL)
|
||||
continue;
|
||||
for(track_no= 0; track_no<num_tracks; track_no++) {
|
||||
track_count++;
|
||||
burn_track_get_entry(tracks[track_no], &toc_entry);
|
||||
if (toc_entry.extensions_valid & 1) {
|
||||
/* DVD extension valid */
|
||||
lba = toc_entry.start_lba;
|
||||
burn_lba_to_msf(lba, &pmin, &psec, &pframe);
|
||||
} else {
|
||||
pmin = toc_entry.pmin;
|
||||
psec = toc_entry.psec;
|
||||
pframe = toc_entry.pframe;
|
||||
lba= burn_msf_to_lba(pmin, psec, pframe);
|
||||
}
|
||||
printf("Media content: session %2d ", session_no+1);
|
||||
printf("track %2d %s lba: %9d %4.2d:%2.2d:%2.2d\n",
|
||||
track_count,
|
||||
((toc_entry.control&7)<4?"audio":"data "),
|
||||
lba, pmin, psec, pframe);
|
||||
last_track_start = lba;
|
||||
}
|
||||
burn_session_get_leadout_entry(sessions[session_no],
|
||||
&toc_entry);
|
||||
if (toc_entry.extensions_valid & 1) {
|
||||
lba = toc_entry.start_lba;
|
||||
burn_lba_to_msf(lba, &pmin, &psec, &pframe);
|
||||
} else {
|
||||
pmin = toc_entry.pmin;
|
||||
psec = toc_entry.psec;
|
||||
pframe = toc_entry.pframe;
|
||||
lba= burn_msf_to_lba(pmin, psec, pframe);
|
||||
}
|
||||
printf("Media content: session %2d ", session_no+1);
|
||||
printf("leadout lba: %9d %4.2d:%2.2d:%2.2d\n",
|
||||
lba, pmin, psec, pframe);
|
||||
last_track_size = lba - last_track_start;
|
||||
if (burn_disc_get_profile(drive, &pno, profile_name) > 0)
|
||||
if (pno == 0x09 || pno == 0x0a)
|
||||
media_is_cd_profile = 1;
|
||||
|
||||
}
|
||||
if (disc!=NULL)
|
||||
burn_disc_free(disc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int telltoc_msinfo(struct burn_drive *drive,
|
||||
int msinfo_explicit, int msinfo_alone)
|
||||
{
|
||||
int ret, lba, nwa = -123456789, aux_lba;
|
||||
enum burn_disc_status s;
|
||||
struct burn_write_opts *o= NULL;
|
||||
|
||||
s = burn_disc_get_status(drive);
|
||||
if (s!=BURN_DISC_APPENDABLE) {
|
||||
if (!msinfo_explicit)
|
||||
return 2;
|
||||
fprintf(stderr,
|
||||
"SORRY: --msinfo can only operate on appendable media.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* man mkisofs , option -C :
|
||||
The first number is the sector number of the first sector in
|
||||
the last session of the disk that should be appended to.
|
||||
*/
|
||||
ret = burn_disc_get_msc1(drive, &lba);
|
||||
if (ret <= 0) {
|
||||
fprintf(stderr,
|
||||
"SORRY: Cannot obtain start address of last session\n");
|
||||
{ ret = 0; goto ex; }
|
||||
}
|
||||
|
||||
/* man mkisofs , option -C :
|
||||
The second number is the starting sector number of the new session.
|
||||
*/
|
||||
/* Set some roughly suitable write opts to be sent to drive. */
|
||||
o= burn_write_opts_new(drive);
|
||||
if(o!=NULL) {
|
||||
burn_write_opts_set_perform_opc(o, 0);
|
||||
burn_write_opts_set_write_type(o,
|
||||
BURN_WRITE_TAO, BURN_BLOCK_MODE1);
|
||||
}
|
||||
/* Now try to inquire nwa from drive */
|
||||
ret= burn_disc_track_lba_nwa(drive,o,0,&aux_lba,&nwa);
|
||||
telltoc_regrab(drive); /* necessary to calm down my NEC drive */
|
||||
if(ret<=0) {
|
||||
fprintf(stderr,
|
||||
"SORRY: Cannot obtain next writeable address\n");
|
||||
{ ret = 0; goto ex; }
|
||||
}
|
||||
|
||||
if (!msinfo_alone)
|
||||
printf("Media msinfo : mkisofs ... -C ");
|
||||
printf("%d,%d\n",lba,nwa);
|
||||
ret = 1;
|
||||
ex:;
|
||||
if (o != NULL)
|
||||
burn_write_opts_free(o);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@param encoding determins how to format output on stdout:
|
||||
0 = default , 1 = raw 8 bit (dangerous for tty) , 2 = hex
|
||||
*/
|
||||
int telltoc_read_and_print(struct burn_drive *drive,
|
||||
int start_sector, int sector_count, char *raw_file, int encoding)
|
||||
{
|
||||
int j, i, request = 16, done, lbas = 0, final_cd_try = -1, todo;
|
||||
int ret = 0;
|
||||
char buf[16 * 2048], line[81];
|
||||
off_t data_count, total_count= 0, last_reported_count= 0;
|
||||
struct stat stbuf;
|
||||
FILE *raw_fp = NULL;
|
||||
|
||||
if (start_sector == -1)
|
||||
start_sector = last_track_start;
|
||||
if (sector_count == -1) {
|
||||
sector_count = last_track_start + last_track_size
|
||||
- start_sector;
|
||||
if (media_is_cd_profile) /* In case it is a TAO track */
|
||||
final_cd_try = 0; /* allow it (-1 is denial) */
|
||||
}
|
||||
if (start_sector < 0)
|
||||
start_sector = 0;
|
||||
if (sector_count <= 0)
|
||||
sector_count = 2147483632;
|
||||
|
||||
if (sector_count <= 0)
|
||||
return -1;
|
||||
if (encoding == 1) {
|
||||
if (stat(raw_file,&stbuf) != -1) {
|
||||
if (!(S_ISCHR(stbuf.st_mode) || S_ISFIFO(stbuf.st_mode)
|
||||
|| (stbuf.st_mode & S_IFMT) == S_IFSOCK )) {
|
||||
fprintf(stderr,
|
||||
"SORRY: target file '%s' already existing\n",
|
||||
raw_file);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
raw_fp = fopen(raw_file,"w");
|
||||
if (raw_fp == NULL) {
|
||||
fprintf(stderr,"SORRY: cannot open target file '%s' (%s)\n", raw_file, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
printf(
|
||||
"Data : start=%ds , count=%ds , read=0s , encoding=%d:'%s'\n",
|
||||
start_sector, sector_count, encoding, raw_file);
|
||||
} else
|
||||
printf(
|
||||
"Data : start=%ds , count=%ds , read=0 , encoding=%d\n",
|
||||
start_sector, sector_count, encoding);
|
||||
todo = sector_count - 2*(final_cd_try > -1);
|
||||
for (done = 0; done < todo && final_cd_try != 1; done += request) {
|
||||
if (todo - done > 16)
|
||||
request = 16;
|
||||
else
|
||||
request = todo - done;
|
||||
ret = burn_read_data(drive,
|
||||
((off_t) start_sector + done) * (off_t) 2048,
|
||||
buf, (off_t) (request * 2048), &data_count, 1);
|
||||
|
||||
print_result:;
|
||||
total_count += data_count;
|
||||
if (encoding == 1) {
|
||||
if (data_count > 0)
|
||||
fwrite(buf, data_count, 1, raw_fp);
|
||||
} else for (i = 0; i < data_count; i += 16) {
|
||||
if (encoding == 0) {
|
||||
sprintf(line, "%8ds + %4d : ",
|
||||
start_sector + done + i / 2048,
|
||||
i % 2048);
|
||||
lbas = strlen(line);
|
||||
}
|
||||
for (j = 0; j < 16 && i + j < data_count; j++) {
|
||||
if (buf[i + j] >= ' ' && buf[i + j] <= 126 &&
|
||||
encoding != 2)
|
||||
sprintf(line + lbas + 3 * j, " %c ",
|
||||
(int) buf[i + j]);
|
||||
else
|
||||
sprintf(line + lbas + 3 * j, "%2.2X ",
|
||||
(unsigned char) buf[i + j]);
|
||||
}
|
||||
line[lbas + 3 * (j - 1) + 2] = 0;
|
||||
printf("%s\n",line);
|
||||
}
|
||||
if (encoding == 1 &&
|
||||
total_count - last_reported_count >= 1000 * 2048) {
|
||||
fprintf(stderr,
|
||||
"\rReading data : start=%ds , count=%ds , read=%ds ",
|
||||
start_sector, sector_count,
|
||||
(int) (total_count / (off_t) 2048));
|
||||
last_reported_count = total_count;
|
||||
}
|
||||
if (ret <= 0) {
|
||||
fprintf(stderr, "SORRY : Reading failed.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret > 0 && media_is_cd_profile && final_cd_try == 0) {
|
||||
/* In a SAO track the last 2 frames should be data too */
|
||||
final_cd_try = 1;
|
||||
burn_read_data(drive,
|
||||
((off_t) start_sector + todo) * (off_t) 2048,
|
||||
buf, (off_t) (2 * 2048), &data_count, 2);
|
||||
if (data_count < 2 * 2048)
|
||||
fprintf(stderr, "\rNOTE : Last two frames of CD track unreadable. This is normal if TAO track.\n");
|
||||
if (data_count > 0)
|
||||
goto print_result;
|
||||
}
|
||||
if (last_reported_count > 0)
|
||||
fprintf(stderr,
|
||||
"\r \r");
|
||||
printf("End Of Data : start=%ds , count=%ds , read=%ds\n",
|
||||
start_sector, sector_count,(int) (total_count / (off_t) 2048));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/** The setup parameters of telltoc */
|
||||
static char drive_adr[BURN_DRIVE_ADR_LEN] = {""};
|
||||
static int driveno = 0;
|
||||
static int do_media = 0;
|
||||
static int do_toc = 0;
|
||||
static int do_msinfo = 0;
|
||||
static int print_help = 0;
|
||||
static int do_capacities = 0;
|
||||
static int read_start = -2, read_count = -2, print_encoding = 0;
|
||||
static char print_raw_file[4096] = {""};
|
||||
|
||||
|
||||
/** Converts command line arguments into above setup parameters.
|
||||
drive_adr[] must provide at least BURN_DRIVE_ADR_LEN bytes.
|
||||
source_adr[] must provide at least 4096 bytes.
|
||||
*/
|
||||
int telltoc_setup(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 1; i < argc; ++i) {
|
||||
if (!strcmp(argv[i], "--drive")) {
|
||||
++i;
|
||||
if (i >= argc) {
|
||||
fprintf(stderr,"--drive requires an argument\n");
|
||||
return 1;
|
||||
} else if (strcmp(argv[i], "-") == 0) {
|
||||
drive_adr[0] = 0;
|
||||
driveno = -1;
|
||||
} else if (isdigit(argv[i][0])) {
|
||||
drive_adr[0] = 0;
|
||||
driveno = atoi(argv[i]);
|
||||
} else {
|
||||
if(strlen(argv[i]) >= BURN_DRIVE_ADR_LEN) {
|
||||
fprintf(stderr,"--drive address too long (max. %d)\n",
|
||||
BURN_DRIVE_ADR_LEN-1);
|
||||
return 2;
|
||||
}
|
||||
strcpy(drive_adr, argv[i]);
|
||||
}
|
||||
} else if (strcmp(argv[i],"--media")==0) {
|
||||
do_media = 1;
|
||||
|
||||
} else if (!strcmp(argv[i], "--msinfo")) {
|
||||
do_msinfo = 1;
|
||||
|
||||
} else if (!strcmp(argv[i], "--capacities")) {
|
||||
do_capacities = 1;
|
||||
|
||||
} else if (!strcmp(argv[i], "--toc")) {
|
||||
do_toc = 1;
|
||||
|
||||
} else if (!strcmp(argv[i], "--read_and_print")) {
|
||||
i+= 3;
|
||||
if (i >= argc) {
|
||||
fprintf(stderr,"--read_and_print requires three arguments: start count encoding(try 0, not 1)\n");
|
||||
return 1;
|
||||
}
|
||||
sscanf(argv[i-2], "%d", &read_start);
|
||||
sscanf(argv[i-1], "%d", &read_count);
|
||||
print_encoding = 0;
|
||||
if(strncmp(argv[i], "raw:", 4) == 0 || strcmp(argv[i],"1:") == 0) {
|
||||
print_encoding = 1;
|
||||
strcpy(print_raw_file, strchr(argv[i], ':') + 1);
|
||||
if (strcmp(print_raw_file, "-") == 0) {
|
||||
fprintf(stderr,
|
||||
"--read_and_print does not write to \"-\" as stdout.\n");
|
||||
return 1;
|
||||
}
|
||||
} else if(strcmp(argv[i], "hex") == 0 || strcmp(argv[i], "2") == 0)
|
||||
print_encoding = 2;
|
||||
|
||||
} else if (!strcmp(argv[i], "--help")) {
|
||||
print_help = 1;
|
||||
|
||||
} else {
|
||||
fprintf(stderr, "Unidentified option: %s\n", argv[i]);
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
if (argc==1)
|
||||
print_help = 1;
|
||||
if (print_help) {
|
||||
printf("Usage: %s\n", argv[0]);
|
||||
printf(" [--drive <address>|<driveno>|\"-\"]\n");
|
||||
printf(" [--media] [--capacities] [--toc] [--msinfo]\n");
|
||||
printf(" [--read_and_print <start> <count> \"0\"|\"hex\"|\"raw\":<path>]\n");
|
||||
printf("Examples\n");
|
||||
printf("A bus scan (needs rw-permissions to see a drive):\n");
|
||||
printf(" %s --drive -\n",argv[0]);
|
||||
printf("Obtain info about the type of loaded media:\n");
|
||||
printf(" %s --drive /dev/hdc --media\n",argv[0]);
|
||||
printf("Obtain table of content:\n");
|
||||
printf(" %s --drive /dev/hdc --toc\n",argv[0]);
|
||||
printf("Obtain parameters for option -C of program mkisofs:\n");
|
||||
printf(" msinfo=$(%s --drive /dev/hdc --msinfo 2>/dev/null)\n",
|
||||
argv[0]);
|
||||
printf(" mkisofs ... -C \"$msinfo\" ...\n");
|
||||
printf("Obtain what is available about drive 0 and its media\n");
|
||||
printf(" %s --drive 0\n",argv[0]);
|
||||
printf("View blocks 16 to 19 of data CD or DVD in human readable form\n");
|
||||
printf(" %s --drive /dev/sr1 --read_and_print 16 4 0 | less\n",
|
||||
argv[0]);
|
||||
printf("Copy last data track from CD to file /tmp/data\n");
|
||||
printf(" %s --drive /dev/sr1 --toc --read_and_print -1 -1 raw:/tmp/data\n",
|
||||
argv[0]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret, toc_failed = 0, msinfo_alone = 0, msinfo_explicit = 0;
|
||||
int full_default = 0;
|
||||
|
||||
ret = telltoc_setup(argc, argv);
|
||||
if (ret)
|
||||
exit(ret);
|
||||
|
||||
/* Behavior shall be different if --msinfo is only option */
|
||||
if (do_msinfo) {
|
||||
msinfo_explicit = 1;
|
||||
if (!(do_media || do_toc))
|
||||
msinfo_alone = 1;
|
||||
}
|
||||
/* Default option is to do everything if possible */
|
||||
if (do_media==0 && do_msinfo==0 && do_capacities==0 && do_toc==0 &&
|
||||
(read_start < 0 || read_count <= 0) && driveno!=-1) {
|
||||
if(print_help)
|
||||
exit(0);
|
||||
full_default = do_media = do_msinfo = do_capacities= do_toc= 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Initializing libburnia-project.org ...\n");
|
||||
if (burn_initialize())
|
||||
fprintf(stderr, "Done\n");
|
||||
else {
|
||||
fprintf(stderr,"\nFATAL: Failed to initialize.\n");
|
||||
exit(33);
|
||||
}
|
||||
|
||||
/* Print messages of severity WARNING or more directly to stderr */
|
||||
burn_msgs_set_severities("NEVER", "WARNING", "telltoc : ");
|
||||
|
||||
/* Activate the default signal handler */
|
||||
burn_set_signal_handling("telltoc : ", NULL, 0);
|
||||
|
||||
/** Note: driveno might change its value in this call */
|
||||
ret = telltoc_aquire_drive(drive_adr, &driveno, !full_default);
|
||||
if (ret<=0) {
|
||||
fprintf(stderr,"\nFATAL: Failed to aquire drive.\n");
|
||||
{ ret = 34; goto finish_libburn; }
|
||||
}
|
||||
if (ret == 2)
|
||||
{ ret = 0; goto release_drive; }
|
||||
|
||||
if (do_media) {
|
||||
ret = telltoc_media(drive_list[driveno].drive);
|
||||
if (ret<=0)
|
||||
{ret = 36; goto release_drive; }
|
||||
}
|
||||
if (do_capacities) {
|
||||
ret = telltoc_speedlist(drive_list[driveno].drive);
|
||||
if (ret<=0)
|
||||
{ret = 39; goto release_drive; }
|
||||
ret = telltoc_formatlist(drive_list[driveno].drive);
|
||||
if (ret<=0)
|
||||
{ret = 39; goto release_drive; }
|
||||
}
|
||||
if (do_toc) {
|
||||
ret = telltoc_toc(drive_list[driveno].drive);
|
||||
if (ret<=0)
|
||||
{ret = 37; goto release_drive; }
|
||||
if (ret==2)
|
||||
toc_failed = 1;
|
||||
}
|
||||
if (do_msinfo) {
|
||||
ret = telltoc_msinfo(drive_list[driveno].drive,
|
||||
msinfo_explicit, msinfo_alone);
|
||||
if (ret<=0)
|
||||
{ret = 38; goto release_drive; }
|
||||
}
|
||||
if (read_start >= -1 && (read_count > 0 || read_count == -1)) {
|
||||
ret = telltoc_read_and_print(drive_list[driveno].drive,
|
||||
read_start, read_count, print_raw_file,
|
||||
print_encoding);
|
||||
if (ret<=0)
|
||||
{ret = 40; goto release_drive; }
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
if (toc_failed)
|
||||
ret = 37;
|
||||
release_drive:;
|
||||
if (drive_is_grabbed)
|
||||
burn_drive_release(drive_list[driveno].drive, 0);
|
||||
|
||||
finish_libburn:;
|
||||
/* This app does not bother to know about exact scan state.
|
||||
Better to accept a memory leak here. We are done anyway. */
|
||||
/* burn_drive_info_free(drive_list); */
|
||||
|
||||
burn_finish();
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
/* License and copyright aspects:
|
||||
See libburner.c
|
||||
*/
|
||||
|
Reference in New Issue
Block a user