Skip to content

Commit 8a35f9d

Browse files
committed
btrfs-progs: dump-tree: escape special characters in paths or xattrs
Filenames can contain a newline (or other funny characters), this makes the dump-tree output confusing, same for xattr names or values that can binary data. Encode the special characters in the C-style ('\e' -> "\e", or \NNN if there's no single letter representation). This is based on the isprint() as it's espected either on a terminal or in a dump file. Issue: #350 Issue: #407 Signed-off-by: David Sterba <[email protected]>
1 parent bfed38f commit 8a35f9d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

Documentation/btrfs-inspect-internal.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,12 @@ dump-tree [options] <device> [device...]
6666
a positive educational effect on understanding the internal filesystem structure.
6767

6868
.. note::
69-
Contains file names, consider that if you're asked to send the dump for
70-
analysis. Does not contain file data.
69+
By default contains file names, consider that if you're asked
70+
to send the dump for analysis and use *--hide-names* eventually.
71+
Does not contain file data.
72+
73+
Special characters in file names, xattr names and values are escaped,
74+
in the C style like ``\n`` and octal encoding ``\NNN``.
7175

7276
``Options``
7377

kernel-shared/print-tree.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ static void print_dir_item(struct extent_buffer *eb, u32 size,
9393
} else {
9494
read_extent_buffer(eb, namebuf,
9595
(unsigned long)(di + 1), len);
96-
printf("\t\tname: %.*s\n", len, namebuf);
96+
printf("\t\tname: ");
97+
string_print_escape_special_len(namebuf, len);
98+
printf("\n");
9799
}
98100

99101
if (data_len) {
@@ -104,7 +106,9 @@ static void print_dir_item(struct extent_buffer *eb, u32 size,
104106
} else {
105107
read_extent_buffer(eb, namebuf,
106108
(unsigned long)(di + 1) + name_len, len);
107-
printf("\t\tdata %.*s\n", len, namebuf);
109+
printf("\t\tdata ");
110+
string_print_escape_special_len(namebuf, len);
111+
printf("\n");
108112
}
109113
}
110114
len = sizeof(*di) + name_len + data_len;
@@ -137,7 +141,9 @@ static void print_inode_extref_item(struct extent_buffer *eb, u32 size,
137141
} else {
138142
read_extent_buffer(eb, namebuf,
139143
(unsigned long)extref->name, len);
140-
printf("name: %.*s\n", len, namebuf);
144+
printf("name: ");
145+
string_print_escape_special_len(namebuf, len);
146+
printf("\n");
141147
}
142148

143149
len = sizeof(*extref) + name_len;
@@ -167,7 +173,9 @@ static void print_inode_ref_item(struct extent_buffer *eb, u32 size,
167173
} else {
168174
read_extent_buffer(eb, namebuf,
169175
(unsigned long)(ref + 1), len);
170-
printf("name: %.*s\n", len, namebuf);
176+
printf("name: ");
177+
string_print_escape_special_len(namebuf, len);
178+
printf("\n");
171179
}
172180
len = sizeof(*ref) + name_len;
173181
ref = (struct btrfs_inode_ref *)((char *)ref + len);

0 commit comments

Comments
 (0)