|
|
|
@ -32,8 +32,8 @@
|
|
|
|
|
|
|
|
|
|
#endif /* Xorriso_standalonE */
|
|
|
|
|
|
|
|
|
|
#include "isoburn.h"
|
|
|
|
|
#include "libisoburn.h"
|
|
|
|
|
#include "isoburn.h"
|
|
|
|
|
|
|
|
|
|
#define BP(a,b) [(b) - (a) + 1]
|
|
|
|
|
|
|
|
|
@ -299,12 +299,111 @@ int isoburn_activate_session(struct burn_drive *drive)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
ret = burn_random_access_write(drive, (off_t) 0, (char*)o->target_iso_head,
|
|
|
|
|
Libisoburn_target_head_sizE, 1);
|
|
|
|
|
o->target_iso_head_size, 1);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** TWINTREE:
|
|
|
|
|
API @since 0.6.2
|
|
|
|
|
*/
|
|
|
|
|
int isoburn_get_img_partition_offset(struct burn_drive *drive,
|
|
|
|
|
uint32_t *block_offset_2k)
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
struct isoburn *o;
|
|
|
|
|
|
|
|
|
|
ret = isoburn_find_emulator(&o, drive, 0);
|
|
|
|
|
if(ret < 0 || o == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
*block_offset_2k= o->loaded_partition_offset;
|
|
|
|
|
if(o->loaded_partition_offset == 0)
|
|
|
|
|
return(0);
|
|
|
|
|
if(o->target_iso_head_size == (off_t) Libisoburn_target_head_sizE
|
|
|
|
|
+ (off_t) 2048 * (off_t) o->loaded_partition_offset)
|
|
|
|
|
return(1);
|
|
|
|
|
return(2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* TWINTREE:
|
|
|
|
|
Check for MBR signature and a first partition that starts at a 2k block
|
|
|
|
|
and ends where the image ends.
|
|
|
|
|
If not too large or too small, accept its start as partition offset.
|
|
|
|
|
*/
|
|
|
|
|
static int isoburn_inspect_partition(struct isoburn *o, uint32_t img_size,
|
|
|
|
|
int flag)
|
|
|
|
|
{
|
|
|
|
|
uint8_t *mbr, *part, buf[2048];
|
|
|
|
|
uint32_t offst, numsec;
|
|
|
|
|
struct ecma119_pri_vol_desc *pvm;
|
|
|
|
|
off_t data_count;
|
|
|
|
|
int ret;
|
|
|
|
|
char msg[160];
|
|
|
|
|
static int max_offst= 512 - 32;
|
|
|
|
|
|
|
|
|
|
mbr= o->target_iso_head;
|
|
|
|
|
part= mbr + 446;
|
|
|
|
|
if(mbr[510] != 0x55 || mbr[511] != 0xAA)
|
|
|
|
|
return(2); /* not an MBR */
|
|
|
|
|
|
|
|
|
|
/* Does the first partition entry look credible ? */
|
|
|
|
|
if(part[0] != 0x80 && part[0] != 0x00)
|
|
|
|
|
return(2); /* Invalid partition status */
|
|
|
|
|
if(part[1] == 0 && part[2] == 0 && part[3] == 0)
|
|
|
|
|
return(2); /* 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 */
|
|
|
|
|
if((offst % 4) || (numsec % 4))
|
|
|
|
|
return(2); /* Not aligned to 2k */
|
|
|
|
|
if(numsec < 72)
|
|
|
|
|
return(2); /* No room for volume descriptors */
|
|
|
|
|
offst/= 4;
|
|
|
|
|
numsec/= 4;
|
|
|
|
|
if(offst + numsec != img_size)
|
|
|
|
|
return(2); /* 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);
|
|
|
|
|
pvm = (struct ecma119_pri_vol_desc *) buf;
|
|
|
|
|
if (strncmp((char*) pvm->std_identifier, "CD001", 5) != 0)
|
|
|
|
|
return(2); /* 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 */
|
|
|
|
|
|
|
|
|
|
if(iso_read_lsb(pvm->vol_space_size, 4) + offst != img_size)
|
|
|
|
|
return(2); /* Image ends do not match */
|
|
|
|
|
|
|
|
|
|
/* Now it is credible. Not yet clear is whether it is acceptable. */
|
|
|
|
|
o->loaded_partition_offset= offst;
|
|
|
|
|
|
|
|
|
|
/* If the partition start is too large: Report but do not accept. */
|
|
|
|
|
if(offst > max_offst) { /* Not more than 1 MB of .target_iso_head */
|
|
|
|
|
sprintf(msg,
|
|
|
|
|
"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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Accept partition start and adjust buffer size */
|
|
|
|
|
ret= isoburn_adjust_target_iso_head(o, offst, 0);
|
|
|
|
|
if(ret <= 0)
|
|
|
|
|
return(ret);
|
|
|
|
|
|
|
|
|
|
return(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Initialize the emulation of multi-session on random access media.
|
|
|
|
|
The need for emulation is confirmed already.
|
|
|
|
|
@param o A freshly created isoburn object. isoburn_create_data_source() was
|
|
|
|
@ -337,8 +436,8 @@ int isoburn_start_emulation(struct isoburn *o, int flag)
|
|
|
|
|
if (capacity > 0 || role == 2) {
|
|
|
|
|
/* Might be a block device on a system where libburn cannot determine its
|
|
|
|
|
size. Try to read anyway. */
|
|
|
|
|
memset(o->target_iso_head, 0, Libisoburn_target_head_sizE);
|
|
|
|
|
to_read = Libisoburn_target_head_sizE;
|
|
|
|
|
to_read = o->target_iso_head_size;
|
|
|
|
|
memset(o->target_iso_head, 0, to_read);
|
|
|
|
|
if(capacity > 0 && (off_t) capacity * (off_t) 2048 < to_read)
|
|
|
|
|
to_read = (off_t) capacity * (off_t) 2048;
|
|
|
|
|
ret = burn_read_data(drive, (off_t) 0, (char*)o->target_iso_head,
|
|
|
|
@ -370,7 +469,7 @@ int isoburn_start_emulation(struct isoburn *o, int flag)
|
|
|
|
|
|
|
|
|
|
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) == 0) {
|
|
|
|
|
off_t size;
|
|
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
@ -383,6 +482,9 @@ int isoburn_start_emulation(struct isoburn *o, int flag)
|
|
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
size *= (off_t) 2048; /* block size in bytes */
|
|
|
|
|
isoburn_set_start_byte(o, size, 0);
|
|
|
|
|
o->fabricated_disc_status= BURN_DISC_APPENDABLE;
|
|
|
|
@ -395,6 +497,7 @@ int isoburn_start_emulation(struct isoburn *o, int flag)
|
|
|
|
|
/* treat any disc in an unknown format as full */
|
|
|
|
|
o->fabricated_disc_status= BURN_DISC_FULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|