From b27a4cca12d949d93360e1a25c570a2e1007d8e0 Mon Sep 17 00:00:00 2001 From: jimharris Date: Wed, 24 Jul 2013 22:38:37 +0000 Subject: [PATCH] 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 git-svn-id: svn://svn.freebsd.org/base/stable/9@253625 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sbin/nvmecontrol/devlist.c | 3 ++- sbin/nvmecontrol/nvmecontrol.c | 14 ++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/sbin/nvmecontrol/devlist.c b/sbin/nvmecontrol/devlist.c index 849b36441..2e81e7617 100644 --- a/sbin/nvmecontrol/devlist.c +++ b/sbin/nvmecontrol/devlist.c @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -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 diff --git a/sbin/nvmecontrol/nvmecontrol.c b/sbin/nvmecontrol/nvmecontrol.c index e258314a0..70f13d5c9 100644 --- a/sbin/nvmecontrol/nvmecontrol.c +++ b/sbin/nvmecontrol/nvmecontrol.c @@ -163,7 +163,6 @@ read_namespace_data(int fd, int nsid, struct nvme_namespace_data *nsdata) 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 show_error, int exit_on_error) 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 show_error, int exit_on_error) if (exit_on_error) exit(1); else - return (1); + return (errno); } return (0); -- 2.45.0