[PATCH 1/4] common/rc: Add helper to calculate percetage 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]>
---
 common/rc | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/common/rc b/common/rc
index 5fe44e2158ff..32c566cdb68a 100644
--- a/common/rc
+++ b/common/rc
@@ -6189,6 +6189,14 @@ _require_fanotify_ioerrors()
 	_notrun "$FSTYP does not support fanotify ioerrors"
 }
 
+# Returns percentage of available space on given mount point.
+# usage example:
+# _mb_pct_of_available_space <mount point> <percents>
+#
+_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.53.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.