summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2012-01-16 17:49:46 -0500
committerTheodore Ts'o <tytso@mit.edu>2012-01-16 17:49:46 -0500
commit2b1cae7a2697ec841c41579d29cdcb0ab39ef73e (patch)
treef3ad44e136df5f97347d25507579026d2bcd8dc2
parent24d364fc43601ea3d2e01cc506633302fa091d8f (diff)
downloade2fsprogs-2b1cae7a2697ec841c41579d29cdcb0ab39ef73e.tar.gz
debugfs: optimize ncheck and improve its error checking
Don't call ext2fs_get_pathname() for every single directory; instead, only call it if we find a matching directory entry. In addition, if ext2fs_get_pathname() fails, print the number of the parent directory in angle parents so the user gets some additional information. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r--debugfs/ncheck.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/debugfs/ncheck.c b/debugfs/ncheck.c
index 739e0014..09b844c9 100644
--- a/debugfs/ncheck.c
+++ b/debugfs/ncheck.c
@@ -20,11 +20,13 @@
#include "debugfs.h"
struct inode_walk_struct {
+ ext2_ino_t dir;
ext2_ino_t *iarray;
int inodes_left;
int num_inodes;
int position;
char *parent;
+ unsigned int get_pathname_failed;
};
static int ncheck_proc(struct ext2_dir_entry *dirent,
@@ -34,15 +36,32 @@ static int ncheck_proc(struct ext2_dir_entry *dirent,
void *private)
{
struct inode_walk_struct *iw = (struct inode_walk_struct *) private;
- int i;
+ errcode_t retval;
+ int i;
iw->position++;
if (iw->position <= 2)
return 0;
for (i=0; i < iw->num_inodes; i++) {
if (iw->iarray[i] == dirent->inode) {
- printf("%u\t%s/%.*s\n", iw->iarray[i], iw->parent,
- (dirent->name_len & 0xFF), dirent->name);
+ if (!iw->parent && !iw->get_pathname_failed) {
+ retval = ext2fs_get_pathname(current_fs,
+ iw->dir,
+ 0, &iw->parent);
+ if (retval) {
+ com_err("ncheck", retval,
+ "while calling ext2fs_get_pathname for inode #%u", iw->dir);
+ iw->get_pathname_failed = 1;
+ }
+ }
+ if (iw->parent)
+ printf("%u\t%s/%.*s\n", iw->iarray[i],
+ iw->parent,
+ (dirent->name_len & 0xFF), dirent->name);
+ else
+ printf("%u\t<%u>/%.*s\n", iw->iarray[i],
+ iw->dir,
+ (dirent->name_len & 0xFF), dirent->name);
}
}
if (!iw->inodes_left)
@@ -115,13 +134,9 @@ void do_ncheck(int argc, char **argv)
goto next;
iw.position = 0;
-
- retval = ext2fs_get_pathname(current_fs, ino, 0, &iw.parent);
- if (retval) {
- com_err("ncheck", retval,
- "while calling ext2fs_get_pathname");
- goto next;
- }
+ iw.parent = 0;
+ iw.dir = ino;
+ iw.get_pathname_failed = 0;
retval = ext2fs_dir_iterate(current_fs, ino, 0, 0,
ncheck_proc, &iw);