diff --git a/bin/df/df.1 b/bin/df/df.1 --- a/bin/df/df.1 +++ b/bin/df/df.1 @@ -26,7 +26,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd July 16, 2025 +.Dd January 3, 2026 .Dt DF 1 .Os .Sh NAME @@ -208,7 +208,7 @@ devfs devfs 1.0K 1.0K 0B 100% /dev /dev/ada0p1 ufs 1.8T 168G 1.5T 10% /data linsysfs linsysfs 4.0K 4.0K 0B 100% /compat/linux/sys -/dev/da0 msdosfs 7.6G 424M 7.2G 5% /mnt/usb +/dev/da0 msdosfs 7.6G 424M 7.2G 6% /mnt/usb .Ed .Pp Show previously collected data including inode statistics except for devfs or @@ -220,13 +220,10 @@ option can be specified only once: .Bd -literal -offset indent $ df -i -n -t nodevfs,linsysfs -Filesystem 1K-blocks Used Avail Capacity iused ifree %iused -Mounted on +Filesystem 1K-blocks Used Avail Capacity iused ifree %iused Mounted on /dev/ada1p2 223235736 159618992 45757888 78% 1657590 27234568 6% / -/dev/ada0p1 1892163184 176319420 1564470712 10% 1319710 243300576 1% -/data -/dev/da0 7989888 433664 7556224 5% 0 0 100% -/mnt/usb +/dev/ada0p1 1892163184 176319420 1564470712 11% 1319710 243300576 1% /data +/dev/da0 7989888 433664 7556224 6% 0 0 - /mnt/usb .Ed .Pp Show human readable information for the file system containing the file @@ -264,8 +261,8 @@ .Xr getmntinfo 3 , .Xr libxo 3 , .Xr localeconv 3 , -.Xr xo_options 7 , .Xr fstab 5 , +.Xr xo_options 7 , .Xr mount 8 , .Xr pstat 8 , .Xr quot 8 , diff --git a/bin/df/df.c b/bin/df/df.c --- a/bin/df/df.c +++ b/bin/df/df.c @@ -76,6 +76,7 @@ static void prthuman(const struct statfs *, int64_t); static void prthumanval(const char *, int64_t); static intmax_t fsbtoblk(int64_t, uint64_t, u_long); +static int percent(int64_t , int64_t); static void prtstat(struct statfs *, struct maxwidths *); static size_t regetmntinfo(struct statfs **, long); static void update_maxwidths(struct maxwidths *, const struct statfs *); @@ -450,6 +451,15 @@ return (num * (intmax_t) fsbs / (int64_t) bs); } +/* + * Calculate the percentage as an integer, rounded up to the next highest value. + */ +static int +percent(int64_t used, int64_t avail) +{ + return (avail == 0 ? 100 : ((used * 100 + avail - 1) / avail)); +} + /* * Print out status about a file system. */ @@ -528,8 +538,7 @@ mwp->avail, fsbtoblk(sfsp->f_bavail, sfsp->f_bsize, blocksize)); } - xo_emit(" {:used-percent/%5.0f}{U:%%}", - availblks == 0 ? 100.0 : (double)used / (double)availblks * 100.0); + xo_emit(" {:used-percent/%5d}{U:%%}", percent(used, availblks)); if (iflag) { inodes = sfsp->f_files; used = inodes - sfsp->f_ffree; @@ -548,8 +557,8 @@ if (inodes == 0) xo_emit(" {:inodes-used-percent/ -}{U:} "); else { - xo_emit(" {:inodes-used-percent/%4.0f}{U:%%} ", - (double)used / (double)inodes * 100.0); + xo_emit(" {:inodes-used-percent/%4d}{U:%%} ", + percent(used, inodes)); } } else xo_emit(" "); diff --git a/bin/df/tests/t_df.sh b/bin/df/tests/t_df.sh --- a/bin/df/tests/t_df.sh +++ b/bin/df/tests/t_df.sh @@ -20,50 +20,50 @@ { cat >expout <expout <