Skip to contentSkip to conversation

debugfs: fix printing of inline data during symlink inode dump

PATCH Applied Darrick J. Wong 2 participants 2 messages Jul 22, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 debugfs: fix printing of inline data during symlink inode dump

When we're dumping a fast symlink inode, we print some odd things to stdout. To clean this up, first don't print inline data EA, since the inode dump doesn't display file and directory contents. Then, teach the inode dump function how to print out either an inline data fast symlink or a non-inline data fast symlink.

(This is a follow-up to the earlier patch "debugfs: Only print the first 60 bytes from i_block on a fast symlink")

---
 debugfs/debugfs.c            |   47 +++++++++++++++++---
 debugfs/xattrs.c             |    9 ++--
 tests/d_inline_dump/expect   |  101 ++++++++++++++++++++++++++++++++++++++++++
 tests/d_inline_dump/image.gz |  Bin
 tests/d_inline_dump/name     |    1 
 tests/d_inline_dump/script   |   43 ++++++++++++++++++
 tests/d_special_files/expect |    2 -
 7 files changed, 194 insertions(+), 9 deletions(-)
 create mode 100644 tests/d_inline_dump/expect
 create mode 100644 tests/d_inline_dump/image.gz
 create mode 100644 tests/d_inline_dump/name
 create mode 100644 tests/d_inline_dump/script
debugfs/debugfs.c +42 -5
index 51f386b..68ed05a 100644
@@ -668,7 +668,46 @@ static void dump_inline_data(FILE *out, const char *prefix, ext2_ino_t inode_num
 
 	retval = ext2fs_inline_data_size(current_fs, inode_num, &size);
 	if (!retval)
-		fprintf(out, "%sSize of inline data: %zu", prefix, size);
+		fprintf(out, "%sSize of inline data: %zu\n", prefix, size);
+}
+
+static void dump_fast_link(FILE *out, ext2_ino_t inode_num,
+			   struct ext2_inode *inode, const char *prefix)
+{
+	errcode_t retval = 0;
+	char *buf;
+	size_t size;
+
+	if (inode->i_flags & EXT4_INLINE_DATA_FL) {
+		retval = ext2fs_inline_data_size(current_fs, inode_num, &size);
+		if (retval)
+			goto out;
+
+		retval = ext2fs_get_memzero(size + 1, &buf);
+		if (retval)
+			goto out;
+
+		retval = ext2fs_inline_data_get(current_fs, inode_num,
+						inode, buf, &size);
+		if (retval)
+			goto out;
+		fprintf(out, "%sFast link dest: \"%.*s\"\n", prefix,
+			(int)size, buf);
+
+		retval = ext2fs_free_mem(&buf);
+		if (retval)
+			goto out;
+	} else {
+		int sz = EXT2_I_SIZE(inode);
+
+		if (sz > sizeof(inode->i_block))
+			sz = sizeof(inode->i_block);
+		fprintf(out, "%sFast link dest: \"%.*s\"\n", prefix, sz,
+			(char *)inode->i_block);
+	}
+out:
+	if (retval)
+		com_err(__func__, retval, "while dumping link destination");
 }
 
 void internal_dump_inode(FILE *out, const char *prefix,
@@ -783,10 +822,8 @@ void internal_dump_inode(FILE *out, const char *prefix,
 	}
 
 	if (LINUX_S_ISLNK(inode->i_mode) &&
-	    ext2fs_inode_data_blocks(current_fs,inode) == 0 &&
-	    !(inode->i_flags & EXT4_INLINE_DATA_FL))
-		fprintf(out, "%sFast_link_dest: %.*s\n", prefix,
-			(int) inode->i_size, (char *)inode->i_block);
+	    ext2fs_inode_data_blocks(current_fs, inode) == 0)
+		dump_fast_link(out, inode_num, inode, prefix);
 	else if (LINUX_S_ISBLK(inode->i_mode) || LINUX_S_ISCHR(inode->i_mode)) {
 		int major, minor;
 		const char *devnote;
debugfs/xattrs.c +6 -3
index f2d7128..1c19b2f 100644
@@ -45,9 +45,12 @@ static int dump_attr(char *name, char *value, size_t value_len, void *data)
 
 	fprintf(out, "  ");
 	dump_xattr_string(out, name, strlen(name));
-	fprintf(out, " = \"");
-	dump_xattr_string(out, value, value_len);
-	fprintf(out, "\" (%zu)\n", value_len);
+	if (strcmp(name, "system.data") != 0) {
+		fprintf(out, " = \"");
+		dump_xattr_string(out, value, value_len);
+		fprintf(out, "\"");
+	}
+	fprintf(out, " (%zu)\n", value_len);
 
 	return 0;
 }
tests/d_inline_dump/expect new file +101 -0

101 lines not on this page · raw message

tests/d_inline_dump/image.gz new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..598a495aa25f7412d8f94150b1b78d5630e17906
GIT binary patch
tests/d_inline_dump/name new file +1 -0
new file mode 100644
index 0000000..dfc1a9c
@@ -0,0 +1 @@
+debugfs dump inline data test
tests/d_inline_dump/script new file +43 -0

43 lines not on this page · raw message

tests/d_special_files/expect +1 -1
index 2b2dbfa..f729b0f 100644
@@ -11,7 +11,7 @@ Fragment:  Address: 0    Number: 0    Size: 0
 ctime: 0x50f560e0 -- Tue Jan 15 14:00:00 2013
 atime: 0x50f560e0 -- Tue Jan 15 14:00:00 2013
 mtime: 0x50f560e0 -- Tue Jan 15 14:00:00 2013
-Fast_link_dest: bar
+Fast link dest: "bar"
 Exit status is 0
 debugfs -R ''stat foo2'' -w test.img
 Inode: 13   Type: symlink    Mode:  0777   Flags: 0x0
#1 lore raw
Quoted 10 lines · Darrick J. Wong

When we're dumping a fast symlink inode, we print some odd things to stdout. To clean this up, first don't print inline data EA, since the inode dump doesn't display file and directory contents. Then, teach the inode dump function how to print out either an inline data fast symlink or a non-inline data fast symlink.

(This is a follow-up to the earlier patch "debugfs: Only print the first 60 bytes from i_block on a fast symlink")

Applied, thanks.

I had to make a minor change in your script to use $test_dir/image.gz instead of $test_name/image.gz. (The former doesn't work when the build directory != the source directory, i.e., when doing a VPATH build).

- Ted