Date: Wed, 26 Jun 2013 23:41:07 +0000 (UTC) From: Jim Harris <jimharris@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r252274 - head/sbin/nvmecontrol Message-ID: <201306262341.r5QNf7tV009348@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jimharris Date: Wed Jun 26 23:41:07 2013 New Revision: 252274 URL: http://svnweb.freebsd.org/changeset/base/252274 Log: Ensure that a device node is specified when invoking the identify or reset commands. Also improve the checking of device node names, so that better error messages are displayed when incorrect names are specified. Sponsored by: Intel MFC after: 3 days Modified: head/sbin/nvmecontrol/identify.c head/sbin/nvmecontrol/nvmecontrol.c head/sbin/nvmecontrol/reset.c Modified: head/sbin/nvmecontrol/identify.c ============================================================================== --- head/sbin/nvmecontrol/identify.c Wed Jun 26 23:37:11 2013 (r252273) +++ head/sbin/nvmecontrol/identify.c Wed Jun 26 23:41:07 2013 (r252274) @@ -200,6 +200,10 @@ identify_ctrlr(int argc, char *argv[]) } } + /* Check that a controller was specified. */ + if (optind >= argc) + identify_usage(); + open_dev(argv[optind], &fd, 1, 1); read_controller_data(fd, &cdata); close(fd); @@ -245,6 +249,10 @@ identify_ns(int argc, char *argv[]) } } + /* Check that a namespace was specified. */ + if (optind >= argc) + identify_usage(); + /* * Check if the specified device node exists before continuing. * This is a cleaner check for cases where the correct controller Modified: head/sbin/nvmecontrol/nvmecontrol.c ============================================================================== --- head/sbin/nvmecontrol/nvmecontrol.c Wed Jun 26 23:37:11 2013 (r252273) +++ head/sbin/nvmecontrol/nvmecontrol.c Wed Jun 26 23:41:07 2013 (r252274) @@ -126,10 +126,22 @@ open_dev(const char *str, int *fd, int s struct stat devstat; char full_path[64]; + if (!strnstr(str, NVME_CTRLR_PREFIX, strlen(NVME_CTRLR_PREFIX))) { + if (show_error) + fprintf(stderr, + "Controller/namespace IDs must begin with '%s'.\n", + NVME_CTRLR_PREFIX); + if (exit_on_error) + exit(EX_USAGE); + else + return (EX_USAGE); + } + snprintf(full_path, sizeof(full_path), "/dev/%s", str); if (stat(full_path, &devstat) != 0) { if (show_error) - fprintf(stderr, "error\n"); + fprintf(stderr, "Could not stat %s. errno=%d (%s)\n", + full_path, errno, strerror(errno)); if (exit_on_error) exit(EX_NOINPUT); else @@ -139,8 +151,8 @@ open_dev(const char *str, int *fd, int s *fd = open(full_path, O_RDWR); if (*fd < 0) { if (show_error) - printf("Could not open %s. errno=%d (%s)\n", full_path, - errno, strerror(errno)); + fprintf(stderr, "Could not open %s. errno=%d (%s)\n", + full_path, errno, strerror(errno)); if (exit_on_error) exit(EX_NOPERM); else Modified: head/sbin/nvmecontrol/reset.c ============================================================================== --- head/sbin/nvmecontrol/reset.c Wed Jun 26 23:37:11 2013 (r252273) +++ head/sbin/nvmecontrol/reset.c Wed Jun 26 23:41:07 2013 (r252274) @@ -60,6 +60,10 @@ reset(int argc, char *argv[]) } } + /* Check that a controller was specified. */ + if (optind >= argc) + reset_usage(); + open_dev(argv[optind], &fd, 1, 1); if (ioctl(fd, NVME_RESET_CONTROLLER) < 0) { printf("Reset request to %s failed. errno=%d (%s)\n",
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201306262341.r5QNf7tV009348>