svn commit: r252669 - stable/9/sbin/nvmecontrol
Jim Harris
jimharris at FreeBSD.org
Thu Jul 4 00:03:31 UTC 2013
Author: jimharris
Date: Thu Jul 4 00:03:30 2013
New Revision: 252669
URL: http://svnweb.freebsd.org/changeset/base/252669
Log:
MFC r252275:
Add generalized helper functions for printing hex data as part of
nvmecontrol commands.
Submitted by: Joe Golio <joseph.golio at emc.com>
Obtained from: EMC / Isilon Storage Division
Modified:
stable/9/sbin/nvmecontrol/identify.c
stable/9/sbin/nvmecontrol/nvmecontrol.c
stable/9/sbin/nvmecontrol/nvmecontrol.h
Directory Properties:
stable/9/sbin/nvmecontrol/ (props changed)
Modified: stable/9/sbin/nvmecontrol/identify.c
==============================================================================
--- stable/9/sbin/nvmecontrol/identify.c Thu Jul 4 00:02:10 2013 (r252668)
+++ stable/9/sbin/nvmecontrol/identify.c Thu Jul 4 00:03:30 2013 (r252669)
@@ -42,25 +42,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)
{
printf("Controller Capabilities/Features\n");
@@ -128,25 +109,6 @@ print_controller(struct nvme_controller_
}
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)
{
uint32_t i;
@@ -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);
}
Modified: stable/9/sbin/nvmecontrol/nvmecontrol.c
==============================================================================
--- stable/9/sbin/nvmecontrol/nvmecontrol.c Thu Jul 4 00:02:10 2013 (r252668)
+++ stable/9/sbin/nvmecontrol/nvmecontrol.c Thu Jul 4 00:03:30 2013 (r252669)
@@ -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)
{
Modified: stable/9/sbin/nvmecontrol/nvmecontrol.h
==============================================================================
--- stable/9/sbin/nvmecontrol/nvmecontrol.h Thu Jul 4 00:02:10 2013 (r252668)
+++ stable/9/sbin/nvmecontrol/nvmecontrol.h Thu Jul 4 00:03:30 2013 (r252669)
@@ -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
More information about the svn-src-stable-9
mailing list