identify.c (252275) | identify.c (253109) |
---|---|
1/*- 2 * Copyright (C) 2012-2013 Intel Corporation 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (C) 2012-2013 Intel Corporation 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sbin/nvmecontrol/identify.c 252275 2013-06-26 23:46:31Z jimharris $"); | 28__FBSDID("$FreeBSD: head/sbin/nvmecontrol/identify.c 253109 2013-07-09 21:14:15Z jimharris $"); |
29 30#include <sys/param.h> 31 32#include <ctype.h> | 29 30#include <sys/param.h> 31 32#include <ctype.h> |
33#include <err.h> |
|
33#include <errno.h> 34#include <fcntl.h> 35#include <stddef.h> 36#include <stdio.h> 37#include <stdlib.h> 38#include <string.h> | 34#include <errno.h> 35#include <fcntl.h> 36#include <stddef.h> 37#include <stdio.h> 38#include <stdlib.h> 39#include <string.h> |
39#include <sysexits.h> | |
40#include <unistd.h> 41 42#include "nvmecontrol.h" 43 44static void 45print_controller(struct nvme_controller_data *cdata) 46{ 47 printf("Controller Capabilities/Features\n"); --- 86 unchanged lines hidden (view full) --- 134 } 135} 136 137static void 138identify_usage(void) 139{ 140 fprintf(stderr, "usage:\n"); 141 fprintf(stderr, IDENTIFY_USAGE); | 40#include <unistd.h> 41 42#include "nvmecontrol.h" 43 44static void 45print_controller(struct nvme_controller_data *cdata) 46{ 47 printf("Controller Capabilities/Features\n"); --- 86 unchanged lines hidden (view full) --- 134 } 135} 136 137static void 138identify_usage(void) 139{ 140 fprintf(stderr, "usage:\n"); 141 fprintf(stderr, IDENTIFY_USAGE); |
142 exit(EX_USAGE); | 142 exit(1); |
143} 144 145static void 146identify_ctrlr(int argc, char *argv[]) 147{ 148 struct nvme_controller_data cdata; 149 int ch, fd, hexflag = 0, hexlength; 150 int verboseflag = 0; --- 21 unchanged lines hidden (view full) --- 172 173 if (hexflag == 1) { 174 if (verboseflag == 1) 175 hexlength = sizeof(struct nvme_controller_data); 176 else 177 hexlength = offsetof(struct nvme_controller_data, 178 reserved5); 179 print_hex(&cdata, hexlength); | 143} 144 145static void 146identify_ctrlr(int argc, char *argv[]) 147{ 148 struct nvme_controller_data cdata; 149 int ch, fd, hexflag = 0, hexlength; 150 int verboseflag = 0; --- 21 unchanged lines hidden (view full) --- 172 173 if (hexflag == 1) { 174 if (verboseflag == 1) 175 hexlength = sizeof(struct nvme_controller_data); 176 else 177 hexlength = offsetof(struct nvme_controller_data, 178 reserved5); 179 print_hex(&cdata, hexlength); |
180 exit(EX_OK); | 180 exit(0); |
181 } 182 183 if (verboseflag == 1) { | 181 } 182 183 if (verboseflag == 1) { |
184 printf("-v not currently supported without -x.\n"); | 184 fprintf(stderr, "-v not currently supported without -x\n"); |
185 identify_usage(); 186 } 187 188 print_controller(&cdata); | 185 identify_usage(); 186 } 187 188 print_controller(&cdata); |
189 exit(EX_OK); | 189 exit(0); |
190} 191 192static void 193identify_ns(int argc, char *argv[]) 194{ 195 struct nvme_namespace_data nsdata; 196 char path[64]; 197 char *nsloc; --- 28 unchanged lines hidden (view full) --- 226 /* 227 * Pull the namespace id from the string. +2 skips past the "ns" part 228 * of the string. Don't search past 10 characters into the string, 229 * otherwise we know it is malformed. 230 */ 231 nsloc = strnstr(argv[optind], NVME_NS_PREFIX, 10); 232 if (nsloc != NULL) 233 nsid = strtol(nsloc + 2, NULL, 10); | 190} 191 192static void 193identify_ns(int argc, char *argv[]) 194{ 195 struct nvme_namespace_data nsdata; 196 char path[64]; 197 char *nsloc; --- 28 unchanged lines hidden (view full) --- 226 /* 227 * Pull the namespace id from the string. +2 skips past the "ns" part 228 * of the string. Don't search past 10 characters into the string, 229 * otherwise we know it is malformed. 230 */ 231 nsloc = strnstr(argv[optind], NVME_NS_PREFIX, 10); 232 if (nsloc != NULL) 233 nsid = strtol(nsloc + 2, NULL, 10); |
234 if (nsloc == NULL || (nsid == 0 && errno != 0)) { 235 printf("Invalid namespace ID %s.\n", argv[optind]); 236 exit(EX_IOERR); 237 } | 234 if (nsloc == NULL || (nsid == 0 && errno != 0)) 235 errx(1, "invalid namespace ID '%s'", argv[optind]); |
238 239 /* 240 * We send IDENTIFY commands to the controller, not the namespace, 241 * since it is an admin cmd. So the path should only include the 242 * nvmeX part of the nvmeXnsY string. 243 */ 244 snprintf(path, nsloc - argv[optind] + 1, "%s", argv[optind]); 245 open_dev(path, &fd, 1, 1); 246 read_namespace_data(fd, nsid, &nsdata); 247 close(fd); 248 249 if (hexflag == 1) { 250 if (verboseflag == 1) 251 hexlength = sizeof(struct nvme_namespace_data); 252 else 253 hexlength = offsetof(struct nvme_namespace_data, 254 reserved6); 255 print_hex(&nsdata, hexlength); | 236 237 /* 238 * We send IDENTIFY commands to the controller, not the namespace, 239 * since it is an admin cmd. So the path should only include the 240 * nvmeX part of the nvmeXnsY string. 241 */ 242 snprintf(path, nsloc - argv[optind] + 1, "%s", argv[optind]); 243 open_dev(path, &fd, 1, 1); 244 read_namespace_data(fd, nsid, &nsdata); 245 close(fd); 246 247 if (hexflag == 1) { 248 if (verboseflag == 1) 249 hexlength = sizeof(struct nvme_namespace_data); 250 else 251 hexlength = offsetof(struct nvme_namespace_data, 252 reserved6); 253 print_hex(&nsdata, hexlength); |
256 exit(EX_OK); | 254 exit(0); |
257 } 258 259 if (verboseflag == 1) { | 255 } 256 257 if (verboseflag == 1) { |
260 printf("-v not currently supported without -x.\n"); | 258 fprintf(stderr, "-v not currently supported without -x\n"); |
261 identify_usage(); 262 } 263 264 print_namespace(&nsdata); | 259 identify_usage(); 260 } 261 262 print_namespace(&nsdata); |
265 exit(EX_OK); | 263 exit(0); |
266} 267 268void 269identify(int argc, char *argv[]) 270{ 271 char *target; 272 273 if (argc < 2) --- 18 unchanged lines hidden --- | 264} 265 266void 267identify(int argc, char *argv[]) 268{ 269 char *target; 270 271 if (argc < 2) --- 18 unchanged lines hidden --- |