--- /dev/null
+'\" t
+.\" Title: nvme-list
+.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
+.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
+.\" Date: 02/09/2015
+.\" Manual: \ \&
+.\" Source: \ \&
+.\" Language: English
+.\"
+.TH "NVME\-LIST" "1" "02/09/2015" "\ \&" "\ \&"
+.\" -----------------------------------------------------------------
+.\" * Define some portability stuff
+.\" -----------------------------------------------------------------
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.\" http://bugs.debian.org/507673
+.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.ie \n(.g .ds Aq \(aq
+.el .ds Aq '
+.\" -----------------------------------------------------------------
+.\" * set default formatting
+.\" -----------------------------------------------------------------
+.\" disable hyphenation
+.nh
+.\" disable justification (adjust text to left margin only)
+.ad l
+.\" -----------------------------------------------------------------
+.\" * MAIN CONTENT STARTS HERE *
+.\" -----------------------------------------------------------------
+.SH "NAME"
+nvme-list \- List all recognized NVMe devices
+.SH "SYNOPSIS"
+.sp
+.nf
+\fInvme list\fR
+.fi
+.SH "DESCRIPTION"
+.sp
+Scan the sysfs tree for NVM Express devices and return the /dev node for those devices as well as some pertinant information about them\&.
+.SH "OPTIONS"
+.sp
+No options yet\&.
+.SH "EXAMPLES"
+.sp
+No examples yet\&.
+.SH "NVME"
+.sp
+Part of the nvme\-user suite
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#ifdef LIBUDEV_EXISTS
+#include <libudev.h>
+#endif
#include <linux/fs.h>
static const char *devicename;
#define COMMAND_LIST \
+ ENTRY(LIST, "list", "List all NVMe devices and namespaces on machine", list) \
ENTRY(ID_CTRL, "id-ctrl", "Send NVMe Identify Controller", id_ctrl) \
ENTRY(ID_NS, "id-ns", "Send NVMe Identify Namespace, display structure", id_ns) \
ENTRY(LIST_NS, "list-ns", "Send NVMe Identify List, display structure", list_ns) \
return err;
}
+#ifndef LIBUDEV_EXISTS
+static int list(int argc, char **argv)
+{
+ fprintf(stderr,"nvme-list: libudev not detected, install and rebuild.\n");
+ return -1;
+}
+#endif
+
+#ifdef LIBUDEV_EXISTS
+static int list(int argc, char **argv)
+{
+ struct udev *udev;
+ struct udev_enumerate *enumerate;
+ struct udev_list_entry *devices, *dev_list_entry;
+ struct udev_device *dev;
+
+ udev = udev_new();
+ if (!udev) {
+ perror("nvme-list: Can not create udev context.");
+ return errno;
+ }
+
+ enumerate = udev_enumerate_new(udev);
+ udev_enumerate_add_match_subsystem(enumerate, "block");
+ udev_enumerate_scan_devices(enumerate);
+ devices = udev_enumerate_get_list_entry(enumerate);
+ udev_list_entry_foreach(dev_list_entry, devices) {
+
+ const char *path, *node;
+ path = udev_list_entry_get_name(dev_list_entry);
+ dev = udev_device_new_from_syspath(udev, path);
+ node = udev_device_get_devnode(dev);
+ if (strstr(node,"nvme")!=NULL){
+ struct nvme_id_ctrl ctrl;
+
+ open_dev(node);
+ int err = identify(0, &ctrl, 1);
+ if (err > 0)
+ return err;
+ printf(" %s\t: NVM Express - %#x - %s - %x\n", node,
+ ctrl.vid, ctrl.mn, ctrl.ver);
+ }
+
+ }
+ udev_enumerate_unref(enumerate);
+ udev_unref(udev);
+
+ return 0;
+}
+#endif
+
static int id_ctrl(int argc, char **argv)
{
int opt, err, raw = 0, vs = 0, long_index = 0;