Compare commits

...

2 Commits

2 changed files with 34 additions and 70 deletions

View File

@ -3800,17 +3800,18 @@ void iso_get_hc_sh(uint8_t *matches, uint32_t iso_image_size,
}
static
int iso_analyze_mbr_ptable(IsoImage *image, int flag)
int iso_analyze_mbr_ptable(IsoImage *image, IsoDataSource *src, int flag)
{
int i, j, ret, cyl_align_mode, part_after_image = 0;
int i, j, ret, cyl_align_mode, part_after_image = 0, ignore_part;
uint32_t start_h, start_s, start_c, end_h, end_s, end_c, sph = 0, hpc = 0;
uint32_t start_lba, num_blocks, end_chs_lba, image_size, lba, cyl_size;
uint8_t *data, pstatus, ptype, *hc_sh = NULL;
uint8_t *data, pstatus, ptype, *hc_sh = NULL, *buf = NULL;
struct iso_imported_sys_area *sai;
/* Bitmap for finding head_per_cyl and sectors_per_head. */
LIBISO_ALLOC_MEM(hc_sh, uint8_t, 32 * 63);
memset(hc_sh, 0xff, 32 * 63);
LIBISO_ALLOC_MEM(buf, uint8_t, 2048);
sai = image->imported_sa_info;
image_size = sai->image_size;
@ -3833,6 +3834,30 @@ int iso_analyze_mbr_ptable(IsoImage *image, int flag)
num_blocks = iso_read_lsb(data + 12, 4);
if (num_blocks <= 0)
continue;
/* Check whether the partition fits into size of medium */
ignore_part= ((off_t) num_blocks + (off_t) start_lba - (off_t) 1 >
(off_t) 0xffffffff);
if (!ignore_part) {
ret= src->read_block(src, start_lba / 4, buf);
if (ret != 1)
ignore_part = 1;
}
if (!ignore_part) {
lba = (start_lba + num_blocks - 1) / 4;
/* make sure not to ignore because of incomplete last 2048 block */
if (lba > 0 && (off_t) lba * (off_t) 4 + (off_t) 3 !=
(off_t) (start_lba + num_blocks - 1))
lba--;
ret= src->read_block(src, lba, buf);
if (ret != 1)
ignore_part = 1;
}
if (ignore_part) {
iso_msg_submit(image->id, ISO_GENERAL_NOTE, 0,
"Ignored non-empty MBR partition outside of medium capacity");
continue;
}
if (sph > 0) {
if (end_s != sph)
sph = 0xffffffff;
@ -3902,6 +3927,7 @@ int iso_analyze_mbr_ptable(IsoImage *image, int flag)
sai->system_area_options |= (cyl_align_mode << 8);
ret = 1;
ex:
LIBISO_FREE_MEM(buf);
LIBISO_FREE_MEM(hc_sh);
return ret;
@ -4016,7 +4042,7 @@ int iso_analyze_mbr(IsoImage *image, IsoDataSource *src, int flag)
((unsigned char *) sad)[511] != 0xaa)
{ret = 0; goto ex;}
ret = iso_analyze_mbr_ptable(image, 0);
ret = iso_analyze_mbr_ptable(image, src, 0);
if (ret <= 0)
goto ex;

View File

@ -930,27 +930,6 @@ int susp_add_ES(Ecma119Image *t, struct susp_info *susp, int to_ce, int seqno)
}
/**
* A field beginning by 0 causes rrip_write_ce_fields() to pad up to the
* next block.
*/
static
int pseudo_susp_add_PAD(Ecma119Image *t, struct susp_info *susp)
{
unsigned char *pad;
int ret;
pad = malloc(1);
if (pad == NULL)
return ISO_OUT_OF_MEM;
pad[0] = 0;
ret = susp_append_ce(t, susp, pad);
if (ret < 0)
return ret;
return ISO_SUCCESS;
}
/**
* see doc/zisofs_format.txt : "ZF System Use Entry Format"
* see doc/zisofs2_format.txt : "ZF System Use Entry Format", "Z2 ..."
@ -1166,7 +1145,7 @@ int susp_calc_nm_sl_al(Ecma119Image *t, Ecma119Node *n, size_t space,
size_t *su_size, size_t *ce, size_t base_ce, int flag)
{
char *name;
size_t namelen, su_mem, ce_mem, ce_prepad = 0;
size_t namelen, su_mem, ce_mem;
void *xipt;
size_t num_aapt = 0, sua_free = 0;
int ret;
@ -1185,21 +1164,8 @@ int susp_calc_nm_sl_al(Ecma119Image *t, Ecma119Node *n, size_t space,
if (*ce > 0 && !(flag & 1))
goto unannounced_ca;
if (flag & 2) {
if (flag & 2)
flag |= 1;
if (base_ce % BLOCK_SIZE) {
#ifdef Libisofs_ce_calc_debuG
fprintf(stderr,
"\nlibburn_DEBUG: Accounting for %d bytes CE padding : %s\n\n",
(int) (BLOCK_SIZE - (base_ce % BLOCK_SIZE)), n->node->name);
#endif /* Libisofs_ce_calc_debuG */
ce_prepad = BLOCK_SIZE - (base_ce % BLOCK_SIZE);
}
}
namelen = 0;
name = get_rr_fname(t, n->node->name);
@ -1210,10 +1176,8 @@ int susp_calc_nm_sl_al(Ecma119Image *t, Ecma119Node *n, size_t space,
if (flag & 1) {
/* Account for 28 bytes of CE field */
if (*su_size + 28 > space) {
*ce += ce_prepad;
if (*su_size + 28 > space)
return -1;
}
*su_size += 28;
}
@ -1244,10 +1208,8 @@ int susp_calc_nm_sl_al(Ecma119Image *t, Ecma119Node *n, size_t space,
int cew = (*ce != 0); /* are we writing to CA ? */
dest = get_rr_fname(t, ((IsoSymlink*)n->node)->dest);
if (dest == NULL) {
*ce += ce_prepad;
if (dest == NULL)
return -2;
}
prev = dest;
cur = strchr(prev, '/');
while (1) {
@ -1357,9 +1319,6 @@ int susp_calc_nm_sl_al(Ecma119Image *t, Ecma119Node *n, size_t space,
if (*ce > 0 && !(flag & 1))
goto unannounced_ca;
*ce += ce_prepad;
ce_prepad = 0;
/* obtain num_aapt from node */
xipt = NULL;
num_aapt = 0;
@ -1412,7 +1371,6 @@ int susp_calc_nm_sl_al(Ecma119Image *t, Ecma119Node *n, size_t space,
}
}
*ce += ce_prepad;
return 1;
unannounced_ca:;
@ -1997,26 +1955,6 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
}
if (ce_is_predicted) {
if ((info->ce_len % BLOCK_SIZE) &&
(info->ce_len + ce_len_pd - 1 ) / BLOCK_SIZE !=
info->ce_len / BLOCK_SIZE) {
/* Linux fs/isofs wants byte_offset + ce_len <= BLOCK_SIZE
* Insert padding to shift CE offset to next block start
*/
#ifdef Libisofs_ce_calc_debuG
fprintf(stderr,
"\nlibburn_DEBUG: Inserting %d bytes of CE padding : %s\n\n",
(int) (BLOCK_SIZE - (info->ce_len % BLOCK_SIZE)),
n->node->name);
#endif /* Libisofs_ce_calc_debuG */
ret = pseudo_susp_add_PAD(t, info);
if (ret < 0)
goto add_susp_cleanup;
}
/* Add the CE entry */
ret = susp_add_CE(t, ce_len_pd, info);
if (ret < 0) {