Skip to contentSkip to conversation

df01.sh: Fix failure when block size < 1024

PATCH New Radoslav Kolev 2 participants 2 messages Dec 21, 2020 – Jan 5, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 df01.sh: Fix failure when block size < 1024

If block size is < 1024 shell integer division will always round down. Add 512 (1024/2) to the left side, to cause round up for values >= .5.

---
 testcases/commands/df/df01.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
testcases/commands/df/df01.sh +2 -2
index 02aeec7b4..0e73a16af 100755
@@ -101,8 +101,8 @@ df_check()
 		local free=$(stat -f mntpoint --printf=%f)
 		local used=$((total-free))
 		local bsize=$(stat -f mntpoint --printf=%s)
-		total=$(($total * $bsize / 1024))
-		used=$(($used * $bsize / 1024))
+		total=$((($total * $bsize + 512)/ 1024))
+		used=$((($used * $bsize + 512) / 1024))
 	fi
 
 	grep ${TST_DEVICE} output | grep -q "${total}.*${used}"
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/1 df01.sh: Fix failure when block size < 1024

Hi Radoslav,

Quoted 2 lines

If block size is < 1024 shell integer division will always round down. Add 512 (1024/2) to the left side, to cause round up for values >= .5.

Correct, merged.
Thanks!

Kind regards,
Petr