Add generalized helper functions for printing hex data as part of
nvmecontrol commands. Submitted by: Joe Golio <joseph.golio@emc.com> Obtained from: EMC / Isilon Storage Division MFC after: 3 days
This commit is contained in:
parent
c089ab01fb
commit
d67aed2f53
@ -41,25 +41,6 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include "nvmecontrol.h"
|
||||
|
||||
static void
|
||||
print_controller_hex(struct nvme_controller_data *cdata, uint32_t length)
|
||||
{
|
||||
uint32_t *p;
|
||||
uint32_t i, j;
|
||||
|
||||
p = (uint32_t *)cdata;
|
||||
length /= sizeof(uint32_t);
|
||||
|
||||
for (i = 0; i < length; i+=8) {
|
||||
printf("%03x: ", i*4);
|
||||
for (j = 0; j < 8; j++)
|
||||
printf("%08x ", p[i+j]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void
|
||||
print_controller(struct nvme_controller_data *cdata)
|
||||
{
|
||||
@ -127,25 +108,6 @@ print_controller(struct nvme_controller_data *cdata)
|
||||
cdata->vwc.present ? "Present" : "Not Present");
|
||||
}
|
||||
|
||||
static void
|
||||
print_namespace_hex(struct nvme_namespace_data *nsdata, uint32_t length)
|
||||
{
|
||||
uint32_t *p;
|
||||
uint32_t i, j;
|
||||
|
||||
p = (uint32_t *)nsdata;
|
||||
length /= sizeof(uint32_t);
|
||||
|
||||
for (i = 0; i < length; i+=8) {
|
||||
printf("%03x: ", i*4);
|
||||
for (j = 0; j < 8; j++)
|
||||
printf("%08x ", p[i+j]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void
|
||||
print_namespace(struct nvme_namespace_data *nsdata)
|
||||
{
|
||||
@ -214,7 +176,7 @@ identify_ctrlr(int argc, char *argv[])
|
||||
else
|
||||
hexlength = offsetof(struct nvme_controller_data,
|
||||
reserved5);
|
||||
print_controller_hex(&cdata, hexlength);
|
||||
print_hex(&cdata, hexlength);
|
||||
exit(EX_OK);
|
||||
}
|
||||
|
||||
@ -290,7 +252,7 @@ identify_ns(int argc, char *argv[])
|
||||
else
|
||||
hexlength = offsetof(struct nvme_namespace_data,
|
||||
reserved6);
|
||||
print_namespace_hex(&nsdata, hexlength);
|
||||
print_hex(&nsdata, hexlength);
|
||||
exit(EX_OK);
|
||||
}
|
||||
|
||||
|
@ -72,6 +72,54 @@ usage(void)
|
||||
exit(EX_USAGE);
|
||||
}
|
||||
|
||||
static void
|
||||
print_bytes(void *data, uint32_t length)
|
||||
{
|
||||
uint32_t i, j;
|
||||
uint8_t *p, *end;
|
||||
|
||||
end = (uint8_t *)data + length;
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
p = (uint8_t *)data + (i*16);
|
||||
printf("%03x: ", i*16);
|
||||
for (j = 0; j < 16 && p < end; j++)
|
||||
printf("%02x ", *p++);
|
||||
if (p >= end)
|
||||
break;
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void
|
||||
print_dwords(void *data, uint32_t length)
|
||||
{
|
||||
uint32_t *p;
|
||||
uint32_t i, j;
|
||||
|
||||
p = (uint32_t *)data;
|
||||
length /= sizeof(uint32_t);
|
||||
|
||||
for (i = 0; i < length; i+=8) {
|
||||
printf("%03x: ", i*4);
|
||||
for (j = 0; j < 8; j++)
|
||||
printf("%08x ", p[i+j]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void
|
||||
print_hex(void *data, uint32_t length)
|
||||
{
|
||||
if (length >= sizeof(uint32_t) || length % sizeof(uint32_t) == 0)
|
||||
print_dwords(data, length);
|
||||
else
|
||||
print_bytes(data, length);
|
||||
}
|
||||
|
||||
void
|
||||
read_controller_data(int fd, struct nvme_controller_data *cdata)
|
||||
{
|
||||
|
@ -57,6 +57,7 @@ void reset(int argc, char *argv[]);
|
||||
int open_dev(const char *str, int *fd, int show_error, int exit_on_error);
|
||||
void read_controller_data(int fd, struct nvme_controller_data *cdata);
|
||||
void read_namespace_data(int fd, int nsid, struct nvme_namespace_data *nsdata);
|
||||
void print_hex(void *data, uint32_t length);
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user