From owner-svn-src-head@FreeBSD.ORG Wed Jun 26 23:46:32 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id C685A71; Wed, 26 Jun 2013 23:46:32 +0000 (UTC) (envelope-from jimharris@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id B8969172B; Wed, 26 Jun 2013 23:46:32 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5QNkW1f010007; Wed, 26 Jun 2013 23:46:32 GMT (envelope-from jimharris@svn.freebsd.org) Received: (from jimharris@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r5QNkWhU010004; Wed, 26 Jun 2013 23:46:32 GMT (envelope-from jimharris@svn.freebsd.org) Message-Id: <201306262346.r5QNkWhU010004@svn.freebsd.org> From: Jim Harris Date: Wed, 26 Jun 2013 23:46:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r252275 - head/sbin/nvmecontrol X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jun 2013 23:46:32 -0000 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 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