Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Jun 2013 23:46:32 +0000 (UTC)
From:      Jim Harris <jimharris@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r252275 - head/sbin/nvmecontrol
Message-ID:  <201306262346.r5QNkWhU010004@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jimharris
Date: Wed Jun 26 23:46:31 2013
New Revision: 252275
URL: http://svnweb.freebsd.org/changeset/base/252275

Log:
  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

Modified:
  head/sbin/nvmecontrol/identify.c
  head/sbin/nvmecontrol/nvmecontrol.c
  head/sbin/nvmecontrol/nvmecontrol.h

Modified: head/sbin/nvmecontrol/identify.c
==============================================================================
--- head/sbin/nvmecontrol/identify.c	Wed Jun 26 23:41:07 2013	(r252274)
+++ head/sbin/nvmecontrol/identify.c	Wed Jun 26 23:46:31 2013	(r252275)
@@ -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: head/sbin/nvmecontrol/nvmecontrol.c
==============================================================================
--- head/sbin/nvmecontrol/nvmecontrol.c	Wed Jun 26 23:41:07 2013	(r252274)
+++ head/sbin/nvmecontrol/nvmecontrol.c	Wed Jun 26 23:46:31 2013	(r252275)
@@ -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: head/sbin/nvmecontrol/nvmecontrol.h
==============================================================================
--- head/sbin/nvmecontrol/nvmecontrol.h	Wed Jun 26 23:41:07 2013	(r252274)
+++ head/sbin/nvmecontrol/nvmecontrol.h	Wed Jun 26 23:46:31 2013	(r252275)
@@ -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
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201306262346.r5QNkWhU010004>