From 267819f6d04ac808a958130b587e85bf33cc19b5 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 17 Mar 2025 11:17:47 +0100 Subject: [PATCH] Update disk.sh --- src/disk.sh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/disk.sh b/src/disk.sh index e65c6b2..1f2da5c 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -141,10 +141,12 @@ createDisk() { else # Create an empty file - if ! fallocate -l "$DATA_SIZE" "$DISK_FILE"; then - if ! truncate -s "$DATA_SIZE" "$DISK_FILE"; then - rm -f "$DISK_FILE" - error "$FAIL" && exit 77 + if ! fallocate -l "$DATA_SIZE" "$DISK_FILE" &>/dev/null; then + if ! fallocate -l -x "$DATA_SIZE" "$DISK_FILE"; then + if ! truncate -s "$DATA_SIZE" "$DISK_FILE"; then + rm -f "$DISK_FILE" + error "$FAIL" && exit 77 + fi fi fi @@ -219,9 +221,11 @@ resizeDisk() { else # Resize file by allocating more space - if ! fallocate -l "$DATA_SIZE" "$DISK_FILE"; then - if ! truncate -s "$DATA_SIZE" "$DISK_FILE"; then - error "$FAIL" && exit 75 + if ! fallocate -l "$DATA_SIZE" "$DISK_FILE" &>/dev/null; then + if ! fallocate -l -x "$DATA_SIZE" "$DISK_FILE"; then + if ! truncate -s "$DATA_SIZE" "$DISK_FILE"; then + error "$FAIL" && exit 75 + fi fi fi @@ -296,8 +300,10 @@ convertDisk() { if [[ "$ALLOCATE" != [Nn]* ]]; then # Work around qemu-img bug CUR_SIZE=$(stat -c%s "$TMP_FILE") - if ! fallocate -l "$CUR_SIZE" "$TMP_FILE"; then + if ! fallocate -l "$CUR_SIZE" "$TMP_FILE" &>/dev/null; then + if ! fallocate -l -x "$CUR_SIZE" "$TMP_FILE"; then error "Failed to allocate $CUR_SIZE bytes for $DISK_DESC image $TMP_FILE" + fi fi fi fi