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

This commit is contained in:
Thomas Schmitt 2006-10-09 12:49:08 +00:00
parent cf8aacb27d
commit bd1577debd
7 changed files with 161 additions and 32 deletions

View File

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

View File

@ -229,60 +229,107 @@ ts A61007
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
17) libburn/mmc.c: assert(o->drive == d); ++ 17) libburn/mmc.c: assert(o->drive == d);
mmc_close_disc(): mmc_close_disc():
alias: struct burn_drive.close_disc() alias: struct burn_drive.close_disc()
Parameters struct burn_drive and struct burn_write_opts do not match Parameters struct burn_drive and struct burn_write_opts do not match
Called by -nobody- ? Called by -nobody- ?
=> Disable unused function ? ( => Disable unused function ? )
=> removed redundant parameter struct burn_drive
ts A61009
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
18) libburn/mmc.c: assert(o->drive == d); ++ 18) libburn/mmc.c: assert(o->drive == d);
mmc_close_session(): mmc_close_session():
Same as 17) Same as 17)
alias: struct burn_drive.close_session() alias: struct burn_drive.close_session()
Called by -nobody- ? Called by -nobody- ?
=> Disable unused function ? ( => Disable unused function ? )
=> removed redundant parameter struct burn_drive
ts A61009
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
19) libburn/mmc.c: assert(buf->bytes >= buf->sectors); /* can be == at 0... */ ++ 19) libburn/mmc.c: assert(buf->bytes >= buf->sectors); /* can be == at 0... */
mmc_write_12(): mmc_write_12():
- Unclear what .bytes and .sectors mean in struct buffer - - Unclear what .bytes and .sectors mean in struct buffer -
Called by -nobody- ? Called by -nobody- ?
=> Disable unused function ? => problems with filling the write buffer have to be handled by callers
=> delete assert
ts A61009
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
20) libburn/mmc.c: assert(buf->bytes >= buf->sectors); /* can be == at 0... */ ++ 20) libburn/mmc.c: assert(buf->bytes >= buf->sectors); /* can be == at 0... */
mmc_write(): mmc_write():
- Unclear what .bytes and .sectors mean in struct buffer - - Unclear what .bytes and .sectors mean in struct buffer -
alias: struct burn_drive.write()
libburn/mmc.c: c.page->sectors = errorblock - start + 1;
mmc_read_sectors() by toc_find_modes() by mmc_read_toc() alias drive.read_toc()
by burn_drive_grab()
This seems to be unrelated to mmc_write().
libburn/sector.c: out->sectors++;
get_sector()
Seems to hand out sector start pointer in opts->drive->buffer
and to count reservation transactions as well as reserved bytes.
Ensures out->bytes >= out->sectors
libburn/mmc.c: c.page->bytes = s->count * 8;
mmc_send_cue_sheet()
Does not use mmc_write() but directly (sg_)issue_command()
libburn/sector.c: out->bytes += seclen;
get_sector()
See above
Ensures out->bytes >= out->sectors
libburn/spc.c: c.page->bytes = 8 + 2 + d->mdata->retry_page_length;
spc_select_error_params()
Does not use mmc_write() but directly (sg_)issue_command()
libburn/spc.c: c.page->bytes = 8 + 2 + d->mdata->write_page_length;
spc_select_error_params()
Does not use mmc_write() but directly (sg_)issue_command()
libburn/spc.c: c.page->bytes = 8 + 2 + 0x32;
spc_probe_write_modes()
Does not use mmc_write() but directly (sg_)issue_command()
alias struct burn_drive.write()
Called by static get_sector, by many Called by static get_sector, by many
Called by burn_write_flush Called by burn_write_flush
Called by burn_write_track Called by burn_write_track
=> ??? => problems with filling the write buffer have to be handled by callers
=> delete assert
ts A61009
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
21) libburn/mmc.c: assert(((dlen - 2) % 11) == 0); ++ 21) libburn/mmc.c: assert(((dlen - 2) % 11) == 0);
mmc_read_toc(): mmc_read_toc():
- Is defunct - - Is defunct -
=> :) => :)
ts A61009
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
22) libburn/mmc.c: assert(len >= 0); ++ 22) libburn/mmc.c: assert(len >= 0);
mmc_read_sectors(): mmc_read_sectors():
Catches a bad parameter Catches a bad parameter
@ -294,9 +341,11 @@ Called by toc_find_modes(), problem cannot occur: mem.sectors = 1;
(=> in burn_disc_read() check page.sectors before d->read_sectors() ) (=> in burn_disc_read() check page.sectors before d->read_sectors() )
=> :) => :)
ts A61009
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
23) libburn/mmc.c: assert(d->busy); ++ 23) libburn/mmc.c: assert(d->busy);
mmc_read_sectors(): mmc_read_sectors():
Catches use of a drive that is not marked as busy Catches use of a drive that is not marked as busy
@ -307,6 +356,8 @@ Called by toc_find_modes(), does the same assert. To be solved there.
: Severe Libburn Error : Severe Libburn Error
=> :) => :)
ts A61009
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
++ 24) libburn/options.c: assert(0); ++ 24) libburn/options.c: assert(0);
@ -563,7 +614,7 @@ ts A61008
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
43) libburn/structure.c: assert(s->track != NULL); ++ 43) libburn/structure.c: assert(s->track != NULL);
API burn_session_remove_track() API burn_session_remove_track()
An application supplied pointer is NULL An application supplied pointer is NULL

View File

@ -1,6 +1,8 @@
/* -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 8; -*- */ /* -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 8; -*- */
#include <assert.h> /* ts A61009 */
/* #include <a ssert.h> */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@ -18,6 +20,12 @@
#include "structure.h" #include "structure.h"
#include "options.h" #include "options.h"
/* ts A61005 */
#include "libdax_msgs.h"
extern struct libdax_msgs *libdax_messenger;
static unsigned char MMC_GET_TOC[] = { 0x43, 2, 2, 0, 0, 0, 0, 16, 0, 0 }; static unsigned char MMC_GET_TOC[] = { 0x43, 2, 2, 0, 0, 0, 0, 16, 0, 0 };
static unsigned char MMC_GET_ATIP[] = { 0x43, 2, 4, 0, 0, 0, 0, 16, 0, 0 }; static unsigned char MMC_GET_ATIP[] = { 0x43, 2, 4, 0, 0, 0, 0, 16, 0, 0 };
static unsigned char MMC_GET_DISC_INFO[] = static unsigned char MMC_GET_DISC_INFO[] =
@ -99,19 +107,43 @@ int mmc_get_nwa(struct burn_drive *d)
+ (data[14] << 8) + data[15]; + (data[14] << 8) + data[15];
} }
void mmc_close_disc(struct burn_drive *d, struct burn_write_opts *o) /* ts A61009 : function is obviously unused. */
/* void mmc_close_disc(struct burn_drive *d, struct burn_write_opts *o) */
void mmc_close_disc(struct burn_write_opts *o)
{ {
struct burn_drive *d;
mmc_function_spy("mmc_close_disc"); mmc_function_spy("mmc_close_disc");
assert(o->drive == d);
libdax_msgs_submit(libdax_messenger, -1, 0x00000002,
LIBDAX_MSGS_SEV_DEBUG, LIBDAX_MSGS_PRIO_ZERO,
"HOW THAT ? mmc_close_disc() was called", 0, 0);
/* ts A61009 : made impossible by removing redundant parameter d */
/* a ssert(o->drive == d); */
d = o->drive;
o->multi = 0; o->multi = 0;
spc_select_write_params(d, o); spc_select_write_params(d, o);
mmc_close(d, 1, 0); mmc_close(d, 1, 0);
} }
void mmc_close_session(struct burn_drive *d, struct burn_write_opts *o) /* ts A61009 : function is obviously unused. */
/* void mmc_close_session(struct burn_drive *d, struct burn_write_opts *o) */
void mmc_close_session(struct burn_write_opts *o)
{ {
struct burn_drive *d;
mmc_function_spy("mmc_close_session"); mmc_function_spy("mmc_close_session");
assert(o->drive == d);
libdax_msgs_submit(libdax_messenger, -1, 0x00000002,
LIBDAX_MSGS_SEV_DEBUG, LIBDAX_MSGS_PRIO_ZERO,
"HOW THAT ? mmc_close_session() was called", 0, 0);
/* ts A61009 : made impossible by removing redundant parameter d */
/* a ssert(o->drive == d); */
d = o->drive;
o->multi = 3; o->multi = 3;
spc_select_write_params(d, o); spc_select_write_params(d, o);
mmc_close(d, 1, 0); mmc_close(d, 1, 0);
@ -121,7 +153,12 @@ void mmc_close(struct burn_drive *d, int session, int track)
{ {
struct command c; struct command c;
mmc_function_spy("mmc_close_session"); mmc_function_spy("mmc_close");
libdax_msgs_submit(libdax_messenger, -1, 0x00000002,
LIBDAX_MSGS_SEV_DEBUG, LIBDAX_MSGS_PRIO_ZERO,
"HOW THAT ? mmc_close() was called", 0, 0);
c.retry = 1; c.retry = 1;
c.oplen = sizeof(MMC_CLOSE); c.oplen = sizeof(MMC_CLOSE);
memcpy(c.opcode, MMC_CLOSE, sizeof(MMC_CLOSE)); memcpy(c.opcode, MMC_CLOSE, sizeof(MMC_CLOSE));
@ -154,6 +191,7 @@ void mmc_get_event(struct burn_drive *d)
c.page->data[5], c.page->data[6], c.page->data[7]); c.page->data[5], c.page->data[6], c.page->data[7]);
} }
void mmc_write_12(struct burn_drive *d, int start, struct buffer *buf) void mmc_write_12(struct burn_drive *d, int start, struct buffer *buf)
{ {
struct command c; struct command c;
@ -161,7 +199,10 @@ void mmc_write_12(struct burn_drive *d, int start, struct buffer *buf)
mmc_function_spy("mmc_write_12"); mmc_function_spy("mmc_write_12");
len = buf->sectors; len = buf->sectors;
assert(buf->bytes >= buf->sectors); /* can be == at 0... */
/* ts A61009 */
/* a ssert(buf->bytes >= buf->sectors);*/ /* can be == at 0... */
burn_print(100, "trying to write %d at %d\n", len, start); burn_print(100, "trying to write %d at %d\n", len, start);
memcpy(c.opcode, MMC_WRITE_12, sizeof(MMC_WRITE_12)); memcpy(c.opcode, MMC_WRITE_12, sizeof(MMC_WRITE_12));
c.retry = 1; c.retry = 1;
@ -195,7 +236,10 @@ int mmc_write(struct burn_drive *d, int start, struct buffer *buf)
return BE_CANCELLED; return BE_CANCELLED;
len = buf->sectors; len = buf->sectors;
assert(buf->bytes >= buf->sectors); /* can be == at 0... */
/* ts A61009 : buffer fill problems are to be handled by caller */
/* a ssert(buf->bytes >= buf->sectors);*/ /* can be == at 0... */
burn_print(100, "trying to write %d at %d\n", len, start); burn_print(100, "trying to write %d at %d\n", len, start);
memcpy(c.opcode, MMC_WRITE_10, sizeof(MMC_WRITE_10)); memcpy(c.opcode, MMC_WRITE_10, sizeof(MMC_WRITE_10));
c.retry = 1; c.retry = 1;
@ -251,6 +295,7 @@ void mmc_read_toc(struct burn_drive *d)
/* /*
some drives fail this check. some drives fail this check.
ts A61007 : if re-enabled then not via Assert.
a ssert(((dlen - 2) % 11) == 0); a ssert(((dlen - 2) % 11) == 0);
*/ */
d->toc_entry = malloc(d->toc_entries * sizeof(struct burn_toc_entry)); d->toc_entry = malloc(d->toc_entries * sizeof(struct burn_toc_entry));
@ -382,9 +427,14 @@ void mmc_read_sectors(struct burn_drive *d,
struct command c; struct command c;
mmc_function_spy("mmc_read_sectors"); mmc_function_spy("mmc_read_sectors");
assert(len >= 0);
/* ts A61009 : to be ensured by callers */
/* a ssert(len >= 0); */
/* if the drive isn't busy, why the hell are we here? */ /* if the drive isn't busy, why the hell are we here? */
assert(d->busy); /* ts A61006 : i second that question */
/* a ssert(d->busy); */
burn_print(12, "reading %d from %d\n", len, start); burn_print(12, "reading %d from %d\n", len, start);
memcpy(c.opcode, MMC_READ_CD, sizeof(MMC_READ_CD)); memcpy(c.opcode, MMC_READ_CD, sizeof(MMC_READ_CD));
c.retry = 1; c.retry = 1;

View File

@ -12,8 +12,13 @@ struct cue_sheet;
/* MMC commands */ /* MMC commands */
void mmc_read(struct burn_drive *); void mmc_read(struct burn_drive *);
void mmc_close_session(struct burn_drive *, struct burn_write_opts *);
void mmc_close_disc(struct burn_drive *, struct burn_write_opts *); /* ts A61009 : removed redundant parameter d in favor of o->drive */
/* void mmc_close_session(struct burn_drive *, struct burn_write_opts *); */
/* void mmc_close_disc(struct burn_drive *, struct burn_write_opts *); */
void mmc_close_session(struct burn_write_opts *o);
void mmc_close_disc(struct burn_write_opts *o);
void mmc_close(struct burn_drive *, int session, int track); void mmc_close(struct burn_drive *, int session, int track);
void mmc_get_event(struct burn_drive *); void mmc_get_event(struct burn_drive *);
int mmc_write(struct burn_drive *, int start, struct buffer *buf); int mmc_write(struct burn_drive *, int start, struct buffer *buf);

View File

@ -47,6 +47,9 @@ void burn_disc_read(struct burn_drive *d, const struct burn_read_opts *o)
a ssert(d->toc->valid); a ssert(d->toc->valid);
a ssert(o->datafd != -1); a ssert(o->datafd != -1);
/* moved up from spc_select_error_params alias d->send_parameters() */
a ssert(d->mdata->valid);
/* XXX not sure this is a good idea. copy it? */ /* XXX not sure this is a good idea. copy it? */
/* XXX also, we have duplicated data now, do we remove the fds from struct /* XXX also, we have duplicated data now, do we remove the fds from struct
drive, or only store a subset of the _opts structs in drives */ drive, or only store a subset of the _opts structs in drives */
@ -56,6 +59,7 @@ drive, or only store a subset of the _opts structs in drives */
d->set_speed(d, speed, 0); d->set_speed(d, speed, 0);
d->params.retries = o->hardware_error_retries; d->params.retries = o->hardware_error_retries;
d->send_parameters(d, o); d->send_parameters(d, o);
d->cancel = 0; d->cancel = 0;
@ -133,7 +137,10 @@ drive, or only store a subset of the _opts structs in drives */
page.sectors = (finish < maxsects) ? finish : maxsects; page.sectors = (finish < maxsects) ? finish : maxsects;
printf("reading %d sectors from %d\n", page.sectors, printf("reading %d sectors from %d\n", page.sectors,
drive_lba); drive_lba);
/* >>> ts A61009 : ensure page.sectors >= 0 before calling */
d->r ead_sectors(d, drive_lba, page.sectors, o, &page); d->r ead_sectors(d, drive_lba, page.sectors, o, &page);
printf("Read %d\n", page.sectors); printf("Read %d\n", page.sectors);
} }
#endif #endif

View File

@ -148,6 +148,9 @@ static void get_bytes(struct burn_track *track, int count, unsigned char *data)
return; return;
memset(data + curr, 0, shortage); memset(data + curr, 0, shortage);
} }
/* ts A61009 : seems to hand out sector start pointer in opts->drive->buffer
and to count hand outs as well as reserved bytes */
static unsigned char *get_sector(struct burn_write_opts *opts, int inmode) static unsigned char *get_sector(struct burn_write_opts *opts, int inmode)
{ {
struct burn_drive *d = opts->drive; struct burn_drive *d = opts->drive;
@ -160,7 +163,13 @@ static unsigned char *get_sector(struct burn_write_opts *opts, int inmode)
if (outmode == 0) if (outmode == 0)
outmode = inmode; outmode = inmode;
seclen = burn_sector_length(outmode) + burn_subcode_length(outmode); /* ts A61009 : react on eventual failure of burn_sector_length()
(should not happen if API tested properly).
Ensures out->bytes >= out->sectors */
seclen = burn_sector_length(outmode);
if (seclen <= 0)
return NULL;
seclen += burn_subcode_length(outmode);
if (out->bytes + (seclen) >= BUFFER_SIZE) { if (out->bytes + (seclen) >= BUFFER_SIZE) {
int err; int err;

View File

@ -161,9 +161,16 @@ struct burn_drive
void (*sync_cache) (struct burn_drive *); void (*sync_cache) (struct burn_drive *);
int (*get_erase_progress) (struct burn_drive *); int (*get_erase_progress) (struct burn_drive *);
int (*get_nwa) (struct burn_drive *); int (*get_nwa) (struct burn_drive *);
void (*close_disc) (struct burn_drive * d, struct burn_write_opts * o);
/* ts A61009 : removed d in favor of o->drive */
/* void (*close_disc) (struct burn_drive * d,
struct burn_write_opts * o);
void (*close_session) (struct burn_drive * d, void (*close_session) (struct burn_drive * d,
struct burn_write_opts * o); struct burn_write_opts * o);
*/
void (*close_disc) (struct burn_write_opts * o);
void (*close_session) ( struct burn_write_opts * o);
int (*test_unit_ready) (struct burn_drive * d); int (*test_unit_ready) (struct burn_drive * d);
void (*probe_write_modes) (struct burn_drive * d); void (*probe_write_modes) (struct burn_drive * d);
struct params params; struct params params;