Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/df field width of blocksize and inode can be changed by ...



details:   https://anonhg.NetBSD.org/src/rev/9f18efa18b38
branches:  trunk
changeset: 937564:9f18efa18b38
user:      ryo <ryo%NetBSD.org@localhost>
date:      Fri Aug 21 16:40:02 2020 +0000

description:
field width of blocksize and inode can be changed by #define

diffstat:

 bin/df/df.c |  47 ++++++++++++++++++++++++++++-------------------
 1 files changed, 28 insertions(+), 19 deletions(-)

diffs (115 lines):

diff -r 84a5da785e54 -r 9f18efa18b38 bin/df/df.c
--- a/bin/df/df.c       Fri Aug 21 15:48:13 2020 +0000
+++ b/bin/df/df.c       Fri Aug 21 16:40:02 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: df.c,v 1.95 2019/09/22 22:59:37 christos Exp $ */
+/*     $NetBSD: df.c,v 1.96 2020/08/21 16:40:02 ryo Exp $ */
 
 /*
  * Copyright (c) 1980, 1990, 1993, 1994
@@ -45,7 +45,7 @@
 #if 0
 static char sccsid[] = "@(#)df.c       8.7 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: df.c,v 1.95 2019/09/22 22:59:37 christos Exp $");
+__RCSID("$NetBSD: df.c,v 1.96 2020/08/21 16:40:02 ryo Exp $");
 #endif
 #endif /* not lint */
 
@@ -72,13 +72,16 @@
 static void     maketypelist(char *);
 static size_t   regetmntinfo(struct statvfs **, size_t);
 __dead static void usage(void);
-static void     prthumanval(int64_t, const char *);
+static void     prthumanval(int64_t, int);
 static void     prthuman(const struct statvfs *, int64_t, int64_t);
 
 static int      aflag, gflag, hflag, iflag, lflag, nflag, Pflag, Wflag;
 static long     usize;
 static char    **typelist;
 
+#define WIDTH_INODE    8
+#define WIDTH_BLKSIZE  10
+
 int
 main(int argc, char *argv[])
 {
@@ -328,7 +331,7 @@
 }
 
 static void
-prthumanval(int64_t bytes, const char *pad)
+prthumanval(int64_t bytes, int width)
 {
        char buf[6];
 
@@ -336,16 +339,16 @@
            bytes, "", HN_AUTOSCALE,
            HN_B | HN_NOSPACE | HN_DECIMAL);
 
-       (void)printf("%s %6s", pad, buf);
+       (void)printf("%*s", width, buf);
 }
 
 static void
 prthuman(const struct statvfs *sfsp, int64_t used, int64_t bavail)
 {
 
-       prthumanval((int64_t)(sfsp->f_blocks * sfsp->f_frsize), "   ");
-       prthumanval((int64_t)(used * sfsp->f_frsize), "    ");
-       prthumanval((int64_t)(bavail * sfsp->f_frsize), "    ");
+       prthumanval((int64_t)(sfsp->f_blocks * sfsp->f_frsize), WIDTH_BLKSIZE);
+       prthumanval((int64_t)(used * sfsp->f_frsize), 1 + WIDTH_BLKSIZE);
+       prthumanval((int64_t)(bavail * sfsp->f_frsize), 1 + WIDTH_BLKSIZE);
 }
 
 /*
@@ -461,12 +464,16 @@
                        (void)printf("Filesystem %s Used Available Capacity "
                            "Mounted on\n", header);
                } else {
-                       (void)printf("%-*.*s %s       Used      Avail %%Cap",
-                           maxwidth - (headerlen - 10),
-                           maxwidth - (headerlen - 10),
-                           "Filesystem", header);
-                       if (iflag)
-                               (void)printf("    iUsed   iAvail %%iCap");
+                       (void)printf("%-*.*s %*s %*s %*s %%Cap",
+                           maxwidth, maxwidth, "Filesystem",
+                           WIDTH_BLKSIZE, header,
+                           WIDTH_BLKSIZE, "Used",
+                           WIDTH_BLKSIZE, "Avail");
+                       if (iflag) {
+                               (void)printf(" %*s %*s %%iCap",
+                                   WIDTH_INODE, "iUsed",
+                                   WIDTH_INODE, "iAvail");
+                       }
                        (void)printf(" Mounted on\n");
                }
        }
@@ -502,18 +509,20 @@
        if (hflag)
                prthuman(sfsp, used, bavail);
        else
-               (void)printf("%10" PRId64 " %10" PRId64 " %10" PRId64,
+               (void)printf("%*" PRId64 " %*" PRId64 " %*" PRId64,
+                   WIDTH_BLKSIZE,
                    fsbtoblk(sfsp->f_blocks, sfsp->f_frsize, blocksize),
-                   fsbtoblk(used, sfsp->f_frsize, blocksize),
-                   fsbtoblk(bavail, sfsp->f_frsize, blocksize));
+                   WIDTH_BLKSIZE, fsbtoblk(used, sfsp->f_frsize, blocksize),
+                   WIDTH_BLKSIZE, fsbtoblk(bavail, sfsp->f_frsize, blocksize));
        (void)printf(" %3s%%",
            availblks == 0 ? full :
            strspct(pb, sizeof(pb), used, availblks, 0));
        if (iflag) {
                inodes = sfsp->f_files;
                used = inodes - sfsp->f_ffree;
-               (void)printf(" %8jd %8jd %4s%%",
-                   (intmax_t)used, (intmax_t)sfsp->f_ffree,
+               (void)printf(" %*jd %*jd %4s%%",
+                   WIDTH_INODE, (intmax_t)used,
+                   WIDTH_INODE, (intmax_t)sfsp->f_ffree,
                    inodes == 0 ? (used == 0 ? empty : full) :
                    strspct(pb, sizeof(pb), used, inodes, 0));
        }



Home | Main Index | Thread Index | Old Index