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
d2cdb28b6f
commit
e83c9e35a7
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=252275
|
@ -41,25 +41,6 @@ __FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include "nvmecontrol.h"
|
#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
|
static void
|
||||||
print_controller(struct nvme_controller_data *cdata)
|
print_controller(struct nvme_controller_data *cdata)
|
||||||
{
|
{
|
||||||
|
@ -127,25 +108,6 @@ print_controller(struct nvme_controller_data *cdata)
|
||||||
cdata->vwc.present ? "Present" : "Not Present");
|
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
|
static void
|
||||||
print_namespace(struct nvme_namespace_data *nsdata)
|
print_namespace(struct nvme_namespace_data *nsdata)
|
||||||
{
|
{
|
||||||
|
@ -214,7 +176,7 @@ identify_ctrlr(int argc, char *argv[])
|
||||||
else
|
else
|
||||||
hexlength = offsetof(struct nvme_controller_data,
|
hexlength = offsetof(struct nvme_controller_data,
|
||||||
reserved5);
|
reserved5);
|
||||||
print_controller_hex(&cdata, hexlength);
|
print_hex(&cdata, hexlength);
|
||||||
exit(EX_OK);
|
exit(EX_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +252,7 @@ identify_ns(int argc, char *argv[])
|
||||||
else
|
else
|
||||||
hexlength = offsetof(struct nvme_namespace_data,
|
hexlength = offsetof(struct nvme_namespace_data,
|
||||||
reserved6);
|
reserved6);
|
||||||
print_namespace_hex(&nsdata, hexlength);
|
print_hex(&nsdata, hexlength);
|
||||||
exit(EX_OK);
|
exit(EX_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,54 @@ usage(void)
|
||||||
exit(EX_USAGE);
|
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
|
void
|
||||||
read_controller_data(int fd, struct nvme_controller_data *cdata)
|
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);
|
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_controller_data(int fd, struct nvme_controller_data *cdata);
|
||||||
void read_namespace_data(int fd, int nsid, struct nvme_namespace_data *nsdata);
|
void read_namespace_data(int fd, int nsid, struct nvme_namespace_data *nsdata);
|
||||||
|
void print_hex(void *data, uint32_t length);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user