Got rid of assert() in sector.c by soft means

This commit is contained in:
Thomas Schmitt 2006-10-10 11:26:46 +00:00
parent bd1577debd
commit 96af620334
8 changed files with 133 additions and 26 deletions

View File

@ -1 +1 @@
#define Cdrskin_timestamP "2006.10.09.123518"
#define Cdrskin_timestamP "2006.10.10.112545"

View File

@ -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");

View File

@ -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;

View File

@ -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

View File

@ -1,7 +1,10 @@
/* -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 8; -*- */
#include <stdio.h>
#include <assert.h>
/* ts A61010 */
/* #include <a ssert.h> */
#include <unistd.h>
#include <string.h>
#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

View File

@ -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,

View File

@ -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;
}

View File

@ -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);