From d028b3998ed20d7c8c45c204d68ea8888c435d25 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 4 Mar 2020 15:43:42 +0100 Subject: [PATCH] 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 --- Documentation/btrfs-inspect-internal.asciidoc | 17 +++++++-- cmds/inspect-dump-tree.c | 10 ++--- ctree.h | 2 +- disk-io.c | 4 +- disk-io.h | 4 +- print-tree.c | 37 ++++++++++++------- 6 files changed, 47 insertions(+), 27 deletions(-) diff --git a/Documentation/btrfs-inspect-internal.asciidoc b/Documentation/btrfs-inspect-internal.asciidoc index 38196959..0718070d 100644 --- a/Documentation/btrfs-inspect-internal.asciidoc +++ b/Documentation/btrfs-inspect-internal.asciidoc @@ -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 diff --git a/cmds/inspect-dump-tree.c b/cmds/inspect-dump-tree.c index 2a7f94f4..1fdbb9a6 100644 --- a/cmds/inspect-dump-tree.c +++ b/cmds/inspect-dump-tree.c @@ -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); diff --git a/ctree.h b/ctree.h index bea1f480..b44fdd5a 100644 --- a/ctree.h +++ b/ctree.h @@ -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; diff --git a/disk-io.c b/disk-io.c index 95316750..c895bd27 100644 --- a/disk-io.c +++ b/disk-io.c @@ -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)) { diff --git a/disk-io.h b/disk-io.h index fc25627c..b450149e 100644 --- a/disk-io.h +++ b/disk-io.h @@ -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), }; /* diff --git a/print-tree.c b/print-tree.c index 0725506d..0c63f6ca 100644 --- a/print-tree.c +++ b/print-tree.c @@ -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);