summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2021-05-07 15:19:34 +0200
committerSimon Rettberg2021-05-07 15:19:34 +0200
commit2da6318f4214725c22d2a403680b3fdcd72f1ff3 (patch)
tree05d0309b5d4da9bae683597e428e6fff95d880bc
parent[cert] Only import hashed symlink certs into nssdb (diff)
downloadslx-tools-2da6318f4214725c22d2a403680b3fdcd72f1ff3.tar.gz
slx-tools-2da6318f4214725c22d2a403680b3fdcd72f1ff3.tar.xz
slx-tools-2da6318f4214725c22d2a403680b3fdcd72f1ff3.zip
[fs/path] Use bc for mathv28
Some awk versions use ugly formatting (scientific notion) for large numbers, which breaks any further handling of thise numbers in scripts.
-rw-r--r--modules/fs/path.inc14
1 files 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 "<free> <total>"
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