Blame SOURCES/e2fsprogs-1.44.4-debugfs-fix-ncheck-so-it-handles-hard-links-correctl.patch

5ce3dc
From 9a504be9857c0c4e3b56cfbe4257ff88284469c7 Mon Sep 17 00:00:00 2001
5ce3dc
From: Jaco Kroon <jaco@uls.co.za>
5ce3dc
Date: Thu, 2 Aug 2018 20:06:46 +0200
5ce3dc
Subject: [PATCH 02/10] debugfs: fix ncheck so it handles hard links correctly
5ce3dc
5ce3dc
Due to hard links inodes can have multiple names (except for folders),
5ce3dc
ncheck should find all of the names (equal to the number of links to the
5ce3dc
inodes, directories excepted), not names to the count of the provided
5ce3dc
inodes.
5ce3dc
5ce3dc
Signed-off-by: Jaco Kroon <jaco@uls.co.za>
5ce3dc
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
5ce3dc
---
5ce3dc
 debugfs/ncheck.c | 17 ++++++++++++-----
5ce3dc
 1 file changed, 12 insertions(+), 5 deletions(-)
5ce3dc
5ce3dc
diff --git a/debugfs/ncheck.c b/debugfs/ncheck.c
5ce3dc
index dc4ab56d..158e8658 100644
5ce3dc
--- a/debugfs/ncheck.c
5ce3dc
+++ b/debugfs/ncheck.c
5ce3dc
@@ -28,7 +28,7 @@ extern char *optarg;
5ce3dc
 struct inode_walk_struct {
5ce3dc
 	ext2_ino_t		dir;
5ce3dc
 	ext2_ino_t		*iarray;
5ce3dc
-	int			inodes_left;
5ce3dc
+	int			names_left;
5ce3dc
 	int			num_inodes;
5ce3dc
 	int			position;
5ce3dc
 	char			*parent;
5ce3dc
@@ -81,10 +81,10 @@ static int ncheck_proc(struct ext2_dir_entry *dirent,
5ce3dc
 				}
5ce3dc
 			}
5ce3dc
 			putc('\n', stdout);
5ce3dc
-			iw->inodes_left--;
5ce3dc
+			iw->names_left--;
5ce3dc
 		}
5ce3dc
 	}
5ce3dc
-	if (!iw->inodes_left)
5ce3dc
+	if (!iw->names_left)
5ce3dc
 		return DIRENT_ABORT;
5ce3dc
 
5ce3dc
 	return 0;
5ce3dc
@@ -131,15 +131,22 @@ void do_ncheck(int argc, char **argv)
5ce3dc
 	}
5ce3dc
 	memset(iw.iarray, 0, sizeof(ext2_ino_t) * argc);
5ce3dc
 
5ce3dc
+	iw.names_left = 0;
5ce3dc
 	for (i=0; i < argc; i++) {
5ce3dc
 		iw.iarray[i] = strtol(argv[i], &tmp, 0);
5ce3dc
 		if (*tmp) {
5ce3dc
 			com_err("ncheck", 0, "Bad inode - %s", argv[i]);
5ce3dc
 			goto error_out;
5ce3dc
 		}
5ce3dc
+		if (debugfs_read_inode(iw.iarray[i], &inode, *argv))
5ce3dc
+			goto error_out;
5ce3dc
+		if (LINUX_S_ISDIR(inode.i_mode))
5ce3dc
+			iw.names_left += 1;
5ce3dc
+		else
5ce3dc
+			iw.names_left += inode.i_links_count;
5ce3dc
 	}
5ce3dc
 
5ce3dc
-	iw.num_inodes = iw.inodes_left = argc;
5ce3dc
+	iw.num_inodes = argc;
5ce3dc
 
5ce3dc
 	retval = ext2fs_open_inode_scan(current_fs, 0, &scan;;
5ce3dc
 	if (retval) {
5ce3dc
@@ -183,7 +190,7 @@ void do_ncheck(int argc, char **argv)
5ce3dc
 			goto next;
5ce3dc
 		}
5ce3dc
 
5ce3dc
-		if (iw.inodes_left == 0)
5ce3dc
+		if (iw.names_left == 0)
5ce3dc
 			break;
5ce3dc
 
5ce3dc
 	next:
5ce3dc
-- 
5ce3dc
2.17.2
5ce3dc