67 #include "../libburn/libburn.h"
72 #include <sys/types.h>
127 if(drive_adr != NULL && drive_adr[0] != 0)
131 if (ret <= 0 || *driveno <= 0)
151 if (strncmp(drive_adr,
"stdio:/dev/fd/", 14) == 0 ||
152 strcmp(drive_adr,
"stdio:-") == 0) {
153 fprintf(stderr,
"Will not work with pseudo-drive '%s'\n",
161 fprintf(stderr,
"Address does not lead to a CD burner: '%s'\n",
165 fprintf(stderr,
"Aquiring drive '%s' ...\n", libburn_drive_adr);
168 fprintf(stderr,
"FAILURE with persistent drive address '%s'\n",
171 fprintf(stderr,
"Done\n");
195 printf(
"Beginning to scan for devices ...\n");
198 if (drive_count <= 0 && *driveno >= 0) {
199 printf(
"FAILED (no drives found)\n");
218 printf(
"\nOverview of accessible drives (%d found) :\n",
220 printf(
"-----------------------------------------------------------------------------\n");
223 strcpy(adr,
"-get_adr_failed-");
224 printf(
"%d --drive '%s' : '%s' '%s'\n",
227 printf(
"-----------------------------------------------------------------------------\n\n");
255 printf(
"Pseudo-drive \"-\" given : bus scanning done.\n");
260 "Found only %d drives. Number %d not available.\n",
271 fprintf(stderr,
"Cannot drop drive %d. Please report \"ret=%d\" to libburn-hackers@pykix.org\n",
274 printf(
"Dropped unwanted drive %d\n",i);
297 double percent = 1.0;
301 "Drive media status: %d (see libburn/libburn.h BURN_DISC_*)\n",
307 "IDLE: Blank media detected. Will leave it untouched\n");
313 fprintf(stderr,
"FATAL: No media detected in drive\n");
317 "FATAL: Unsuitable drive and media state\n");
322 "FATAL : Media is not of erasable type\n");
328 printf(
"Beginning to %s-blank media.\n", (blank_fast?
"fast":
"full"));
334 percent = 1.0 + ((double) p.
sector+1.0)
336 printf(
"Blanking ( %.1f%% done )\n", percent);
363 double percent = 1.0;
364 int ret, status, num_formats, format_flag= 0;
370 fprintf(stderr,
"IDLE: DVD-RW media is already formatted\n");
376 "FATAL: BD-R is not blank. Cannot format.\n");
383 "IDLE: BD media is already formatted\n");
389 size = 128 * 1024 * 1024;
392 fprintf(stderr,
"FATAL: Can only format DVD-RW or BD\n");
397 printf(
"Beginning to format media.\n");
403 percent = 1.0 + ((double) p.
sector+1.0)
405 printf(
"Formatting ( %.1f%% done )\n", percent);
414 printf(
"Media type now: %4.4xh \"%s\"\n",
418 "FATAL: Failed to change media profile to desired value\n");
445 struct burn_disc *target_disc;
446 struct burn_session *session;
447 struct burn_write_opts *burn_options;
449 struct burn_track *track, *tracklist[99];
452 int last_sector = 0, padding = 0, trackno, unpredicted_size = 0, fd;
453 int fifo_chunksize = 2352, fifo_chunks = 1783;
462 fifo_chunksize = 2048;
475 adr = source_adr[trackno];
477 if (adr[0] ==
'-' && adr[1] == 0) {
480 fd = open(adr, O_RDONLY);
482 if (fstat(fd,&stbuf)!=-1)
483 if((stbuf.st_mode&S_IFMT)==S_IFREG)
484 fixed_size = stbuf.st_size;
487 unpredicted_size = 1;
493 if (data_src == NULL) {
495 "FATAL: Could not open data source '%s'.\n",adr);
497 fprintf(stderr,
"(Most recent system error: %s )\n",
503 fifo_chunksize, fifo_chunks, 0);
504 if (fifo_src[trackno] == NULL) {
506 "FATAL: Could not create fifo object of 4 MB\n");
514 "FATAL: Cannot attach source object to track object\n");
519 printf(
"Track %d : source is '%s'\n", trackno+1, adr);
531 fprintf(stderr,
"FATAL: Closed media with data detected. Need blank or appendable media.\n");
533 fprintf(stderr,
"HINT: Try --blank_fast\n\n");
535 fprintf(stderr,
"FATAL: No media detected in drive\n");
538 "FATAL: Cannot recognize state of drive and media\n");
546 printf(
"\n*** Will TRY to SIMULATE burning ***\n\n");
552 fprintf(stderr,
"FATAL: Failed to find a suitable write mode with this media.\n");
553 fprintf(stderr,
"Reasons given:\n%s\n", reasons);
558 printf(
"Burning starts. With e.g. 4x media expect up to a minute of zero progress.\n");
559 start_time = time(0);
568 !unpredicted_size) ||
569 (unpredicted_size && progress.
sector == last_sector))
571 "Thank you for being patient since %d seconds.",
572 (
int) (time(0) - start_time));
573 else if(unpredicted_size)
574 printf(
"Track %d : sector %d", progress.
track+1,
577 printf(
"Track %d : sector %d of %d",progress.
track+1,
579 last_sector = progress.
sector;
580 if (progress.
track >= 0 && progress.
track < source_adr_count) {
581 int size, free_bytes, ret;
585 fifo_src[progress.
track], &size, &free_bytes,
588 printf(
" [fifo %s, %2d%% fill]", status_text,
589 (
int) (100.0 - 100.0 *
590 ((
double) free_bytes) /
609 printf(
"NOTE: Media left appendable.\n");
611 printf(
"\n*** Did TRY to SIMULATE burning ***\n\n");
631 int i, insuffient_parameters = 0, print_help = 0;
633 for (i = 1; i < argc; ++i) {
634 if (!strcmp(argv[i],
"--audio")) {
637 }
else if (!strcmp(argv[i],
"--blank_fast")) {
640 }
else if (!strcmp(argv[i],
"--blank_full")) {
643 }
else if (!strcmp(argv[i],
"--burn_for_real")) {
646 }
else if (!strcmp(argv[i],
"--drive")) {
649 fprintf(stderr,
"--drive requires an argument\n");
651 }
else if (strcmp(argv[i],
"-") == 0) {
654 }
else if (isdigit(argv[i][0])) {
659 fprintf(stderr,
"--drive address too long (max. %d)\n",
665 }
else if ((!strcmp(argv[i],
"--format_overwrite")) ||
666 (!strcmp(argv[i],
"--format"))) {
669 }
else if (!strcmp(argv[i],
"--multi")) {
672 }
else if (!strcmp(argv[i],
"--stdin_size")) {
675 }
else if (!strcmp(argv[i],
"--try_to_simulate")) {
678 }
else if (!strcmp(argv[i],
"--help")) {
681 }
else if (!strncmp(argv[i],
"--",2)) {
682 fprintf(stderr,
"Unidentified option: %s\n", argv[i]);
685 if(strlen(argv[i]) >= 4096) {
686 fprintf(stderr,
"Source address too long (max. %d)\n", 4096-1);
690 fprintf(stderr,
"Too many tracks (max. 99)\n");
697 insuffient_parameters = 1;
699 insuffient_parameters = 0;
701 insuffient_parameters = 0;
703 insuffient_parameters = 0;
704 if (print_help || insuffient_parameters ) {
705 printf(
"Usage: %s\n", argv[0]);
706 printf(
" [--drive <address>|<driveno>|\"-\"] [--audio]\n");
707 printf(
" [--blank_fast|--blank_full|--format] [--try_to_simulate]\n");
708 printf(
" [--multi] [<one or more imagefiles>|\"-\"]\n");
709 printf(
"Examples\n");
710 printf(
"A bus scan (needs rw-permissions to see a drive):\n");
711 printf(
" %s --drive -\n",argv[0]);
712 printf(
"Burn a file to drive chosen by number, leave appendable:\n");
713 printf(
" %s --drive 0 --multi my_image_file\n", argv[0]);
714 printf(
"Burn a file to drive chosen by persistent address, close:\n");
715 printf(
" %s --drive /dev/hdc my_image_file\n", argv[0]);
716 printf(
"Blank a used CD-RW (is combinable with burning in one run):\n");
717 printf(
" %s --drive /dev/hdc --blank_fast\n",argv[0]);
718 printf(
"Blank a used DVD-RW (is combinable with burning in one run):\n");
719 printf(
" %s --drive /dev/hdc --blank_full\n",argv[0]);
720 printf(
"Format a DVD-RW, BD-RE or BD-R:\n");
721 printf(
" %s --drive /dev/hdc --format\n", argv[0]);
722 printf(
"Burn two audio tracks (to CD only):\n");
723 printf(
" lame --decode -t /path/to/track1.mp3 track1.cd\n");
724 printf(
" test/dewav /path/to/track2.wav -o track2.cd\n");
725 printf(
" %s --drive /dev/hdc --audio track1.cd track2.cd\n", argv[0]);
726 printf(
"Burn a compressed afio archive on-the-fly:\n");
727 printf(
" ( cd my_directory ; find . -print | afio -oZ - ) | \\\n");
728 printf(
" %s --drive /dev/hdc -\n", argv[0]);
729 printf(
"To be read from *not mounted* media via: afio -tvZ /dev/hdc\n");
730 if (insuffient_parameters)
737 int main(
int argc,
char **argv)
742 if (
sizeof(off_t) != 8) {
744 "\nFATAL: Compile time misconfiguration. off_t is not 64 bit.\n\n");
752 printf(
"Initializing libburnia-project.org ...\n");
757 fprintf(stderr,
"\nFATAL: Failed to initialize.\n");
771 fprintf(stderr,
"\nFATAL: Failed to aquire drive.\n");
772 { ret = 34;
goto finish_libburn; }
775 { ret = 0;
goto release_drive; }
783 { ret = 36;
goto release_drive; }
790 { ret = 38;
goto release_drive; }
800 fprintf(stderr,
"\nlibburner run aborted\n");
void burn_disc_write(struct burn_write_opts *o, struct burn_disc *disc)
Write a disc in the drive.
void burn_write_opts_free(struct burn_write_opts *opts)
Frees a write_opts struct created with burn_write_opts_new.
Operation progress report.
static int all_tracks_type
struct burn_write_opts * burn_write_opts_new(struct burn_drive *drive)
Creates a write_opts struct for burning to the specified drive.
void burn_disc_erase(struct burn_drive *drive, int fast)
Erase a disc in the drive.
#define BURN_DRIVE_ADR_LEN
Maximum length+1 to expect with a drive device file address string.
enum burn_drive_status burn_drive_get_status(struct burn_drive *drive, struct burn_progress *p)
Returns the progress and status of a drive.
struct burn_drive * drive
The value by which this drive can be indexed when using functions in the library. ...
The library is spawning the processes to handle a pending operation (A read/write/etc is about to sta...
static int drive_is_grabbed
This variable indicates wether the drive is grabbed and must be finally released. ...
int burn_disc_add_session(struct burn_disc *d, struct burn_session *s, unsigned int pos)
Add a session to a disc at a specific position, increasing the sessions's reference count...
int burn_disc_erasable(struct burn_drive *d)
Tells whether a disc can be erased or not.
In replies this indicates that not any writing will work.
#define BURN_FORMAT_IS_UNFORMATTED
Possible formatting status values.
int burn_is_aborting(int flag)
void burn_session_free(struct burn_session *s)
Free a session (and decrease reference count on all tracks inside)
int burn_write_opts_set_underrun_proof(struct burn_write_opts *opts, int underrun_proof)
Controls buffer underrun prevention.
static int source_adr_count
int main(int argc, char **argv)
struct burn_disc * burn_disc_create(void)
Create a new disc.
int burn_msgs_set_severities(char *queue_severity, char *print_severity, char *print_id)
Control queueing and stderr printing of messages from libburn.
burn_disc_status
Possible status of the drive in regard to the disc in it.
The drive is not in an operation.
struct burn_track * burn_track_create(void)
Create a track.
static unsigned int drive_count
If you start a long lasting operation with drive_count > 1 then you are not friendly to the users of ...
int burn_abort(int patience, int(*pacifier_func)(void *handle, int patience, int elapsed), void *handle)
Abort any running drive operation and eventually call burn_finish().
There is no disc at all in the drive.
void burn_finish(void)
Shutdown the library.
int burn_initialize(void)
Initialize the library.
int burn_disc_get_formats(struct burn_drive *drive, int *status, off_t *size, unsigned *bl_sas, int *num_formats)
Inquire the formatting status, the associated sizes and the number of available formats.
static int current_profile
A number and a text describing the type of media in aquired drive.
void burn_drive_set_speed(struct burn_drive *d, int read, int write)
Sets drive read and write speed Note: "k" is 1000, not 1024.
Information on a drive in the system.
void burn_set_signal_handling(void *handle, burn_abort_handler_t handler, int mode)
Control built-in signal handling.
char product[17]
Name of the drive.
int burn_abort_pacifier(void *handle, int patience, int elapsed)
A pacifier function suitable for burn_abort.
static char drive_adr[BURN_DRIVE_ADR_LEN]
The setup parameters of libburner.
#define BURN_AUDIO
Track mode - audio 2352 bytes per sector.
Data source interface for tracks.
int burn_drive_convert_fs_adr(char *path, char adr[])
Try to convert a given existing filesystem address into a drive device file address.
void burn_track_free(struct burn_track *t)
Free a track.
static char source_adr[99][4096]
void burn_disc_free(struct burn_disc *d)
Delete disc and decrease the reference count on all its sessions.
void burn_source_free(struct burn_source *s)
Free a burn_source (decrease its refcount and maybe free it)
void burn_disc_format(struct burn_drive *drive, off_t size, int flag)
Format media for use with libburn.
struct burn_source * burn_fd_source_new(int datafd, int subfd, off_t size)
Creates a data source for an image file (a track) from an open readable filedescriptor, an eventually open readable subcodes file descriptor and eventually a fixed size in bytes.
int burn_drive_scan_and_grab(struct burn_drive_info *drive_infos[], char *adr, int load)
Aquire a drive with known device file address.
void burn_write_opts_set_multi(struct burn_write_opts *opts, int multi)
Sets the multi flag which eventually marks the emerging session as not being the last one and thus cr...
int libburner_format(struct burn_drive *drive)
Formats unformatted DVD-RW to profile 0013h "Restricted Overwrite" which needs no blanking for re-use...
#define BURN_MODE1
Track mode - mode 1 data 2048 bytes user data, and all the LEC money can buy.
int burn_drive_scan(struct burn_drive_info *drive_infos[], unsigned int *n_drives)
Scan for drives.
int libburner_payload(struct burn_drive *drive, char source_adr[][4096], int source_adr_count, int multi, int simulate_burn, int all_tracks_type)
Brings preformatted track images (ISO 9660, audio, ...) onto media.
int burn_drive_info_forget(struct burn_drive_info *drive_info, int force)
Release memory about a single drive and any exclusive lock on it.
int libburner_aquire_drive(char *drive_adr, int *driveno)
You need to aquire a drive before burning.
int burn_disc_get_profile(struct burn_drive *d, int *pno, char name[80])
Tells the MMC Profile identifier of the loaded media.
int libburner_aquire_by_driveno(int *drive_no)
This method demonstrates how to use libburn without knowing a persistent drive address in advance...
void burn_drive_release(struct burn_drive *drive, int eject)
Release a drive.
int libburner_aquire_by_adr(char *drive_adr)
If the persistent drive address is known, then this approach is much more un-obtrusive to the systemw...
static struct burn_drive_info * drive_list
Overview.
int burn_drive_get_adr(struct burn_drive_info *drive_info, char adr[])
Inquire the device file address of a drive via a given drive_info object.
There is a disc with data on it in the drive.
struct burn_source * burn_fifo_source_new(struct burn_source *inp, int chunksize, int chunks, int flag)
Creates a fifo which acts as proxy for an already existing data source.
int libburner_setup(int argc, char **argv)
Converts command line arguments into above setup parameters.
int sector
On write: The current sector being processed.
int burn_session_add_track(struct burn_session *s, struct burn_track *t, unsigned int pos)
Add a track to a session at specified position.
int sectors
On write: The number of sectors.
char vendor[9]
Name of the vendor of the drive.
enum burn_source_status burn_track_set_source(struct burn_track *t, struct burn_source *s)
Set the track's data source.
There is an incomplete disc in the drive.
int libburner_blank_disc(struct burn_drive *drive, int blank_fast)
Makes a previously used CD-RW or unformatted DVD-RW ready for thorough re-usal.
int burn_drive_grab(struct burn_drive *drive, int load)
Grab a drive.
void burn_track_define_data(struct burn_track *t, int offset, int tail, int pad, int mode)
Define the data in a track.
void burn_write_opts_set_perform_opc(struct burn_write_opts *opts, int opc)
Sets whether to use opc or not with the write_opts struct.
static char current_profile_name[80]
The drive holds a blank disc.
enum burn_disc_status burn_disc_get_status(struct burn_drive *drive)
Returns what kind of disc a drive is holding.
enum burn_write_types burn_write_opts_auto_write_type(struct burn_write_opts *opts, struct burn_disc *disc, char reasons[BURN_REASONS_LEN], int flag)
As an alternative to burn_write_opts_set_write_type() this function tries to find a suitable write ty...
#define BURN_REASONS_LEN
The length of a rejection reasons string for burn_precheck_write() and burn_write_opts_auto_write_typ...
int burn_write_opts_set_simulate(struct burn_write_opts *opts, int sim)
Sets the simulate value for the write_opts struct .
int burn_fifo_inquire_status(struct burn_source *fifo, int *size, int *free_bytes, char **status_text)
Inquires state and fill parameters of a fifo burn_source which was created by burn_fifo_source_new() ...
struct burn_session * burn_session_create(void)
Create a new session.