1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (C) 2012-2013 Intel Corporation 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 __FBSDID("$FreeBSD$"); 31 32 #include <sys/param.h> 33 34 #include <ctype.h> 35 #include <err.h> 36 #include <fcntl.h> 37 #include <stddef.h> 38 #include <stdio.h> 39 #include <stdlib.h> 40 #include <string.h> 41 #include <unistd.h> 42 43 #include "nvmecontrol.h" 44 45 static void 46 print_controller(struct nvme_controller_data *cdata) 47 { 48 uint8_t str[128]; 49 char cbuf[UINT128_DIG + 1]; 50 uint16_t oncs, oacs; 51 uint8_t compare, write_unc, dsm, vwc_present; 52 uint8_t security, fmt, fw, nsmgmt; 53 uint8_t fw_slot1_ro, fw_num_slots; 54 uint8_t ns_smart; 55 uint8_t sqes_max, sqes_min; 56 uint8_t cqes_max, cqes_min; 57 58 oncs = cdata->oncs; 59 compare = (oncs >> NVME_CTRLR_DATA_ONCS_COMPARE_SHIFT) & 60 NVME_CTRLR_DATA_ONCS_COMPARE_MASK; 61 write_unc = (oncs >> NVME_CTRLR_DATA_ONCS_WRITE_UNC_SHIFT) & 62 NVME_CTRLR_DATA_ONCS_WRITE_UNC_MASK; 63 dsm = (oncs >> NVME_CTRLR_DATA_ONCS_DSM_SHIFT) & 64 NVME_CTRLR_DATA_ONCS_DSM_MASK; 65 vwc_present = (cdata->vwc >> NVME_CTRLR_DATA_VWC_PRESENT_SHIFT) & 66 NVME_CTRLR_DATA_VWC_PRESENT_MASK; 67 68 oacs = cdata->oacs; 69 security = (oacs >> NVME_CTRLR_DATA_OACS_SECURITY_SHIFT) & 70 NVME_CTRLR_DATA_OACS_SECURITY_MASK; 71 fmt = (oacs >> NVME_CTRLR_DATA_OACS_FORMAT_SHIFT) & 72 NVME_CTRLR_DATA_OACS_FORMAT_MASK; 73 fw = (oacs >> NVME_CTRLR_DATA_OACS_FIRMWARE_SHIFT) & 74 NVME_CTRLR_DATA_OACS_FIRMWARE_MASK; 75 nsmgmt = (oacs >> NVME_CTRLR_DATA_OACS_NSMGMT_SHIFT) & 76 NVME_CTRLR_DATA_OACS_NSMGMT_MASK; 77 78 fw_num_slots = (cdata->frmw >> NVME_CTRLR_DATA_FRMW_NUM_SLOTS_SHIFT) & 79 NVME_CTRLR_DATA_FRMW_NUM_SLOTS_MASK; 80 fw_slot1_ro = (cdata->frmw >> NVME_CTRLR_DATA_FRMW_SLOT1_RO_SHIFT) & 81 NVME_CTRLR_DATA_FRMW_SLOT1_RO_MASK; 82 83 ns_smart = (cdata->lpa >> NVME_CTRLR_DATA_LPA_NS_SMART_SHIFT) & 84 NVME_CTRLR_DATA_LPA_NS_SMART_MASK; 85 86 sqes_min = (cdata->sqes >> NVME_CTRLR_DATA_SQES_MIN_SHIFT) & 87 NVME_CTRLR_DATA_SQES_MIN_MASK; 88 sqes_max = (cdata->sqes >> NVME_CTRLR_DATA_SQES_MAX_SHIFT) & 89 NVME_CTRLR_DATA_SQES_MAX_MASK; 90 91 cqes_min = (cdata->cqes >> NVME_CTRLR_DATA_CQES_MIN_SHIFT) & 92 NVME_CTRLR_DATA_CQES_MIN_MASK; 93 cqes_max = (cdata->cqes >> NVME_CTRLR_DATA_CQES_MAX_SHIFT) & 94 NVME_CTRLR_DATA_CQES_MAX_MASK; 95 96 printf("Controller Capabilities/Features\n"); 97 printf("================================\n"); 98 printf("Vendor ID: %04x\n", cdata->vid); 99 printf("Subsystem Vendor ID: %04x\n", cdata->ssvid); 100 nvme_strvis(str, cdata->sn, sizeof(str), NVME_SERIAL_NUMBER_LENGTH); 101 printf("Serial Number: %s\n", str); 102 nvme_strvis(str, cdata->mn, sizeof(str), NVME_MODEL_NUMBER_LENGTH); 103 printf("Model Number: %s\n", str); 104 nvme_strvis(str, cdata->fr, sizeof(str), NVME_FIRMWARE_REVISION_LENGTH); 105 printf("Firmware Version: %s\n", str); 106 printf("Recommended Arb Burst: %d\n", cdata->rab); 107 printf("IEEE OUI Identifier: %02x %02x %02x\n", 108 cdata->ieee[0], cdata->ieee[1], cdata->ieee[2]); 109 printf("Multi-Path I/O Capabilities: %s%s%s%s\n", 110 (cdata->mic == 0) ? "Not Supported" : "", 111 ((cdata->mic >> NVME_CTRLR_DATA_MIC_SRIOVVF_SHIFT) & 112 NVME_CTRLR_DATA_MIC_SRIOVVF_MASK) ? "SR-IOV VF, " : "", 113 ((cdata->mic >> NVME_CTRLR_DATA_MIC_MCTRLRS_SHIFT) & 114 NVME_CTRLR_DATA_MIC_MCTRLRS_MASK) ? "Multiple controllers, " : "", 115 ((cdata->mic >> NVME_CTRLR_DATA_MIC_MPORTS_SHIFT) & 116 NVME_CTRLR_DATA_MIC_MPORTS_MASK) ? "Multiple ports" : ""); 117 /* TODO: Use CAP.MPSMIN to determine true memory page size. */ 118 printf("Max Data Transfer Size: "); 119 if (cdata->mdts == 0) 120 printf("Unlimited\n"); 121 else 122 printf("%d\n", PAGE_SIZE * (1 << cdata->mdts)); 123 printf("Controller ID: 0x%02x\n", cdata->ctrlr_id); 124 printf("Version: %d.%d.%d\n", 125 (cdata->ver >> 16) & 0xffff, (cdata->ver >> 8) & 0xff, 126 cdata->ver & 0xff); 127 printf("\n"); 128 129 printf("Admin Command Set Attributes\n"); 130 printf("============================\n"); 131 printf("Security Send/Receive: %s\n", 132 security ? "Supported" : "Not Supported"); 133 printf("Format NVM: %s\n", 134 fmt ? "Supported" : "Not Supported"); 135 printf("Firmware Activate/Download: %s\n", 136 fw ? "Supported" : "Not Supported"); 137 printf("Namespace Managment: %s\n", 138 nsmgmt ? "Supported" : "Not Supported"); 139 printf("Device Self-test: %sSupported\n", 140 ((oacs >> NVME_CTRLR_DATA_OACS_SELFTEST_SHIFT) & 141 NVME_CTRLR_DATA_OACS_SELFTEST_MASK) ? "" : "Not "); 142 printf("Directives: %sSupported\n", 143 ((oacs >> NVME_CTRLR_DATA_OACS_DIRECTIVES_SHIFT) & 144 NVME_CTRLR_DATA_OACS_DIRECTIVES_MASK) ? "" : "Not "); 145 printf("NVMe-MI Send/Receive: %sSupported\n", 146 ((oacs >> NVME_CTRLR_DATA_OACS_NVMEMI_SHIFT) & 147 NVME_CTRLR_DATA_OACS_NVMEMI_MASK) ? "" : "Not "); 148 printf("Virtualization Management: %sSupported\n", 149 ((oacs >> NVME_CTRLR_DATA_OACS_VM_SHIFT) & 150 NVME_CTRLR_DATA_OACS_VM_MASK) ? "" : "Not "); 151 printf("Doorbell Buffer Config %sSupported\n", 152 ((oacs >> NVME_CTRLR_DATA_OACS_DBBUFFER_SHIFT) & 153 NVME_CTRLR_DATA_OACS_DBBUFFER_MASK) ? "" : "Not "); 154 printf("Abort Command Limit: %d\n", cdata->acl+1); 155 printf("Async Event Request Limit: %d\n", cdata->aerl+1); 156 printf("Number of Firmware Slots: "); 157 if (fw != 0) 158 printf("%d\n", fw_num_slots); 159 else 160 printf("N/A\n"); 161 printf("Firmware Slot 1 Read-Only: "); 162 if (fw != 0) 163 printf("%s\n", fw_slot1_ro ? "Yes" : "No"); 164 else 165 printf("N/A\n"); 166 printf("Per-Namespace SMART Log: %s\n", 167 ns_smart ? "Yes" : "No"); 168 printf("Error Log Page Entries: %d\n", cdata->elpe+1); 169 printf("Number of Power States: %d\n", cdata->npss+1); 170 171 printf("\n"); 172 printf("NVM Command Set Attributes\n"); 173 printf("==========================\n"); 174 printf("Submission Queue Entry Size\n"); 175 printf(" Max: %d\n", 1 << sqes_max); 176 printf(" Min: %d\n", 1 << sqes_min); 177 printf("Completion Queue Entry Size\n"); 178 printf(" Max: %d\n", 1 << cqes_max); 179 printf(" Min: %d\n", 1 << cqes_min); 180 printf("Number of Namespaces: %d\n", cdata->nn); 181 printf("Compare Command: %s\n", 182 compare ? "Supported" : "Not Supported"); 183 printf("Write Uncorrectable Command: %s\n", 184 write_unc ? "Supported" : "Not Supported"); 185 printf("Dataset Management Command: %s\n", 186 dsm ? "Supported" : "Not Supported"); 187 printf("Write Zeroes Command: %sSupported\n", 188 ((oncs >> NVME_CTRLR_DATA_ONCS_WRZERO_SHIFT) & 189 NVME_CTRLR_DATA_ONCS_WRZERO_MASK) ? "" : "Not "); 190 printf("Save Features: %sSupported\n", 191 ((oncs >> NVME_CTRLR_DATA_ONCS_SAVEFEAT_SHIFT) & 192 NVME_CTRLR_DATA_ONCS_SAVEFEAT_MASK) ? "" : "Not "); 193 printf("Reservations: %sSupported\n", 194 ((oncs >> NVME_CTRLR_DATA_ONCS_RESERV_SHIFT) & 195 NVME_CTRLR_DATA_ONCS_RESERV_MASK) ? "" : "Not "); 196 printf("Timestamp feature: %sSupported\n", 197 ((oncs >> NVME_CTRLR_DATA_ONCS_TIMESTAMP_SHIFT) & 198 NVME_CTRLR_DATA_ONCS_TIMESTAMP_MASK) ? "" : "Not "); 199 printf("Fused Operation Support: %s%s\n", 200 (cdata->fuses == 0) ? "Not Supported" : "", 201 ((cdata->fuses >> NVME_CTRLR_DATA_FUSES_CNW_SHIFT) & 202 NVME_CTRLR_DATA_FUSES_CNW_MASK) ? "Compare and Write" : ""); 203 printf("Format NVM Attributes: %s%s Erase, %s Format\n", 204 ((cdata->fna >> NVME_CTRLR_DATA_FNA_CRYPTO_ERASE_SHIFT) & 205 NVME_CTRLR_DATA_FNA_CRYPTO_ERASE_MASK) ? "Crypto Erase, " : "", 206 ((cdata->fna >> NVME_CTRLR_DATA_FNA_ERASE_ALL_SHIFT) & 207 NVME_CTRLR_DATA_FNA_ERASE_ALL_MASK) ? "All-NVM" : "Per-NS", 208 ((cdata->fna >> NVME_CTRLR_DATA_FNA_FORMAT_ALL_SHIFT) & 209 NVME_CTRLR_DATA_FNA_FORMAT_ALL_MASK) ? "All-NVM" : "Per-NS"); 210 printf("Volatile Write Cache: %s\n", 211 vwc_present ? "Present" : "Not Present"); 212 213 if (nsmgmt) { 214 printf("\n"); 215 printf("Namespace Drive Attributes\n"); 216 printf("==========================\n"); 217 printf("NVM total cap: %s\n", 218 uint128_to_str(to128(cdata->untncap.tnvmcap), cbuf, sizeof(cbuf))); 219 printf("NVM unallocated cap: %s\n", 220 uint128_to_str(to128(cdata->untncap.unvmcap), cbuf, sizeof(cbuf))); 221 } 222 } 223 224 static void 225 print_namespace(struct nvme_namespace_data *nsdata) 226 { 227 uint32_t i; 228 uint32_t lbaf, lbads, ms, rp; 229 uint8_t thin_prov, ptype; 230 uint8_t flbas_fmt; 231 232 thin_prov = (nsdata->nsfeat >> NVME_NS_DATA_NSFEAT_THIN_PROV_SHIFT) & 233 NVME_NS_DATA_NSFEAT_THIN_PROV_MASK; 234 235 flbas_fmt = (nsdata->flbas >> NVME_NS_DATA_FLBAS_FORMAT_SHIFT) & 236 NVME_NS_DATA_FLBAS_FORMAT_MASK; 237 238 printf("Size (in LBAs): %lld (%lldM)\n", 239 (long long)nsdata->nsze, 240 (long long)nsdata->nsze / 1024 / 1024); 241 printf("Capacity (in LBAs): %lld (%lldM)\n", 242 (long long)nsdata->ncap, 243 (long long)nsdata->ncap / 1024 / 1024); 244 printf("Utilization (in LBAs): %lld (%lldM)\n", 245 (long long)nsdata->nuse, 246 (long long)nsdata->nuse / 1024 / 1024); 247 printf("Thin Provisioning: %s\n", 248 thin_prov ? "Supported" : "Not Supported"); 249 printf("Number of LBA Formats: %d\n", nsdata->nlbaf+1); 250 printf("Current LBA Format: LBA Format #%02d\n", flbas_fmt); 251 printf("Data Protection Caps: %s%s%s%s%s%s\n", 252 (nsdata->dpc == 0) ? "Not Supported" : "", 253 ((nsdata->dpc >> NVME_NS_DATA_DPC_MD_END_SHIFT) & 254 NVME_NS_DATA_DPC_MD_END_MASK) ? "Last Bytes, " : "", 255 ((nsdata->dpc >> NVME_NS_DATA_DPC_MD_START_SHIFT) & 256 NVME_NS_DATA_DPC_MD_START_MASK) ? "First Bytes, " : "", 257 ((nsdata->dpc >> NVME_NS_DATA_DPC_PIT3_SHIFT) & 258 NVME_NS_DATA_DPC_PIT3_MASK) ? "Type 3, " : "", 259 ((nsdata->dpc >> NVME_NS_DATA_DPC_PIT2_SHIFT) & 260 NVME_NS_DATA_DPC_PIT2_MASK) ? "Type 2, " : "", 261 ((nsdata->dpc >> NVME_NS_DATA_DPC_PIT2_MASK) & 262 NVME_NS_DATA_DPC_PIT1_MASK) ? "Type 1" : ""); 263 printf("Data Protection Settings: "); 264 ptype = (nsdata->dps >> NVME_NS_DATA_DPS_PIT_SHIFT) & 265 NVME_NS_DATA_DPS_PIT_MASK; 266 if (ptype) { 267 printf("Type %d, %s Bytes\n", ptype, 268 ((nsdata->dps >> NVME_NS_DATA_DPS_MD_START_SHIFT) & 269 NVME_NS_DATA_DPS_MD_START_MASK) ? "First" : "Last"); 270 } else { 271 printf("Not Enabled\n"); 272 } 273 printf("Multi-Path I/O Capabilities: %s%s\n", 274 (nsdata->nmic == 0) ? "Not Supported" : "", 275 ((nsdata->nmic >> NVME_NS_DATA_NMIC_MAY_BE_SHARED_SHIFT) & 276 NVME_NS_DATA_NMIC_MAY_BE_SHARED_MASK) ? "May be shared" : ""); 277 printf("Reservation Capabilities: %s%s%s%s%s%s%s%s%s\n", 278 (nsdata->rescap == 0) ? "Not Supported" : "", 279 ((nsdata->rescap >> NVME_NS_DATA_RESCAP_IEKEY13_SHIFT) & 280 NVME_NS_DATA_RESCAP_IEKEY13_MASK) ? "IEKEY13, " : "", 281 ((nsdata->rescap >> NVME_NS_DATA_RESCAP_EX_AC_AR_SHIFT) & 282 NVME_NS_DATA_RESCAP_EX_AC_AR_MASK) ? "EX_AC_AR, " : "", 283 ((nsdata->rescap >> NVME_NS_DATA_RESCAP_WR_EX_AR_SHIFT) & 284 NVME_NS_DATA_RESCAP_WR_EX_AR_MASK) ? "WR_EX_AR, " : "", 285 ((nsdata->rescap >> NVME_NS_DATA_RESCAP_EX_AC_RO_SHIFT) & 286 NVME_NS_DATA_RESCAP_EX_AC_RO_MASK) ? "EX_AC_RO, " : "", 287 ((nsdata->rescap >> NVME_NS_DATA_RESCAP_WR_EX_RO_SHIFT) & 288 NVME_NS_DATA_RESCAP_WR_EX_RO_MASK) ? "WR_EX_RO, " : "", 289 ((nsdata->rescap >> NVME_NS_DATA_RESCAP_EX_AC_SHIFT) & 290 NVME_NS_DATA_RESCAP_EX_AC_MASK) ? "EX_AC, " : "", 291 ((nsdata->rescap >> NVME_NS_DATA_RESCAP_WR_EX_SHIFT) & 292 NVME_NS_DATA_RESCAP_WR_EX_MASK) ? "WR_EX, " : "", 293 ((nsdata->rescap >> NVME_NS_DATA_RESCAP_PTPL_SHIFT) & 294 NVME_NS_DATA_RESCAP_PTPL_MASK) ? "PTPL" : ""); 295 printf("Format Progress Indicator: "); 296 if ((nsdata->fpi >> NVME_NS_DATA_FPI_SUPP_SHIFT) & 297 NVME_NS_DATA_FPI_SUPP_MASK) { 298 printf("%u%% remains\n", 299 (nsdata->fpi >> NVME_NS_DATA_FPI_PERC_SHIFT) & 300 NVME_NS_DATA_FPI_PERC_MASK); 301 } else 302 printf("Not Supported\n"); 303 printf("Optimal I/O Boundary (LBAs): %u\n", nsdata->noiob); 304 printf("Globally Unique Identifier: "); 305 for (i = 0; i < sizeof(nsdata->nguid); i++) 306 printf("%02x", nsdata->nguid[i]); 307 printf("\n"); 308 printf("IEEE EUI64: "); 309 for (i = 0; i < sizeof(nsdata->eui64); i++) 310 printf("%02x", nsdata->eui64[i]); 311 printf("\n"); 312 for (i = 0; i <= nsdata->nlbaf; i++) { 313 lbaf = nsdata->lbaf[i]; 314 lbads = (lbaf >> NVME_NS_DATA_LBAF_LBADS_SHIFT) & 315 NVME_NS_DATA_LBAF_LBADS_MASK; 316 ms = (lbaf >> NVME_NS_DATA_LBAF_MS_SHIFT) & 317 NVME_NS_DATA_LBAF_MS_MASK; 318 rp = (lbaf >> NVME_NS_DATA_LBAF_RP_SHIFT) & 319 NVME_NS_DATA_LBAF_RP_MASK; 320 printf("LBA Format #%02d: Data Size: %5d Metadata Size: %5d" 321 " Performance: %s\n", 322 i, 1 << lbads, ms, (rp == 0) ? "Best" : 323 (rp == 1) ? "Better" : (rp == 2) ? "Good" : "Degraded"); 324 } 325 } 326 327 static void 328 identify_usage(void) 329 { 330 fprintf(stderr, "usage:\n"); 331 fprintf(stderr, IDENTIFY_USAGE); 332 exit(1); 333 } 334 335 static void 336 identify_ctrlr(int argc, char *argv[]) 337 { 338 struct nvme_controller_data cdata; 339 int ch, fd, hexflag = 0, hexlength; 340 int verboseflag = 0; 341 342 while ((ch = getopt(argc, argv, "vx")) != -1) { 343 switch ((char)ch) { 344 case 'v': 345 verboseflag = 1; 346 break; 347 case 'x': 348 hexflag = 1; 349 break; 350 default: 351 identify_usage(); 352 } 353 } 354 355 /* Check that a controller was specified. */ 356 if (optind >= argc) 357 identify_usage(); 358 359 open_dev(argv[optind], &fd, 1, 1); 360 read_controller_data(fd, &cdata); 361 close(fd); 362 363 if (hexflag == 1) { 364 if (verboseflag == 1) 365 hexlength = sizeof(struct nvme_controller_data); 366 else 367 hexlength = offsetof(struct nvme_controller_data, 368 reserved8); 369 print_hex(&cdata, hexlength); 370 exit(0); 371 } 372 373 if (verboseflag == 1) { 374 fprintf(stderr, "-v not currently supported without -x\n"); 375 identify_usage(); 376 } 377 378 print_controller(&cdata); 379 exit(0); 380 } 381 382 static void 383 identify_ns(int argc, char *argv[]) 384 { 385 struct nvme_namespace_data nsdata; 386 char path[64]; 387 int ch, fd, hexflag = 0, hexlength; 388 int verboseflag = 0; 389 uint32_t nsid; 390 391 while ((ch = getopt(argc, argv, "vx")) != -1) { 392 switch ((char)ch) { 393 case 'v': 394 verboseflag = 1; 395 break; 396 case 'x': 397 hexflag = 1; 398 break; 399 default: 400 identify_usage(); 401 } 402 } 403 404 /* Check that a namespace was specified. */ 405 if (optind >= argc) 406 identify_usage(); 407 408 /* 409 * Check if the specified device node exists before continuing. 410 * This is a cleaner check for cases where the correct controller 411 * is specified, but an invalid namespace on that controller. 412 */ 413 open_dev(argv[optind], &fd, 1, 1); 414 close(fd); 415 416 /* 417 * We send IDENTIFY commands to the controller, not the namespace, 418 * since it is an admin cmd. The namespace ID will be specified in 419 * the IDENTIFY command itself. So parse the namespace's device node 420 * string to get the controller substring and namespace ID. 421 */ 422 parse_ns_str(argv[optind], path, &nsid); 423 open_dev(path, &fd, 1, 1); 424 read_namespace_data(fd, nsid, &nsdata); 425 close(fd); 426 427 if (hexflag == 1) { 428 if (verboseflag == 1) 429 hexlength = sizeof(struct nvme_namespace_data); 430 else 431 hexlength = offsetof(struct nvme_namespace_data, 432 reserved6); 433 print_hex(&nsdata, hexlength); 434 exit(0); 435 } 436 437 if (verboseflag == 1) { 438 fprintf(stderr, "-v not currently supported without -x\n"); 439 identify_usage(); 440 } 441 442 print_namespace(&nsdata); 443 exit(0); 444 } 445 446 void 447 identify(int argc, char *argv[]) 448 { 449 char *target; 450 451 if (argc < 2) 452 identify_usage(); 453 454 while (getopt(argc, argv, "vx") != -1) ; 455 456 /* Check that a controller or namespace was specified. */ 457 if (optind >= argc) 458 identify_usage(); 459 460 target = argv[optind]; 461 462 optreset = 1; 463 optind = 1; 464 465 /* 466 * If device node contains "ns", we consider it a namespace, 467 * otherwise, consider it a controller. 468 */ 469 if (strstr(target, NVME_NS_PREFIX) == NULL) 470 identify_ctrlr(argc, argv); 471 else 472 identify_ns(argc, argv); 473 } 474