From owner-svn-src-all@FreeBSD.ORG Thu Jul 4 00:01:00 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 8AFBFEC2; Thu, 4 Jul 2013 00:01:00 +0000 (UTC) (envelope-from jimharris@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 6DB551FA1; Thu, 4 Jul 2013 00:01:00 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r64010uP072067; Thu, 4 Jul 2013 00:01:00 GMT (envelope-from jimharris@svn.freebsd.org) Received: (from jimharris@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r6400xJQ072040; Thu, 4 Jul 2013 00:00:59 GMT (envelope-from jimharris@svn.freebsd.org) Message-Id: <201307040000.r6400xJQ072040@svn.freebsd.org> From: Jim Harris Date: Thu, 4 Jul 2013 00:00:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r252667 - stable/9/sbin/nvmecontrol X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Jul 2013 00:01:00 -0000 Author: jimharris Date: Thu Jul 4 00:00:59 2013 New Revision: 252667 URL: http://svnweb.freebsd.org/changeset/base/252667 Log: MFC r252274: 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 Modified: stable/9/sbin/nvmecontrol/identify.c stable/9/sbin/nvmecontrol/nvmecontrol.c stable/9/sbin/nvmecontrol/reset.c Directory Properties: stable/9/sbin/nvmecontrol/ (props changed) Modified: stable/9/sbin/nvmecontrol/identify.c ============================================================================== --- stable/9/sbin/nvmecontrol/identify.c Wed Jul 3 23:59:08 2013 (r252666) +++ stable/9/sbin/nvmecontrol/identify.c Thu Jul 4 00:00:59 2013 (r252667) @@ -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: stable/9/sbin/nvmecontrol/nvmecontrol.c ============================================================================== --- stable/9/sbin/nvmecontrol/nvmecontrol.c Wed Jul 3 23:59:08 2013 (r252666) +++ stable/9/sbin/nvmecontrol/nvmecontrol.c Thu Jul 4 00:00:59 2013 (r252667) @@ -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: stable/9/sbin/nvmecontrol/reset.c ============================================================================== --- stable/9/sbin/nvmecontrol/reset.c Wed Jul 3 23:59:08 2013 (r252666) +++ stable/9/sbin/nvmecontrol/reset.c Thu Jul 4 00:00:59 2013 (r252667) @@ -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",