From 96af6203345abddf3a01255e7e65fb9885664acc Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Tue, 10 Oct 2006 11:26:46 +0000 Subject: [PATCH] Got rid of assert() in sector.c by soft means --- cdrskin/cdrskin_timestamp.h | 2 +- libburn/asserts.txt | 25 ++++++---- libburn/async.c | 3 ++ libburn/libdax_msgs.h | 6 +++ libburn/sector.c | 91 ++++++++++++++++++++++++++++++------- libburn/sector.h | 4 ++ libburn/write.c | 24 ++++++++++ libburn/write.h | 4 ++ 8 files changed, 133 insertions(+), 26 deletions(-) diff --git a/cdrskin/cdrskin_timestamp.h b/cdrskin/cdrskin_timestamp.h index 986dfdc..1213f22 100644 --- a/cdrskin/cdrskin_timestamp.h +++ b/cdrskin/cdrskin_timestamp.h @@ -1 +1 @@ -#define Cdrskin_timestamP "2006.10.09.123518" +#define Cdrskin_timestamP "2006.10.10.112545" diff --git a/libburn/asserts.txt b/libburn/asserts.txt index 504fa96..de5b72e 100644 --- a/libburn/asserts.txt +++ b/libburn/asserts.txt @@ -409,7 +409,7 @@ ts A61007 ------------------------------------------------------------------------------ - 27) libburn/sector.c: assert(outlen >= inlen); +++ 27) libburn/sector.c: assert(outlen >= inlen); libburn/sector.c: assert(outmode & BURN_MODE_RAW); libburn/sector.c: assert(offset != -1); static convert_data(): @@ -422,6 +422,8 @@ Called by sector_toc() sector_pregap() sector_postgap() sector_lout() => change return type of convert_data() => all callers interpret return value and eventually return failure +ts A61007 + ------------------------------------------------------------------------------ ++ 28) libburn/sector.c: assert(0); @@ -438,34 +440,41 @@ ts A61008 ------------------------------------------------------------------------------ - 29) libburn/sector.c: assert(qmode == 1 || qmode == 2 || qmode == 3); +++ 29) libburn/sector.c: assert(qmode == 1 || qmode == 2 || qmode == 3); subcode_user(): - can not happen - : Unknown reason of assert() => remove assert() +ts A61010 + ------------------------------------------------------------------------------ - 30) libburn/sector.c: assert(modebyte == 1); +++ 30) libburn/sector.c: assert(modebyte == 1); sector_headers(): -Several unacceptable settings within struct burn_write_opts and mode parameter +Does only accept modes BURN_AUDIO, BURN_MODE1 or write_type BURN_WRITE_SAO Called by sector_toc() sector_pregap() sector_postgap() sector_lout() sector_data() -: Severe Application Error -=> change return type of convert_data() -=> all callers interpret return value and eventually return failure +: Severe Libburn Error +=> new functions sector_headers_is_ok(), burn_disc_write_is_ok() + help to catch problem in API burn_disc_write() +=> issue LIBDAX_MSGS_SEV_FATAL + +ts A61009 ------------------------------------------------------------------------------ - 31) libburn/sector.c: assert(0); +++ 31) libburn/sector.c: assert(0); process_q() - defunct - => :) +ts A61009 + ------------------------------------------------------------------------------ ++ 32) libburn/sg.c: assert("drive busy" == "non fatal"); diff --git a/libburn/async.c b/libburn/async.c index fe40c5a..e48d719 100644 --- a/libburn/async.c +++ b/libburn/async.c @@ -258,6 +258,9 @@ void burn_disc_write(struct burn_write_opts *opts, struct burn_disc *disc) "Drive capabilities not inquired yet", 0, 0); return; } + /* ts A61009 : obsolete Assert in sector_headers() */ + if (! burn_disc_write_is_ok(opts, disc)) /* issues own msgs */ + return; o.drive = opts->drive; o.opts = opts; diff --git a/libburn/libdax_msgs.h b/libburn/libdax_msgs.h index df8e4bd..40464db 100644 --- a/libburn/libdax_msgs.h +++ b/libburn/libdax_msgs.h @@ -315,6 +315,12 @@ Range "scdbackup" : 0x00020000 to 0x0002ffff 0x00020108 (SORRY,HIGH) = Drive is not grabbed on disc status inquiry 0x00020108 (FATAL,HIGH) = Could not allocate new drive object 0x00020109 (FATAL,HIGH) = Library not running + 0x0002010a (FATAL,HIGH) = Unsuitable track mode + 0x0002010b (FATAL,HIGH) = Burn run failed + 0x0002010c + 0x0002010d + 0x0002010e + 0x0002010f 0x00020110 (FATAL,HIGH) = Persistent drive address too long 0x00020111 (FATAL,HIGH) = Could not allocate new auxiliary object 0x00020112 (SORRY,HIGH) = Bad combination of write_type and block_type diff --git a/libburn/sector.c b/libburn/sector.c index 3b1319e..6bdb49b 100644 --- a/libburn/sector.c +++ b/libburn/sector.c @@ -1,7 +1,10 @@ /* -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 8; -*- */ #include -#include + +/* ts A61010 */ +/* #include */ + #include #include #include "error.h" @@ -189,7 +192,9 @@ static unsigned char *get_sector(struct burn_write_opts *opts, int inmode) } /* either inmode == outmode, or outmode == raw. anything else is bad news */ -static void convert_data(struct burn_write_opts *o, struct burn_track *track, +/* ts A61010 : changed type to int in order to propagate said bad news */ +/** @return 1 is ok, <= 0 is failure */ +static int convert_data(struct burn_write_opts *o, struct burn_track *track, int inmode, unsigned char *data) { int outlen, inlen; @@ -202,14 +207,21 @@ static void convert_data(struct burn_write_opts *o, struct burn_track *track, outlen = burn_sector_length(outmode); inlen = burn_sector_length(inmode); - assert(outlen >= inlen); + + /* ts A61010 */ + /* a ssert(outlen >= inlen); */ + if (outlen < inlen) + return 0; if ((outmode & BURN_MODE_BITS) == (inmode & BURN_MODE_BITS)) { get_bytes(track, inlen, data); - return; + return 1; } - assert(outmode & BURN_MODE_RAW); + /* ts A61010 */ + /* a ssert(outmode & BURN_MODE_RAW); */ + if (!(outmode & BURN_MODE_RAW)) + return 0; if (inmode & BURN_MODE1) offset = 16; @@ -217,9 +229,16 @@ static void convert_data(struct burn_write_opts *o, struct burn_track *track, offset = 0; if (inmode & BURN_AUDIO) offset = 0; - assert(offset != -1); + + /* ts A61010 */ + /* a ssert(offset != -1); */ + if (offset == -1) + return 0; + get_bytes(track, inlen, data + offset); + return 1; } + static void convert_subs(struct burn_write_opts *o, int inmode, unsigned char *subs, unsigned char *sector) { @@ -300,9 +319,11 @@ int sector_toc(struct burn_write_opts *o, int mode) unsigned char subs[96]; data = get_sector(o, mode); - if (!data) + if (data == NULL) + return 0; + /* ts A61010 */ + if (convert_data(o, NULL, mode, data) <= 0) return 0; - convert_data(o, NULL, mode, data); subcode_toc(d, mode, subs); convert_subs(o, mode, subs, data); sector_headers(o, data, mode, 1); @@ -318,9 +339,11 @@ int sector_pregap(struct burn_write_opts *o, unsigned char subs[96]; data = get_sector(o, mode); - if (!data) + if (data == NULL) + return 0; + /* ts A61010 */ + if (convert_data(o, NULL, mode, data) <= 0) return 0; - convert_data(o, NULL, mode, data); subcode_user(o, subs, tno, control, 0, NULL, 1); convert_subs(o, mode, subs, data); sector_headers(o, data, mode, 0); @@ -336,9 +359,11 @@ int sector_postgap(struct burn_write_opts *o, unsigned char *data; data = get_sector(o, mode); - if (!data) + if (data == NULL) return 0; - convert_data(o, NULL, mode, data); + /* ts A61010 */ + if (convert_data(o, NULL, mode, data) <= 0) + return 0;; /* use last index in track */ subcode_user(o, subs, tno, control, 1, NULL, 1); convert_subs(o, mode, subs, data); @@ -425,7 +450,8 @@ void subcode_user(struct burn_write_opts *o, unsigned char *subcodes, } } - assert(qmode == 1 || qmode == 2 || qmode == 3); + /* ts A61010 : this cannot happen. Assert for fun ? */ + /* a ssert(qmode == 1 || qmode == 2 || qmode == 3); */ switch (qmode) { case 1: @@ -507,7 +533,9 @@ int sector_lout(struct burn_write_opts *o, unsigned char control, int mode) data = get_sector(o, mode); if (!data) return 0; - convert_data(o, NULL, mode, data); + /* ts A61010 */ + if (convert_data(o, NULL, mode, data) <= 0) + return 0; subcode_lout(o, control, subs); convert_subs(o, mode, subs, data); sector_headers(o, data, mode, 0); @@ -524,7 +552,9 @@ int sector_data(struct burn_write_opts *o, struct burn_track *t, int psub) data = get_sector(o, t->mode); if (!data) return 0; - convert_data(o, t, t->mode, data); + /* ts A61010 */ + if (convert_data(o, t, t->mode, data) <= 0) + return 0; if (!t->source->read_sub) subcode_user(o, subs, t->entry->point, @@ -569,6 +599,17 @@ int dec_to_bcd(int d) return (top << 4) + bottom; } +int sector_headers_is_ok(struct burn_write_opts *o, int mode) +{ + if (mode & BURN_AUDIO) /* no headers for "audio" */ + return 1; + if (o->write_type == BURN_WRITE_SAO) + return 1; + if (mode & BURN_MODE1) + return 2; + return 0; +} + void sector_headers(struct burn_write_opts *o, unsigned char *out, int mode, int leadin) { @@ -577,6 +618,17 @@ void sector_headers(struct burn_write_opts *o, unsigned char *out, int min, sec, frame; int modebyte = -1; + /* ts A61009 */ +#if 1 + int ret; + + ret = sector_headers_is_ok(o, mode); + if (ret != 2) + return; + modebyte = 1; + +#else + if (mode & BURN_AUDIO) /* no headers for "audio" */ return; if (o->write_type == BURN_WRITE_SAO) @@ -584,7 +636,10 @@ void sector_headers(struct burn_write_opts *o, unsigned char *out, if (mode & BURN_MODE1) modebyte = 1; - assert(modebyte == 1); +#endif + + /* ts A61009 : now ensured by burn_disc_write_is_ok() */ + /* a ssert(modebyte == 1); */ out[0] = 0; memset(out + 1, 0xFF, 10); /* sync */ @@ -656,7 +711,9 @@ void process_q(struct burn_drive *d, unsigned char *q) */ break; default: - assert(0); + + /* ts A61009 : if reactivated then witout Assert */ + a ssert(0); } } #endif diff --git a/libburn/sector.h b/libburn/sector.h index 91b68d3..ecb609a 100644 --- a/libburn/sector.h +++ b/libburn/sector.h @@ -18,6 +18,10 @@ int sector_postgap(struct burn_write_opts *, unsigned char tno, unsigned char control, int mode); int sector_lout(struct burn_write_opts *, unsigned char control, int mode); int sector_data(struct burn_write_opts *, struct burn_track *t, int psub); + +/* ts A61009 */ +int sector_headers_is_ok(struct burn_write_opts *o, int mode); + void sector_headers(struct burn_write_opts *, unsigned char *, int mode, int leadin); void subcode_user(struct burn_write_opts *, unsigned char *s, diff --git a/libburn/write.c b/libburn/write.c index 56d46c9..e0ceb4a 100644 --- a/libburn/write.c +++ b/libburn/write.c @@ -530,6 +530,27 @@ int burn_write_track(struct burn_write_opts *o, struct burn_session *s, return 1; } +/* ts A61009 */ +int burn_disc_write_is_ok(struct burn_write_opts *o, struct burn_disc *disc) +{ + int i, t; + char msg[80]; + + for (i = 0; i < disc->sessions; i++) + for (t = 0; t < disc->session[i]->tracks; t++) + if (!sector_headers_is_ok( + o, disc->session[i]->track[t]->mode)) + goto bad_track_mode_found; + return 1; +bad_track_mode_found:; + sprintf(msg, "Unsuitable track mode 0x%x in track %d of session %d", + disc->session[i]->track[t]->mode, i+1, t+1); + libdax_msgs_submit(libdax_messenger, -1, 0x0002010a, + LIBDAX_MSGS_SEV_FATAL, LIBDAX_MSGS_PRIO_HIGH, + msg, 0, 0); + return 0; +} + void burn_disc_write_sync(struct burn_write_opts *o, struct burn_disc *disc) { struct cue_sheet *sheet; @@ -640,5 +661,8 @@ return crap. so we send the command, then ignore the result. fail: d->sync_cache(d); burn_print(1, "done - failed\n"); + libdax_msgs_submit(libdax_messenger, d->global_index, 0x0002010b, + LIBDAX_MSGS_SEV_FATAL, LIBDAX_MSGS_PRIO_HIGH, + "Burn run failed", 0, 0); d->busy = BURN_DRIVE_IDLE; } diff --git a/libburn/write.h b/libburn/write.h index d7eb733..737ffb8 100644 --- a/libburn/write.h +++ b/libburn/write.h @@ -12,6 +12,10 @@ struct cue_sheet *burn_create_toc_entries(struct burn_write_opts *o, struct burn_session *session); int burn_sector_length(int trackmode); int burn_subcode_length(int trackmode); + +/* ts A61009 */ +int burn_disc_write_is_ok(struct burn_write_opts *o, struct burn_disc *disc); + void burn_disc_write_sync(struct burn_write_opts *o, struct burn_disc *disc); int burn_write_leadin(struct burn_write_opts *o, struct burn_session *s, int first);