2006-10-30 05:32:33 +00:00
|
|
|
/* -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 8; -*- */
|
|
|
|
|
2010-02-14 08:45:14 +00:00
|
|
|
/* Copyright (c) 2004 - 2006 Derek Foreman, Ben Jansens
|
|
|
|
Copyright (c) 2006 - 2010 Thomas Schmitt <scdbackup@gmx.net>
|
|
|
|
Provided under GPL version 2 or later.
|
|
|
|
*/
|
2007-10-19 11:53:19 +00:00
|
|
|
|
2007-10-19 13:32:49 +00:00
|
|
|
/* ts A71019 */
|
2007-10-19 11:53:19 +00:00
|
|
|
|
2007-10-19 13:32:49 +00:00
|
|
|
/* Standard measure should be: Threads are created detached.
|
2007-10-19 11:53:19 +00:00
|
|
|
According to the man pages they should then care for disposing themselves.
|
|
|
|
|
2007-10-19 13:32:49 +00:00
|
|
|
>>> ??? It is yet unclear why the threads vanish from the process list
|
|
|
|
even if joinable and even if never joined.
|
2007-10-19 11:53:19 +00:00
|
|
|
|
2007-10-19 13:32:49 +00:00
|
|
|
To be activated after release of libburn-0.4.0
|
2007-10-19 11:53:19 +00:00
|
|
|
*/
|
2007-12-07 18:53:22 +00:00
|
|
|
#define Libburn_create_detached_threadS 1
|
2007-10-19 11:53:19 +00:00
|
|
|
|
2007-10-19 13:32:49 +00:00
|
|
|
/* Alternative : Threads are created joinable.
|
2007-10-19 11:53:19 +00:00
|
|
|
Threads get detached in remove_worker() and thus should dispose themselves.
|
|
|
|
|
|
|
|
#define Libburn_detach_done_workeR 1
|
|
|
|
*/
|
2007-10-19 13:32:49 +00:00
|
|
|
|
2010-05-16 09:07:42 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../config.h"
|
|
|
|
#endif
|
2007-10-19 11:53:19 +00:00
|
|
|
|
2006-10-30 05:32:33 +00:00
|
|
|
#include "libburn.h"
|
|
|
|
#include "transport.h"
|
|
|
|
#include "drive.h"
|
|
|
|
#include "write.h"
|
|
|
|
#include "options.h"
|
2008-11-08 14:18:14 +00:00
|
|
|
#include "file.h"
|
2006-10-30 05:32:33 +00:00
|
|
|
#include "async.h"
|
|
|
|
#include "init.h"
|
2007-01-03 16:49:09 +00:00
|
|
|
#include "back_hacks.h"
|
2006-10-30 05:32:33 +00:00
|
|
|
|
|
|
|
#include <pthread.h>
|
2007-09-30 21:24:55 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2006-10-30 05:32:33 +00:00
|
|
|
#include <stdlib.h>
|
2007-01-03 16:49:09 +00:00
|
|
|
#include <stdio.h>
|
2007-02-19 22:51:39 +00:00
|
|
|
#include <string.h>
|
2010-03-05 09:08:16 +00:00
|
|
|
#include <signal.h>
|
2006-10-30 05:32:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
#include <a ssert.h>
|
|
|
|
*/
|
|
|
|
#include "libdax_msgs.h"
|
|
|
|
extern struct libdax_msgs *libdax_messenger;
|
|
|
|
|
2008-07-14 11:38:22 +00:00
|
|
|
/* ts A80714 : introduced type codes for the worker list */
|
|
|
|
#define Burnworker_type_scaN 0
|
|
|
|
#define Burnworker_type_erasE 1
|
|
|
|
#define Burnworker_type_formaT 2
|
|
|
|
#define Burnworker_type_writE 3
|
|
|
|
#define Burnworker_type_fifO 4
|
|
|
|
|
|
|
|
#define SCAN_GOING() (workers != NULL && \
|
|
|
|
workers->w_type == Burnworker_type_scaN)
|
2006-10-30 05:32:33 +00:00
|
|
|
|
|
|
|
typedef void *(*WorkerFunc) (void *);
|
|
|
|
|
|
|
|
struct scan_opts
|
|
|
|
{
|
|
|
|
struct burn_drive_info **drives;
|
|
|
|
unsigned int *n_drives;
|
|
|
|
|
|
|
|
int done;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct erase_opts
|
|
|
|
{
|
|
|
|
struct burn_drive *drive;
|
|
|
|
int fast;
|
|
|
|
};
|
|
|
|
|
2007-01-01 17:10:54 +00:00
|
|
|
/* ts A61230 */
|
|
|
|
struct format_opts
|
|
|
|
{
|
|
|
|
struct burn_drive *drive;
|
2007-01-06 12:08:57 +00:00
|
|
|
off_t size;
|
2007-01-01 17:10:54 +00:00
|
|
|
int flag;
|
|
|
|
};
|
|
|
|
|
2006-10-30 05:32:33 +00:00
|
|
|
struct write_opts
|
|
|
|
{
|
|
|
|
struct burn_drive *drive;
|
|
|
|
struct burn_write_opts *opts;
|
|
|
|
struct burn_disc *disc;
|
|
|
|
};
|
|
|
|
|
2007-09-30 21:24:55 +00:00
|
|
|
struct fifo_opts
|
|
|
|
{
|
|
|
|
struct burn_source *source;
|
|
|
|
int flag;
|
|
|
|
};
|
|
|
|
|
2007-01-01 17:10:54 +00:00
|
|
|
|
2006-10-30 05:32:33 +00:00
|
|
|
struct w_list
|
|
|
|
{
|
2008-07-14 11:38:22 +00:00
|
|
|
/* ts A80714 */
|
|
|
|
int w_type; /* see above define Burnworker_type_* */
|
|
|
|
|
2006-10-30 05:32:33 +00:00
|
|
|
struct burn_drive *drive;
|
|
|
|
pthread_t thread;
|
|
|
|
|
|
|
|
struct w_list *next;
|
|
|
|
|
|
|
|
union w_list_data
|
|
|
|
{
|
|
|
|
struct scan_opts scan;
|
|
|
|
struct erase_opts erase;
|
2007-01-01 17:10:54 +00:00
|
|
|
struct format_opts format;
|
2006-10-30 05:32:33 +00:00
|
|
|
struct write_opts write;
|
2007-09-30 21:24:55 +00:00
|
|
|
struct fifo_opts fifo;
|
2006-10-30 05:32:33 +00:00
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
2007-10-19 11:53:19 +00:00
|
|
|
static struct w_list *workers = NULL;
|
|
|
|
|
2006-10-30 05:32:33 +00:00
|
|
|
|
|
|
|
static struct w_list *find_worker(struct burn_drive *d)
|
|
|
|
{
|
|
|
|
struct w_list *a;
|
|
|
|
|
|
|
|
for (a = workers; a; a = a->next)
|
|
|
|
if (a->drive == d)
|
|
|
|
return a;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-07-14 11:38:22 +00:00
|
|
|
static void add_worker(int w_type, struct burn_drive *d,
|
|
|
|
WorkerFunc f, void *data)
|
2006-10-30 05:32:33 +00:00
|
|
|
{
|
|
|
|
struct w_list *a;
|
|
|
|
struct w_list *tmp;
|
2007-10-19 11:53:19 +00:00
|
|
|
pthread_attr_t *attr_pt = NULL;
|
|
|
|
|
|
|
|
#ifdef Libburn_create_detached_threadS
|
|
|
|
pthread_attr_t attr;
|
|
|
|
#endif
|
|
|
|
|
2010-07-12 19:37:31 +00:00
|
|
|
a = calloc(1, sizeof(struct w_list));
|
2008-07-14 11:38:22 +00:00
|
|
|
a->w_type = w_type;
|
2006-10-30 05:32:33 +00:00
|
|
|
a->drive = d;
|
|
|
|
a->u = *(union w_list_data *)data;
|
|
|
|
|
|
|
|
/* insert at front of the list */
|
|
|
|
a->next = workers;
|
|
|
|
tmp = workers;
|
|
|
|
workers = a;
|
|
|
|
|
2007-09-04 22:50:04 +00:00
|
|
|
if (d != NULL)
|
2006-10-30 05:32:33 +00:00
|
|
|
d->busy = BURN_DRIVE_SPAWNING;
|
|
|
|
|
2007-10-19 11:53:19 +00:00
|
|
|
#ifdef Libburn_create_detached_threadS
|
|
|
|
/* ts A71019 :
|
|
|
|
Trying to start the threads detached to get rid of the zombies
|
|
|
|
which do neither react on pthread_join() nor on pthread_detach().
|
|
|
|
*/
|
|
|
|
pthread_attr_init(&attr);
|
|
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
|
|
|
attr_pt= &attr;
|
2008-01-26 18:03:36 +00:00
|
|
|
/*
|
2007-10-19 11:53:19 +00:00
|
|
|
libdax_msgs_submit(libdax_messenger, -1, 0x00020158,
|
|
|
|
LIBDAX_MSGS_SEV_DEBUG, LIBDAX_MSGS_PRIO_LOW,
|
|
|
|
"add_worker(): Creating detached thread.", 0, 0);
|
2008-01-26 18:03:36 +00:00
|
|
|
*/
|
2007-10-19 11:53:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (pthread_create(&a->thread, attr_pt, f, a)) {
|
2006-10-30 05:32:33 +00:00
|
|
|
free(a);
|
|
|
|
workers = tmp;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-19 11:53:19 +00:00
|
|
|
|
2006-10-30 05:32:33 +00:00
|
|
|
static void remove_worker(pthread_t th)
|
|
|
|
{
|
|
|
|
struct w_list *a, *l = NULL;
|
|
|
|
|
2007-10-19 11:53:19 +00:00
|
|
|
#ifdef Libburn_detach_done_workeR
|
|
|
|
int ret;
|
|
|
|
char msg[80];
|
|
|
|
#endif
|
|
|
|
|
2006-10-30 05:32:33 +00:00
|
|
|
for (a = workers; a; l = a, a = a->next)
|
|
|
|
if (a->thread == th) {
|
|
|
|
if (l)
|
|
|
|
l->next = a->next;
|
|
|
|
else
|
|
|
|
workers = a->next;
|
2007-10-19 11:53:19 +00:00
|
|
|
|
|
|
|
#ifdef Libburn_detach_done_workeR
|
|
|
|
/* ts A71019 : burry dead puppy before forgetting it */
|
2007-10-19 13:32:49 +00:00
|
|
|
/* Alternative : threads get detached and thus should
|
2007-10-19 11:53:19 +00:00
|
|
|
dispose themselves.
|
|
|
|
*/
|
|
|
|
ret = pthread_detach(th);
|
2008-01-26 18:03:36 +00:00
|
|
|
/*
|
2007-10-19 11:53:19 +00:00
|
|
|
sprintf(msg,
|
|
|
|
"remove_workers(): pid= %lu pthread_detach(%lu)= %d",
|
|
|
|
(unsigned long) getpid(), (unsigned long) th, ret);
|
|
|
|
libdax_msgs_submit(libdax_messenger, -1, 0x00020158,
|
|
|
|
LIBDAX_MSGS_SEV_DEBUG, LIBDAX_MSGS_PRIO_LOW,
|
|
|
|
msg, 0, 0);
|
2008-01-26 18:03:36 +00:00
|
|
|
*/
|
2007-10-19 11:53:19 +00:00
|
|
|
|
|
|
|
#endif /* Libburn_detach_done_workeR */
|
|
|
|
|
2006-10-30 05:32:33 +00:00
|
|
|
free(a);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ts A61006 */
|
|
|
|
/* a ssert(a != NULL);/ * wasn't found.. this should not be possible */
|
|
|
|
if (a == NULL)
|
|
|
|
libdax_msgs_submit(libdax_messenger, -1, 0x00020101,
|
|
|
|
LIBDAX_MSGS_SEV_WARNING, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
"remove_worker() cannot find given worker item", 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *scan_worker_func(struct w_list *w)
|
|
|
|
{
|
2007-09-07 12:38:20 +00:00
|
|
|
int ret;
|
|
|
|
|
2007-09-07 16:40:38 +00:00
|
|
|
ret = burn_drive_scan_sync(w->u.scan.drives, w->u.scan.n_drives, 1);
|
2007-09-07 12:38:20 +00:00
|
|
|
if (ret <= 0)
|
|
|
|
w->u.scan.done = -1;
|
|
|
|
else
|
|
|
|
w->u.scan.done = 1;
|
2006-10-30 05:32:33 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-02-17 14:12:23 +00:00
|
|
|
static void reset_progress(struct burn_drive *d, int sessions, int tracks,
|
|
|
|
int indices, int sectors, int flag)
|
|
|
|
{
|
|
|
|
/* reset the progress indicator */
|
|
|
|
d->progress.session = 0;
|
|
|
|
d->progress.sessions = sessions;
|
|
|
|
d->progress.track = 0;
|
|
|
|
d->progress.tracks = tracks;
|
|
|
|
d->progress.index = 0;
|
|
|
|
d->progress.indices = indices;
|
|
|
|
d->progress.start_sector = 0;
|
|
|
|
d->progress.sectors = sectors;
|
|
|
|
d->progress.sector = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-30 05:32:33 +00:00
|
|
|
int burn_drive_scan(struct burn_drive_info *drives[], unsigned int *n_drives)
|
|
|
|
{
|
|
|
|
struct scan_opts o;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* ts A61006 : moved up from burn_drive_scan_sync , former Assert */
|
|
|
|
if (!burn_running) {
|
|
|
|
libdax_msgs_submit(libdax_messenger, -1, 0x00020109,
|
|
|
|
LIBDAX_MSGS_SEV_FATAL, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
"Library not running (on attempt to scan)", 0, 0);
|
|
|
|
*drives = NULL;
|
|
|
|
*n_drives = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cant be anything working! */
|
|
|
|
|
|
|
|
/* ts A61006 */
|
|
|
|
/* a ssert(!(workers && workers->drive)); */
|
|
|
|
if (workers != NULL && workers->drive != NULL) {
|
|
|
|
drive_is_active:;
|
|
|
|
libdax_msgs_submit(libdax_messenger, -1, 0x00020102,
|
|
|
|
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
"A drive operation is still going on (want to scan)",
|
|
|
|
0, 0);
|
|
|
|
*drives = NULL;
|
|
|
|
*n_drives = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-09-07 12:38:20 +00:00
|
|
|
if (workers == NULL) {
|
2006-10-30 05:32:33 +00:00
|
|
|
/* start it */
|
|
|
|
|
|
|
|
/* ts A61007 : test moved up from burn_drive_scan_sync()
|
|
|
|
was burn_wait_all() */
|
2007-09-07 15:50:31 +00:00
|
|
|
/* ts A70907 : now demanding freed drives, not only released */
|
|
|
|
if (!burn_drives_are_clear(1))
|
2006-10-30 05:32:33 +00:00
|
|
|
goto drive_is_active;
|
|
|
|
*drives = NULL;
|
|
|
|
*n_drives = 0;
|
|
|
|
|
|
|
|
o.drives = drives;
|
|
|
|
o.n_drives = n_drives;
|
|
|
|
o.done = 0;
|
2008-07-14 11:38:22 +00:00
|
|
|
add_worker(Burnworker_type_scaN, NULL,
|
|
|
|
(WorkerFunc) scan_worker_func, &o);
|
2006-10-30 05:32:33 +00:00
|
|
|
} else if (workers->u.scan.done) {
|
|
|
|
/* its done */
|
|
|
|
ret = workers->u.scan.done;
|
|
|
|
remove_worker(workers->thread);
|
|
|
|
|
|
|
|
/* ts A61006 */
|
|
|
|
/* a ssert(workers == NULL); */
|
|
|
|
if (workers != NULL) {
|
|
|
|
libdax_msgs_submit(libdax_messenger, -1, 0x00020101,
|
|
|
|
LIBDAX_MSGS_SEV_WARNING, LIBDAX_MSGS_PRIO_HIGH,
|
2007-09-07 16:40:38 +00:00
|
|
|
"After scan a drive operation is still going on",
|
2006-10-30 05:32:33 +00:00
|
|
|
0, 0);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* still going */
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *erase_worker_func(struct w_list *w)
|
|
|
|
{
|
2010-03-05 18:59:21 +00:00
|
|
|
|
|
|
|
#define Libburn_protect_erase_threaD 1
|
|
|
|
|
|
|
|
#ifdef Libburn_protect_erase_threaD
|
|
|
|
sigset_t sigset, oldset;
|
|
|
|
|
|
|
|
/* Protect blank thread from being interrupted by external signals */
|
|
|
|
sigfillset(&sigset);
|
|
|
|
sigdelset(&sigset, SIGSEGV);
|
|
|
|
sigdelset(&sigset, SIGILL);
|
|
|
|
pthread_sigmask(SIG_SETMASK, &sigset, &oldset);
|
|
|
|
#endif /* Libburn_protect_erase_threaD */
|
|
|
|
|
2006-10-30 05:32:33 +00:00
|
|
|
burn_disc_erase_sync(w->u.erase.drive, w->u.erase.fast);
|
|
|
|
remove_worker(pthread_self());
|
2010-03-05 18:59:21 +00:00
|
|
|
|
|
|
|
#ifdef Libburn_protect_erase_threaD
|
|
|
|
/* (just in case it would not end with all signals blocked) */
|
|
|
|
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
|
|
|
|
#endif /* Libburn_protect_erase_threaD */
|
|
|
|
|
2006-10-30 05:32:33 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void burn_disc_erase(struct burn_drive *drive, int fast)
|
|
|
|
{
|
|
|
|
struct erase_opts o;
|
|
|
|
|
|
|
|
/* ts A61006 */
|
|
|
|
/* a ssert(drive); */
|
|
|
|
/* a ssert(!SCAN_GOING()); */
|
|
|
|
/* a ssert(!find_worker(drive)); */
|
2010-02-17 14:12:23 +00:00
|
|
|
|
2006-10-30 05:32:33 +00:00
|
|
|
if((drive == NULL)) {
|
2011-02-24 19:17:06 +00:00
|
|
|
libdax_msgs_submit(libdax_messenger, -1,
|
2006-10-30 05:32:33 +00:00
|
|
|
0x00020104,
|
|
|
|
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
"NULL pointer caught in burn_disc_erase", 0, 0);
|
|
|
|
return;
|
|
|
|
}
|
2008-07-14 11:38:22 +00:00
|
|
|
if ((SCAN_GOING()) || find_worker(drive) != NULL) {
|
2006-10-30 05:32:33 +00:00
|
|
|
libdax_msgs_submit(libdax_messenger, drive->global_index,
|
|
|
|
0x00020102,
|
|
|
|
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
"A drive operation is still going on (want to erase)",
|
|
|
|
0, 0);
|
|
|
|
return;
|
|
|
|
}
|
2010-02-17 14:12:23 +00:00
|
|
|
|
|
|
|
reset_progress(drive, 1, 1, 1, 0x10000, 0);
|
|
|
|
|
2007-09-04 22:50:04 +00:00
|
|
|
/* A70103 : will be set to 0 by burn_disc_erase_sync() */
|
|
|
|
drive->cancel = 1;
|
2006-10-30 05:32:33 +00:00
|
|
|
|
2007-01-03 16:49:09 +00:00
|
|
|
/* ts A70103 moved up from burn_disc_erase_sync() */
|
|
|
|
/* ts A60825 : allow on parole to blank appendable CDs */
|
2007-01-31 12:59:51 +00:00
|
|
|
/* ts A70131 : allow blanking of overwriteable DVD-RW (profile 0x13) */
|
2007-02-17 08:56:41 +00:00
|
|
|
/* ts A70216 : allow blanking of CD-RW or DVD-RW in any regular state
|
|
|
|
and of any kind of full media */
|
2007-09-09 18:28:05 +00:00
|
|
|
/* ts A70909 : the willingness to burn any BURN_DISC_FULL media is
|
|
|
|
inappropriate. One would rather need a -force option
|
|
|
|
Note: keep this in sync with mmc_read_disc_info() */
|
2011-03-21 09:22:04 +00:00
|
|
|
/* ts B10321 : Allowed role 5 to be blanked */
|
|
|
|
if ((drive->drive_role == 1 &&
|
|
|
|
drive->current_profile != 0x0a &&
|
2007-02-17 08:56:41 +00:00
|
|
|
drive->current_profile != 0x13 &&
|
|
|
|
drive->current_profile != 0x14 &&
|
|
|
|
drive->status != BURN_DISC_FULL)
|
|
|
|
||
|
|
|
|
(drive->status != BURN_DISC_FULL &&
|
|
|
|
drive->status != BURN_DISC_APPENDABLE &&
|
|
|
|
drive->status != BURN_DISC_BLANK)
|
2007-09-04 22:50:04 +00:00
|
|
|
||
|
2011-03-18 09:33:54 +00:00
|
|
|
(drive->drive_role != 1 && drive->drive_role != 5)
|
2007-02-17 08:56:41 +00:00
|
|
|
) {
|
2007-01-03 16:49:09 +00:00
|
|
|
libdax_msgs_submit(libdax_messenger, drive->global_index,
|
|
|
|
0x00020130,
|
|
|
|
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
"Drive and media state unsuitable for blanking",
|
|
|
|
0, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-10-30 05:32:33 +00:00
|
|
|
o.drive = drive;
|
|
|
|
o.fast = fast;
|
2008-07-14 11:38:22 +00:00
|
|
|
add_worker(Burnworker_type_erasE, drive,
|
|
|
|
(WorkerFunc) erase_worker_func, &o);
|
2006-10-30 05:32:33 +00:00
|
|
|
}
|
|
|
|
|
2007-01-01 17:10:54 +00:00
|
|
|
|
|
|
|
/* ts A61230 */
|
|
|
|
static void *format_worker_func(struct w_list *w)
|
|
|
|
{
|
2010-03-05 18:59:21 +00:00
|
|
|
|
|
|
|
#define Libburn_protect_format_threaD 1
|
|
|
|
|
|
|
|
#ifdef Libburn_protect_format_threaD
|
|
|
|
sigset_t sigset, oldset;
|
|
|
|
|
|
|
|
/* Protect format thread from being interrupted by external signals */
|
|
|
|
sigfillset(&sigset);
|
|
|
|
sigdelset(&sigset, SIGSEGV);
|
|
|
|
sigdelset(&sigset, SIGILL);
|
|
|
|
pthread_sigmask(SIG_SETMASK, &sigset, &oldset);
|
|
|
|
#endif /* Libburn_protect_format_threaD */
|
|
|
|
|
2007-01-06 12:08:57 +00:00
|
|
|
burn_disc_format_sync(w->u.format.drive, w->u.format.size,
|
|
|
|
w->u.format.flag);
|
2007-01-01 17:10:54 +00:00
|
|
|
remove_worker(pthread_self());
|
2010-03-05 18:59:21 +00:00
|
|
|
|
|
|
|
#ifdef Libburn_protect_format_threaD
|
|
|
|
/* (just in case it would not end with all signals blocked) */
|
|
|
|
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
|
|
|
|
#endif /* Libburn_protect_format_threaD */
|
|
|
|
|
2007-01-01 17:10:54 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ts A61230 */
|
2007-01-06 12:08:57 +00:00
|
|
|
void burn_disc_format(struct burn_drive *drive, off_t size, int flag)
|
2007-01-01 17:10:54 +00:00
|
|
|
{
|
|
|
|
struct format_opts o;
|
2008-12-11 07:23:29 +00:00
|
|
|
int ok = 0, ret;
|
2011-05-15 10:48:59 +00:00
|
|
|
char msg[40];
|
2007-01-01 17:10:54 +00:00
|
|
|
|
2010-02-17 14:12:23 +00:00
|
|
|
reset_progress(drive, 1, 1, 1, 0x10000, 0);
|
|
|
|
|
2008-07-14 11:38:22 +00:00
|
|
|
if ((SCAN_GOING()) || find_worker(drive) != NULL) {
|
2007-01-01 17:10:54 +00:00
|
|
|
libdax_msgs_submit(libdax_messenger, drive->global_index,
|
|
|
|
0x00020102,
|
|
|
|
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
"A drive operation is still going on (want to format)",
|
|
|
|
0, 0);
|
|
|
|
return;
|
|
|
|
}
|
2007-09-04 22:50:04 +00:00
|
|
|
if (drive->drive_role != 1) {
|
|
|
|
libdax_msgs_submit(libdax_messenger, drive->global_index,
|
|
|
|
0x00020146,
|
|
|
|
LIBDAX_MSGS_SEV_FATAL, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
"Drive is a virtual placeholder", 0, 0);
|
|
|
|
drive->cancel = 1;
|
|
|
|
return;
|
|
|
|
}
|
2007-01-13 21:18:20 +00:00
|
|
|
if (flag & 128) /* application prescribed format type */
|
|
|
|
flag |= 16; /* enforce re-format */
|
2007-01-01 17:10:54 +00:00
|
|
|
|
2007-01-10 15:26:30 +00:00
|
|
|
if (drive->current_profile == 0x14)
|
|
|
|
ok = 1; /* DVD-RW sequential */
|
2007-01-10 21:07:48 +00:00
|
|
|
else if (drive->current_profile == 0x13 && (flag & 16))
|
2007-01-10 15:26:30 +00:00
|
|
|
ok = 1; /* DVD-RW Restricted Overwrite with force bit */
|
2007-01-10 21:07:48 +00:00
|
|
|
else if (drive->current_profile == 0x1a) {
|
|
|
|
ok = 1; /* DVD+RW */
|
|
|
|
size = 0;
|
|
|
|
flag &= ~(2|8); /* no insisting in size 0, no expansion */
|
|
|
|
flag |= 4; /* format up to maximum size */
|
2008-04-18 09:27:16 +00:00
|
|
|
} else if (drive->current_profile == 0x12) {
|
|
|
|
ok = 1; /* DVD-RAM */
|
2008-12-09 12:35:13 +00:00
|
|
|
|
|
|
|
} else if (drive->current_profile == 0x41) {
|
2008-12-11 07:23:29 +00:00
|
|
|
/* BD-R SRM */
|
2008-12-10 09:26:09 +00:00
|
|
|
ok= 1;
|
2008-12-11 07:23:29 +00:00
|
|
|
ret = drive->read_format_capacities(drive, 0x00);
|
|
|
|
if (ret > 0 &&
|
|
|
|
drive->format_descr_type == BURN_FORMAT_IS_FORMATTED)
|
|
|
|
ok = 0;
|
|
|
|
if (drive->status != BURN_DISC_BLANK)
|
|
|
|
ok = 0;
|
|
|
|
if (!ok) {
|
|
|
|
libdax_msgs_submit(libdax_messenger,
|
2008-12-11 09:22:33 +00:00
|
|
|
drive->global_index, 0x00020162,
|
2008-12-11 07:23:29 +00:00
|
|
|
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
"BD-R not unformatted blank any more. Cannot format.",
|
|
|
|
0, 0);
|
|
|
|
drive->cancel = 1;
|
|
|
|
return;
|
|
|
|
}
|
2008-12-11 09:22:33 +00:00
|
|
|
if (flag & 32) {
|
|
|
|
libdax_msgs_submit(libdax_messenger,
|
|
|
|
drive->global_index, 0x00020163,
|
|
|
|
LIBDAX_MSGS_SEV_NOTE, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
"Blank BD-R left unformatted for zero spare capacity.",
|
|
|
|
0, 0);
|
|
|
|
return;
|
|
|
|
}
|
2008-04-18 09:27:16 +00:00
|
|
|
} else if (drive->current_profile == 0x43) {
|
|
|
|
ok = 1; /* BD-RE */
|
2008-12-12 11:22:14 +00:00
|
|
|
|
2008-12-12 21:40:34 +00:00
|
|
|
if ((flag & 32) && !(drive->current_feat23h_byte4 & 8)) {
|
|
|
|
libdax_msgs_submit(libdax_messenger,
|
|
|
|
drive->global_index, 0x00020164,
|
|
|
|
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
"Drive does not format BD-RE without spares.",
|
|
|
|
0, 0);
|
|
|
|
drive->cancel = 1;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
2007-01-10 21:07:48 +00:00
|
|
|
}
|
2007-01-10 15:26:30 +00:00
|
|
|
|
|
|
|
if (!ok) {
|
2007-01-01 17:10:54 +00:00
|
|
|
sprintf(msg,"Will not format media type %4.4Xh",
|
|
|
|
drive->current_profile);
|
|
|
|
libdax_msgs_submit(libdax_messenger, drive->global_index,
|
|
|
|
0x00020129,
|
|
|
|
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
msg, 0, 0);
|
|
|
|
drive->cancel = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
o.drive = drive;
|
2007-01-06 12:08:57 +00:00
|
|
|
o.size = size;
|
2007-01-01 17:10:54 +00:00
|
|
|
o.flag = flag;
|
2008-07-14 11:38:22 +00:00
|
|
|
add_worker(Burnworker_type_formaT, drive,
|
|
|
|
(WorkerFunc) format_worker_func, &o);
|
2007-01-01 17:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-30 05:32:33 +00:00
|
|
|
static void *write_disc_worker_func(struct w_list *w)
|
|
|
|
{
|
2007-09-29 18:50:19 +00:00
|
|
|
struct burn_drive *d = w->u.write.drive;
|
2010-03-05 09:08:16 +00:00
|
|
|
char msg[80];
|
|
|
|
|
|
|
|
#define Libburn_protect_write_threaD 1
|
|
|
|
|
|
|
|
#ifdef Libburn_protect_write_threaD
|
|
|
|
sigset_t sigset, oldset;
|
|
|
|
|
|
|
|
/* Protect write thread from being interrupted by external signals */
|
|
|
|
sigfillset(&sigset);
|
|
|
|
sigdelset(&sigset, SIGSEGV);
|
|
|
|
sigdelset(&sigset, SIGILL);
|
|
|
|
pthread_sigmask(SIG_SETMASK, &sigset, &oldset);
|
|
|
|
#endif /* Libburn_protect_write_threaD */
|
2007-09-29 18:50:19 +00:00
|
|
|
|
|
|
|
d->thread_pid = getpid();
|
2010-03-05 09:08:16 +00:00
|
|
|
d->thread_tid = pthread_self();
|
2007-09-29 18:50:19 +00:00
|
|
|
d->thread_pid_valid= 1;
|
2006-10-30 05:32:33 +00:00
|
|
|
burn_disc_write_sync(w->u.write.opts, w->u.write.disc);
|
2007-09-29 18:50:19 +00:00
|
|
|
d->thread_pid_valid= 0;
|
|
|
|
d->thread_pid = 0;
|
2006-10-30 05:32:33 +00:00
|
|
|
|
|
|
|
/* the options are refcounted, free out ref count which we added below
|
|
|
|
*/
|
|
|
|
burn_write_opts_free(w->u.write.opts);
|
|
|
|
|
2010-03-05 09:08:16 +00:00
|
|
|
sprintf(msg, "Write thread on drive %d ended", d->global_index);
|
|
|
|
libdax_msgs_submit(libdax_messenger, d->global_index, 0x00020178,
|
|
|
|
LIBDAX_MSGS_SEV_DEBUG, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
msg, 0, 0);
|
|
|
|
|
2010-03-05 18:59:21 +00:00
|
|
|
remove_worker(pthread_self());
|
|
|
|
d->busy = BURN_DRIVE_IDLE;
|
|
|
|
|
2010-03-05 09:08:16 +00:00
|
|
|
#ifdef Libburn_protect_write_threaD
|
|
|
|
/* (just in case it would not end with all signals blocked) */
|
|
|
|
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
|
|
|
|
#endif /* Libburn_protect_write_threaD */
|
|
|
|
|
2006-10-30 05:32:33 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void burn_disc_write(struct burn_write_opts *opts, struct burn_disc *disc)
|
|
|
|
{
|
2011-05-15 20:31:15 +00:00
|
|
|
int ret;
|
2006-10-30 05:32:33 +00:00
|
|
|
struct write_opts o;
|
2011-05-15 10:48:59 +00:00
|
|
|
char *reasons= NULL;
|
2009-01-06 12:28:20 +00:00
|
|
|
struct burn_drive *d;
|
|
|
|
|
|
|
|
d = opts->drive;
|
2006-10-30 05:32:33 +00:00
|
|
|
|
|
|
|
/* ts A61006 */
|
|
|
|
/* a ssert(!SCAN_GOING()); */
|
|
|
|
/* a ssert(!find_worker(opts->drive)); */
|
2008-07-14 11:38:22 +00:00
|
|
|
if ((SCAN_GOING()) || find_worker(opts->drive) != NULL) {
|
2009-01-06 12:28:20 +00:00
|
|
|
libdax_msgs_submit(libdax_messenger, d->global_index,
|
2006-10-30 05:32:33 +00:00
|
|
|
0x00020102,
|
|
|
|
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
"A drive operation is still going on (want to write)",
|
|
|
|
0, 0);
|
|
|
|
return;
|
|
|
|
}
|
2007-09-04 22:50:04 +00:00
|
|
|
|
2010-02-17 14:12:23 +00:00
|
|
|
reset_progress(d, disc->sessions, disc->session[0]->tracks,
|
|
|
|
disc->session[0]->track[0]->indices, 0, 0);
|
|
|
|
|
2007-09-04 22:50:04 +00:00
|
|
|
/* For the next lines any return indicates failure */
|
2009-01-06 12:28:20 +00:00
|
|
|
d->cancel = 1;
|
2007-09-04 22:50:04 +00:00
|
|
|
|
|
|
|
/* ts A70203 : people have been warned in API specs */
|
2010-10-19 16:59:34 +00:00
|
|
|
if (opts->write_type == BURN_WRITE_NONE) {
|
|
|
|
libdax_msgs_submit(libdax_messenger, d->global_index,
|
|
|
|
0x0002017c,
|
|
|
|
LIBDAX_MSGS_SEV_FAILURE, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
"No valid write type selected", 0, 0);
|
2007-09-04 22:50:04 +00:00
|
|
|
return;
|
2010-10-19 16:59:34 +00:00
|
|
|
}
|
2007-09-04 22:50:04 +00:00
|
|
|
|
2009-01-06 12:28:20 +00:00
|
|
|
if (d->drive_role == 0) {
|
|
|
|
libdax_msgs_submit(libdax_messenger, d->global_index,
|
2007-09-04 22:50:04 +00:00
|
|
|
0x00020146,
|
|
|
|
LIBDAX_MSGS_SEV_FATAL, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
"Drive is a virtual placeholder (null-drive)", 0, 0);
|
|
|
|
return;
|
|
|
|
}
|
2011-03-13 13:07:46 +00:00
|
|
|
if (d->drive_role == 4) {
|
|
|
|
libdax_msgs_submit(libdax_messenger, d->global_index,
|
|
|
|
0x00020181,
|
|
|
|
LIBDAX_MSGS_SEV_FAILURE, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
"Pseudo-drive is a read-only file. Cannot write.",
|
|
|
|
0, 0);
|
|
|
|
return;
|
|
|
|
}
|
2007-09-04 22:50:04 +00:00
|
|
|
|
2006-10-30 05:32:33 +00:00
|
|
|
/* ts A61007 : obsolete Assert in spc_select_write_params() */
|
2009-06-02 16:28:33 +00:00
|
|
|
if (d->drive_role == 1 && d->mdata->valid <= 0) {
|
2006-10-30 05:32:33 +00:00
|
|
|
libdax_msgs_submit(libdax_messenger,
|
2009-01-06 12:28:20 +00:00
|
|
|
d->global_index, 0x00020113,
|
2006-10-30 05:32:33 +00:00
|
|
|
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
"Drive capabilities not inquired yet", 0, 0);
|
|
|
|
return;
|
|
|
|
}
|
2007-02-19 22:51:39 +00:00
|
|
|
|
|
|
|
/* ts A70219 : intended to replace all further tests here and many
|
|
|
|
tests in burn_*_write_sync()
|
|
|
|
*/
|
2011-05-15 10:48:59 +00:00
|
|
|
|
|
|
|
BURN_ALLOC_MEM(reasons, char, BURN_REASONS_LEN + 80);
|
2007-02-21 20:53:28 +00:00
|
|
|
strcpy(reasons, "Write job parameters are unsuitable:\n");
|
|
|
|
if (burn_precheck_write(opts, disc, reasons + strlen(reasons), 1)
|
2008-11-01 12:13:26 +00:00
|
|
|
<= 0) {
|
2007-02-19 22:51:39 +00:00
|
|
|
libdax_msgs_submit(libdax_messenger,
|
2009-01-06 12:28:20 +00:00
|
|
|
d->global_index, 0x00020139,
|
2007-02-19 22:51:39 +00:00
|
|
|
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
reasons, 0, 0);
|
2011-05-15 10:48:59 +00:00
|
|
|
goto ex;
|
2007-01-22 11:42:17 +00:00
|
|
|
}
|
2011-05-15 10:48:59 +00:00
|
|
|
BURN_FREE_MEM(reasons); reasons= NULL;
|
2007-01-22 11:42:17 +00:00
|
|
|
|
2009-01-06 12:28:20 +00:00
|
|
|
/* ts A90106 : early catching of unformatted BD-RE */
|
|
|
|
if (d->current_profile == 0x43)
|
|
|
|
if (d->read_format_capacities(d, 0x00) > 0 &&
|
|
|
|
d->format_descr_type != BURN_FORMAT_IS_FORMATTED) {
|
|
|
|
libdax_msgs_submit(libdax_messenger,
|
|
|
|
d->global_index, 0x00020168,
|
2009-01-06 13:53:01 +00:00
|
|
|
LIBDAX_MSGS_SEV_FAILURE, LIBDAX_MSGS_PRIO_HIGH,
|
2009-01-06 12:28:20 +00:00
|
|
|
"Media not properly formatted. Cannot write.",
|
|
|
|
0, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->cancel = 0; /* End of the return = failure area */
|
2007-02-04 07:30:14 +00:00
|
|
|
|
2009-01-06 12:28:20 +00:00
|
|
|
o.drive = d;
|
2006-10-30 05:32:33 +00:00
|
|
|
o.opts = opts;
|
|
|
|
o.disc = disc;
|
|
|
|
|
|
|
|
opts->refcount++;
|
|
|
|
|
2009-01-06 12:28:20 +00:00
|
|
|
add_worker(Burnworker_type_writE, d,
|
2008-07-14 11:38:22 +00:00
|
|
|
(WorkerFunc) write_disc_worker_func, &o);
|
2011-05-15 10:48:59 +00:00
|
|
|
|
|
|
|
ex:;
|
|
|
|
BURN_FREE_MEM(reasons);
|
2006-10-30 05:32:33 +00:00
|
|
|
}
|
|
|
|
|
2007-09-30 21:24:55 +00:00
|
|
|
|
|
|
|
static void *fifo_worker_func(struct w_list *w)
|
|
|
|
{
|
2008-11-08 14:18:14 +00:00
|
|
|
int old;
|
|
|
|
|
2010-03-05 18:59:21 +00:00
|
|
|
#define Libburn_protect_fifo_threaD 1
|
|
|
|
|
|
|
|
#ifdef Libburn_protect_fifo_threaD
|
|
|
|
sigset_t sigset, oldset;
|
|
|
|
|
|
|
|
/* Protect fifo thread from being interrupted by external signals */
|
|
|
|
sigfillset(&sigset);
|
|
|
|
sigdelset(&sigset, SIGSEGV);
|
|
|
|
sigdelset(&sigset, SIGILL);
|
|
|
|
pthread_sigmask(SIG_SETMASK, &sigset, &oldset);
|
|
|
|
#endif /* Libburn_protect_fifo_threaD */
|
|
|
|
|
2008-11-08 14:18:14 +00:00
|
|
|
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old);
|
|
|
|
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old);
|
|
|
|
/* Note: Only burn_fifo_abort() shall cancel the fifo thread */
|
|
|
|
|
2007-10-03 22:35:37 +00:00
|
|
|
burn_fifo_source_shoveller(w->u.fifo.source, w->u.fifo.flag);
|
2007-09-30 21:24:55 +00:00
|
|
|
remove_worker(pthread_self());
|
2010-03-05 18:59:21 +00:00
|
|
|
|
|
|
|
#ifdef Libburn_protect_fifo_threaD
|
|
|
|
/* (just in case it would not end with all signals blocked) */
|
|
|
|
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
|
|
|
|
#endif /* Libburn_protect_fifo_threaD */
|
|
|
|
|
2007-09-30 21:24:55 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int burn_fifo_start(struct burn_source *source, int flag)
|
|
|
|
{
|
|
|
|
struct fifo_opts o;
|
|
|
|
struct burn_source_fifo *fs = source->data;
|
|
|
|
|
|
|
|
fs->is_started = -1;
|
|
|
|
|
2007-10-03 22:35:37 +00:00
|
|
|
/* create and set up ring buffer */;
|
2009-11-23 18:56:18 +00:00
|
|
|
fs->buf = burn_os_alloc_buffer(
|
|
|
|
((size_t) fs->chunksize) * (size_t) fs->chunks, 0);
|
2007-09-30 21:24:55 +00:00
|
|
|
if (fs->buf == NULL) {
|
|
|
|
/* >>> could not start ring buffer */;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
o.source = source;
|
|
|
|
o.flag = flag;
|
2008-07-14 11:38:22 +00:00
|
|
|
add_worker(Burnworker_type_fifO, NULL,
|
|
|
|
(WorkerFunc) fifo_worker_func, &o);
|
2007-09-30 21:24:55 +00:00
|
|
|
fs->is_started = 1;
|
2010-03-05 09:08:16 +00:00
|
|
|
|
2007-09-30 21:24:55 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-08 14:18:14 +00:00
|
|
|
int burn_fifo_abort(struct burn_source_fifo *fs, int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
pthread_t pt;
|
|
|
|
|
|
|
|
if (fs->thread_is_valid <= 0 || fs->thread_handle == NULL)
|
|
|
|
return(2);
|
|
|
|
|
2008-11-08 20:25:38 +00:00
|
|
|
#ifdef NIX
|
2008-11-08 14:18:14 +00:00
|
|
|
libdax_msgs_submit(libdax_messenger, -1, 0x00000002,
|
|
|
|
LIBDAX_MSGS_SEV_DEBUG, LIBDAX_MSGS_PRIO_HIGH,
|
|
|
|
"Aborting running burn_source_fifo thread", 0, 0);
|
2008-11-08 20:25:38 +00:00
|
|
|
#endif /* NIX */
|
|
|
|
|
2008-11-08 14:18:14 +00:00
|
|
|
pt= *((pthread_t *) fs->thread_handle);
|
|
|
|
remove_worker(pt);
|
|
|
|
ret = pthread_cancel(pt);
|
|
|
|
return (ret == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-19 13:32:49 +00:00
|
|
|
#ifdef Libburn_has_burn_async_join_alL
|
|
|
|
|
|
|
|
/* ts A71019 : never used */
|
2006-10-30 05:32:33 +00:00
|
|
|
void burn_async_join_all(void)
|
|
|
|
{
|
|
|
|
void *ret;
|
|
|
|
|
|
|
|
while (workers)
|
|
|
|
pthread_join(workers->thread, &ret);
|
|
|
|
}
|
2007-10-19 13:32:49 +00:00
|
|
|
|
|
|
|
#endif /* Libburn_has_burn_async_join_alL */
|
|
|
|
|
|
|
|
|