diff --git a/bin/df/df.c b/bin/df/df.c --- a/bin/df/df.c +++ b/bin/df/df.c @@ -81,7 +81,7 @@ static void update_maxwidths(struct maxwidths *, const struct statfs *); static void usage(void); -static bool aflag, cflag, iflag, kflag, lflag, nflag, Tflag; +static bool aflag, cflag, iflag, kflag, lflag, nflag, Pflag, Tflag; static int hflag; static int thousands; static int skipvfs_l, skipvfs_t; @@ -123,6 +123,7 @@ case 'b': /* FALLTHROUGH */ case 'P': + Pflag = true; /* * POSIX specifically discusses the behavior of * both -k and -P. It states that the blocksize should @@ -460,7 +461,7 @@ static int headerlen, timesthrough = 0; static const char *header; int64_t used, availblks, inodes; - const char *format; + const char *availheader, *format; if (++timesthrough == 1) { mwp->mntfrom = MAX(mwp->mntfrom, (int)strlen("Filesystem")); @@ -481,14 +482,15 @@ mwp->total = MAX(mwp->total, headerlen); } mwp->used = MAX(mwp->used, (int)strlen("Used")); - mwp->avail = MAX(mwp->avail, (int)strlen("Avail")); + availheader = Pflag ? "Available" : "Avail"; + mwp->avail = MAX(mwp->avail, (int)strlen(availheader)); xo_emit("{T:/%-*s}", mwp->mntfrom, "Filesystem"); if (Tflag) xo_emit(" {T:/%-*s}", mwp->fstype, "Type"); xo_emit(" {T:/%*s} {T:/%*s} {T:/%*s} {T:Capacity}", mwp->total, header, - mwp->used, "Used", mwp->avail, "Avail"); + mwp->used, "Used", mwp->avail, availheader); if (iflag) { mwp->iused = MAX(hflag ? 0 : mwp->iused, (int)strlen(" iused")); diff --git a/bin/df/tests/Makefile b/bin/df/tests/Makefile --- a/bin/df/tests/Makefile +++ b/bin/df/tests/Makefile @@ -1,6 +1,7 @@ PACKAGE= tests -ATF_TESTS_SH= t_df +ATF_TESTS_SH= df_test +ATF_TESTS_SH+= t_df PROGS+= h_df BINDIR.h_df= ${TESTSDIR} diff --git a/bin/df/tests/df_test.sh b/bin/df/tests/df_test.sh new file mode 100644 --- /dev/null +++ b/bin/df/tests/df_test.sh @@ -0,0 +1,41 @@ +# +# Copyright (c) 2026 Jose Luis Duran +# +# SPDX-License-Identifier: BSD-2-Clause +# + +atf_test_case Pflag +Pflag_head() +{ + atf_set "descr" "Tests the output of df when using the -P flag" +} +Pflag_body() +{ + cat >expout <expout <