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 <dsterba@suse.com>
This commit is contained in:
David Sterba 2024-07-17 03:40:43 +02:00
parent 3d2e879463
commit ef73193623
2 changed files with 18 additions and 6 deletions

View File

@ -66,8 +66,12 @@ dump-tree [options] <device> [device...]
a positive educational effect on understanding the internal filesystem structure.
.. note::
Contains file names, consider that if you're asked to send the dump for
analysis. Does not contain file data.
By default contains file names, consider that if you're asked
to send the dump for analysis and use *--hide-names* eventually.
Does not contain file data.
Special characters in file names, xattr names and values are escaped,
in the C style like ``\n`` and octal encoding ``\NNN``.
``Options``

View File

@ -93,7 +93,9 @@ 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);
printf("\t\tname: ");
string_print_escape_special_len(namebuf, len);
printf("\n");
}
if (data_len) {
@ -104,7 +106,9 @@ static void print_dir_item(struct extent_buffer *eb, u32 size,
} else {
read_extent_buffer(eb, namebuf,
(unsigned long)(di + 1) + name_len, len);
printf("\t\tdata %.*s\n", len, namebuf);
printf("\t\tdata ");
string_print_escape_special_len(namebuf, len);
printf("\n");
}
}
len = sizeof(*di) + name_len + data_len;
@ -137,7 +141,9 @@ 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);
printf("name: ");
string_print_escape_special_len(namebuf, len);
printf("\n");
}
len = sizeof(*extref) + name_len;
@ -167,7 +173,9 @@ 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);
printf("name: ");
string_print_escape_special_len(namebuf, len);
printf("\n");
}
len = sizeof(*ref) + name_len;
ref = (struct btrfs_inode_ref *)((char *)ref + len);