Re: [PATCH 1/4] common/rc: Add helper to calculate percetage of free space available
"Darrick J. Wong" <[email protected]>
| Newsgroups | org.kernel.vger.fstests |
|---|---|
| Message-ID | <20260430164244.GU7739@frogsfrogsfrogs> |
"percentage" in the subject line On Thu, Apr 30, 2026 at 03:13:16PM +0200, Lukas Herbolt wrote: > 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. “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> <percents> s/percents/percent/ --D > +# > +_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 > >