Little code changes to improve isoburn_start_emulation().

This commit is contained in:
Vreixo Formoso Lopes 2007-09-21 15:37:04 +00:00
parent 6d7d67baaa
commit a904ef7abf

View File

@ -202,7 +202,7 @@ int isoburn_free_rwopts(struct isoburn *o)
*/ */
int isoburn_start_emulation(struct isoburn *o, int flag) int isoburn_start_emulation(struct isoburn *o, int flag)
{ {
int ret; int ret, i;
off_t *data_count; off_t *data_count;
struct burn_drive *drive; struct burn_drive *drive;
struct ecma119_pri_vol_desc *pvm; struct ecma119_pri_vol_desc *pvm;
@ -213,22 +213,34 @@ int isoburn_start_emulation(struct isoburn *o, int flag)
// TODO what about ms? where we validate valid iso image in ms disc? // TODO what about ms? where we validate valid iso image in ms disc?
ret = burn_read_data(drive, (off_t) 0, o->target_iso_head, ret = burn_read_data(drive, (off_t) 0, o->target_iso_head,
sizeof(o->target_iso_head), &data_count, 0); sizeof(o->target_iso_head), &data_count, 0);
// TODO mmm, can a read error mean an empty disc (e.g. CD-R)?
if (ret <= 0) if (ret <= 0)
return -1; return -1;
pvm = (struct ecma119_pri_vol_desc *)(o->target_iso_head + 16 * 2048); /* check first 64K. If 0's, the disc is treated as a blank disc, and thus
overwritten without extra check. */
i = sizeof(o->target_iso_head);
while (i && !o->target_iso_head[i-1])
--i;
/* sanity check */ if (!i) {
if (pvm->vol_desc_type[0] != 1 || pvm->vol_desc_version[0] != 1 o->fabricated_disc_status= BURN_DISC_BLANK;
|| pvm->file_structure_version[0] != 1 ) {
// TODO for now I treat this as a full disc
o->fabricated_disc_status= BURN_DISC_FULL;
return 1; return 1;
} }
pvm = (struct ecma119_pri_vol_desc *)(o->target_iso_head + 16 * 2048);
if (!strncmp((char*)pvm->std_identifier, "CD001", 5)) { if (!strncmp((char*)pvm->std_identifier, "CD001", 5)) {
off_t size; off_t size;
/* sanity check */
if (pvm->vol_desc_type[0] != 1 || pvm->vol_desc_version[0] != 1
|| pvm->file_structure_version[0] != 1 ) {
// TODO for now I treat this as a full disc
o->fabricated_disc_status= BURN_DISC_FULL;
return 1;
}
/* ok, PVM found, set size */ /* ok, PVM found, set size */
size = (off_t) iso_read_lsb(pvm->vol_space_size, 4); size = (off_t) iso_read_lsb(pvm->vol_space_size, 4);
size *= (off_t) 2048; /* block size in bytes */ size *= (off_t) 2048; /* block size in bytes */
@ -240,19 +252,8 @@ int isoburn_start_emulation(struct isoburn *o, int flag)
isoburn_set_start_byte(o, (off_t) 0, 0); isoburn_set_start_byte(o, (off_t) 0, 0);
o->fabricated_disc_status= BURN_DISC_BLANK; o->fabricated_disc_status= BURN_DISC_BLANK;
} else { } else {
int i; /* treat any disc in an unknown format as full */
o->fabricated_disc_status= BURN_DISC_FULL;
/* check first 64K. If 0's, the disc is treated as a blank disc, and thus
overwritten without extra check. If not, the disc is treated as full,
and user needs to isoburn_disc_erase() it before burn it again */
i = sizeof(o->target_iso_head);
while (i && !o->target_iso_head[i-1])
--i;
if (i)
o->fabricated_disc_status= BURN_DISC_FULL;
else
o->fabricated_disc_status= BURN_DISC_BLANK;
} }
return 1; return 1;
} }