fix: Fallback to POSIX fallocate (#209)
This commit is contained in:
parent
87fbfecd92
commit
824c7a42f4
2 changed files with 21 additions and 13 deletions
12
src/disk.sh
12
src/disk.sh
|
@ -135,12 +135,14 @@ createDisk() {
|
||||||
else
|
else
|
||||||
|
|
||||||
# Create an empty file
|
# Create an empty file
|
||||||
if ! fallocate -l "$DATA_SIZE" "$DISK_FILE"; then
|
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
|
if ! truncate -s "$DATA_SIZE" "$DISK_FILE"; then
|
||||||
rm -f "$DISK_FILE"
|
rm -f "$DISK_FILE"
|
||||||
error "$FAIL" && exit 77
|
error "$FAIL" && exit 77
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
@ -213,11 +215,13 @@ resizeDisk() {
|
||||||
else
|
else
|
||||||
|
|
||||||
# Resize file by allocating more space
|
# Resize file by allocating more space
|
||||||
if ! fallocate -l "$DATA_SIZE" "$DISK_FILE"; then
|
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
|
if ! truncate -s "$DATA_SIZE" "$DISK_FILE"; then
|
||||||
error "$FAIL" && exit 75
|
error "$FAIL" && exit 75
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
@ -290,11 +294,13 @@ convertDisk() {
|
||||||
if [[ "$ALLOCATE" != [Nn]* ]]; then
|
if [[ "$ALLOCATE" != [Nn]* ]]; then
|
||||||
# Work around qemu-img bug
|
# Work around qemu-img bug
|
||||||
CUR_SIZE=$(stat -c%s "$TMP_FILE")
|
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"
|
error "Failed to allocate $CUR_SIZE bytes for $DISK_DESC image $TMP_FILE"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
rm -f "$SOURCE_FILE"
|
rm -f "$SOURCE_FILE"
|
||||||
mv "$TMP_FILE" "$DST_FILE"
|
mv "$TMP_FILE" "$DST_FILE"
|
||||||
|
|
|
@ -58,7 +58,7 @@ downloadFile() {
|
||||||
local url="$1"
|
local url="$1"
|
||||||
local base="$2"
|
local base="$2"
|
||||||
local name="$3"
|
local name="$3"
|
||||||
local msg rc total total_mb progress name
|
local msg rc total size progress
|
||||||
|
|
||||||
local dest="$STORAGE/$base.tmp"
|
local dest="$STORAGE/$base.tmp"
|
||||||
rm -f "$dest"
|
rm -f "$dest"
|
||||||
|
@ -88,9 +88,9 @@ downloadFile() {
|
||||||
|
|
||||||
if (( rc == 0 )) && [ -f "$dest" ]; then
|
if (( rc == 0 )) && [ -f "$dest" ]; then
|
||||||
total=$(stat -c%s "$dest")
|
total=$(stat -c%s "$dest")
|
||||||
total_gb=$(formatBytes "$total")
|
size=$(formatBytes "$total")
|
||||||
if [ "$total" -lt 100000 ]; then
|
if [ "$total" -lt 100000 ]; then
|
||||||
error "Invalid image file: is only $total_gb ?" && return 1
|
error "Invalid image file: is only $size ?" && return 1
|
||||||
fi
|
fi
|
||||||
html "Download finished successfully..."
|
html "Download finished successfully..."
|
||||||
mv -f "$dest" "$STORAGE/$base"
|
mv -f "$dest" "$STORAGE/$base"
|
||||||
|
@ -173,11 +173,13 @@ convertImage() {
|
||||||
# Work around qemu-img bug
|
# Work around qemu-img bug
|
||||||
cur_size=$(stat -c%s "$tmp_file")
|
cur_size=$(stat -c%s "$tmp_file")
|
||||||
cur_gb=$(formatBytes "$cur_size")
|
cur_gb=$(formatBytes "$cur_size")
|
||||||
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_gb for image!"
|
error "Failed to allocate $cur_gb for image!"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
rm -f "$source_file"
|
rm -f "$source_file"
|
||||||
mv "$tmp_file" "$dst_file"
|
mv "$tmp_file" "$dst_file"
|
||||||
|
|
Loading…
Reference in a new issue