summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2012-01-17 15:38:31 -0500
committerTheodore Ts'o <tytso@mit.edu>2012-01-17 15:38:31 -0500
commit1f572d1f88628c1e0dc88cb8cfaf2bb480b81e4f (patch)
tree7a91b642b92d1f1f84daf4e78a864b0482c0e370
parent2b1cae7a2697ec841c41579d29cdcb0ab39ef73e (diff)
downloade2fsprogs-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>
-rw-r--r--lib/ext2fs/get_pathname.c21
-rw-r--r--tests/f_badroot/expect.12
-rw-r--r--tests/f_dupdot/expect.14
-rw-r--r--tests/f_expand/expect.1.gzbin13440 -> 13462 bytes
-rw-r--r--tests/f_orphan_dotdot_ft/expect.112
5 files changed, 25 insertions, 14 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;
}
diff --git a/tests/f_badroot/expect.1 b/tests/f_badroot/expect.1
index 66ff32ee..f9d01e57 100644
--- a/tests/f_badroot/expect.1
+++ b/tests/f_badroot/expect.1
@@ -4,7 +4,7 @@ Pass 1: Checking inodes, blocks, and sizes
Root inode is not a directory. Clear? yes
Pass 2: Checking directory structure
-Entry '..' in ??? (11) has deleted/unused inode 2. Clear? yes
+Entry '..' in <2>/<11> (11) has deleted/unused inode 2. Clear? yes
Pass 3: Checking directory connectivity
Root inode not allocated. Allocate? yes
diff --git a/tests/f_dupdot/expect.1 b/tests/f_dupdot/expect.1
index 611f8701..afce8d6e 100644
--- a/tests/f_dupdot/expect.1
+++ b/tests/f_dupdot/expect.1
@@ -1,9 +1,9 @@
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
-Entry '.' in ??? (12) is duplicate '.' entry.
+Entry '.' in <14>/<12> (12) is duplicate '.' entry.
Fix? yes
-Entry '..' in ??? (12) is duplicate '..' entry.
+Entry '..' in <14>/<12> (12) is duplicate '..' entry.
Fix? yes
Pass 3: Checking directory connectivity
diff --git a/tests/f_expand/expect.1.gz b/tests/f_expand/expect.1.gz
index 91799bb0..1015e155 100644
--- a/tests/f_expand/expect.1.gz
+++ b/tests/f_expand/expect.1.gz
Binary files differ
diff --git a/tests/f_orphan_dotdot_ft/expect.1 b/tests/f_orphan_dotdot_ft/expect.1
index ac309e8a..6a1373f2 100644
--- a/tests/f_orphan_dotdot_ft/expect.1
+++ b/tests/f_orphan_dotdot_ft/expect.1
@@ -7,23 +7,23 @@ Pass 2: Checking directory structure
Entry 'dir' in / (2) has an incorrect filetype (was 2, should be 6).
Fix? yes
-Entry '..' in ??? (13) has an incorrect filetype (was 2, should be 6).
+Entry '..' in <12>/<13> (13) has an incorrect filetype (was 2, should be 6).
Fix? yes
-Entry '..' in ??? (14) has an incorrect filetype (was 2, should be 6).
+Entry '..' in <12>/<14> (14) has an incorrect filetype (was 2, should be 6).
Fix? yes
-Entry '..' in ??? (15) has an incorrect filetype (was 2, should be 6).
+Entry '..' in <12>/<15> (15) has an incorrect filetype (was 2, should be 6).
Fix? yes
Pass 3: Checking directory connectivity
-Unconnected directory inode 13 (???)
+Unconnected directory inode 13 (<12>/<13>)
Connect to /lost+found? yes
-Unconnected directory inode 14 (???)
+Unconnected directory inode 14 (<12>/<14>)
Connect to /lost+found? yes
-Unconnected directory inode 15 (???)
+Unconnected directory inode 15 (<12>/<15>)
Connect to /lost+found? yes
Pass 4: Checking reference counts