From 2da6318f4214725c22d2a403680b3fdcd72f1ff3 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 7 May 2021 15:19:34 +0200 Subject: [fs/path] Use bc for math Some awk versions use ugly formatting (scientific notion) for large numbers, which breaks any further handling of thise numbers in scripts. --- modules/fs/path.inc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/fs/path.inc b/modules/fs/path.inc index fd035b5..714578f 100644 --- a/modules/fs/path.inc +++ b/modules/fs/path.inc @@ -71,7 +71,7 @@ fs_path_isvolatile() { # Returns " " fs_path_space() { [ -z "$1" ] && return 1 - local _free _total _dev _type _id _name _bs _tmp _tfree _ttotal + local _free _total _dev _type _id _name _bs _tmp _tused _tfree _ttotal _type="$( fs_path_gettype "$1" )" [ -z "$_type" ] && return 1 _free="$( df -P "$1" | awk '$6 ~ "^/" {print $4 " " $2}' )" @@ -95,9 +95,11 @@ fs_path_space() { case "$_type" in snapshot) # Field 4 is used/total in sectors of 512 byte, so divide by two for KiB - _tmp="$( dmsetup status "$_dev" | awk '{split($4, a, "/"); print (a[2] - a[1]) / 2 " " a[2] / 2}' )" - _tfree="${_tmp% *}" + _tmp="$( dmsetup status "$_dev" | awk '{split($4, a, "/"); print a[1] " " a[2]}' )" + _tused="${_tmp% *}" _ttotal="${_tmp#* }" + _tfree=$( echo "($_ttotal - $_tused) / 2" | bc ) + _ttotal=$( echo "$_ttotal / 2" | bc ) ;; thin) # Determine matching pool @@ -109,9 +111,11 @@ fs_path_space() { _bs="$( dmsetup table "$_name" | awk '{print $6}' )" if [ "$_bs" -gt 0 ]; then # Field 6 is used/total (in data blocks), so transform into KiB - _tmp="$( dmsetup status "$_name" | awk -v "bs=$_bs" '{split($6, a, "/"); print ((a[2] - a[1]) / 2) * bs " " (a[2] / 2) * bs}' )" - _tfree="${_tmp% *}" + _tmp="$( dmsetup status "$_name" | awk '{split($6, a, "/"); print a[1] " " a[2]}' )" + _tused="${_tmp% *}" _ttotal="${_tmp#* }" + _tfree=$( echo "(($_ttotal - $_tused) / 2) * $_bs" | bc ) + _ttotal=$( echo "($_ttotal / 2) * $_bs" | bc ) fi fi fi -- cgit v1.2.3-55-g7522