[PATCH v2 1/4] common/rc: Add helper to calculate percentage of free space available

Lukas Herbolt <[email protected]>
Newsgroups org.kernel.vger.fstests
Message-ID <[email protected]>
It calculates percentage of filesystem available space and returns it
in MB. This helper will be used in the following test/generic fixes.

Signed-off-by: Lukas Herbolt <[email protected]>
---
 changes v2:
	spelling and description
 common/rc | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/common/rc b/common/rc
index 5fe44e2158ff..9fc733ebdcf4 100644
--- a/common/rc
+++ b/common/rc
@@ -6189,6 +6189,16 @@ _require_fanotify_ioerrors()
 	_notrun "$FSTYP does not support fanotify ioerrors"
 }
 
+# Computes a percentage of the available space in a filesystem and
+# returns that quantity in MB. The percentage must not contain a percent
+# sign ("%").
+# usage example:
+# _mb_pct_of_available_space <mount point> <percent>
+#
+_mb_pct_of_available_space()
+{
+        _df_device $1 | $AWK_PROG -v pct=$2 '{printf "%.f", (($5*(pct/100))/1024)}'
+}
 ################################################################################
 # make sure this script returns success
 /bin/true
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.