Hi Ted,
Commit 03206bd introduced regression in ncheck while printing all the
pathnames of an inode. For files which have hardlink in the same
directory we will print the same pathname instead of all possible like
below :-
debugfs: ncheck 14
Inode Pathname
14 /a/f1
14 /a/f1
14 /b/f3
where it should have printed
debugfs: ncheck 14
Inode Pathname
14 /a/f1
14 /a/f2
14 /b/f3
Below patch fixes it.
Signed-off-by : Manish Katiyar <[email protected]>
---
debugfs/ncheck.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/debugfs/ncheck.c b/debugfs/ncheck.c
index 22fa29f..c850739 100644
--- a/debugfs/ncheck.c
+++ b/debugfs/ncheck.c
@@ -36,14 +36,16 @@ static int ncheck_proc(struct ext2_dir_entry *dirent,
int i;
char *pathname;
errcode_t retval;
+ static ext2_ino_t parent;
iw->position++;
+ if (iw->position == 2)
+ parent = dirent->inode;
if (iw->position <= 2)
return 0;
for (i=0; i < iw->num_inodes; i++) {
if (iw->iarray[i] == dirent->inode) {
- retval = ext2fs_get_pathname(current_fs, iw->parent,
- iw->iarray[i],
+ retval = ext2fs_get_pathname(current_fs, parent, iw->parent,
&pathname);
if (retval)
com_err("ncheck", retval,
@@ -51,7 +53,7 @@ static int ncheck_proc(struct ext2_dir_entry *dirent,
"inode %d (%d)", iw->parent,
iw->iarray[i]);
else
- printf("%u\t%s\n", iw->iarray[i], pathname);
+ printf("%u\t%s/%s\n", iw->iarray[i], pathname, dirent->name);
}
}
if (!iw->inodes_left)
--
1.5.4.3
Thanks -
Manish
On Thu, Oct 09, 2008 at 11:04:45PM +0530, Manish Katiyar wrote:
> Hi Ted,
>
> Commit 03206bd introduced regression in ncheck while printing all the
> pathnames of an inode. For files which have hardlink in the same
> directory we will print the same pathname instead of all possible like
> below :-
This patch is a better way to fix things. It fixes a memory leak,
avoids the static variable, and avoids calling ext2fs_get_pathname
multiple times for each directory.
- Ted
commit b4c36addc0279193018a4bb59871c5365db1489b
Author: Theodore Ts'o <[email protected]>
Date: Fri Oct 10 14:53:09 2008 -0400
debugfs: Fix ncheck when printing pathnames for multiple hardlinks in a directory
Signed-off-by: "Theodore Ts'o" <[email protected]>
diff --git a/debugfs/ncheck.c b/debugfs/ncheck.c
index 22fa29f..abb38a8 100644
--- a/debugfs/ncheck.c
+++ b/debugfs/ncheck.c
@@ -23,7 +23,7 @@ struct inode_walk_struct {
int inodes_left;
int num_inodes;
int position;
- ext2_ino_t parent;
+ char *parent;
};
static int ncheck_proc(struct ext2_dir_entry *dirent,
@@ -42,16 +42,8 @@ static int ncheck_proc(struct ext2_dir_entry *dirent,
return 0;
for (i=0; i < iw->num_inodes; i++) {
if (iw->iarray[i] == dirent->inode) {
- retval = ext2fs_get_pathname(current_fs, iw->parent,
- iw->iarray[i],
- &pathname);
- if (retval)
- com_err("ncheck", retval,
- "while resolving pathname for "
- "inode %d (%d)", iw->parent,
- iw->iarray[i]);
- else
- printf("%u\t%s\n", iw->iarray[i], pathname);
+ printf("%u\t%s/%*s\n", iw->iarray[i], iw->parent,
+ (dirent->name_len & 0xFF), dirent->name);
}
}
if (!iw->inodes_left)
@@ -124,10 +116,17 @@ void do_ncheck(int argc, char **argv)
goto next;
iw.position = 0;
- iw.parent = ino;
+
+ retval = ext2fs_get_pathname(current_fs, ino, 0, &iw.parent);
+ if (retval) {
+ com_err("ncheck", retval,
+ "while calling ext2fs_get_pathname");
+ goto next;
+ }
retval = ext2fs_dir_iterate(current_fs, ino, 0, 0,
ncheck_proc, &iw);
+ ext2fs_free_mem(&iw.parent);
if (retval) {
com_err("ncheck", retval,
"while calling ext2_dir_iterate");