Skip to content

Commit 516fd60

Browse files
committed
nvme-print-stdout: change stdout_d() to not print all zeros
This is for the id-ns command empty vendor-specific fields. Note: This will change for other commands d() outputs. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent e9b11a7 commit 516fd60

1 file changed

Lines changed: 51 additions & 1 deletion

File tree

nvme-print-stdout.c

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4901,10 +4901,45 @@ static void stdout_lba_status_info(__u64 result)
49014901
(__u32)NVME_FEAT_LBAS_LSIRI(result));
49024902
}
49034903

4904+
static bool is_all_zero(unsigned char *buf, int len, int width)
4905+
{
4906+
int i;
4907+
4908+
if (len < width)
4909+
return false;
4910+
4911+
for (i = 0; i < width; i++) {
4912+
if (buf[i])
4913+
return false;
4914+
}
4915+
4916+
return true;
4917+
}
4918+
4919+
static bool is_ommit(unsigned char *buf, int len, int width, int offset)
4920+
{
4921+
static bool all_zero;
4922+
4923+
if (!offset)
4924+
all_zero = false;
4925+
4926+
if (is_all_zero(&buf[offset], len - offset, width)) {
4927+
if (all_zero) {
4928+
return true;
4929+
}
4930+
all_zero = true;
4931+
} else {
4932+
all_zero = false;
4933+
}
4934+
4935+
return false;
4936+
}
4937+
49044938
void stdout_d(unsigned char *buf, int len, int width, int group)
49054939
{
49064940
int i, offset = 0;
49074941
char ascii[32 + 1] = { 0 };
4942+
bool ommit = false;
49084943

49094944
assert(width < sizeof(ascii));
49104945

@@ -4914,8 +4949,21 @@ void stdout_d(unsigned char *buf, int len, int width, int group)
49144949
printf("%3x", i);
49154950

49164951
for (i = 0; i < len; i++) {
4917-
if (!(i % width))
4952+
if (!(i % width)) {
4953+
if (is_ommit(buf, len, width, offset)) {
4954+
if (!ommit) {
4955+
ommit = true;
4956+
printf("\n*");
4957+
}
4958+
offset += width;
4959+
continue;
4960+
} else if (ommit) {
4961+
ommit = false;
4962+
}
49184963
printf("\n%04x:", offset);
4964+
}
4965+
if (ommit)
4966+
continue;
49194967
if (i % group)
49204968
printf("%02x", buf[i]);
49214969
else
@@ -4927,6 +4975,8 @@ void stdout_d(unsigned char *buf, int len, int width, int group)
49274975
memset(ascii, 0, sizeof(ascii));
49284976
}
49294977
}
4978+
if (ommit)
4979+
printf("\n%04x:\n", offset);
49304980

49314981
if (strlen(ascii)) {
49324982
unsigned int b = width - (i % width);

0 commit comments

Comments
 (0)