blob: f53ec4cc134928fb6e71360e23ecd514b0901cb6 [file] [log] [blame]
Ram Chandrasekar613e1f42022-08-25 00:02:12 +00001#!/bin/sh
2# Copyright 2022 The ChromiumOS Authors
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6# This script is automatically generated by @SCRIPT_GENERATOR@.
7# Do not edit!
8
9if ! type numsectors >/dev/null 2>&1; then
10 # shellcheck disable=SC1091
11 . "/usr/share/misc/chromeos-common.sh" || exit 1
12fi
13locate_gpt
14
15# Usage: create_image <device> <min_disk_size>
16# If <device> is a block device, wipes out the GPT
17# If it's not, it creates a new file of the requested size
18create_image() {
19 local dev="$1"
20 local min_disk_size="$2"
21
22 if [ -b "${dev}" ]; then
23 # Make sure block size is not greater than 8K. Otherwise the partition
24 # start calculation won't fit.
25 block_size=$(blocksize "${dev}")
26 if [ "${block_size}" -gt 8192 ]; then
27 echo "Destination blocksize too large. Only blocksizes of 8192 bytes and \
28 smaller are supported." >&2
29 exit 1
30 fi
31
32 # Zap any old partitions (otherwise gpt complains).
33 dd if=/dev/zero of="${dev}" conv=notrunc bs=512 count=64
34 dd if=/dev/zero of="${dev}" conv=notrunc bs=512 count=64 \
Mike Frysinger946987e2023-03-10 22:55:45 -050035 seek=$((min_disk_size / 512 - 64))
Ram Chandrasekar613e1f42022-08-25 00:02:12 +000036 else
37 if [ ! -e "${dev}" ]; then
38 # Align to 512 bytes
Mike Frysinger946987e2023-03-10 22:55:45 -050039 min_disk_size=$(((min_disk_size + 511) & ~511))
Ram Chandrasekar613e1f42022-08-25 00:02:12 +000040 truncate -s "${min_disk_size}" "${dev}"
41 fi
42 fi
43}