#991398 Wrong file sizing

Package:
dphys-swapfile
Source:
dphys-swapfile
Submitter:
Totorito Totorito
Date:
2024-12-15 14:33:02 UTC
Severity:
normal
Tags:
#991398#5
Date:
2021-07-22 16:58:28 UTC
From:
To:
Dear Maintainer,
When I use an external usb to create a swap file, with the actual configuration I cannot go over 50% of the whole size of the drive.

Please correct the code at this part
"
HALF_AVAIL_MB=$(echo "${AVAIL_KB} 2048 / p" | dc)
 if [ "${CONF_SWAPSIZE}" -gt "${HALF_AVAIL_MB}" ] ; then
 echo -n ", restricting to ${CONF_MAXDISK_PCT}% of remaining disk size: ${HALF_AVA$
 CONF_SWAPSIZE="${HALF_AVAIL_MB}"
 fi
"

So I can use the variable CONF_MAXDISK_PCT correctly and go over 50% of the whole space.
I’m using "Linux Raspbian 5.10.17-v7+ #1421 SMP Thu May 27 13:59:01 BST 2021 armv7l GNU/Linux"

—
Tommaso Carraro

#991398#16
Date:
2024-12-15 14:28:48 UTC
From:
To:
Code offered by Tommaso in 2021 could be changed to
"
    if [ "${CONF_MAXDISK_PCT}" != "" ] ; then
      # check for free disk size percentage and don't overstep it
      AVAIL_KB=$(/bin/df --output=avail "$(dirname "${CONF_SWAPFILE}")/." |
tail -1)
      if [ -n "${CONF_SWAPFILE}" -a -e "${CONF_SWAPFILE}" ]; then
          CURRENT_SIZE_B=$(stat --printf='%s' "${CONF_SWAPFILE}")
          AVAIL_KB=$(echo "${AVAIL_KB} ${CURRENT_SIZE_B} 1024 / + p" | dc)
      fi
      MAX_AVAIL_MB=$(echo "${AVAIL_KB} 1024 / ${CONF_MAXDISK_PCT} * 100 /
p" | dc)
      if [ "${CONF_SWAPSIZE}" -gt "${MAX_AVAIL_MB}" ] ; then
        echo -n ", restricting to ${CONF_MAXDISK_PCT}% of remaining disk
size: ${MAX_AVAIL_MB}MBytes"
        CONF_SWAPSIZE="${MAX_AVAIL_MB}"
      fi
    fi
"
This works for me
Thanks
Mike