]> Sergey Matveev's repositories - nnn.git/commitdiff
Show volume used information in help
authorArun Prakash Jana <engineerarun@gmail.com>
Thu, 14 Jul 2022 02:38:31 +0000 (08:08 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Mon, 18 Jul 2022 12:58:16 +0000 (18:28 +0530)
src/nnn.c

index 9eb91396f2d19459d80b54013f6ad7a1aa3e2e0d..5344ebfaf1bb8f70520943396549c4df4c5fbe45 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
 #define VLEN 3
 
 /* Volume info */
-#define FREE     0
-#define CAPACITY 1
+#define VFS_AVAIL 0
+#define VFS_USED  1
+#define VFS_SIZE  2
 
 /* TYPE DEFINITIONS */
 typedef unsigned int uint_t;
@@ -4527,17 +4528,20 @@ static bool xchmod(const char *fpath, mode_t mode)
        return (chmod(fpath, mode) == 0);
 }
 
-static size_t get_fs_info(const char *path, bool type)
+static size_t get_fs_info(const char *path, uchar_t type)
 {
        struct statvfs svb;
 
        if (statvfs(path, &svb) == -1)
                return 0;
 
-       if (type == CAPACITY)
-               return (size_t)svb.f_blocks << ffs((int)(svb.f_frsize >> 1));
+       if (type == VFS_AVAIL)
+               return (size_t)svb.f_bavail << ffs((int)(svb.f_frsize >> 1));
 
-       return (size_t)svb.f_bavail << ffs((int)(svb.f_frsize >> 1));
+       if (type == VFS_USED)
+               return ((size_t)svb.f_blocks - (size_t)svb.f_bfree) << ffs((int)(svb.f_frsize >> 1));
+
+       return (size_t)svb.f_blocks << ffs((int)(svb.f_frsize >> 1)); /* VFS_SIZE */
 }
 
 /* Create non-existent parents and a file or dir */
@@ -5069,13 +5073,14 @@ static void show_help(const char *path)
                ++end;
        }
 
-       dprintf(fd, "\nLOCATIONS:\n");
+       dprintf(fd, "\nLOCATIONS\n");
        for (uchar_t i = 0; i < CTX_MAX; ++i)
                if (g_ctx[i].c_cfg.ctxactive)
                        dprintf(fd, " %u: %s\n", i + 1, g_ctx[i].c_path);
 
-       dprintf(fd, "\nVOLUME: %s of ", coolsize(get_fs_info(path, FREE)));
-       dprintf(fd, "%s free\n\n", coolsize(get_fs_info(path, CAPACITY)));
+       dprintf(fd, "\nVOLUME: avail:%s ", coolsize(get_fs_info(path, VFS_AVAIL)));
+       dprintf(fd, "used:%s ", coolsize(get_fs_info(path, VFS_USED)));
+       dprintf(fd, "size:%s\n\n", coolsize(get_fs_info(path, VFS_SIZE)));
 
        if (bookmark) {
                dprintf(fd, "BOOKMARKS\n");
@@ -6296,8 +6301,8 @@ static void statusbar(char *path)
 
                xstrsncpy(buf, coolsize(dir_blocks << blk_shift), 12);
 
-               printw("%cu:%s free:%s files:%llu %lluB %s\n",
-                      (cfg.apparentsz ? 'a' : 'd'), buf, coolsize(get_fs_info(path, FREE)),
+               printw("%cu:%s avail:%s files:%llu %lluB %s\n",
+                      (cfg.apparentsz ? 'a' : 'd'), buf, coolsize(get_fs_info(path, VFS_AVAIL)),
                       num_files, (ullong_t)pent->blocks << blk_shift, ptr);
        } else { /* light or detail mode */
                char sort[] = "\0\0\0\0\0";