summaryrefslogtreecommitdiffstats
path: root/Documentation/nvme-id-ns.txt
blob: 4b3c258f6436175f1b4d6e8a2cc209306ec1b39b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
nvme-id-ns(1)
=============

NAME
----
nvme-id-ns - Send NVMe Identify Namespace, return result and structure

SYNOPSIS
--------
[verse]
'nvme id-ns' <device> [-v | --vendor-specific] [-b | --raw-binary]
		    [--namespace-id=<nsid> | -n <nsid>] [-f | --force]
		    [--human-readable | -H]
		    [--output-format=<fmt> | -o <fmt>]

DESCRIPTION
-----------
For the NVMe device given, sends an identify namespace command and
provides the result and returned structure.

The <device> parameter is mandatory and may be either the NVMe character
device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1).
If the character device is given, the `'--namespace-id'` option is
mandatory, otherwise it will use the ns-id of the namespace for the block
device you opened. For block devices, the ns-id used can be overridden
with the same option.

On success, the structure may be returned in one of several ways depending
on the option flags; the structure may be parsed by the program or the
raw buffer may be printed to stdout.

OPTIONS
-------
-n <nsid>::
--namespace-id=<nsid>::
	Retrieve the identify namespace structure for the given nsid. This
	is required for the character devices, or overrides the block nsid
	if given.

-f::
--force::
	Request controller return the identify namespace structure even
	if the namespace is not attached to the controller. This is valid
	only for controllers at or newer than revision 1.2. Controllers
	at revision lower than this may interpret the command incorrectly.

-b::
--raw-binary::
	Print the raw buffer to stdout. Structure is not parsed by
	program. This overrides the vendor specific and human readable options.

-v::
--vendor-specific::
	In addition to parsing known fields, this option will dump
	the vendor specific region of the structure in hex with ascii
	interpretation.

-H::
--human-readable::
	This option will parse and format many of the bit fields
	into human-readable formats.

-o <format>::
--output-format=<format>::
              Set the reporting format to 'normal', 'json', or
              'binary'. Only one output format can be used at a time.



EXAMPLES
--------
* Has the program interpret the returned buffer and display the known
fields in a human readable format:
+
------------
# nvme id-ns /dev/nvme0n1
------------
+

* If using the character device or overriding namespace id:
+
------------
# nvme id-ns /dev/nvme0 -n 1
# nvme id-ns /dev/nvme0n1 -n 1
# nvme id-ns /dev/nvme0 --namespace-id=1
------------
+

* In addition to showing the known fields, have the program to display
the vendor unique field:
+
------------
# nvme id-ns /dev/nvme0n1 --vendor-specific
# nvme id-ns /dev/nvme0n1 -v
------------
+
The above will dump the \'vs' buffer in hex since it doesn't know how to
interpret it.

* Have the program return the raw structure in binary:
+
------------
# nvme id-ns /dev/nvme0n1 --raw-binary > id_ns.raw
# nvme id-ns /dev/nvme0n1 -b > id_ns.raw
------------
+
It is probably a bad idea to not redirect stdout when using this mode.

* Alternatively you may want to send the data to another program that
can parse the raw buffer.
+
------------
# nvme id-ns /dev/nvme0n1 --raw-binary | nvme_parse_id_ns
------------
+
The parse program in the above example can be a program that shows the
structure in a way you like. The following program is such an example
that will parse it and can accept the output through a pipe, `'|'`,
as shown in the above example, or you can `'cat'` a saved output buffer
to it.
------------
/* File: nvme_parse_id_ns.c */

#include <linux/nvme.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv)
{
	unsigned char buf[sizeof(struct nvme_id_ns)];
	struct nvme_id_ns *ns = (struct nvme_id_ns *)buf;

	if (read(STDIN_FILENO, buf, sizeof(buf)))
		return 1;

	printf("nsze : %#llx\n", ns->nsze);
	printf("ncap : %#llx\n", ns->ncap);
	return 0;
}
------------

NVME
----
Part of the nvme-user suite