From 576c8996f49dd1e98ca42843c2ab1f8888e99991 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Thu, 19 Dec 2013 18:25:11 -0800 Subject: [PATCH] fix(disk_util): Remove support for --adjust_part This isn't a feature we've been using as far as I know and if someone needs a custom partition layout it's probably better to just add it to the json file. Removing this avoids some complexity. --- bin/cros_make_image_bootable | 2 - build_image | 2 - build_library/base_image_util.sh | 2 +- build_library/disk_layout_util.sh | 9 ---- build_library/disk_util | 72 ------------------------------- image_to_vm.sh | 2 - 6 files changed, 1 insertion(+), 88 deletions(-) diff --git a/bin/cros_make_image_bootable b/bin/cros_make_image_bootable index e27862c367..182a5f8248 100755 --- a/bin/cros_make_image_bootable +++ b/bin/cros_make_image_bootable @@ -71,8 +71,6 @@ locate_gpt set +e # Now parse the build settings from ${OUTPUT_DIR}/boot.desc -DEFINE_string adjust_part "" \ - "Adjustments to apply to the partition table" DEFINE_string board "${DEFAULT_BOARD}" \ "Board we're building for." DEFINE_string output_dir "/tmp" \ diff --git a/build_image b/build_image index e28fa96635..2c042688d7 100755 --- a/build_image +++ b/build_image @@ -13,8 +13,6 @@ SCRIPT_ROOT=$(dirname $(readlink -f "$0")) . "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1 # Developer-visible flags. -DEFINE_string adjust_part "" \ - "Adjustments to apply to the partition table" DEFINE_string board "${DEFAULT_BOARD}" \ "The board to build an image for." DEFINE_string boot_args "" \ diff --git a/build_library/base_image_util.sh b/build_library/base_image_util.sh index 55fc293c45..9844c86032 100755 --- a/build_library/base_image_util.sh +++ b/build_library/base_image_util.sh @@ -215,7 +215,7 @@ create_base_image() { emit_gpt_scripts "${BUILD_DIR}/${image_name}" "${BUILD_DIR}" ${SCRIPTS_DIR}/bin/cros_make_image_bootable "${BUILD_DIR}" \ - ${image_name} --adjust_part="${FLAGS_adjust_part}" + "${image_name}" trap - EXIT } diff --git a/build_library/disk_layout_util.sh b/build_library/disk_layout_util.sh index 59b869bf39..e89cbf33e4 100644 --- a/build_library/disk_layout_util.sh +++ b/build_library/disk_layout_util.sh @@ -5,15 +5,6 @@ CGPT_PY="${BUILD_LIBRARY_DIR}/disk_util" cgpt_py() { - if [[ -n "${FLAGS_adjust_part-}" ]]; then - set -- --adjust_part "${FLAGS_adjust_part}" "$@" - if [[ ! -t 0 ]]; then - warn "The --adjust_part flag was passed." \ - "This option must ONLY be used interactively. If" \ - "you need to pass a size from another script, you're" \ - "doing it wrong and should be using a disk layout type." - fi - fi "${CGPT_PY}" "$@" } diff --git a/build_library/disk_util b/build_library/disk_util index 3751a9c70f..dc8e3ce520 100755 --- a/build_library/disk_util +++ b/build_library/disk_util @@ -6,7 +6,6 @@ import argparse import json import os -import re import subprocess import sys import uuid @@ -125,78 +124,9 @@ def GetPartitionTable(options, config): for k, v in partition_t.items(): partition[k] = v - for adjustment_str in options.adjust_part.split(): - adjustment = adjustment_str.split(':') - if len(adjustment) < 2: - raise InvalidAdjustment('Adjustment specified was incomplete') - - label = adjustment[0] - operator = adjustment[1][0] - operand = adjustment[1][1:] - ApplyPartitionAdjustment(partitions, metadata, label, operator, operand) - return partitions -def ApplyPartitionAdjustment(partitions, metadata, label, operator, operand): - """Applies an adjustment to a partition specified by label - - Args: - partitions: Partition table to modify - metadata: Partition table metadata - label: The label of the partition to adjust - operator: Type of adjustment (+/-/=) - operand: How much to adjust by - """ - - partition = GetPartitionByLabel(partitions, label) - - operand_digits = re.sub('\D', '', operand) - size_factor = block_factor = 1 - suffix = operand[len(operand_digits):] - if suffix: - size_factors = { 'B': 0, 'K': 1, 'M': 2, 'G': 3, 'T': 4, } - try: - size_factor = size_factors[suffix[0].upper()] - except KeyError: - raise InvalidAdjustment('Unknown size type %s' % suffix) - if size_factor == 0 and len(suffix) > 1: - raise InvalidAdjustment('Unknown size type %s' % suffix) - block_factors = { '': 1024, 'B': 1000, 'IB': 1024, } - try: - block_factor = block_factors[suffix[1:].upper()] - except KeyError: - raise InvalidAdjustment('Unknown size type %s' % suffix) - - operand_bytes = int(operand_digits) * pow(block_factor, size_factor) - - if operand_bytes % metadata['block_size'] == 0: - operand_blocks = operand_bytes / metadata['block_size'] - else: - raise InvalidAdjustment('Adjustment size not divisible by block size') - - if operator == '+': - partition['blocks'] += operand_blocks - partition['bytes'] += operand_bytes - elif operator == '-': - partition['blocks'] -= operand_blocks - partition['bytes'] -= operand_bytes - elif operator == '=': - partition['blocks'] = operand_blocks - partition['bytes'] = operand_bytes - else: - raise ValueError('unknown operator %s' % operator) - - if partition['type'] == 'rootfs': - # If we're adjusting a rootFS partition, we assume the full partition size - # specified is being used for the filesytem, minus the space reserved for - # the hashpad. - partition['fs_bytes'] = partition['bytes'] - partition['fs_blocks'] = partition['fs_bytes'] / metadata['fs_block_size'] - partition['blocks'] = int(partition['blocks'] * 1.15) - partition['bytes'] = partition['blocks'] * metadata['block_size'] - - def GetPartitionTableFromConfig(options): """Loads a partition table and returns a given partition table type @@ -453,8 +383,6 @@ def main(argv): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) - parser.add_argument('--adjust_part', default='', - help='adjust partition sizes') parser.add_argument('--disk_layout_file', default=default_layout_file, help='path to disk layout json file') parser.add_argument('--disk_layout', default=default_layout_type, diff --git a/image_to_vm.sh b/image_to_vm.sh index 1e35812d6b..149b791d79 100755 --- a/image_to_vm.sh +++ b/image_to_vm.sh @@ -26,8 +26,6 @@ assert_inside_chroot . "${SCRIPT_ROOT}/lib/cros_vm_constants.sh" || exit 1 # Flags -DEFINE_string adjust_part "" \ - "Adjustments to apply to the partition table" DEFINE_string board "${DEFAULT_BOARD}" \ "Board for which the image was built"