@@ -30,6 +30,19 @@
#include "kernel-shared/file-item.h"
#include "common/utils.h"
+static void print_name(const char *buf, size_t len)
+{
+ size_t i;
+ printf("name: ");
+ for(i = 0; i < len; i++) {
+ if (buf[i] >= ' ' && buf[i] <= '~')
+ printf("%c", buf[i]);
+ else
+ printf("\\x%02hhx", buf[i]);
+ }
+ printf("\n");
+}
+
static void print_dir_item_type(struct extent_buffer *eb,
struct btrfs_dir_item *di)
{
@@ -79,7 +92,7 @@ static void print_dir_item(struct extent_buffer *eb, u32 size,
} else {
read_extent_buffer(eb, namebuf,
(unsigned long)(di + 1), len);
- printf("\t\tname: %.*s\n", len, namebuf);
+ print_name(namebuf, len);
}
if (data_len) {
@@ -137,7 +150,7 @@ static void print_inode_extref_item(struct extent_buffer *eb, u32 size,
} else {
read_extent_buffer(eb, namebuf,
(unsigned long)extref->name, len);
- printf("name: %.*s\n", len, namebuf);
+ print_name(namebuf, len);
}
len = sizeof(*extref) + name_len;
@@ -167,7 +180,7 @@ static void print_inode_ref_item(struct extent_buffer *eb, u32 size,
} else {
read_extent_buffer(eb, namebuf,
(unsigned long)(ref + 1), len);
- printf("name: %.*s\n", len, namebuf);
+ print_name(namebuf, len);
}
len = sizeof(*ref) + name_len;
ref = (struct btrfs_inode_ref *)((char *)ref + len);
There are several item types which have an associated name: inode refs and dir items. While they could always be unprintable, the advent of encryption makes it much more likely that the names contain characters outside the normal ASCII range. As such, it's useful to print the characters outside normal ASCII in hex format. Signed-off-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me> --- kernel-shared/print-tree.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)