Replaced some large local variables by other means in

This commit is contained in:
2011-05-09 15:49:47 +00:00
parent cc30f4043b
commit 31300231df
4 changed files with 166 additions and 80 deletions

View File

@@ -121,22 +121,24 @@ int isoburn_read_image(struct burn_drive *d,
IsoReadOpts *ropts= NULL;
IsoReadImageFeatures *features= NULL;
uint32_t ms_block;
char msg[160];
char *msg= NULL;
enum burn_disc_status status= BURN_DISC_BLANK;
IsoDataSource *ds= NULL;
struct isoburn *o= NULL;
msg= calloc(1, 160);
if(d != NULL) {
ret = isoburn_find_emulator(&o, d, 0);
if (ret < 0 || o == NULL)
return 0;
{ret= 0; goto ex;}
status = isoburn_disc_get_status(d);
}
if(read_opts==NULL) {
isoburn_msgs_submit(o, 0x00060000,
"Program error: isoburn_read_image: read_opts==NULL",
0, "FATAL", 0);
return(-1);
{ret= -1; goto ex;}
}
if (d == NULL || status == BURN_DISC_BLANK || read_opts->pretend_blank) {
create_blank_image:;
@@ -150,13 +152,13 @@ create_blank_image:;
isoburn_msgs_submit(o, 0x00060000,
"Program error: isoburn_read_image: image==NULL",
0, "FATAL", 0);
return -1;
{ret= -1; goto ex;}
}
/* create a new image */
ret = iso_image_new("ISOIMAGE", image);
if (ret < 0) {
isoburn_report_iso_error(ret, "Cannot create image", 0, "FATAL", 0);
return ret;
goto ex;
}
iso_image_set_ignore_aclea(*image,
(!!(read_opts->noacl)) | ((!!read_opts->noea) << 1) );
@@ -166,7 +168,7 @@ create_blank_image:;
ret = iso_image_new("ISOIMAGE", &o->image);
if (ret < 0) {
isoburn_report_iso_error(ret, "Cannot create image", 0, "FATAL", 0);
return ret;
goto ex;
}
if (image != NULL) {
*image = o->image;
@@ -175,21 +177,21 @@ create_blank_image:;
iso_image_set_ignore_aclea(o->image,
(!!(read_opts->noacl)) | ((!!read_opts->noea) << 1) );
}
return 1;
{ret= 1; goto ex;}
}
if (status != BURN_DISC_APPENDABLE && status != BURN_DISC_FULL) {
isoburn_msgs_submit(o, 0x00060000,
"Program error: isoburn_read_image: incorrect disc status",
0, "FATAL", 0);
return -4;
{ret= -4; goto ex;}
}
memset((char *) &ropts, 0, sizeof(ropts));
ret = isoburn_disc_get_msc1(d, &int_num);
if (ret <= 0)
return -2;
{ret= -2; goto ex;}
ms_block= int_num;
ret = isoburn_read_iso_head(d, int_num, &dummy, NULL, 0);
if (ret <= 0) {
@@ -205,7 +207,7 @@ create_blank_image:;
displacement_rollover:;
sprintf(msg, "Displacement offset leads outside 32 bit range.");
isoburn_msgs_submit(o, 0x00060000, msg, 0, "FAILURE", 0);
return 0;
{ret= 0; goto ex;}
}
ms_block+= read_opts->displacement;
} else {
@@ -220,7 +222,7 @@ displacement_rollover:;
ret = iso_read_opts_new(&ropts, 0);
if (ret < 0) {
isoburn_report_iso_error(ret, "Cannot create write opts", 0, "FATAL", 0);
return ret;
goto ex;
}
/* Important: do not return until iso_read_opts_free() */
@@ -253,7 +255,7 @@ displacement_rollover:;
if (ds == NULL) {
isoburn_report_iso_error(ret, "Cannot create IsoDataSource object", 0,
"FATAL", 0);
return ret;
goto ex;
}
if(o->iso_data_source!=NULL)
iso_data_source_unref(o->iso_data_source);
@@ -270,7 +272,7 @@ displacement_rollover:;
if (ret < 0) {
isoburn_report_iso_error(ret, "Cannot import image", 0, "FAILURE", 0);
return ret;
goto ex;
}
/* Important: do not return until free(features) */
if (image!=NULL) {
@@ -283,7 +285,11 @@ displacement_rollover:;
read_opts->hasElTorito = iso_read_image_features_has_eltorito(features);
read_opts->size = iso_read_image_features_get_size(features);
iso_read_image_features_destroy(features);
return 1;
ret= 1;
ex:;
if(msg != NULL)
free(msg);
return(ret);
}
@@ -366,53 +372,58 @@ int isoburn_get_img_partition_offset(struct burn_drive *drive,
static int isoburn_inspect_partition(struct isoburn *o, uint32_t img_size,
int flag)
{
uint8_t *mbr, *part, buf[2048];
uint8_t *mbr, *part, *buf= NULL;
uint32_t offst, numsec;
struct ecma119_pri_vol_desc *pvm;
off_t data_count;
int ret;
char msg[160];
char *msg= NULL;
static int max_offst= 512 - 32;
buf= (uint8_t *) calloc(1, 2048);
msg= calloc(1, 160);
if(buf == NULL || msg == NULL)
{ret= -1; goto ex;}
mbr= o->target_iso_head;
part= mbr + 446;
if(mbr[510] != 0x55 || mbr[511] != 0xAA)
return(2); /* not an MBR */
{ret= 2; goto ex;} /* not an MBR */
/* Does the first partition entry look credible ? */
if(part[0] != 0x80 && part[0] != 0x00)
return(2); /* Invalid partition status */
{ret= 2; goto ex;} /* Invalid partition status */
if(part[1] == 0 && part[2] == 0 && part[3] == 0)
return(2); /* Zero C/H/S start address */
{ret= 2; goto ex;} /* Zero C/H/S start address */
/* Does it match the normal ISO image ? */
offst= iso_read_lsb(part + 8, 4);
numsec= iso_read_lsb(part + 12, 4);
if(offst < 64)
return(2); /* Zero or unusably small partition start */
{ret= 2; goto ex;} /* Zero or unusably small partition start */
if((offst % 4) || (numsec % 4))
return(2); /* Not aligned to 2k */
{ret= 2; goto ex;} /* Not aligned to 2k */
if(numsec < 72)
return(2); /* No room for volume descriptors */
{ret= 2; goto ex;} /* No room for volume descriptors */
offst/= 4;
numsec/= 4;
if(offst + numsec != img_size)
return(2); /* Partition end does not match image end */
{ret= 2; goto ex;} /* Partition end does not match image end */
/* Is there a PVD at the partition start ? */
ret = burn_read_data(o->drive, (off_t) (offst + 16) * (off_t) 2048,
(char*) buf, 2048, &data_count, 2);
if(ret <= 0)
return(2);
{ret= 2; goto ex;}
pvm = (struct ecma119_pri_vol_desc *) buf;
if (strncmp((char*) pvm->std_identifier, "CD001", 5) != 0)
return(2); /* not a PVD */
{ret= 2; goto ex;} /* not a PVD */
if (pvm->vol_desc_type[0] != 1 || pvm->vol_desc_version[0] != 1
|| pvm->file_structure_version[0] != 1 )
return(2); /* failed sanity check */
{ret= 2; goto ex;} /* failed sanity check */
if(iso_read_lsb(pvm->vol_space_size, 4) + offst != img_size)
return(2); /* Image ends do not match */
{ret= 2; goto ex;} /* Image ends do not match */
/* Now it is credible. Not yet clear is whether it is acceptable. */
o->loaded_partition_offset= offst;
@@ -423,15 +434,21 @@ static int isoburn_inspect_partition(struct isoburn *o, uint32_t img_size,
"Detected partition offset of %.f blocks. Maximum for load buffer is %d",
(double) offst, max_offst);
isoburn_msgs_submit(NULL, 0x00060000, msg, 0, "WARNING", 0);
return(3);
{ret= 3; goto ex;}
}
/* Accept partition start and adjust buffer size */
ret= isoburn_adjust_target_iso_head(o, offst, 0);
if(ret <= 0)
return(ret);
goto ex;
return(1);
ret= 1;
ex:;
if(buf != NULL)
free(buf);
if(msg != NULL)
free(msg);
return(ret);
}
@@ -449,13 +466,18 @@ int isoburn_start_emulation(struct isoburn *o, int flag)
struct burn_drive *drive;
struct ecma119_pri_vol_desc *pvm;
enum burn_disc_status s;
char path[BURN_DRIVE_ADR_LEN], msg[2 * BURN_DRIVE_ADR_LEN];
char *path= NULL, *msg= NULL;
path= calloc(1, BURN_DRIVE_ADR_LEN);
msg= calloc(1, 2 * BURN_DRIVE_ADR_LEN);
if(path == NULL || msg == NULL)
{ret= -1; goto ex;}
if(o==NULL) {
isoburn_msgs_submit(NULL, 0x00060000,
"Program error: isoburn_start_emulation: o==NULL",
0, "FATAL", 0);
return -1;
{ret= -1; goto ex;}
}
drive= o->drive;
@@ -474,7 +496,7 @@ int isoburn_start_emulation(struct isoburn *o, int flag)
s = burn_disc_get_status(drive);
o->fabricated_disc_status= s;
burn_disc_track_lba_nwa(drive, NULL, 0, &dummy, &(o->nwa));
return 1;
{ret= 1; goto ex;}
} else if (capacity > 0 || role == 2 || role == 4) {
/* Might be a block device on a system where libburn cannot determine its
size. Try to read anyway. */
@@ -500,13 +522,13 @@ int isoburn_start_emulation(struct isoburn *o, int flag)
o->fabricated_disc_status= BURN_DISC_FULL;
else if(!(flag & 1))
o->fabricated_disc_status= BURN_DISC_BLANK;
return 1;
{ret= 1; goto ex;}
}
} else {
/* No read capacity means blank media */
if(!(flag & 1))
o->fabricated_disc_status= BURN_DISC_BLANK;
return 1;
{ret= 1; goto ex;}
}
/* check first 64K. If 0's, the disc is treated as a blank disc, and thus
@@ -518,7 +540,7 @@ int isoburn_start_emulation(struct isoburn *o, int flag)
if (!i) {
if(!(flag & 1))
o->fabricated_disc_status= BURN_DISC_BLANK;
return 1;
{ret= 1; goto ex;}
}
pvm = (struct ecma119_pri_vol_desc *)(o->target_iso_head + 16 * 2048);
@@ -531,14 +553,14 @@ int isoburn_start_emulation(struct isoburn *o, int flag)
|| 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;
{ret= 1; goto ex;}
}
/* ok, PVM found, set size */
size = (off_t) iso_read_lsb(pvm->vol_space_size, 4);
ret= isoburn_inspect_partition(o, (uint32_t) size, 0);
if (ret <= 0)
return ret;
goto ex;
size *= (off_t) 2048; /* block size in bytes */
isoburn_set_start_byte(o, size, 0);
if(!(flag & 1))
@@ -554,7 +576,13 @@ int isoburn_start_emulation(struct isoburn *o, int flag)
o->fabricated_disc_status= BURN_DISC_FULL;
}
return 1;
ret= 1;
ex:;
if(path != NULL)
free(path);
if(msg != NULL)
free(msg);
return(ret);
}