btrfs-progs: dump-tree: rename to option to --hide-names

Previously, no filenames/xattrs would be printed with --nofilename, but
to keep the format of dump, print a placeholder instead of all names.
This is:

* directory entries (files, directories, subvolumes)
* default subvolume
* extended attributes (name, value)
* hardlink names if stored inside another item

Note that lengths are not hidden because they can be calculated from the
item size anyway.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2020-03-04 15:43:42 +01:00
parent 4d4e7d7c9f
commit d028b3998e
6 changed files with 47 additions and 27 deletions

View File

@ -100,9 +100,20 @@ intermixed in the output
+
use breadth-first search to print trees, the nodes are printed before all
leaves
--nofilename::::
do not print any filename of the filesystem. Useful for developer to inspect
the filesystem while keep confidential info hiden.
+
--hide-names::::
print a placeholder 'HIDDEN' instead of various names, useful for developers to
inspect the dump while keeping potentially sensitive information hidden
+
This is:
[options="compact"]
* directory entries (files, directories, subvolumes)
* default subvolume
* extended attributes (name, value)
* hardlink names (if stored inside another item or as extended references in standalone items)
+
NOTE: lengths are not hidden because they can be calculated from the item size anyway.
+
--noscan::::
do not automatically scan the system for other devices from the same
filesystem, only use the devices provided as the arguments

View File

@ -206,6 +206,7 @@ static const char * const cmd_inspect_dump_tree_usage[] = {
"--noscan do not scan the devices from the filesystem, use only the listed ones",
"--bfs breadth-first traversal of the trees, print nodes, then leaves (default)",
"--dfs depth-first traversal of the trees",
"--hide-names hide filenames/subvolume/xattrs and other name references",
NULL
};
@ -330,7 +331,7 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,
while (1) {
int c;
enum { GETOPT_VAL_FOLLOW = 256, GETOPT_VAL_DFS, GETOPT_VAL_BFS,
GETOPT_VAL_NOSCAN, GETOPT_VAL_NOFILENAME };
GETOPT_VAL_NOSCAN, GETOPT_VAL_HIDE_NAMES };
static const struct option long_options[] = {
{ "extents", no_argument, NULL, 'e'},
{ "device", no_argument, NULL, 'd'},
@ -343,8 +344,7 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,
{ "bfs", no_argument, NULL, GETOPT_VAL_BFS },
{ "dfs", no_argument, NULL, GETOPT_VAL_DFS },
{ "noscan", no_argument, NULL, GETOPT_VAL_NOSCAN },
{ "nofilename", no_argument, NULL,
GETOPT_VAL_NOFILENAME },
{ "hide-names", no_argument, NULL, GETOPT_VAL_HIDE_NAMES },
{ NULL, 0, NULL, 0 }
};
@ -412,8 +412,8 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,
case GETOPT_VAL_NOSCAN:
open_ctree_flags |= OPEN_CTREE_NO_DEVICES;
break;
case GETOPT_VAL_NOFILENAME:
open_ctree_flags |= OPEN_CTREE_DONT_PRINT_FILENAME;
case GETOPT_VAL_HIDE_NAMES:
open_ctree_flags |= OPEN_CTREE_HIDE_NAMES;
break;
default:
usage_unknown_option(cmd, argv);

View File

@ -1193,7 +1193,7 @@ struct btrfs_fs_info {
unsigned int avoid_meta_chunk_alloc:1;
unsigned int avoid_sys_chunk_alloc:1;
unsigned int finalize_on_close:1;
unsigned int dont_print_filename:1;
unsigned int hide_names:1;
int transaction_aborted;

View File

@ -1218,8 +1218,8 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
fs_info->ignore_fsid_mismatch = 1;
if (flags & OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR)
fs_info->ignore_chunk_tree_error = 1;
if (flags & OPEN_CTREE_DONT_PRINT_FILENAME)
fs_info->dont_print_filename = 1;
if (flags & OPEN_CTREE_HIDE_NAMES)
fs_info->hide_names = 1;
if ((flags & OPEN_CTREE_RECOVER_SUPER)
&& (flags & OPEN_CTREE_TEMPORARY_SUPER)) {

View File

@ -86,8 +86,8 @@ enum btrfs_open_ctree_flags {
*/
OPEN_CTREE_INVALIDATE_FST = (1U << 13),
/* For print-tree only, skip filename output */
OPEN_CTREE_DONT_PRINT_FILENAME = (1U << 14),
/* For print-tree, print HIDDEN instead of filenames/xattrs/refs */
OPEN_CTREE_HIDE_NAMES = (1U << 14),
};
/*

View File

@ -70,13 +70,20 @@ static void print_dir_item(struct extent_buffer *eb, u32 size,
printf("\t\ttransid %llu data_len %u name_len %u\n",
btrfs_dir_transid(eb, di),
data_len, name_len);
if (!(eb->fs_info && eb->fs_info->dont_print_filename)) {
if (eb->fs_info && eb->fs_info->hide_names) {
printf("\t\tname: HIDDEN\n");
} else {
read_extent_buffer(eb, namebuf,
(unsigned long)(di + 1), len);
printf("\t\tname: %.*s\n", len, namebuf);
if (data_len) {
len = (data_len <= sizeof(namebuf))? data_len:
sizeof(namebuf);
}
if (data_len) {
len = (data_len <= sizeof(namebuf)) ? data_len :
sizeof(namebuf);
if (eb->fs_info && eb->fs_info->hide_names) {
printf("\t\tdata HIDDEN\n");
} else {
read_extent_buffer(eb, namebuf,
(unsigned long)(di + 1) + name_len, len);
printf("\t\tdata %.*s\n", len, namebuf);
@ -105,15 +112,14 @@ static void print_inode_extref_item(struct extent_buffer *eb, u32 size,
len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
if (eb->fs_info && eb->fs_info->dont_print_filename) {
printf("\t\tindex %llu [arent %llu namelen %u\n",
printf("\t\tindex %llu parent %llu namelen %u ",
index, parent_objid, name_len);
if (eb->fs_info && eb->fs_info->hide_names) {
printf("name: HIDDEN\n");
} else {
read_extent_buffer(eb, namebuf,
(unsigned long)extref->name, len);
printf(
"\t\tindex %llu parent %llu namelen %u name: %.*s\n",
index, parent_objid, name_len, len, namebuf);
printf("name: %.*s\n", len, namebuf);
}
len = sizeof(*extref) + name_len;
@ -135,12 +141,15 @@ static void print_inode_ref_item(struct extent_buffer *eb, u32 size,
name_len = btrfs_inode_ref_name_len(eb, ref);
index = btrfs_inode_ref_index(eb, ref);
len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
if (eb->fs_info && eb->fs_info->dont_print_filename) {
printf("\t\tindex %llu namelen %u\n", index, name_len);
printf("\t\tindex %llu namelen %u ",
(unsigned long long)index, name_len);
if (eb->fs_info && eb->fs_info->hide_names) {
printf("name: HIDDEN\n");
} else {
read_extent_buffer(eb, namebuf, (unsigned long)(ref + 1), len);
printf("\t\tindex %llu namelen %u name: %.*s\n",
(unsigned long long)index, name_len, len, namebuf);
read_extent_buffer(eb, namebuf,
(unsigned long)(ref + 1), len);
printf("name: %.*s\n", len, namebuf);
}
len = sizeof(*ref) + name_len;
ref = (struct btrfs_inode_ref *)((char *)ref + len);