forked from Mirrors/btrfs-progs
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>
parent
3babb783ab
commit
4d4e7d7c9f
|
@ -100,6 +100,9 @@ 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
|
||||||
|
the filesystem while keep confidential info hiden.
|
||||||
--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
|
||||||
|
|
|
@ -330,7 +330,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_NOSCAN, GETOPT_VAL_NOFILENAME };
|
||||||
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,6 +343,8 @@ 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,
|
||||||
|
GETOPT_VAL_NOFILENAME },
|
||||||
{ NULL, 0, NULL, 0 }
|
{ NULL, 0, NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -410,6 +412,9 @@ 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:
|
||||||
|
open_ctree_flags |= OPEN_CTREE_DONT_PRINT_FILENAME;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage_unknown_option(cmd, argv);
|
usage_unknown_option(cmd, argv);
|
||||||
}
|
}
|
||||||
|
|
1
ctree.h
1
ctree.h
|
@ -1193,6 +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;
|
||||||
|
|
||||||
int transaction_aborted;
|
int transaction_aborted;
|
||||||
|
|
||||||
|
|
|
@ -1218,6 +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)
|
||||||
|
fs_info->dont_print_filename = 1;
|
||||||
|
|
||||||
if ((flags & OPEN_CTREE_RECOVER_SUPER)
|
if ((flags & OPEN_CTREE_RECOVER_SUPER)
|
||||||
&& (flags & OPEN_CTREE_TEMPORARY_SUPER)) {
|
&& (flags & OPEN_CTREE_TEMPORARY_SUPER)) {
|
||||||
|
|
|
@ -85,6 +85,9 @@ enum btrfs_open_ctree_flags {
|
||||||
* compat_ro bit).
|
* compat_ro bit).
|
||||||
*/
|
*/
|
||||||
OPEN_CTREE_INVALIDATE_FST = (1U << 13),
|
OPEN_CTREE_INVALIDATE_FST = (1U << 13),
|
||||||
|
|
||||||
|
/* For print-tree only, skip filename output */
|
||||||
|
OPEN_CTREE_DONT_PRINT_FILENAME = (1U << 14),
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
40
print-tree.c
40
print-tree.c
|
@ -67,16 +67,20 @@ static void print_dir_item(struct extent_buffer *eb, u32 size,
|
||||||
name_len = btrfs_dir_name_len(eb, di);
|
name_len = btrfs_dir_name_len(eb, di);
|
||||||
data_len = btrfs_dir_data_len(eb, di);
|
data_len = btrfs_dir_data_len(eb, di);
|
||||||
len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
|
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",
|
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);
|
||||||
printf("\t\tname: %.*s\n", len, namebuf);
|
if (!(eb->fs_info && eb->fs_info->dont_print_filename)) {
|
||||||
if (data_len) {
|
|
||||||
len = (data_len <= sizeof(namebuf))? data_len: sizeof(namebuf);
|
|
||||||
read_extent_buffer(eb, namebuf,
|
read_extent_buffer(eb, namebuf,
|
||||||
(unsigned long)(di + 1) + name_len, len);
|
(unsigned long)(di + 1), len);
|
||||||
printf("\t\tdata %.*s\n", len, namebuf);
|
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;
|
len = sizeof(*di) + name_len + data_len;
|
||||||
di = (struct btrfs_dir_item *)((char *)di + 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);
|
len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
|
||||||
|
|
||||||
read_extent_buffer(eb, namebuf, (unsigned long)(extref->name), len);
|
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 name: %.*s\n",
|
index, parent_objid, name_len);
|
||||||
(unsigned long long)index,
|
} else {
|
||||||
(unsigned long long)parent_objid,
|
read_extent_buffer(eb, namebuf,
|
||||||
name_len, len, 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;
|
len = sizeof(*extref) + name_len;
|
||||||
extref = (struct btrfs_inode_extref *)((char *)extref + 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);
|
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);
|
||||||
read_extent_buffer(eb, namebuf, (unsigned long)(ref + 1), len);
|
if (eb->fs_info && eb->fs_info->dont_print_filename) {
|
||||||
printf("\t\tindex %llu namelen %u name: %.*s\n",
|
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);
|
(unsigned long long)index, name_len, 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);
|
||||||
cur += len;
|
cur += len;
|
||||||
|
|
Loading…
Reference in New Issue