Whamcloud - gitweb
debugfs: fix ncheck so it handles hard links correctly 75/33575/3
authorJaco Kroon <jaco@uls.co.za>
Thu, 2 Aug 2018 18:06:46 +0000 (20:06 +0200)
committerAndreas Dilger <adilger@whamcloud.com>
Fri, 9 Nov 2018 07:09:29 +0000 (07:09 +0000)
Due to hard links inodes can have multiple names (except for folders),
ncheck should find all of the names (equal to the number of links to the
inodes, directories excepted), not names to the count of the provided
inodes.

Commit: 4a30e2ae7ced039189ee438065b2f656d83e7e44
Change-Id: I09ae767057ce5c89b6232f1e9bbc94db4fc4e9c1
Signed-off-by: Jaco Kroon <jaco@uls.co.za>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-on: https://review.whamcloud.com/33575
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Tested-by: Andreas Dilger <adilger@whamcloud.com>
debugfs/ncheck.c

index 5936d5d..9304c75 100644 (file)
@@ -28,7 +28,7 @@ extern char *optarg;
 struct inode_walk_struct {
        ext2_ino_t              dir;
        ext2_ino_t              *iarray;
-       int                     inodes_left;
+       int                     names_left;
        int                     num_inodes;
        int                     position;
        char                    *parent;
@@ -84,10 +84,10 @@ static int ncheck_proc(struct ext2_dir_entry *dirent,
                                }
                        }
                        putc('\n', stdout);
-                       iw->inodes_left--;
+                       iw->names_left--;
                }
        }
-       if (!iw->inodes_left)
+       if (!iw->names_left)
                return DIRENT_ABORT;
 
        return 0;
@@ -134,15 +134,22 @@ void do_ncheck(int argc, char **argv)
        }
        memset(iw.iarray, 0, sizeof(ext2_ino_t) * argc);
 
+       iw.names_left = 0;
        for (i=0; i < argc; i++) {
                iw.iarray[i] = strtol(argv[i], &tmp, 0);
                if (*tmp) {
                        com_err("ncheck", 0, "Bad inode - %s", argv[i]);
                        goto error_out;
                }
+               if (debugfs_read_inode(iw.iarray[i], &inode, *argv))
+                       goto error_out;
+               if (LINUX_S_ISDIR(inode.i_mode))
+                       iw.names_left += 1;
+               else
+                       iw.names_left += inode.i_links_count;
        }
 
-       iw.num_inodes = iw.inodes_left = argc;
+       iw.num_inodes = argc;
 
        retval = ext2fs_open_inode_scan(current_fs, 0, &scan);
        if (retval) {
@@ -186,7 +193,7 @@ void do_ncheck(int argc, char **argv)
                        goto next;
                }
 
-               if (iw.inodes_left == 0)
+               if (iw.names_left == 0)
                        break;
 
        next: