summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjimharris <jimharris@FreeBSD.org>2013-06-26 23:20:08 +0000
committerjimharris <jimharris@FreeBSD.org>2013-06-26 23:20:08 +0000
commit4d63e9a6042335ac179666efa53e626cb0d723c3 (patch)
treed7a15392485454a9cdc5a520c67591d63fb9dfaa
parent57728d033757510c81668f7054bc1ccc5945933e (diff)
downloadFreeBSD-src-4d63e9a6042335ac179666efa53e626cb0d723c3.zip
FreeBSD-src-4d63e9a6042335ac179666efa53e626cb0d723c3.tar.gz
Create #defines for NVME_CTRLR_PREFIX and NVME_NS_PREFIX for the "nvme"
and "ns" strings, rather than hardcoding the string values throughout the nvmecontrol code base. Sponsored by: Intel MFC after: 3 days
-rw-r--r--sbin/nvmecontrol/devlist.c5
-rw-r--r--sbin/nvmecontrol/identify.c4
-rw-r--r--sbin/nvmecontrol/nvmecontrol.h3
3 files changed, 8 insertions, 4 deletions
diff --git a/sbin/nvmecontrol/devlist.c b/sbin/nvmecontrol/devlist.c
index 4085e7e..8c99c99 100644
--- a/sbin/nvmecontrol/devlist.c
+++ b/sbin/nvmecontrol/devlist.c
@@ -78,7 +78,7 @@ devlist(int argc, char *argv[])
while (1) {
ctrlr++;
- sprintf(name, "nvme%d", ctrlr);
+ sprintf(name, "%s%d", NVME_CTRLR_PREFIX, ctrlr);
exit_code = open_dev(name, &fd, 0, 0);
@@ -95,7 +95,8 @@ devlist(int argc, char *argv[])
printf("%6s: %s\n", name, cdata.mn);
for (i = 0; i < cdata.nn; i++) {
- sprintf(name, "nvme%dns%d", ctrlr, i+1);
+ sprintf(name, "%s%d%s%d", NVME_CTRLR_PREFIX, ctrlr,
+ NVME_NS_PREFIX, i+1);
read_namespace_data(fd, i+1, &nsdata);
printf(" %10s (%lldGB)\n",
name,
diff --git a/sbin/nvmecontrol/identify.c b/sbin/nvmecontrol/identify.c
index 6dcbebd..cd1d746 100644
--- a/sbin/nvmecontrol/identify.c
+++ b/sbin/nvmecontrol/identify.c
@@ -258,7 +258,7 @@ identify_ns(int argc, char *argv[])
* of the string. Don't search past 10 characters into the string,
* otherwise we know it is malformed.
*/
- nsloc = strnstr(argv[optind], "ns", 10);
+ nsloc = strnstr(argv[optind], NVME_NS_PREFIX, 10);
if (nsloc != NULL)
nsid = strtol(nsloc + 2, NULL, 10);
if (nsloc == NULL || (nsid == 0 && errno != 0)) {
@@ -314,7 +314,7 @@ identify(int argc, char *argv[])
* If device node contains "ns", we consider it a namespace,
* otherwise, consider it a controller.
*/
- if (strstr(target, "ns") == NULL)
+ if (strstr(target, NVME_NS_PREFIX) == NULL)
identify_ctrlr(argc, argv);
else
identify_ns(argc, argv);
diff --git a/sbin/nvmecontrol/nvmecontrol.h b/sbin/nvmecontrol/nvmecontrol.h
index ec61e95..c05792e 100644
--- a/sbin/nvmecontrol/nvmecontrol.h
+++ b/sbin/nvmecontrol/nvmecontrol.h
@@ -31,6 +31,9 @@
#include <dev/nvme/nvme.h>
+#define NVME_CTRLR_PREFIX "nvme"
+#define NVME_NS_PREFIX "ns"
+
#define DEVLIST_USAGE \
" nvmecontrol devlist\n"
OpenPOWER on IntegriCloud