diff --git a/bin/df/df.c b/bin/df/df.c --- a/bin/df/df.c +++ b/bin/df/df.c @@ -84,7 +84,8 @@ return (a > b ? a : b); } -static int aflag = 0, cflag, hflag, iflag, kflag, lflag = 0, nflag, Tflag; +static int aflag = 0, cflag, hflag, iflag, kflag, lflag = 0, nflag, + Pflag = 0, Tflag; static int thousands; static int skipvfs_l, skipvfs_t; static const char **vfslist_l, **vfslist_t; @@ -125,6 +126,7 @@ case 'b': /* FALLTHROUGH */ case 'P': + Pflag = 1; /* * POSIX specifically discusses the behavior of * both -k and -P. It states that the blocksize should @@ -462,7 +464,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 = imax(mwp->mntfrom, (int)strlen("Filesystem")); @@ -483,14 +485,15 @@ mwp->total = imax(mwp->total, headerlen); } mwp->used = imax(mwp->used, (int)strlen("Used")); - mwp->avail = imax(mwp->avail, (int)strlen("Avail")); + availheader = Pflag ? "Available" : "Avail"; + mwp->avail = imax(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 = imax(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) 2025 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 <