Skip to content

Commit 5271a57

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 5271a57

1 file changed

Lines changed: 50 additions & 1 deletion

File tree

nvme-print-stdout.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4901,10 +4901,44 @@ 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+
all_zero = true;
4930+
} else {
4931+
all_zero = false;
4932+
}
4933+
4934+
return false;
4935+
}
4936+
49044937
void stdout_d(unsigned char *buf, int len, int width, int group)
49054938
{
49064939
int i, offset = 0;
49074940
char ascii[32 + 1] = { 0 };
4941+
bool ommit = false;
49084942

49094943
assert(width < sizeof(ascii));
49104944

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

49164950
for (i = 0; i < len; i++) {
4917-
if (!(i % width))
4951+
if (!(i % width)) {
4952+
if (is_ommit(buf, len, width, offset)) {
4953+
if (!ommit) {
4954+
ommit = true;
4955+
printf("\n*");
4956+
}
4957+
offset += width;
4958+
continue;
4959+
} else if (ommit) {
4960+
ommit = false;
4961+
}
49184962
printf("\n%04x:", offset);
4963+
}
4964+
if (ommit)
4965+
continue;
49194966
if (i % group)
49204967
printf("%02x", buf[i]);
49214968
else
@@ -4927,6 +4974,8 @@ void stdout_d(unsigned char *buf, int len, int width, int group)
49274974
memset(ascii, 0, sizeof(ascii));
49284975
}
49294976
}
4977+
if (ommit)
4978+
printf("\n%04x:\n", offset);
49304979

49314980
if (strlen(ascii)) {
49324981
unsigned int b = width - (i % width);

0 commit comments

Comments
 (0)