From c0d56a45db8a38f7121a13eff4e68c10a6cf0db7 Mon Sep 17 00:00:00 2001
From: "Roberto A. Foglietta" <roberto.foglietta@gmail.com>
Date: Wed, 14 Dec 2022 12:37:26 +0100
Subject: [PATCH] In expand last partition checking the size is useless

code maintenance, superflous operations commented, kept for the future

Tests shown that resize in full a ext4 or btrfs partition/filesystem does not
hurt and does not report a failure, so nothing changes without the size check

Signed-off-by: Roberto A. Foglietta <roberto.foglietta@gmail.com>
---
 .../files/expand-last-partition.sh            | 34 +++++++++++--------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
index 2c52b16..4d36733 100755
--- a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
+++ b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
@@ -27,22 +27,26 @@ if [ "${ROOT_DEV}" = "${BOOT_DEV}" ]; then
 	exit 0
 fi
 
-# this value is in blocks. Normally a block has 512 bytes.
-BUFFER_SIZE=32768
-BOOT_DEV_NAME=${BOOT_DEV##*/}
-DISK_SIZE="$(cat /sys/class/block/"${BOOT_DEV_NAME}"/size)"
-ALL_PARTS_SIZE=0
-for PARTITION in /sys/class/block/"${BOOT_DEV_NAME}"/"${BOOT_DEV_NAME}"*; do
-	PART_SIZE=$(cat "${PARTITION}"/size)
-	ALL_PARTS_SIZE=$((ALL_PARTS_SIZE + PART_SIZE))
-done
+# full resizing of ext4 and btrfs does not fail nor hurt but supporting more
+# filesystems in future might change this condition, so commenting this code
+useless_for_now() {
+	# this value is in blocks. Normally a block has 512 bytes.
+	BUFFER_SIZE=32768
+	BOOT_DEV_NAME=${BOOT_DEV##*/}
+	DISK_SIZE="$(cat /sys/class/block/"${BOOT_DEV_NAME}"/size)"
+	ALL_PARTS_SIZE=0
+	for PARTITION in /sys/class/block/"${BOOT_DEV_NAME}"/"${BOOT_DEV_NAME}"*; do
+		PART_SIZE=$(cat "${PARTITION}"/size)
+		ALL_PARTS_SIZE=$((ALL_PARTS_SIZE + PART_SIZE))
+	done
 
-MINIMAL_SIZE=$((ALL_PARTS_SIZE + BUFFER_SIZE))
-if [ "$DISK_SIZE" -lt "$MINIMAL_SIZE" ]; then
-	echo "Disk is practically already full, doing nothing." >&2
-	trap - EXIT
-	exit 0
-fi
+	MINIMAL_SIZE=$((ALL_PARTS_SIZE + BUFFER_SIZE))
+	if [ "$DISK_SIZE" -lt "$MINIMAL_SIZE" ]; then
+		echo "Disk is practically already full, doing nothing." >&2
+		trap - EXIT
+		exit 0
+	fi
+}
 
 LAST_PART="$(sfdisk -d "${BOOT_DEV}" 2>/dev/null | tail -1 | cut -d ' ' -f 1)"
 
-- 
2.34.1

