From b17e472983e02c63d71c1fbe978bafc7da9f6a5b Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Mon, 8 May 2023 11:17:41 -0700 Subject: [PATCH] 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 Signed-off-by: Brian Behlendorf Closes #14830 --- cmd/zdb/zdb.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index f424dd771f..bcd520de38 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -3102,13 +3102,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])) + if (!isprint(value[idx])) { + can_print = B_FALSE; + break; + } + } + + for (idx = 0; idx < cnt; ++idx) { + if (can_print) (void) putchar(value[idx]); else (void) printf("\\%3.3o", value[idx]);