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>
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 use breadth-first search to print trees, the nodes are printed before all
leaves leaves
--nofilename:::: +
do not print any filename of the filesystem. Useful for developer to inspect --hide-names::::
the filesystem while keep confidential info hiden. 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:::: --noscan::::
do not automatically scan the system for other devices from the same do not automatically scan the system for other devices from the same
filesystem, only use the devices provided as the arguments 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", "--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)", "--bfs breadth-first traversal of the trees, print nodes, then leaves (default)",
"--dfs depth-first traversal of the trees", "--dfs depth-first traversal of the trees",
"--hide-names hide filenames/subvolume/xattrs and other name references",
NULL NULL
}; };
@ -330,7 +331,7 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,
while (1) { while (1) {
int c; int c;
enum { GETOPT_VAL_FOLLOW = 256, GETOPT_VAL_DFS, GETOPT_VAL_BFS, 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[] = { static const struct option long_options[] = {
{ "extents", no_argument, NULL, 'e'}, { "extents", no_argument, NULL, 'e'},
{ "device", no_argument, NULL, 'd'}, { "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 }, { "bfs", no_argument, NULL, GETOPT_VAL_BFS },
{ "dfs", no_argument, NULL, GETOPT_VAL_DFS }, { "dfs", no_argument, NULL, GETOPT_VAL_DFS },
{ "noscan", no_argument, NULL, GETOPT_VAL_NOSCAN }, { "noscan", no_argument, NULL, GETOPT_VAL_NOSCAN },
{ "nofilename", no_argument, NULL, { "hide-names", no_argument, NULL, GETOPT_VAL_HIDE_NAMES },
GETOPT_VAL_NOFILENAME },
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
@ -412,8 +412,8 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,
case GETOPT_VAL_NOSCAN: case GETOPT_VAL_NOSCAN:
open_ctree_flags |= OPEN_CTREE_NO_DEVICES; open_ctree_flags |= OPEN_CTREE_NO_DEVICES;
break; break;
case GETOPT_VAL_NOFILENAME: case GETOPT_VAL_HIDE_NAMES:
open_ctree_flags |= OPEN_CTREE_DONT_PRINT_FILENAME; open_ctree_flags |= OPEN_CTREE_HIDE_NAMES;
break; break;
default: default:
usage_unknown_option(cmd, argv); 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_meta_chunk_alloc:1;
unsigned int avoid_sys_chunk_alloc:1; unsigned int avoid_sys_chunk_alloc:1;
unsigned int finalize_on_close:1; unsigned int finalize_on_close:1;
unsigned int dont_print_filename:1; unsigned int hide_names:1;
int transaction_aborted; 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; fs_info->ignore_fsid_mismatch = 1;
if (flags & OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR) if (flags & OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR)
fs_info->ignore_chunk_tree_error = 1; fs_info->ignore_chunk_tree_error = 1;
if (flags & OPEN_CTREE_DONT_PRINT_FILENAME) if (flags & OPEN_CTREE_HIDE_NAMES)
fs_info->dont_print_filename = 1; fs_info->hide_names = 1;
if ((flags & OPEN_CTREE_RECOVER_SUPER) if ((flags & OPEN_CTREE_RECOVER_SUPER)
&& (flags & OPEN_CTREE_TEMPORARY_SUPER)) { && (flags & OPEN_CTREE_TEMPORARY_SUPER)) {

View File

@ -86,8 +86,8 @@ enum btrfs_open_ctree_flags {
*/ */
OPEN_CTREE_INVALIDATE_FST = (1U << 13), OPEN_CTREE_INVALIDATE_FST = (1U << 13),
/* For print-tree only, skip filename output */ /* For print-tree, print HIDDEN instead of filenames/xattrs/refs */
OPEN_CTREE_DONT_PRINT_FILENAME = (1U << 14), 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", printf("\t\ttransid %llu data_len %u name_len %u\n",
btrfs_dir_transid(eb, di), btrfs_dir_transid(eb, di),
data_len, name_len); 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, read_extent_buffer(eb, namebuf,
(unsigned long)(di + 1), len); (unsigned long)(di + 1), len);
printf("\t\tname: %.*s\n", len, namebuf); 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, read_extent_buffer(eb, namebuf,
(unsigned long)(di + 1) + name_len, len); (unsigned long)(di + 1) + name_len, len);
printf("\t\tdata %.*s\n", len, namebuf); 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); len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
if (eb->fs_info && eb->fs_info->dont_print_filename) { printf("\t\tindex %llu parent %llu namelen %u ",
printf("\t\tindex %llu [arent %llu namelen %u\n",
index, parent_objid, name_len); index, parent_objid, name_len);
if (eb->fs_info && eb->fs_info->hide_names) {
printf("name: HIDDEN\n");
} else { } else {
read_extent_buffer(eb, namebuf, read_extent_buffer(eb, namebuf,
(unsigned long)extref->name, len); (unsigned long)extref->name, len);
printf( printf("name: %.*s\n", len, namebuf);
"\t\tindex %llu parent %llu namelen %u name: %.*s\n",
index, parent_objid, name_len, len, namebuf);
} }
len = sizeof(*extref) + name_len; 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); name_len = btrfs_inode_ref_name_len(eb, ref);
index = btrfs_inode_ref_index(eb, ref); index = btrfs_inode_ref_index(eb, ref);
len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf); 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 { } else {
read_extent_buffer(eb, namebuf, (unsigned long)(ref + 1), len); read_extent_buffer(eb, namebuf,
printf("\t\tindex %llu namelen %u name: %.*s\n", (unsigned long)(ref + 1), len);
(unsigned long long)index, name_len, len, namebuf); printf("name: %.*s\n", len, namebuf);
} }
len = sizeof(*ref) + name_len; len = sizeof(*ref) + name_len;
ref = (struct btrfs_inode_ref *)((char *)ref + len); ref = (struct btrfs_inode_ref *)((char *)ref + len);