diff options
author | Brian Behlendorf <[email protected]> | 2023-05-08 11:17:41 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2023-05-08 11:17:41 -0700 |
commit | dd19821149cb7e3785249eb9be75dd9864c88d56 (patch) | |
tree | b102cec5befb5c29a1bae2cef6ab5de329e2d012 /cmd | |
parent | 245f4a346779e29fe995f69d8eb2b724cddf5277 (diff) |
zdb: consistent xattr output
When using zdb to output the value of an xattr only interpret it
as printable characters if the entire byte array is printable.
Additionally, if the --parseable option is set always output the
buffer contents as octal for easy parsing.
Reviewed-by: Olaf Faaland <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #14830
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/zdb/zdb.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index ec5d1acac..cea80b690 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -3322,13 +3322,22 @@ dump_znode_sa_xattr(sa_handle_t *hdl) (void) printf("\tSA xattrs: %d bytes, %d entries\n\n", sa_xattr_size, sa_xattr_entries); while ((elem = nvlist_next_nvpair(sa_xattr, elem)) != NULL) { + boolean_t can_print = !dump_opt['P']; uchar_t *value; uint_t cnt, idx; (void) printf("\t\t%s = ", nvpair_name(elem)); nvpair_value_byte_array(elem, &value, &cnt); + + for (idx = 0; idx < cnt; ++idx) { + if (!isprint(value[idx])) { + can_print = B_FALSE; + break; + } + } + for (idx = 0; idx < cnt; ++idx) { - if (isprint(value[idx])) + if (can_print) (void) putchar(value[idx]); else (void) printf("\\%3.3o", value[idx]); |