Let -truncate "sbsector" "new" work even if LBA-0-superblock is damaged

This commit is contained in:
Thomas Schmitt 2023-02-24 17:28:41 +01:00
parent 6a921c7411
commit b837ff30fc
5 changed files with 132 additions and 77 deletions

View File

@ -3028,6 +3028,7 @@ int Xorriso_overwrite_iso_head(struct XorrisO *xorriso,
/* @param flag bit0= insist on tag_type 4 (relocated superblock tag)
bit1= accept tag with ISO_MD5_AREA_CORRUPTED
*/
int Xorriso_find_sb_checksum(struct XorrisO *xorriso,
char *head_buffer, int *vd_end, int flag)
@ -3049,8 +3050,9 @@ int Xorriso_find_sb_checksum(struct XorrisO *xorriso,
i++;
ret= iso_util_decode_md5_tag(head_buffer + i * 2048, &tag_type, &pos,
&range_start, &range_size, &next_tag, md5, 0);
if(ret <= 0)
return(ret);
if(((unsigned int) ret) != ISO_MD5_AREA_CORRUPTED || !(flag & 2))
if(ret <= 0)
return(ret);
if((flag & 1) && tag_type != 4)
return(0); /* No other tag type is supposed to occur before type 4 */
}
@ -3158,6 +3160,8 @@ md5_comp_failed:;
bit2= issue message about success
bit3= check whether source blocks are banned by in_sector_map
bit4= refresh relocated sb checksum tag
bit5= bit1 for Xorriso_find_sb_checksum:
accept tag with ISO_MD5_AREA_CORRUPTED
*/
int Xorriso_update_iso_lba0(struct XorrisO *xorriso, int iso_lba, int isosize,
char *head_buffer, struct CheckmediajoB *job,
@ -3255,7 +3259,8 @@ int Xorriso_update_iso_lba0(struct XorrisO *xorriso, int iso_lba, int isosize,
if(flag & 16) {
/* Find relocated sb checksum tag */
ret= Xorriso_find_sb_checksum(xorriso, head_buffer, &vd_end, 1);
ret= Xorriso_find_sb_checksum(xorriso, head_buffer, &vd_end,
1 | ((flag >> 4) & 2));
if(ret > 0) {
/* If it is recognizable then it matched in Xorriso_adjust_relocated_sb */
checksum_block= ret - 1;
@ -3271,7 +3276,7 @@ int Xorriso_update_iso_lba0(struct XorrisO *xorriso, int iso_lba, int isosize,
Write only up to PVD end plus eventual invalidated tag.
*/
to_write= 2048 * 32;
ret= Xorriso_find_sb_checksum(xorriso, head_buffer, &i, 0);
ret= Xorriso_find_sb_checksum(xorriso, head_buffer, &i, ((flag >> 4) & 2));
if(ret > 0) {
if(!(flag & 16)) /* invalidate */
memset(head_buffer + (ret - 1) * 2048, 0, 8);
@ -3625,9 +3630,9 @@ int Xorriso_truncate_overwritable(struct XorrisO *xorriso, char *adr_mode,
{
int ret, iso_lba= 0, iso_session, iso_track, iso_size= 0, image_start_mode= 0;
int old_size, new_size, blocks, was_indev= 0, checksum_block= 0, vd_end;
int readable_blocks;
int readable_blocks, headless_mode= 0, i;
char image_start_value[81], *head_buffer= NULL, iso_volid[33];
char *sb_buffer= NULL;
char *sb_buffer= NULL, *checksum_pt;
struct burn_drive_info *dinfo;
struct burn_drive *drive = NULL, *in_drive = NULL;
struct burn_multi_caps *caps= NULL;
@ -3671,36 +3676,54 @@ int Xorriso_truncate_overwritable(struct XorrisO *xorriso, char *adr_mode,
if(ret <= 0) {
sprintf(xorriso->info_text,
"-truncate_overwritable: Cannot read ISO 9660 Volume Descriptor from LBA 0");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
goto ex;
if((strcmp(adr_mode, "lba") == 0 || strcmp(adr_mode, "sbsector") == 0)
&& strcmp(adjust, "new") == 0) {
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
ret= burn_get_read_capacity(drive, &old_size, 0);
if(ret <= 0)
goto ex;
headless_mode= 1;
} else {
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
goto ex;
}
}
/* Check for PVD at image_start_value and learn new size */
ret= Xorriso_decode_load_adr(xorriso, "-truncate_overwritable",
adr_mode, adr_value, &image_start_mode,
image_start_value, 0);
if(ret <= 0)
goto ex;
ret= isoburn_get_mount_params(drive, image_start_mode, image_start_value,
&iso_lba, &iso_track, &iso_session, iso_volid,
0);
if(ret <= 0)
goto ex;
if(ret != 1) {
sprintf(xorriso->info_text,
if(headless_mode) {
iso_lba= Scanf_io_size(adr_value, 0);
ret= isoburn_read_iso_head(drive, iso_lba, &new_size, head_buffer,
2 | (1 << 12));
if(ret <= 0)
goto not_iso_9660;
} else {
/* Check for PVD at image_start_value and learn new size */
ret= Xorriso_decode_load_adr(xorriso, "-truncate_overwritable",
adr_mode, adr_value, &image_start_mode,
image_start_value, 0);
if(ret <= 0)
goto ex;
ret= isoburn_get_mount_params(drive, image_start_mode, image_start_value,
&iso_lba, &iso_track, &iso_session, iso_volid,
0);
if(ret <= 0)
goto ex;
if(ret != 1) {
not_iso_9660:;
sprintf(xorriso->info_text,
"-truncate_overwritable: Given address does not lead to ISO 9660 Volume Descriptor");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= 0; goto ex;
}
if(iso_lba >= old_size) {
sprintf(xorriso->info_text,
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= 0; goto ex;
}
if(iso_lba >= old_size) {
sprintf(xorriso->info_text,
"-truncate_overwritable: Given address is larger than current ISO size");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= 0; goto ex;
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= 0; goto ex;
}
ret= isoburn_read_iso_head(drive, iso_lba, &new_size, head_buffer, 2);
if(ret <= 0)
goto ex;
}
ret= isoburn_read_iso_head(drive, iso_lba, &new_size, head_buffer, 2);
if(ret <= 0)
goto ex;
ret= Xorriso_find_sb_checksum(xorriso, head_buffer, &vd_end, 0);
if(ret > 0)
@ -3760,13 +3783,33 @@ wrong_adjust:;
}
/* Load first 64 kB and transfer VDs from head_buffer */
ret= Xorriso_adjust_relocated_sb(xorriso, drive, head_buffer, &sb_buffer, 0);
if(ret <= 0)
goto ex;
if(headless_mode) {
Xorriso_alloc_meM(sb_buffer, char, 32 * 2048);
memcpy(sb_buffer, head_buffer, 32 * 2048);
for(i= 17; i < 32; i++)
if(strncmp(sb_buffer + i * 2048, "libisofs_sb_checksum_tag_v1", 27) == 0)
break;
if(i < 32) {
/* Convert superblock tag to provisory relocated superblock tag */
checksum_pt= sb_buffer + i * 2048;
memset(checksum_pt, 0, 2048);
sprintf(checksum_pt,
"libisofs_rlsb32_checksum_tag_v1 pos=%d range_start=0 range_size=%d",
i, i);
sprintf(checksum_pt + strlen(checksum_pt),
" session_start=%d md5=0123456789abcdef0123456789abcdef self=0123456789abcdef0123456789abcdef",
iso_lba);
}
} else {
ret= Xorriso_adjust_relocated_sb(xorriso, drive, head_buffer, &sb_buffer,
0);
if(ret <= 0)
goto ex;
}
/* Patch the size and write back */
ret= Xorriso_update_iso_lba0(xorriso, iso_lba, iso_size, sb_buffer,
NULL, 2 | 16);
NULL, 2 | 16 | ((!!headless_mode) << 5));
if(ret <= 0)
goto ex;

View File

@ -9,7 +9,7 @@
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1)
.TH XORRISO 1 "Version 1.5.5, Jan 15, 2023"
.TH XORRISO 1 "Version 1.5.5, Feb 22, 2023"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
@ -2785,6 +2785,10 @@ A number without "+" gives the overall number of bytes. In any case the result
may not be smaller than "new". Numbers may have a unit suffix: "d"=512,
"k"=1024, "s"=2048, "m"=1024k, "g"=1024m.
.br
Normally the volume descriptors at block 16 ff. have to be readable. Only with
entity "lba" or "sbsector" and adjust mode "new" it is possible to address
a session if block 16 ff. yields no valid volume descriptors.
.br
Examples:
.br
Activate session 4 and enable overwriting of the blocks of younger sessions:

View File

@ -2372,6 +2372,10 @@ File: xorriso.info, Node: Writing, Next: SetWrite, Prev: Filter, Up: Command
any case the result may not be smaller than "new". Numbers may
have a unit suffix: "d"=512, "k"=1024, "s"=2048, "m"=1024k,
"g"=1024m.
Normally the volume descriptors at block 16 ff. have to be
readable. Only with entity "lba" or "sbsector" and adjust mode
"new" it is possible to address a session if block 16 ff. yields
no valid volume descriptors.
Examples:
Activate session 4 and enable overwriting of the blocks of younger
sessions:
@ -5710,7 +5714,7 @@ File: xorriso.info, Node: CommandIdx, Next: ConceptIdx, Prev: Legal, Up: Top
* -chown_r sets ownership in ISO image: Manip. (line 47)
* -clone copies ISO directory tree: Insert. (line 195)
* -close controls media closing: SetWrite. (line 505)
* -close_damaged closes damaged track and session: Writing. (line 205)
* -close_damaged closes damaged track and session: Writing. (line 209)
* -close_filter_list bans filter registration: Filter. (line 50)
* -commit writes pending ISO image: Writing. (line 27)
* -commit_eject writes and ejects: Writing. (line 53)
@ -5963,7 +5967,7 @@ File: xorriso.info, Node: ConceptIdx, Prev: CommandIdx, Up: Top
* Create, new ISO image, _definition: Methods. (line 7)
* Cylinder alignment, _definition: Bootable. (line 340)
* Cylinder size, _definition: Bootable. (line 325)
* Damaged track and session, close, -close_damaged: Writing. (line 205)
* Damaged track and session, close, -close_damaged: Writing. (line 209)
* DEC Alpha SRM boot sector, production: Bootable. (line 410)
* Delete, from ISO image, -rm: Manip. (line 20)
* Delete, from ISO image, -rm_r: Manip. (line 26)
@ -6265,42 +6269,42 @@ Node: Manip80374
Node: CmdFind90474
Node: Filter110498
Node: Writing115120
Node: SetWrite127375
Node: Bootable158650
Node: Jigdo186531
Node: Charset191534
Node: Exception194863
Node: DialogCtl200992
Node: Inquiry203594
Node: Navigate214852
Node: Verify223559
Node: Restore234708
Node: Emulation246916
Node: Scripting257372
Node: Frontend265155
Node: Examples274781
Node: ExDevices275959
Node: ExCreate276620
Node: ExDialog277920
Node: ExGrowing279191
Node: ExModifying280000
Node: ExBootable280510
Node: ExCharset281065
Node: ExPseudo281961
Node: ExCdrecord282888
Node: ExMkisofs283208
Node: ExGrowisofs285105
Node: ExException286258
Node: ExTime286716
Node: ExIncBackup287174
Node: ExRestore291200
Node: ExRecovery292146
Node: Files292718
Node: Environ294052
Node: Seealso294800
Node: Bugreport295517
Node: Legal296108
Node: CommandIdx297120
Node: ConceptIdx315018
Node: SetWrite127614
Node: Bootable158889
Node: Jigdo186770
Node: Charset191773
Node: Exception195102
Node: DialogCtl201231
Node: Inquiry203833
Node: Navigate215091
Node: Verify223798
Node: Restore234947
Node: Emulation247155
Node: Scripting257611
Node: Frontend265394
Node: Examples275020
Node: ExDevices276198
Node: ExCreate276859
Node: ExDialog278159
Node: ExGrowing279430
Node: ExModifying280239
Node: ExBootable280749
Node: ExCharset281304
Node: ExPseudo282200
Node: ExCdrecord283127
Node: ExMkisofs283447
Node: ExGrowisofs285344
Node: ExException286497
Node: ExTime286955
Node: ExIncBackup287413
Node: ExRestore291439
Node: ExRecovery292385
Node: Files292957
Node: Environ294291
Node: Seealso295039
Node: Bugreport295756
Node: Legal296347
Node: CommandIdx297359
Node: ConceptIdx315257

End Tag Table

View File

@ -50,7 +50,7 @@
@c man .\" First parameter, NAME, should be all caps
@c man .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
@c man .\" other parameters are allowed: see man(7), man(1)
@c man .TH XORRISO 1 "Version 1.5.5, Jan 15, 2023"
@c man .TH XORRISO 1 "Version 1.5.5, Feb 22, 2023"
@c man .\" Please adjust this date whenever revising the manpage.
@c man .\"
@c man .\" Some roff macros, for reference:
@ -3252,6 +3252,10 @@ A number without "+" gives the overall number of bytes. In any case the result
may not be smaller than "new". Numbers may have a unit suffix: "d"=512,
"k"=1024, "s"=2048, "m"=1024k, "g"=1024m.
@*
Normally the volume descriptors at block 16 ff. have to be readable. Only with
entity "lba" or "sbsector" and adjust mode "new" it is possible to address
a session if block 16 ff. yields no valid volume descriptors.
@*
Examples:
@*
Activate session 4 and enable overwriting of the blocks of younger sessions:

View File

@ -1 +1 @@
#define Xorriso_timestamP "2023.02.24.080036"
#define Xorriso_timestamP "2023.02.24.162752"