Improved handling of hidden boot images in -boot_image cmd/as_mkisofs/replay

This commit is contained in:
Thomas Schmitt 2023-11-21 11:32:38 +01:00
parent 651f42955d
commit aace531ca8
4 changed files with 123 additions and 28 deletions

View File

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2022 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2023 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later.
@ -1678,6 +1678,97 @@ ex:;
}
/* Note: These macros use local variables of Xorriso_scan_report_lines() and
Xorriso_make_boot_cut_out().
*/
#define Xorriso_record_cmd_linE { \
ret= Xorriso_record_cmd_line(xorriso, buf, cmds, cmd_count, flag & 1); \
buf[0]= 0; \
if(ret <= 0) \
goto ex; \
}
#define Xorriso_record_boot_imglinE { \
ret= Xorriso_record_cmd_line(xorriso, buf, boot_imgs, boot_img_count, \
flag & 1); \
buf[0]= 0; \
if(ret <= 0) \
goto ex; \
}
/* @param flag bit0= do not record but only count
bit1= as_mkisofs
bit2= no sorry messages
*/
int Xorriso_make_boot_cut_out(struct XorrisO *xorriso,
unsigned long lba, unsigned long blocks,
char **cmds, int *cmd_count,
char *buf, int buf_size, char **path,
int flag)
{
int ret= 0, i;
char uuid_path[37 + 13];
IsoNode *node;
/* Choose a path "hidden_boot_$UUID" which must not exist yet */
for(i = 0; i < 10; i++) {
strcpy(uuid_path, "/hidden_boot_");
ret = Xorriso_make_guid(xorriso, uuid_path + 13, 1);
if(ret <= 0)
goto ex;
ret= Xorriso_get_node_by_path(xorriso, uuid_path, NULL, &node, 1);
if(ret <= 0)
break;
/* wait a short time just in case that Xorriso_make_guid() relies on time */
usleep(12345);
}
if(i >= 10) {
if(!(flag & 5)) {
sprintf(xorriso->info_text,
"Composition of -cut_out command failed because no unused file path can be found");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
}
ret= 0; goto ex;
}
/* Issue command or option for cutting out from indev */
strcpy(buf, "-cut_out ");
if(strlen(buf) + strlen(xorriso->indev) * 5 + 1 >
(unsigned long) buf_size) {
buffer_overflow:
if(!(flag & 5)) {
sprintf(xorriso->info_text,
"Composition of -cut_out command failed because it becomes too long");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
}
ret= 0; goto ex;
}
Text_shellsafe(xorriso->indev, buf, 1);
if(strlen(buf) + 1 + 11 + 1 + 11 + 1 + strlen(uuid_path) + 1 >
(unsigned long) buf_size)
goto buffer_overflow;
sprintf(buf + strlen(buf), " %lus %lus %s", lba, blocks, uuid_path);
Xorriso_record_cmd_linE
/* Issue command or option for hiding cut out file */
if(flag & 2) {
sprintf(buf, "-hide_iso_path on %s", uuid_path);
Xorriso_record_cmd_linE
} else {
sprintf(buf, "-hide on %s --", uuid_path);
Xorriso_record_cmd_linE
}
*path= strdup(uuid_path);
if(*path == NULL)
{ret= -1; goto ex;}
ret= 1;
ex:;
return(ret);
}
/* @param flag bit0= do not record but only count
bit1= as_mkisofs
bit2= no sorry messages
@ -1701,7 +1792,7 @@ static int Xorriso_scan_report_lines(struct XorrisO *xorriso,
int appended_partition= 0;
#endif
int iso_mbr_part_type= -1, iso_gpt_part_idx= -1;
int iso_mbr_part_type= -1, iso_gpt_part_idx= -1, buf_size;
unsigned int prev_pltf= 0;
unsigned long int sa_options= 0, partno, id_tag, perms, start_cyl;
unsigned long int part_status, part_type, mbr_start_block, mbr_num_blocks;
@ -1758,20 +1849,6 @@ static int Xorriso_scan_report_lines(struct XorrisO *xorriso,
struct apm_par *apms= NULL;
int apm_count= 0;
#define Xorriso_record_cmd_linE { \
ret= Xorriso_record_cmd_line(xorriso, buf, cmds, cmd_count, flag & 1); \
buf[0]= 0; \
if(ret <= 0) \
goto ex; \
}
#define Xorriso_record_boot_imglinE { \
ret= Xorriso_record_cmd_line(xorriso, buf, boot_imgs, boot_img_count, \
flag & 1); \
buf[0]= 0; \
if(ret <= 0) \
goto ex; \
}
/* 2 exp 19 blocks = 1 GiB */
#define Xorriso_max_endless_uefi_sizE (1 << 19)
@ -1784,7 +1861,8 @@ static int Xorriso_scan_report_lines(struct XorrisO *xorriso,
if(line_count <= 0)
{ret= 1; goto ex;}
Xorriso_alloc_meM(buf, char, 80 + SfileadrL);
buf_size= 80 + 5 * SfileadrL;
Xorriso_alloc_meM(buf, char, buf_size);
Xorriso_alloc_meM(lines, char *, line_count);
for(i= 0; i < et_line_count; i++)
lines[i]= et_lines[i];
@ -2853,9 +2931,22 @@ static int Xorriso_scan_report_lines(struct XorrisO *xorriso,
}
}
if (et_imgs[idx].path[0] == 0) {
/* >>> need way to exploit .extract_size by cutting out from ISO */;
if (et_imgs[idx].path[0] == 0 && et_imgs[idx].extract_size > 0) {
ret= Xorriso_make_boot_cut_out(xorriso, et_imgs[idx].lba,
et_imgs[idx].extract_size,
cmds, cmd_count,
buf, buf_size, &(et_imgs[idx].path),
flag & 7);
if(ret <= 0) {
if(!(flag & 5)) {
sprintf(xorriso->info_text,
"Cannot enable hidden EL Torito boot image #%d by a -cut_out command",
idx + 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
}
buf[0]= 0;
continue;
}
}

View File

@ -196,6 +196,8 @@ ex:;
}
/* @param flag bit0=do not complain about non existent node
*/
int Xorriso_get_node_by_path(struct XorrisO *xorriso,
char *in_path, char *eff_path,
IsoNode **node, int flag)
@ -206,7 +208,8 @@ int Xorriso_get_node_by_path(struct XorrisO *xorriso,
Xorriso_alloc_meM(path, char, SfileadrL);
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, in_path, path, 0);
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, in_path, path,
flag & 1);
if(ret<=0)
goto ex;
if(eff_path!=NULL)
@ -214,7 +217,7 @@ int Xorriso_get_node_by_path(struct XorrisO *xorriso,
ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0)
goto ex;
ret= Xorriso_node_from_path(xorriso, volume, path, node, 0);
ret= Xorriso_node_from_path(xorriso, volume, path, node, flag & 1);
if(ret<=0)
{ret= 0; goto ex;}
ret= 1;

View File

@ -1007,24 +1007,25 @@ int Xorriso_set_data_cache(struct XorrisO *xorriso, void *o,
}
/* @param flag bit0= issue hex string rather than structured text format
*/
int Xorriso_format_guid(struct XorrisO *xorriso, uint8_t guid[16], char *line,
int flag)
{
/* >>> Maybe let the user switch between hex string and structured text */;
Xorriso__format_guid(guid, line, 1);
Xorriso__format_guid(guid, line, !(flag & 1));
return(1);
}
/* @param flag bit0= issue hex string rather than structured text format
*/
int Xorriso_make_guid(struct XorrisO *xorriso, char *line, int flag)
{
uint8_t guid[16];
int ret;
iso_generate_gpt_guid(guid);
ret= Xorriso_format_guid(xorriso, guid, line, 0);
ret= Xorriso_format_guid(xorriso, guid, line, flag & 1);
return(ret);
}

View File

@ -1 +1 @@
#define Xorriso_timestamP "2023.11.20.105009"
#define Xorriso_timestamP "2023.11.21.103206"