svn commit: r253625 - stable/9/sbin/nvmecontrol
Jim Harris
jimharris at FreeBSD.org
Wed Jul 24 22:38:38 UTC 2013
Author: jimharris
Date: Wed Jul 24 22:38:37 2013
New Revision: 253625
URL: http://svnweb.freebsd.org/changeset/base/253625
Log:
MFC r253436, r253458:
Simplify open_dev() by returning errno values rather than just 0 or 1.
Also remove stat() call and just rely on errno from open() call to discern
whether dev node exists or not.
Approved by: re (kib)
Sponsored by: Intel
Modified:
stable/9/sbin/nvmecontrol/devlist.c
stable/9/sbin/nvmecontrol/nvmecontrol.c
Directory Properties:
stable/9/sbin/nvmecontrol/ (props changed)
Modified: stable/9/sbin/nvmecontrol/devlist.c
==============================================================================
--- stable/9/sbin/nvmecontrol/devlist.c Wed Jul 24 22:34:06 2013 (r253624)
+++ stable/9/sbin/nvmecontrol/devlist.c Wed Jul 24 22:38:37 2013 (r253625)
@@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <err.h>
+#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdio.h>
@@ -80,7 +81,7 @@ devlist(int argc, char *argv[])
ret = open_dev(name, &fd, 0, 0);
if (ret != 0) {
- if (fd < 0) {
+ if (ret == EACCES) {
warnx("could not open /dev/%s\n", name);
continue;
} else
Modified: stable/9/sbin/nvmecontrol/nvmecontrol.c
==============================================================================
--- stable/9/sbin/nvmecontrol/nvmecontrol.c Wed Jul 24 22:34:06 2013 (r253624)
+++ stable/9/sbin/nvmecontrol/nvmecontrol.c Wed Jul 24 22:38:37 2013 (r253625)
@@ -163,7 +163,6 @@ read_namespace_data(int fd, int nsid, st
int
open_dev(const char *str, int *fd, int show_error, int exit_on_error)
{
- struct stat devstat;
char full_path[64];
if (!strnstr(str, NVME_CTRLR_PREFIX, strlen(NVME_CTRLR_PREFIX))) {
@@ -173,19 +172,10 @@ open_dev(const char *str, int *fd, int s
if (exit_on_error)
exit(1);
else
- return (1);
+ return (EINVAL);
}
snprintf(full_path, sizeof(full_path), "/dev/%s", str);
- if (stat(full_path, &devstat) != 0) {
- if (show_error)
- warn("could not stat %s", full_path);
- if (exit_on_error)
- exit(1);
- else
- return (1);
- }
-
*fd = open(full_path, O_RDWR);
if (*fd < 0) {
if (show_error)
@@ -193,7 +183,7 @@ open_dev(const char *str, int *fd, int s
if (exit_on_error)
exit(1);
else
- return (1);
+ return (errno);
}
return (0);
More information about the svn-src-stable-9
mailing list