"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "libisofs/system_area.c" between
xorriso-1.4.6.tar.gz and xorriso-1.4.8.tar.gz

About: GNU xorriso creates, loads, manipulates and writes ISO 9660 filesystem images with Rock Ridge extensions. It is suitable for incremental data backup and for production of bootable ISO 9660 images. GNU xorriso is a statical compilation of the libraries libburn, libisofs, libisoburn, and libjte.

system_area.c  (xorriso-1.4.6):system_area.c  (xorriso-1.4.8)
/* /*
* Copyright (c) 2008 Vreixo Formoso * Copyright (c) 2008 Vreixo Formoso
* Copyright (c) 2010 - 2016 Thomas Schmitt * Copyright (c) 2010 - 2017 Thomas Schmitt
* *
* This file is part of the libisofs project; you can redistribute it and/or * This file is part of the libisofs project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2 * modify it under the terms of the GNU General Public License version 2
* or later as published by the Free Software Foundation. * or later as published by the Free Software Foundation.
* See COPYING file for details. * See COPYING file for details.
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "../config.h" #include "../config.h"
#endif #endif
skipping to change at line 108 skipping to change at line 108
*end_head = secs / sph; *end_head = secs / sph;
*end_sec = secs - *end_head * sph + 1; /* Sector count starts by 1 */ *end_sec = secs - *end_head * sph + 1; /* Sector count starts by 1 */
if (*end_cyl >= 1024) { if (*end_cyl >= 1024) {
*end_cyl = 1023; *end_cyl = 1023;
*end_head = hpc - 1; *end_head = hpc - 1;
*end_sec = sph; *end_sec = sph;
} }
} }
/* @param flag bit0= The path contains instructions for the interval reader /* @param flag bit0= The path contains instructions for the interval reader
@return ISO_SUCCESS = ok, partition will be written
ISO_SUCCESS + 1 = interval which shall be kept in place
else : error code
*/ */
static int compute_partition_size(Ecma119Image *t, char *disk_path, static int compute_partition_size(Ecma119Image *t, char *disk_path,
uint32_t *size, int flag) uint32_t *size, int flag)
{ {
int ret; int ret, keep;
off_t num; off_t num;
struct stat stbuf; struct stat stbuf;
struct iso_interval_reader *ivr; struct iso_interval_reader *ivr;
off_t byte_count; off_t byte_count;
if (flag & 1) { if (flag & 1) {
ret = iso_interval_reader_new(t->image, disk_path, ret = iso_interval_reader_new(t->image, disk_path,
&ivr, &byte_count, 0); &ivr, &byte_count, 0);
if (ret < 0) if (ret < 0)
return ret; return ret;
*size = (byte_count + BLOCK_SIZE - 1) / BLOCK_SIZE; *size = (byte_count + BLOCK_SIZE - 1) / BLOCK_SIZE;
keep = iso_interval_reader_keep(t, ivr, 0);
iso_interval_reader_destroy(&ivr, 0); iso_interval_reader_destroy(&ivr, 0);
return ISO_SUCCESS; if (keep < 0)
return keep;
return ISO_SUCCESS + (keep > 0);
} }
*size = 0; *size = 0;
ret = stat(disk_path, &stbuf); ret = stat(disk_path, &stbuf);
if (ret == -1) if (ret == -1)
return ISO_BAD_PARTITION_FILE; return ISO_BAD_PARTITION_FILE;
if (! S_ISREG(stbuf.st_mode)) if (! S_ISREG(stbuf.st_mode))
return ISO_BAD_PARTITION_FILE; return ISO_BAD_PARTITION_FILE;
num = ((stbuf.st_size + 2047) / 2048); num = ((stbuf.st_size + 2047) / 2048);
if (num > 0x3fffffff || num == 0) if (num > 0x3fffffff || num == 0)
skipping to change at line 148 skipping to change at line 154
return ISO_SUCCESS; return ISO_SUCCESS;
} }
/* Compute size and position of appended partitions. /* Compute size and position of appended partitions.
@param flag bit0= Partitions inside ISO : update t->curblock @param flag bit0= Partitions inside ISO : update t->curblock
*/ */
int iso_compute_append_partitions(Ecma119Image *t, int flag) int iso_compute_append_partitions(Ecma119Image *t, int flag)
{ {
int ret, i, sa_type, cyl_align, cyl_size = 0; int ret, i, sa_type, cyl_align, cyl_size = 0;
uint32_t pos, size, add_pos = 0; uint32_t pos, size, add_pos = 0;
off_t start_byte, byte_count;
sa_type = (t->system_area_options >> 2) & 0x3f; sa_type = (t->system_area_options >> 2) & 0x3f;
cyl_align = (t->system_area_options >> 8) & 0x3; cyl_align = (t->system_area_options >> 8) & 0x3;
if (sa_type == 0 && cyl_align == 3) { if (sa_type == 0 && cyl_align == 3) {
cyl_size = t->partition_heads_per_cyl * t->partition_secs_per_head; cyl_size = t->partition_heads_per_cyl * t->partition_secs_per_head;
if (cyl_size % 4) if (cyl_size % 4)
cyl_size = 0; cyl_size = 0;
else else
cyl_size /= 4; cyl_size /= 4;
} }
pos = (t->vol_space_size + t->opts->ms_block); pos = (t->vol_space_size + t->opts->ms_block);
for (i = 0; i < ISO_MAX_PARTITIONS; i++) { for (i = 0; i < ISO_MAX_PARTITIONS; i++) {
if (t->opts->appended_partitions[i] == NULL) if (t->opts->appended_partitions[i] == NULL)
continue; continue;
if (t->opts->appended_partitions[i][0] == 0) if (t->opts->appended_partitions[i][0] == 0)
continue; continue;
ret = compute_partition_size(t, t->opts->appended_partitions[i], &size, ret = compute_partition_size(t, t->opts->appended_partitions[i], &size,
t->opts->appended_part_flags[i]); t->opts->appended_part_flags[i]);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ret == ISO_SUCCESS + 1) {
/* Interval from imported_iso in add-on session */
t->appended_part_prepad[i] = 0;
ret = iso_interval_reader_start_size(t,
t->opts->appended_partitions[i],
&start_byte, &byte_count, 0);
if (ret < 0)
return ret;
t->appended_part_start[i] = start_byte / 2048;
t->appended_part_size[i] = size;
t->opts->iso_mbr_part_type = 0;
continue;
}
add_pos = 0; add_pos = 0;
if (sa_type == 3 && (pos % ISO_SUN_CYL_SIZE)) { if (sa_type == 3 && (pos % ISO_SUN_CYL_SIZE)) {
add_pos = ISO_SUN_CYL_SIZE - (pos % ISO_SUN_CYL_SIZE); add_pos = ISO_SUN_CYL_SIZE - (pos % ISO_SUN_CYL_SIZE);
} else if (cyl_size > 0 && (pos % cyl_size)) { } else if (cyl_size > 0 && (pos % cyl_size)) {
add_pos = cyl_size - (pos % cyl_size); add_pos = cyl_size - (pos % cyl_size);
} }
t->appended_part_prepad[i] = add_pos; t->appended_part_prepad[i] = add_pos;
t->appended_part_start[i] = pos + add_pos; t->appended_part_start[i] = pos + add_pos;
if (cyl_size > 0 && (size % cyl_size)) { if (cyl_size > 0 && (size % cyl_size)) {
/* Obey cylinder alignment (missing data will be written as /* Obey cylinder alignment (missing data will be written as
zeros by iso_write_partition_file()) */ zeros by iso_write_partition_file()) */
size += cyl_size - (size % cyl_size); size += cyl_size - (size % cyl_size);
} }
t->appended_part_size[i] = size; t->appended_part_size[i] = size;
pos += add_pos + size; pos += add_pos + size;
t->total_size += (add_pos + size) * 2048; t->total_size += (((off_t) add_pos) + size) * 2048;
if (flag & 1) if (flag & 1)
t->curblock = pos; t->curblock = pos;
} }
return ISO_SUCCESS; return ISO_SUCCESS;
} }
static int mbr_part_slot_is_unused(uint8_t *slot)
{
int i;
for (i = 0; i < 16; i++)
if (slot[i] != 0)
break;
if (i >= 16)
return 1;
return 0;
}
/* @param flag /* @param flag
bit1= partition_offset and partition_size are counted in bit1= partition_offset and partition_size are counted in
blocks of 512 rather than 2048 blocks of 512 rather than 2048
*/ */
static int write_mbr_partition_entry(int partition_number, int partition_type, static int write_mbr_partition_entry(int partition_number, int partition_type,
uint64_t partition_offset, uint64_t partition_size, uint64_t partition_offset, uint64_t partition_size,
int sph, int hpc, uint8_t *buf, int flag) int sph, int hpc, uint8_t *buf, int flag)
{ {
uint8_t *wpt; uint8_t *wpt;
uint32_t end_lba, end_sec, end_head, end_cyl; uint32_t end_lba, end_sec, end_head, end_cyl;
skipping to change at line 285 skipping to change at line 318
/* 1) Zero-fill 446-510 */ /* 1) Zero-fill 446-510 */
wpt = buf + 446; wpt = buf + 446;
memset(wpt, 0, 64); memset(wpt, 0, 64);
if (!(flag & 1)) { if (!(flag & 1)) {
/* 2) Put 0x55, 0xAA into 510-512 (actually 510-511) */ /* 2) Put 0x55, 0xAA into 510-512 (actually 510-511) */
buf[510] = 0x55; buf[510] = 0x55;
buf[511] = 0xAA; buf[511] = 0xAA;
} }
if (!(flag & 2)) { if ((!(flag & 2)) && part_type != 0xee && part_type != 0xef) {
/* 3) Put 0x80 (for bootable partition), */ /* 3) Put 0x80 (for bootable partition), */
*(wpt++) = 0x80; *(wpt++) = 0x80;
} else { } else {
*(wpt++) = 0; *(wpt++) = 0;
} }
/* 0, 2, 0 (C/H/S of the start), */ /* 0, 2, 0 (C/H/S of the start), */
*(wpt++) = 0; *(wpt++) = 0;
*(wpt++) = 2; *(wpt++) = 2;
*(wpt++) = 0; *(wpt++) = 0;
skipping to change at line 1746 skipping to change at line 1779
static void iso_dummy_mbr_partition(uint8_t *buf, int mode) static void iso_dummy_mbr_partition(uint8_t *buf, int mode)
{ {
int i; int i;
/* bootable , start 0/0/1, type 0x00, end 0/0/1, /* bootable , start 0/0/1, type 0x00, end 0/0/1,
start LBA 0, block count 1 */ start LBA 0, block count 1 */
static uint8_t dummy_entry[16] = { static uint8_t dummy_entry[16] = {
0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 }; 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (buf[446 + 16 * i + 4] == 0x00) { if (mbr_part_slot_is_unused(buf + 446 + 16 * i)) {
memcpy(buf + 446 + 16 * i, dummy_entry, 16); memcpy(buf + 446 + 16 * i, dummy_entry, 16);
return; return;
} }
} }
/* Abundance of 0xee and 0xef partitions. No other one free. */ /* Abundance of 0xee and 0xef partitions. No other one free. */
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (buf[446 + 16 * i + 4] != 0xef) { if (buf[446 + 16 * i + 4] != 0xef) {
buf[446 + 16 * i] |= 0x80; buf[446 + 16 * i] |= 0x80;
return; return;
} }
skipping to change at line 1886 skipping to change at line 1919
if (sa_type == 0 && (t->system_area_options & 1)) { if (sa_type == 0 && (t->system_area_options & 1)) {
if (t->mbr_req_count == 0){ if (t->mbr_req_count == 0){
/* Write GRUB protective msdos label, i.e. a simple partition /* Write GRUB protective msdos label, i.e. a simple partition
table */ table */
if (t->gpt_req_count > 0 && ! t->opts->part_like_isohybrid) { if (t->gpt_req_count > 0 && ! t->opts->part_like_isohybrid) {
part_type = 0xee; part_type = 0xee;
pml_blocks = gpt_blocks; pml_blocks = gpt_blocks;
} else { } else {
part_type = 0xcd; part_type = 0xcd;
if (t->opts->iso_mbr_part_type >= 0 &&
t->opts->iso_mbr_part_type <= 255)
part_type= t->opts->iso_mbr_part_type;
pml_blocks = img_blocks; pml_blocks = img_blocks;
} }
ret = make_grub_msdos_label(pml_blocks, t->partition_secs_per_head, ret = make_grub_msdos_label(pml_blocks, t->partition_secs_per_head,
t->partition_heads_per_cyl, t->partition_heads_per_cyl,
(uint8_t) part_type, buf, 0); (uint8_t) part_type, buf, 0);
if (ret != ISO_SUCCESS) /* error should never happen */ if (ret != ISO_SUCCESS) /* error should never happen */
return ISO_ASSERT_FAILURE; return ISO_ASSERT_FAILURE;
risk_of_ee = 1; risk_of_ee = 1;
} else if (t->gpt_req_count > 0) { } else if (t->gpt_req_count > 0) {
skipping to change at line 1910 skipping to change at line 1946
/* Patch externally provided system area as isohybrid MBR */ /* Patch externally provided system area as isohybrid MBR */
if (t->catalog == NULL || t->system_area_data == NULL) { if (t->catalog == NULL || t->system_area_data == NULL) {
/* isohybrid makes only sense together with ISOLINUX boot image /* isohybrid makes only sense together with ISOLINUX boot image
and externally provided System Area. and externally provided System Area.
*/ */
return ISO_ISOLINUX_CANT_PATCH; return ISO_ISOLINUX_CANT_PATCH;
} }
if (gpt_count > 0 || apm_count > 0) if (gpt_count > 0 || apm_count > 0)
part_type = 0x00; part_type = 0x00;
else else {
part_type = 0x17; part_type = 0x17;
if (t->opts->iso_mbr_part_type >= 0 &&
t->opts->iso_mbr_part_type <= 255)
part_type= t->opts->iso_mbr_part_type;
}
if (t->opts->appended_as_gpt && t->have_appended_partitions) { if (t->opts->appended_as_gpt && t->have_appended_partitions) {
part_type = 0xee; part_type = 0xee;
risk_of_ee = 1; risk_of_ee = 1;
img_blocks = gpt_blocks; img_blocks = gpt_blocks;
no_boot_mbr = 2; no_boot_mbr = 2;
} }
/* >>> ??? Why is partition_offset 0 here ? /* >>> ??? Why is partition_offset 0 here ?
It gets adjusted later by iso_offset_partition_start() It gets adjusted later by iso_offset_partition_start()
skipping to change at line 1953 skipping to change at line 1993
ret = make_hppa_palo_sector(t, buf, sa_type, 0); ret = make_hppa_palo_sector(t, buf, sa_type, 0);
if (ret != ISO_SUCCESS) if (ret != ISO_SUCCESS)
return ret; return ret;
} else if (sa_type == 6) { } else if (sa_type == 6) {
ret = make_dec_alpha_sector(t, buf, 0); ret = make_dec_alpha_sector(t, buf, 0);
if (ret != ISO_SUCCESS) if (ret != ISO_SUCCESS)
return ret; return ret;
} else if ((t->opts->partition_offset > 0 || will_append) && } else if ((t->opts->partition_offset > 0 || will_append) &&
sa_type == 0 && t->mbr_req_count == 0) { sa_type == 0 && t->mbr_req_count == 0) {
/* Write a simple partition table. */ /* Write a simple partition table. */
part_type = 0xcd;
if (t->opts->iso_mbr_part_type >= 0 &&
t->opts->iso_mbr_part_type <= 255)
part_type= t->opts->iso_mbr_part_type;
ret = make_grub_msdos_label(img_blocks, t->partition_secs_per_head, ret = make_grub_msdos_label(img_blocks, t->partition_secs_per_head,
t->partition_heads_per_cyl, t->partition_heads_per_cyl,
(uint8_t) 0xcd, buf, 2); (uint8_t) part_type, buf, 2);
if (ret != ISO_SUCCESS) /* error should never happen */ if (ret != ISO_SUCCESS) /* error should never happen */
return ISO_ASSERT_FAILURE; return ISO_ASSERT_FAILURE;
risk_of_ee = 1; risk_of_ee = 1;
if (t->opts->appended_as_gpt && t->have_appended_partitions) { if (t->opts->appended_as_gpt && t->have_appended_partitions) {
/* >>> ??? Do this in any case of t->gpt_req_count > ? */; /* >>> ??? Do this in any case of t->gpt_req_count > ? */;
/* Re-write partion entry 1 : protective MBR for GPT */ /* Re-write partion entry 1 : protective MBR for GPT */
part_type = 0xee; part_type = 0xee;
risk_of_ee = 1; risk_of_ee = 1;
ret = write_mbr_partition_entry(1, part_type, ret = write_mbr_partition_entry(1, part_type,
(uint64_t) 1, ((uint64_t) gpt_blocks) * 4 - 1, (uint64_t) 1, ((uint64_t) gpt_blocks) * 4 - 1,
t->partition_secs_per_head, t->partition_heads_per_cyl, t->partition_secs_per_head, t->partition_heads_per_cyl,
buf, 2); buf, 2);
if (ret < 0) if (ret < 0)
return ret; return ret;
} else if (t->opts->partition_offset == 0) { } else if (t->opts->partition_offset == 0) {
/* Re-write partion entry 1 : start at 0, type Linux */ /* Re-write partion entry 1 : start at 0, type Linux */
blk = ((uint64_t) img_blocks) * 4 - t->post_iso_part_pad / 512; blk = ((uint64_t) img_blocks) * 4 - t->post_iso_part_pad / 512;
ret = write_mbr_partition_entry(1, 0x83, (uint64_t) 0, blk, part_type = 0x83;
if (t->opts->iso_mbr_part_type >= 0 &&
t->opts->iso_mbr_part_type <= 255)
part_type= t->opts->iso_mbr_part_type;
ret = write_mbr_partition_entry(1, part_type, (uint64_t) 0, blk,
t->partition_secs_per_head, t->partition_heads_per_cyl, t->partition_secs_per_head, t->partition_heads_per_cyl,
buf, 2); buf, 2);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
} }
if (t->opts->partition_offset > 0 && sa_type == 0 && if (t->opts->partition_offset > 0 && sa_type == 0 &&
t->mbr_req_count == 0) { t->mbr_req_count == 0) {
/* Adjust partition table to partition offset. /* Adjust partition table to partition offset.
skipping to change at line 2049 skipping to change at line 2097
wpt = buf + Libisofs_grub2_mbr_patch_poS; wpt = buf + Libisofs_grub2_mbr_patch_poS;
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
wpt[i] = blk >> (i * 8); wpt[i] = blk >> (i * 8);
} }
/* Prevent partition type 0xee if no GPT emerged */ /* Prevent partition type 0xee if no GPT emerged */
/* >>> ??? check for GPT magic number at byte 512 ff. ? */; /* >>> ??? check for GPT magic number at byte 512 ff. ? */;
if (sa_type == 0 && ((t->system_area_options & 3) || risk_of_ee) && if (sa_type == 0 && ((t->system_area_options & 3) || risk_of_ee) &&
(t->opts->part_like_isohybrid || t->gpt_req_count == 0)) { (t->opts->part_like_isohybrid || t->gpt_req_count == 0) &&
t->opts->iso_mbr_part_type != 0xee) {
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (buf[446 + 16 * i + 4] == 0xee) { if (buf[446 + 16 * i + 4] == 0xee) {
iso_msgs_submit(0, iso_msgs_submit(0,
"Prevented partition type 0xEE in MBR without GPT", "Prevented partition type 0xEE in MBR without GPT",
0, "WARNING", 0); 0, "WARNING", 0);
buf[446 + 16 * i + 4] = 0xcd; part_type = 0xcd;
if (t->opts->iso_mbr_part_type >= 0 &&
t->opts->iso_mbr_part_type <= 255)
part_type= t->opts->iso_mbr_part_type;
buf[446 + 16 * i + 4] = (uint8_t) part_type;
} }
} }
} }
if (sa_type == 0 && ( if (sa_type == 0 && (
(t->system_area_options & 3) || (t->system_area_options & 3) ||
(t->system_area_options & (1 << 14)) || (t->system_area_options & (1 << 14)) ||
(((t->system_area_options >> 2) & 0x3f) == 2 && (((t->system_area_options >> 10) & 15) != 1 &&
(t->system_area_options & (1 << 15))) (t->system_area_options & (1 << 15)))
)) { )) {
/* This is an MBR which shall have a bootable/active flag /* This is an MBR which shall have a bootable/active flag
protective-msdos-label, isohybrid, grub2-mbr, mbr-force-bootable protective-msdos-label, isohybrid, grub2-mbr, mbr-force-bootable
*/ */
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
if (buf[446 + 16 * i] & 0x80) if (buf[446 + 16 * i] & 0x80)
break; break;
if (i >= 4) { /* no bootable/active flag set yet */ if (i >= 4) { /* no bootable/active flag set yet */
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (buf[446 + 16 * i + 4] != 0x00 && if ((!mbr_part_slot_is_unused(buf + 446 + 16 * i)) &&
buf[446 + 16 * i + 4] != 0xee && buf[446 + 16 * i + 4] != 0xee &&
buf[446 + 16 * i + 4] != 0xef) { buf[446 + 16 * i + 4] != 0xef) {
buf[446 + 16 * i] |= 0x80; buf[446 + 16 * i] |= 0x80;
break; break;
} }
} }
if (i >= 4) { /* still no bootable/active flag set */ if (i >= 4) { /* still no bootable/active flag set */
if (t->system_area_options & (1 << 15)) /* Force it */ if (t->system_area_options & (1 << 15)) /* Force it */
iso_dummy_mbr_partition(buf, 0); iso_dummy_mbr_partition(buf, 0);
} }
} }
} }
if ((((t->system_area_options >> 2) & 0x3f) == 0 &&
(t->system_area_options & 3) == 1) ||
t->opts->partition_offset > 0) {
/* Protective MBR || partition offset */
/* ISO will not be a partition. It can span the whole image. */
t->pvd_size_is_total_size = 1;
}
return ISO_SUCCESS; return ISO_SUCCESS;
} }
/* Choose *heads_per_cyl so that /* Choose *heads_per_cyl so that
- *heads_per_cyl * secs_per_head * 1024 >= imgsize / 512 - *heads_per_cyl * secs_per_head * 1024 >= imgsize / 512
- *heads_per_cyl * secs_per_head is divisible by 4 - *heads_per_cyl * secs_per_head is divisible by 4
- it is as small as possible (to reduce alignment overhead) - it is as small as possible (to reduce alignment overhead)
- it is <= 255 - it is <= 255
@return 1= success , 0= cannot achieve goals @return 1= success , 0= cannot achieve goals
*/ */
skipping to change at line 2439 skipping to change at line 2500
{ {
static uint8_t basic_data_uuid[16] = { static uint8_t basic_data_uuid[16] = {
0xa2, 0xa0, 0xd0, 0xeb, 0xe5, 0xb9, 0x33, 0x44, 0xa2, 0xa0, 0xd0, 0xeb, 0xe5, 0xb9, 0x33, 0x44,
0x87, 0xc0, 0x68, 0xb6, 0xb7, 0x26, 0x99, 0xc7 0x87, 0xc0, 0x68, 0xb6, 0xb7, 0x26, 0x99, 0xc7
}; };
static uint8_t efi_sys_uuid[16] = { static uint8_t efi_sys_uuid[16] = {
0x28, 0x73, 0x2a, 0xc1, 0x1f, 0xf8, 0xd2, 0x11, 0x28, 0x73, 0x2a, 0xc1, 0x1f, 0xf8, 0xd2, 0x11,
0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b 0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b
}; };
static uint8_t zero_uuid[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; static uint8_t zero_uuid[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int i, ret, do_apm = 0, do_gpt = 0, index, already_in_gpt; int i, ret, do_apm = 0, do_gpt = 0, index, already_in_gpt = 0;
uint8_t gpt_name[72], *type_uuid; uint8_t gpt_name[72], *type_uuid;
#ifndef Libisofs_appended_partitions_inlinE #ifndef Libisofs_appended_partitions_inlinE
if (!t->gpt_backup_outside) if (!t->gpt_backup_outside)
return 2; return 2;
#endif #endif
if ((t->apm_req_count > 0 && t->opts->part_like_isohybrid) || if ((t->apm_req_count > 0 && t->opts->part_like_isohybrid) ||
(t->have_appended_partitions && t->opts->appended_as_apm)) (t->have_appended_partitions && t->opts->appended_as_apm))
do_apm = 1; do_apm = 1;
skipping to change at line 2777 skipping to change at line 2838
return ISO_SUCCESS; return ISO_SUCCESS;
} }
/* ---------------------- Partition Prepend Writer --------------------- */ /* ---------------------- Partition Prepend Writer --------------------- */
static int partprepend_writer_compute_data_blocks(IsoImageWriter *writer) static int partprepend_writer_compute_data_blocks(IsoImageWriter *writer)
{ {
Ecma119Image *t; Ecma119Image *t;
IsoFileSrc *src; IsoFileSrc *src;
int ret, will_have_gpt = 0, with_chrp = 0, i; int ret, will_have_gpt = 0, with_chrp = 0, i, part_type, keep;
static uint8_t zero_uuid[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; static uint8_t zero_uuid[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static uint64_t gpt_flags = (((uint64_t) 1) << 60) | 1; static uint64_t gpt_flags = (((uint64_t) 1) << 60) | 1;
uint8_t gpt_name[72]; uint8_t gpt_name[72];
uint64_t part_start;
off_t start_byte, byte_count;
/* <<< ??? Move to system_area.h and publish as macro ? */ /* <<< ??? Move to system_area.h and publish as macro ? */
static uint8_t efi_sys_uuid[16] = { static uint8_t efi_sys_uuid[16] = {
0x28, 0x73, 0x2a, 0xc1, 0x1f, 0xf8, 0xd2, 0x11, 0x28, 0x73, 0x2a, 0xc1, 0x1f, 0xf8, 0xd2, 0x11,
0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b 0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b
}; };
if (writer == NULL) if (writer == NULL)
return ISO_ASSERT_FAILURE; return ISO_ASSERT_FAILURE;
t = writer->target; t = writer->target;
with_chrp = ((t->system_area_options & 0x3cff) == 0x0400); with_chrp = ((t->system_area_options & 0x3cff) == 0x0400);
if (t->opts->efi_boot_partition != NULL || if (t->opts->efi_boot_partition != NULL ||
t->gpt_req_count > 0) /* Might not catch all cases with GPT */ t->gpt_req_count > 0) /* Might not catch all cases with GPT */
will_have_gpt = 1; will_have_gpt = 1;
if (t->opts->efi_boot_partition != NULL) { if (t->opts->efi_boot_partition != NULL) {
keep = 0;
if (t->efi_boot_part_filesrc != NULL) { if (t->efi_boot_part_filesrc != NULL) {
/* A file in the emerging ISO image shall store its content /* A file in the emerging ISO image shall store its content
as prepended partition. as prepended partition.
Install absolute block addresses and determine partition size. Install absolute block addresses and determine partition size.
*/ */
src = t->efi_boot_part_filesrc; src = t->efi_boot_part_filesrc;
t->efi_boot_part_size = 0; t->efi_boot_part_size = 0;
for (i = 0; i < src->nsections; i++) { for (i = 0; i < src->nsections; i++) {
src->sections[i].block = t->curblock + t->efi_boot_part_size; src->sections[i].block = t->curblock + t->efi_boot_part_size;
t->efi_boot_part_size += (src->sections[i].size + 2047) / 2048; t->efi_boot_part_size += (src->sections[i].size + 2047) / 2048;
} }
part_start = t->curblock * 4;
} else { } else {
ret = compute_partition_size(t, t->opts->efi_boot_partition, ret = compute_partition_size(t, t->opts->efi_boot_partition,
&(t->efi_boot_part_size), &(t->efi_boot_part_size),
t->opts->efi_boot_part_flag & 1); t->opts->efi_boot_part_flag & 1);
if (ret < 0) if (ret < 0)
return ret; return ret;
part_start = t->curblock * 4;
if (ret == ISO_SUCCESS + 1) {
/* Interval from imported_iso in add-on session will be kept */
ret = iso_interval_reader_start_size(t,
t->opts->efi_boot_partition,
&start_byte, &byte_count, 0);
if (ret < 0)
return ret;
part_start = start_byte / 512;
keep = 1;
}
} }
memset(gpt_name, 0, 72); memset(gpt_name, 0, 72);
strcpy((char *) gpt_name, "EFI boot partition"); strcpy((char *) gpt_name, "EFI boot partition");
iso_ascii_utf_16le(gpt_name); iso_ascii_utf_16le(gpt_name);
ret = iso_quick_gpt_entry(t->gpt_req, &(t->gpt_req_count), ret = iso_quick_gpt_entry(t->gpt_req, &(t->gpt_req_count), part_start,
((uint64_t) t->curblock) * 4,
((uint64_t) t->efi_boot_part_size) * 4, ((uint64_t) t->efi_boot_part_size) * 4,
efi_sys_uuid, zero_uuid, gpt_flags, gpt_name); efi_sys_uuid, zero_uuid, gpt_flags, gpt_name);
if (ret < 0) if (ret < 0)
return ret; return ret;
t->curblock += t->efi_boot_part_size; if (!keep)
t->curblock += t->efi_boot_part_size;
} }
if (with_chrp) { if (with_chrp) {
/* CHRP is not compatible with any other partition in MBR */ /* CHRP is not compatible with any other partition in MBR */
if (t->opts->prep_partition != NULL || t->opts->fat || will_have_gpt || if (t->opts->prep_partition != NULL || t->opts->fat || will_have_gpt ||
t->mbr_req_count > 0) t->mbr_req_count > 0)
return ISO_BOOT_MBR_OVERLAP; return ISO_BOOT_MBR_OVERLAP;
ret = iso_quick_mbr_entry(t->mbr_req, &(t->mbr_req_count), ret = iso_quick_mbr_entry(t->mbr_req, &(t->mbr_req_count),
(uint64_t) 0, (uint64_t) 0, 0x96, 0x80, 0); (uint64_t) 0, (uint64_t) 0, 0x96, 0x80, 0);
if (ret < 0) if (ret < 0)
return ret; return ret;
return ISO_SUCCESS; return ISO_SUCCESS;
} }
part_start = t->curblock * 4;
keep = 0;
if (t->opts->prep_partition != NULL) { if (t->opts->prep_partition != NULL) {
ret = compute_partition_size(t, t->opts->prep_partition, ret = compute_partition_size(t, t->opts->prep_partition,
&(t->prep_part_size), &(t->prep_part_size),
t->opts->prep_part_flag & 1); t->opts->prep_part_flag & 1);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ret == ISO_SUCCESS + 1) {
/* Interval from imported_iso in add-on session will be kept */
ret = iso_interval_reader_start_size(t,
t->opts->prep_partition,
&start_byte, &byte_count, 0);
if (ret < 0)
return ret;
part_start = start_byte / 512;
keep = 1;
}
} }
if (t->prep_part_size > 0 || t->opts->fat || will_have_gpt) { if (t->prep_part_size > 0 || t->opts->fat || will_have_gpt) {
/* Protecting MBR entry for ISO start or whole ISO */ /* Protecting MBR entry for ISO start or whole ISO */
part_type = 0xcd;
if (t->opts->iso_mbr_part_type >= 0 &&
t->opts->iso_mbr_part_type <= 255)
part_type= t->opts->iso_mbr_part_type;
if (will_have_gpt)
part_type = 0xee;
ret = iso_quick_mbr_entry(t->mbr_req, &(t->mbr_req_count), ret = iso_quick_mbr_entry(t->mbr_req, &(t->mbr_req_count),
will_have_gpt ? (uint64_t) 1 : will_have_gpt ? (uint64_t) 1 :
((uint64_t) t->opts->partition_offset) * 4, ((uint64_t) t->opts->partition_offset) * 4,
(uint64_t) 0, (uint64_t) 0, part_type, 0, 0);
will_have_gpt ? 0xee : 0xcd, 0, 0);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
if (t->prep_part_size > 0) { if (t->prep_part_size > 0) {
ret = iso_quick_mbr_entry(t->mbr_req, &(t->mbr_req_count), ret = iso_quick_mbr_entry(t->mbr_req, &(t->mbr_req_count), part_start,
((uint64_t) t->curblock) * 4,
((uint64_t) t->prep_part_size) * 4, ((uint64_t) t->prep_part_size) * 4,
0x41, 0, 0); 0x41, 0, 0);
if (ret < 0) if (ret < 0)
return ret; return ret;
t->curblock += t->prep_part_size; if (!keep) {
t->curblock += t->prep_part_size;
part_start = t->curblock * 4;
} else {
part_start += t->prep_part_size * 4;
}
} else {
part_start = t->curblock * 4;
} }
if (t->prep_part_size > 0 || t->opts->fat) { if (t->prep_part_size > 0 || t->opts->fat) {
/* FAT partition or protecting MBR entry for ISO end */ /* FAT partition or protecting MBR entry for ISO end */
ret = iso_quick_mbr_entry(t->mbr_req, &(t->mbr_req_count), ret = iso_quick_mbr_entry(t->mbr_req, &(t->mbr_req_count),
((uint64_t) t->curblock) * 4, (uint64_t) 0, part_start, (uint64_t) 0,
t->opts->fat ? 0x0c : 0xcd, 0, 0); t->opts->fat ? 0x0c : 0xcd, 0, 0);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
return ISO_SUCCESS; return ISO_SUCCESS;
} }
static int partprepend_writer_write_vol_desc(IsoImageWriter *writer) static int partprepend_writer_write_vol_desc(IsoImageWriter *writer)
{ {
 End of changes. 37 change blocks. 
24 lines changed or deleted 123 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)