btrfs-progs: dump-tree: Introduce --nofilename option

In the mail list, it's pretty common that a developer is asking dump tree
output from the reporter, it's better to protect those kind reporters by
hiding the filename if the reporter wants.

This option will skip @name/@data output for the following items:
- DIR_INDEX
- DIR_ITEM
- INODE_REF

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Qu Wenruo 2019-11-11 15:24:35 +08:00 committed by David Sterba
parent 3babb783ab
commit 4d4e7d7c9f
6 changed files with 41 additions and 15 deletions

View File

@ -100,6 +100,9 @@ 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.
--noscan::::
do not automatically scan the system for other devices from the same
filesystem, only use the devices provided as the arguments

View File

@ -330,7 +330,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_NOSCAN, GETOPT_VAL_NOFILENAME };
static const struct option long_options[] = {
{ "extents", no_argument, NULL, 'e'},
{ "device", no_argument, NULL, 'd'},
@ -343,6 +343,8 @@ 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 },
{ NULL, 0, NULL, 0 }
};
@ -410,6 +412,9 @@ 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;
break;
default:
usage_unknown_option(cmd, argv);
}

View File

@ -1193,6 +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;
int transaction_aborted;

View File

@ -1218,6 +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_RECOVER_SUPER)
&& (flags & OPEN_CTREE_TEMPORARY_SUPER)) {

View File

@ -85,6 +85,9 @@ enum btrfs_open_ctree_flags {
* compat_ro bit).
*/
OPEN_CTREE_INVALIDATE_FST = (1U << 13),
/* For print-tree only, skip filename output */
OPEN_CTREE_DONT_PRINT_FILENAME = (1U << 14),
};
/*

View File

@ -67,16 +67,20 @@ static void print_dir_item(struct extent_buffer *eb, u32 size,
name_len = btrfs_dir_name_len(eb, di);
data_len = btrfs_dir_data_len(eb, di);
len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
read_extent_buffer(eb, namebuf, (unsigned long)(di + 1), len);
printf("\t\ttransid %llu data_len %u name_len %u\n",
btrfs_dir_transid(eb, di),
data_len, name_len);
printf("\t\tname: %.*s\n", len, namebuf);
if (data_len) {
len = (data_len <= sizeof(namebuf))? data_len: sizeof(namebuf);
if (!(eb->fs_info && eb->fs_info->dont_print_filename)) {
read_extent_buffer(eb, namebuf,
(unsigned long)(di + 1) + name_len, len);
printf("\t\tdata %.*s\n", len, 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);
read_extent_buffer(eb, namebuf,
(unsigned long)(di + 1) + name_len, len);
printf("\t\tdata %.*s\n", len, namebuf);
}
}
len = sizeof(*di) + name_len + data_len;
di = (struct btrfs_dir_item *)((char *)di + len);
@ -101,12 +105,16 @@ static void print_inode_extref_item(struct extent_buffer *eb, u32 size,
len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
read_extent_buffer(eb, namebuf, (unsigned long)(extref->name), len);
printf("\t\tindex %llu parent %llu namelen %u name: %.*s\n",
(unsigned long long)index,
(unsigned long long)parent_objid,
name_len, len, namebuf);
if (eb->fs_info && eb->fs_info->dont_print_filename) {
printf("\t\tindex %llu [arent %llu namelen %u\n",
index, parent_objid, name_len);
} 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);
}
len = sizeof(*extref) + name_len;
extref = (struct btrfs_inode_extref *)((char *)extref + len);
@ -127,9 +135,13 @@ 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);
read_extent_buffer(eb, namebuf, (unsigned long)(ref + 1), len);
printf("\t\tindex %llu namelen %u name: %.*s\n",
if (eb->fs_info && eb->fs_info->dont_print_filename) {
printf("\t\tindex %llu namelen %u\n", index, name_len);
} 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);
}
len = sizeof(*ref) + name_len;
ref = (struct btrfs_inode_ref *)((char *)ref + len);
cur += len;