Introduced xorriso sector bitmap v3 with 8-byte N and S

This commit is contained in:
2024-03-17 17:09:00 +01:00
parent 73b3923f72
commit 86261b7972
3 changed files with 57 additions and 24 deletions

View File

@ -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;