diff options
author | Theodore Ts'o <tytso@mit.edu> | 2012-01-17 15:38:31 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2012-01-17 15:38:31 -0500 |
commit | 1f572d1f88628c1e0dc88cb8cfaf2bb480b81e4f (patch) | |
tree | 7a91b642b92d1f1f84daf4e78a864b0482c0e370 /lib | |
parent | 2b1cae7a2697ec841c41579d29cdcb0ab39ef73e (diff) | |
download | e2fsprogs-1f572d1f88628c1e0dc88cb8cfaf2bb480b81e4f.tar.gz |
libext2fs: display partial path if fs corrupted in ext2fs_get_pathname()
The function ext2fs_get_pathname() used to return EXT2_ET_NO_DIRECTORY
if one of the directories in an inode's pathname is not a directory.
This is not very useful in an emergency, when the file system is
corrupted. This commit will cause ext2fs_get_pathname() to return a
partial pathname, which should help system administrators trying to
use debugfs to investigate a corrupted file system.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ext2fs/get_pathname.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/ext2fs/get_pathname.c b/lib/ext2fs/get_pathname.c index e259eee7..33209949 100644 --- a/lib/ext2fs/get_pathname.c +++ b/lib/ext2fs/get_pathname.c @@ -74,7 +74,7 @@ static errcode_t ext2fs_get_pathname_int(ext2_filsys fs, ext2_ino_t dir, char *buf, char **name) { struct get_pathname_struct gp; - char *parent_name, *ret; + char *parent_name = 0, *ret; errcode_t retval; if (dir == ino) { @@ -99,7 +99,19 @@ static errcode_t ext2fs_get_pathname_int(ext2_filsys fs, ext2_ino_t dir, gp.errcode = 0; retval = ext2fs_dir_iterate(fs, dir, 0, buf, get_pathname_proc, &gp); - if (retval) + if (retval == EXT2_ET_NO_DIRECTORY) { + char buf[32]; + + if (ino) + snprintf(buf, sizeof(buf), "<%u>/<%u>", dir, ino); + else + snprintf(buf, sizeof(buf), "<%u>", dir); + retval = ext2fs_get_mem(strlen(buf)+1, name); + if (retval) + goto cleanup; + strcpy(*name, buf); + return 0; + } else if (retval) goto cleanup; if (gp.errcode) { retval = gp.errcode; @@ -132,12 +144,11 @@ static errcode_t ext2fs_get_pathname_int(ext2_filsys fs, ext2_ino_t dir, else strcat(ret, "???"); *name = ret; - ext2fs_free_mem(&parent_name); retval = 0; cleanup: - if (gp.name) - ext2fs_free_mem(&gp.name); + ext2fs_free_mem(&parent_name); + ext2fs_free_mem(&gp.name); return retval; } |