]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix handling hard-links
authorArun Prakash Jana <engineerarun@gmail.com>
Thu, 27 Feb 2020 13:19:44 +0000 (18:49 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Thu, 27 Feb 2020 13:19:44 +0000 (18:49 +0530)
src/nnn.c

index bfb6568a0da4d3ce937cc323171a8ee5fa2fd220..1d031601c5b2145744812859e2d87798a9e5e047 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
 #define BLK_SHIFT_512 9
 
 /* Detect hardlinks in du */
-#define HASH_BITS (0xFFFF)
+#define HASH_BITS (0xFFFFFF)
 #define HASH_OCTETS (HASH_BITS >> 6) /* 2^6 = 64 */
 
 /* Program return codes */
@@ -700,8 +700,10 @@ static char *xitoa(uint val)
 /*
  * Source: https://elixir.bootlin.com/linux/latest/source/arch/alpha/include/asm/bitops.h
  */
-static bool test_set_bit(ulong nr)
+static bool test_set_bit(uint nr)
 {
+       nr &= HASH_BITS;
+
        ull *m = ((ull *)ihashbmp) + (nr >> 6);
 
        if (*m & (1 << (nr & 63)))
@@ -713,8 +715,10 @@ static bool test_set_bit(ulong nr)
 }
 
 #if 0
-static bool test_clear_bit(ulong nr)
+static bool test_clear_bit(uint nr)
 {
+       nr &= HASH_BITS;
+
        ull *m = ((ull *) ihashbmp) + (nr >> 6);
 
        if (!(*m & (1 << (nr & 63))))
@@ -4189,7 +4193,7 @@ static void launch_app(const char *path, char *newpath)
 static int sum_bsize(const char *UNUSED(fpath), const struct stat *sb, int typeflag, struct FTW *UNUSED(ftwbuf))
 {
        if (sb->st_blocks && (typeflag == FTW_F || typeflag == FTW_D)
-           && (sb->st_nlink <= 1 || test_set_bit((ulong)sb->st_ino + (ulong)sb->st_size)))
+           && (sb->st_nlink <= 1 || test_set_bit((uint)sb->st_ino)))
                ent_blocks += sb->st_blocks;
 
        ++num_files;
@@ -4199,7 +4203,7 @@ static int sum_bsize(const char *UNUSED(fpath), const struct stat *sb, int typef
 static int sum_asize(const char *UNUSED(fpath), const struct stat *sb, int typeflag, struct FTW *UNUSED(ftwbuf))
 {
        if (sb->st_size && (typeflag == FTW_F || typeflag == FTW_D)
-           && (sb->st_nlink <= 1 || test_set_bit((ulong)sb->st_ino + (ulong)sb->st_size)))
+           && (sb->st_nlink <= 1 || test_set_bit((uint)sb->st_ino)))
                ent_blocks += sb->st_size;
 
        ++num_files;
@@ -4319,8 +4323,7 @@ static int dentfill(char *path, struct entry **dents)
                                }
                        } else {
                                /* Do not recount hard links */
-                               if (sb.st_nlink <= 1
-                                   || test_set_bit((ulong)sb.st_ino + (ulong)sb.st_size))
+                               if (sb.st_nlink <= 1 || test_set_bit((uint)sb.st_ino))
                                        dir_blocks += (cfg.apparentsz ? sb.st_size : sb.st_blocks);
                                ++num_files;
                        }
@@ -4417,8 +4420,7 @@ static int dentfill(char *path, struct entry **dents)
                        } else {
                                dentp->blocks = (cfg.apparentsz ? sb.st_size : sb.st_blocks);
                                /* Do not recount hard links */
-                               if (sb.st_nlink <= 1
-                                   || test_set_bit((ulong)sb.st_ino + (ulong)sb.st_size))
+                               if (sb.st_nlink <= 1 || test_set_bit((uint)sb.st_ino))
                                        dir_blocks += dentp->blocks;
                                ++num_files;
                        }