Ticket #13312: DF-columns-width-and-units-names-2017-02-18.patch

File DF-columns-width-and-units-names-2017-02-18.patch, 2.2 KB (added by dknoto, 8 years ago)
  • src/bin/df.cpp

    From 059ab346cdd4b637cb40fe093032903b67458fe3 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Dariusz=20Knoci=C5=84ski?= <dknoto@gmail.com>
    Date: Sat, 18 Feb 2017 01:41:12 +0100
    Subject: [PATCH] df: adjusted width of columns due to introduction new name of
     file system     and new default mount points. Added correct unit names based
     on norm     IEC 60027-2.
    
    ---
     src/bin/df.cpp | 19 ++++++++++---------
     1 file changed, 10 insertions(+), 9 deletions(-)
    
    diff --git a/src/bin/df.cpp b/src/bin/df.cpp
    index d7e66e9eb2..cb281a3759 100644
    a b PrintMountPoint(dev_t device, bool verbose)  
    4545    if (verbose)
    4646        printf("   Mounted at: %s\n", mount);
    4747    else {
    48         printf("%-15s ", mount);
    49         if (strlen(mount) > 15)
    50             printf("\n%15s ", "");
     48        printf("%-17s ", mount);
     49        if (strlen(mount) > 17)
     50            printf("\n%17s ", "");
    5151    }
    5252}
    5353
    PrintMountPoint(dev_t device, bool verbose)  
    5555void
    5656PrintType(const char *fileSystem)
    5757{
    58     char type[10];
     58    char type[16];
    5959    strlcpy(type, fileSystem, sizeof(type));
    6060
    61     printf("%-8s", type);
     61    printf("%-9s", type);
    6262}
    6363
    6464
    ByteString(int64 numBlocks, int64 blockSize)  
    7171    if (blocks < 1024)
    7272        sprintf(string, "%" B_PRId64, numBlocks * blockSize);
    7373    else {
    74         const char *units[] = {"K", "M", "G", NULL};
     74        const char *units[] = {"KiB", "MiB", "GiB", "TiB", "PiB", "EiB",
     75                               "ZiB", "YiB", NULL};
    7576        int32 i = -1;
    7677
    7778        do {
    ByteString(int64 numBlocks, int64 blockSize)  
    7980            i++;
    8081        } while (blocks >= 1024 && units[i + 1]);
    8182
    82         sprintf(string, "%.1f%s", blocks, units[i]);
     83        sprintf(string, "%.1f %s", blocks, units[i]);
    8384    }
    8485
    8586    return string;
    main(int argc, char **argv)  
    236237
    237238    // If not, then just iterate over all devices and give a compact summary
    238239
    239     printf("Mount           Type      Total     Free     Flags   Device\n"
    240         "--------------- -------- --------- --------- ------- --------------------------\n");
     240    printf(" Mount             Type      Total     Free      Flags   Device\n"
     241           "----------------- --------- --------- --------- ------- ------------------------\n");
    241242
    242243    int32 cookie = 0;
    243244    while ((device = next_dev(&cookie)) >= B_OK) {