installer: chromeos-common: support blocksize function.
The write_gpt.sh in new release image expects to have blocksize function
in chromeos-common.sh but old factory branch didn't support it yet.
BUG=b:119292628
TEST=create a diskimg by `make_factory_package.sh` in chroot.
Change-Id: I0f09d59a400b6969266d7c2cdc0d862bf890c70e
Reviewed-on: https://chromium-review.googlesource.com/c/1345869
Reviewed-by: Marco Chen <marcochen@chromium.org>
Commit-Queue: Marco Chen <marcochen@chromium.org>
Tested-by: Marco Chen <marcochen@chromium.org>
diff --git a/installer/share/chromeos-common.sh b/installer/share/chromeos-common.sh
index ebf4a92..57c4812 100644
--- a/installer/share/chromeos-common.sh
+++ b/installer/share/chromeos-common.sh
@@ -39,6 +39,28 @@
fi
}
+# This returns the block size of a file or device in byte
+# Invoke as: subshell
+# Args: FILENAME
+# Return: block size in bytes
+blocksize() {
+ local path="$1"
+ if [ -b "${path}" ]; then
+ local dev="${path##*/}"
+ local sys="/sys/block/${dev}/queue/logical_block_size"
+ if [ -e "${sys}" ]; then
+ cat "${sys}"
+ else
+ local part="${path##*/}"
+ local block="$(get_block_dev_from_partition_dev "${path}")"
+ local block="${block##*/}"
+ cat "/sys/block/${block}/${part}/queue/logical_block_size"
+ fi
+ else
+ echo 512
+ fi
+}
+
# Locate the cgpt tool. It should already be installed in the build chroot,
# but some of these functions may be invoked outside the chroot (by
# image_to_usb or similar), so we need to find it.