From 86261b79721ec4181988e34626ecc016b064e690 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Sun, 17 Mar 2024 17:09:00 +0100 Subject: [PATCH] Introduced xorriso sector bitmap v3 with 8-byte N and S --- xorriso/README_gnu_xorriso | 17 +++++----- xorriso/check_media.c | 62 +++++++++++++++++++++++++++---------- xorriso/xorriso_timestamp.h | 2 +- 3 files changed, 57 insertions(+), 24 deletions(-) diff --git a/xorriso/README_gnu_xorriso b/xorriso/README_gnu_xorriso index b5ab6544..d32e0851 100644 --- a/xorriso/README_gnu_xorriso +++ b/xorriso/README_gnu_xorriso @@ -323,14 +323,17 @@ Sector maps describe the valid and invalid blocks on a media or a disk copy of a media. xorriso creates and reads these file with its option -check_media. The file begins with 32 bytes of cleartext of which the last one is a -newline character. The first 25 say "xorriso sector bitmap v2 ", the -remaining six characters give the size of the info text as decimal number. +newline character. The first 25 say "xorriso sector bitmap v2 " or +"xorriso sector bitmap v3 ". The remaining six characters give the size +of the info text as decimal number. This number of bytes follows the first 32 and will not be interpreted by xorriso. They are rather to inform a human reader about the media type and its track layout. -After the info text there are two 4 byte signed integers, most significant -byte first. The first one, N, gives the number of bits in the following bitmap -and the second number S gives the number of 2 KiB blocks governed by a single +After the info text there are two signed integers, most significant byte +first. The number of bytes per integer is 4 for "v2" and 8 for "v3". +In both cases, the highest bit of the integers must be 0. +The first integer, N, gives the number of bits in the following bitmap. +The second number, S, gives the number of 2 KiB blocks governed by a single bit in the map. Then come the bits in form of 8-bit bytes. Data block M is covered by bit B=M/S in the map, bit number B is stored in byte B/8 as bit B%8. A valid readable data block has its bit set to 1. @@ -521,7 +524,7 @@ By Mario Danic , libburn, libisofs Vreixo Formoso , libisofs, libisoburn Thomas Schmitt , libburn, libisofs, libisoburn, xorriso -Copyright (C) 2006-2023 Mario Danic, Vreixo Formoso, Thomas Schmitt. +Copyright (C) 2006-2024 Mario Danic, Vreixo Formoso, Thomas Schmitt. libburnia-project.org is inspired by and in libburn still containing parts of old @@ -540,7 +543,7 @@ Copyright (C) 2019-2021 Nio Wiklund alias sudodus, Thomas Schmitt ------------------------------------------------------------------------------ This text itself is -Copyright (c) 2007 - 2023 Thomas Schmitt +Copyright (c) 2007 - 2024 Thomas Schmitt and is freely distributable. It shall only be modified in sync with the technical properties of xorriso. If you make use of the license to derive modified versions of xorriso diff --git a/xorriso/check_media.c b/xorriso/check_media.c index d1422eaa..f85fd210 100644 --- a/xorriso/check_media.c +++ b/xorriso/check_media.c @@ -323,7 +323,8 @@ wrong_filetype:; } if(strncmp((char *) buf, "xorriso sector bitmap v1 ", 32) == 0) /* ok */; - else if(strncmp((char *) buf, "xorriso sector bitmap v2 ", 25) == 0) { + else if(strncmp((char *) buf, "xorriso sector bitmap v2 ", 25) == 0 || + strncmp((char *) buf, "xorriso sector bitmap v3 ", 25) == 0) { skip= -1; sscanf(((char *) buf) + 25, "%d", &skip); if(skip < 0) @@ -338,13 +339,28 @@ wrong_filetype:; } } else {ret= 0; goto wrong_filetype;} - ret= read(fd, buf, 8); - if(ret < 4) - goto wrong_filetype; - sectors= (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; - sector_size= (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]; - if(sectors <= 0 || sector_size <= 0) - goto wrong_filetype; + if(strncmp((char *) buf, "xorriso sector bitmap v2 ", 25) == 0) { + ret= read(fd, buf, 8); + if(ret < 8) + goto wrong_filetype; + if((buf[0] & 128) || (buf[4] & 128)) + goto wrong_filetype; + sectors= (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; + sector_size= (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]; + } else { + ret= read(fd, buf, 16); + if(ret < 16) + goto wrong_filetype; + if((buf[0] & 128) || (buf[8] & 128)) + goto wrong_filetype; + /* (My compiler hates off_t = 1 << 32. So i do it by multiplication) */ + sectors= ((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]) * + (off_t) 0x100000000; + sectors|= (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]; + sector_size= ((buf[8] << 24) | (buf[9] << 16) | (buf[10] << 8) | buf[11]) * + (off_t) 0x100000000; + sector_size|= (buf[12] << 24) | (buf[13] << 16) | (buf[14] << 8) | buf[15]; + } ret= Sectorbitmap_new(o, sectors, sector_size, 0); if(ret <= 0) { if(msg != NULL) @@ -378,7 +394,8 @@ ex:; int Sectorbitmap_to_file(struct SectorbitmaP *o, char *path, char *info, char *msg, int *os_errno, int flag) { - int ret, fd= -1, j, l; + int fd= -1, j, l, version= 2; + ssize_t ret; unsigned char buf[40]; *os_errno= 0; @@ -392,6 +409,8 @@ int Sectorbitmap_to_file(struct SectorbitmaP *o, char *path, char *info, ret= 0; goto ex; } + if(o->sectors > 0x7fffffff || o->sector_size > 0x7fffffff) + version= 3; l= 0; if(info != NULL) l= strlen(info); @@ -399,7 +418,7 @@ int Sectorbitmap_to_file(struct SectorbitmaP *o, char *path, char *info, strcpy(msg, "Info string is longer than 999999 bytes"); ret= 0; goto ex; } - sprintf((char *) buf, "xorriso sector bitmap v2 %-6d\n", l); + sprintf((char *) buf, "xorriso sector bitmap v%d %-6d\n", version, l); ret= write(fd, buf, 32); if(ret != 32) { @@ -417,13 +436,24 @@ cannot_write:; goto cannot_write; } - for(j= 0; j < 4; j++) { - buf[j]= o->sectors >> (24 - j * 8); - buf[j+4]= o->sector_size >> (24 - j * 8); + if(version == 2) { + for(j= 0; j < 4; j++) { + buf[j]= o->sectors >> (24 - j * 8); + buf[j + 4]= o->sector_size >> (24 - j * 8); + } + ret= write(fd, buf, 8); + if(ret != 8) + goto cannot_write; + } else { + for(j= 0; j < 8; j++) { + buf[j]= o->sectors >> (56 - j * 8); + buf[j + 8]= o->sector_size >> (56 - j * 8); + } + ret= write(fd, buf, 16); + if(ret != 16) + goto cannot_write; } - ret= write(fd, buf, 8); - if(ret != 8) - goto cannot_write; + ret= write(fd, o->map, o->map_size); if(ret != o->map_size) goto cannot_write; diff --git a/xorriso/xorriso_timestamp.h b/xorriso/xorriso_timestamp.h index 2658e7bf..7995eeb2 100644 --- a/xorriso/xorriso_timestamp.h +++ b/xorriso/xorriso_timestamp.h @@ -1 +1 @@ -#define Xorriso_timestamP "2024.03.17.152556" +#define Xorriso_timestamP "2024.03.17.160830"