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) /* @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, int Xorriso_find_sb_checksum(struct XorrisO *xorriso,
char *head_buffer, int *vd_end, int flag) char *head_buffer, int *vd_end, int flag)
@ -3049,6 +3050,7 @@ int Xorriso_find_sb_checksum(struct XorrisO *xorriso,
i++; i++;
ret= iso_util_decode_md5_tag(head_buffer + i * 2048, &tag_type, &pos, ret= iso_util_decode_md5_tag(head_buffer + i * 2048, &tag_type, &pos,
&range_start, &range_size, &next_tag, md5, 0); &range_start, &range_size, &next_tag, md5, 0);
if(((unsigned int) ret) != ISO_MD5_AREA_CORRUPTED || !(flag & 2))
if(ret <= 0) if(ret <= 0)
return(ret); return(ret);
if((flag & 1) && tag_type != 4) if((flag & 1) && tag_type != 4)
@ -3158,6 +3160,8 @@ md5_comp_failed:;
bit2= issue message about success bit2= issue message about success
bit3= check whether source blocks are banned by in_sector_map bit3= check whether source blocks are banned by in_sector_map
bit4= refresh relocated sb checksum tag 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, int Xorriso_update_iso_lba0(struct XorrisO *xorriso, int iso_lba, int isosize,
char *head_buffer, struct CheckmediajoB *job, 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) { if(flag & 16) {
/* Find relocated sb checksum tag */ /* 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(ret > 0) {
/* If it is recognizable then it matched in Xorriso_adjust_relocated_sb */ /* If it is recognizable then it matched in Xorriso_adjust_relocated_sb */
checksum_block= ret - 1; 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. Write only up to PVD end plus eventual invalidated tag.
*/ */
to_write= 2048 * 32; 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(ret > 0) {
if(!(flag & 16)) /* invalidate */ if(!(flag & 16)) /* invalidate */
memset(head_buffer + (ret - 1) * 2048, 0, 8); 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 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 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 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_info *dinfo;
struct burn_drive *drive = NULL, *in_drive = NULL; struct burn_drive *drive = NULL, *in_drive = NULL;
struct burn_multi_caps *caps= NULL; struct burn_multi_caps *caps= NULL;
@ -3671,10 +3676,26 @@ int Xorriso_truncate_overwritable(struct XorrisO *xorriso, char *adr_mode,
if(ret <= 0) { if(ret <= 0) {
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
"-truncate_overwritable: Cannot read ISO 9660 Volume Descriptor from LBA 0"); "-truncate_overwritable: Cannot read ISO 9660 Volume Descriptor from LBA 0");
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); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
goto ex; goto ex;
} }
}
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 */ /* Check for PVD at image_start_value and learn new size */
ret= Xorriso_decode_load_adr(xorriso, "-truncate_overwritable", ret= Xorriso_decode_load_adr(xorriso, "-truncate_overwritable",
adr_mode, adr_value, &image_start_mode, adr_mode, adr_value, &image_start_mode,
@ -3687,6 +3708,7 @@ int Xorriso_truncate_overwritable(struct XorrisO *xorriso, char *adr_mode,
if(ret <= 0) if(ret <= 0)
goto ex; goto ex;
if(ret != 1) { if(ret != 1) {
not_iso_9660:;
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
"-truncate_overwritable: Given address does not lead to ISO 9660 Volume Descriptor"); "-truncate_overwritable: Given address does not lead to ISO 9660 Volume Descriptor");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
@ -3701,6 +3723,7 @@ int Xorriso_truncate_overwritable(struct XorrisO *xorriso, char *adr_mode,
ret= isoburn_read_iso_head(drive, iso_lba, &new_size, head_buffer, 2); ret= isoburn_read_iso_head(drive, iso_lba, &new_size, head_buffer, 2);
if(ret <= 0) if(ret <= 0)
goto ex; goto ex;
}
ret= Xorriso_find_sb_checksum(xorriso, head_buffer, &vd_end, 0); ret= Xorriso_find_sb_checksum(xorriso, head_buffer, &vd_end, 0);
if(ret > 0) if(ret > 0)
@ -3760,13 +3783,33 @@ wrong_adjust:;
} }
/* Load first 64 kB and transfer VDs from head_buffer */ /* Load first 64 kB and transfer VDs from head_buffer */
ret= Xorriso_adjust_relocated_sb(xorriso, drive, head_buffer, &sb_buffer, 0); 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) if(ret <= 0)
goto ex; goto ex;
}
/* Patch the size and write back */ /* Patch the size and write back */
ret= Xorriso_update_iso_lba0(xorriso, iso_lba, iso_size, sb_buffer, ret= Xorriso_update_iso_lba0(xorriso, iso_lba, iso_size, sb_buffer,
NULL, 2 | 16); NULL, 2 | 16 | ((!!headless_mode) << 5));
if(ret <= 0) if(ret <= 0)
goto ex; goto ex;

View File

@ -9,7 +9,7 @@
.\" First parameter, NAME, should be all caps .\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1) .\" 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. .\" Please adjust this date whenever revising the manpage.
.\" .\"
.\" Some roff macros, for reference: .\" 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, may not be smaller than "new". Numbers may have a unit suffix: "d"=512,
"k"=1024, "s"=2048, "m"=1024k, "g"=1024m. "k"=1024, "s"=2048, "m"=1024k, "g"=1024m.
.br .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: Examples:
.br .br
Activate session 4 and enable overwriting of the blocks of younger sessions: 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 any case the result may not be smaller than "new". Numbers may
have a unit suffix: "d"=512, "k"=1024, "s"=2048, "m"=1024k, have a unit suffix: "d"=512, "k"=1024, "s"=2048, "m"=1024k,
"g"=1024m. "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: Examples:
Activate session 4 and enable overwriting of the blocks of younger Activate session 4 and enable overwriting of the blocks of younger
sessions: 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) * -chown_r sets ownership in ISO image: Manip. (line 47)
* -clone copies ISO directory tree: Insert. (line 195) * -clone copies ISO directory tree: Insert. (line 195)
* -close controls media closing: SetWrite. (line 505) * -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) * -close_filter_list bans filter registration: Filter. (line 50)
* -commit writes pending ISO image: Writing. (line 27) * -commit writes pending ISO image: Writing. (line 27)
* -commit_eject writes and ejects: Writing. (line 53) * -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) * Create, new ISO image, _definition: Methods. (line 7)
* Cylinder alignment, _definition: Bootable. (line 340) * Cylinder alignment, _definition: Bootable. (line 340)
* Cylinder size, _definition: Bootable. (line 325) * 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) * DEC Alpha SRM boot sector, production: Bootable. (line 410)
* Delete, from ISO image, -rm: Manip. (line 20) * Delete, from ISO image, -rm: Manip. (line 20)
* Delete, from ISO image, -rm_r: Manip. (line 26) * Delete, from ISO image, -rm_r: Manip. (line 26)
@ -6265,42 +6269,42 @@ Node: Manip80374
Node: CmdFind90474 Node: CmdFind90474
Node: Filter110498 Node: Filter110498
Node: Writing115120 Node: Writing115120
Node: SetWrite127375 Node: SetWrite127614
Node: Bootable158650 Node: Bootable158889
Node: Jigdo186531 Node: Jigdo186770
Node: Charset191534 Node: Charset191773
Node: Exception194863 Node: Exception195102
Node: DialogCtl200992 Node: DialogCtl201231
Node: Inquiry203594 Node: Inquiry203833
Node: Navigate214852 Node: Navigate215091
Node: Verify223559 Node: Verify223798
Node: Restore234708 Node: Restore234947
Node: Emulation246916 Node: Emulation247155
Node: Scripting257372 Node: Scripting257611
Node: Frontend265155 Node: Frontend265394
Node: Examples274781 Node: Examples275020
Node: ExDevices275959 Node: ExDevices276198
Node: ExCreate276620 Node: ExCreate276859
Node: ExDialog277920 Node: ExDialog278159
Node: ExGrowing279191 Node: ExGrowing279430
Node: ExModifying280000 Node: ExModifying280239
Node: ExBootable280510 Node: ExBootable280749
Node: ExCharset281065 Node: ExCharset281304
Node: ExPseudo281961 Node: ExPseudo282200
Node: ExCdrecord282888 Node: ExCdrecord283127
Node: ExMkisofs283208 Node: ExMkisofs283447
Node: ExGrowisofs285105 Node: ExGrowisofs285344
Node: ExException286258 Node: ExException286497
Node: ExTime286716 Node: ExTime286955
Node: ExIncBackup287174 Node: ExIncBackup287413
Node: ExRestore291200 Node: ExRestore291439
Node: ExRecovery292146 Node: ExRecovery292385
Node: Files292718 Node: Files292957
Node: Environ294052 Node: Environ294291
Node: Seealso294800 Node: Seealso295039
Node: Bugreport295517 Node: Bugreport295756
Node: Legal296108 Node: Legal296347
Node: CommandIdx297120 Node: CommandIdx297359
Node: ConceptIdx315018 Node: ConceptIdx315257
 
End Tag Table End Tag Table

View File

@ -50,7 +50,7 @@
@c man .\" First parameter, NAME, should be all caps @c man .\" First parameter, NAME, should be all caps
@c man .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection @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 .\" 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 .\" Please adjust this date whenever revising the manpage.
@c man .\" @c man .\"
@c man .\" Some roff macros, for reference: @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, may not be smaller than "new". Numbers may have a unit suffix: "d"=512,
"k"=1024, "s"=2048, "m"=1024k, "g"=1024m. "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: Examples:
@* @*
Activate session 4 and enable overwriting of the blocks of younger sessions: 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"