-.\" $OpenBSD: opendev.3,v 1.22 2015/01/15 19:06:32 schwarze Exp $
+.\" $OpenBSD: opendev.3,v 1.23 2022/08/25 17:09:54 kn Exp $
.\"
.\" Copyright (c) 2000, Todd C. Miller. All rights reserved.
.\" Copyright (c) 1996, Jason Downs. All rights reserved.
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: January 15 2015 $
+.Dd $Mdocdate: August 25 2022 $
.Dt OPENDEV 3
.Os
.Sh NAME
.Dv NULL ,
it is modified to point at the fully expanded device name.
.Sh RETURN VALUES
-The
+If successful,
.Fn opendev
-return value and errors are the same as the return value and errors of
-.Xr open 2 .
+returns a file descriptor.
+Otherwise, a value of -1 is returned and
+.Va errno
+is set to indicate the error.
.Sh SEE ALSO
.Xr open 2 ,
.Xr getrawpartition 3 ,
-/* $OpenBSD: opendev.c,v 1.15 2011/06/30 15:04:58 jsing Exp $ */
+/* $OpenBSD: opendev.c,v 1.16 2022/08/25 17:09:54 kn Exp $ */
/*
* Copyright (c) 2000, Todd C. Miller. All rights reserved.
#include <sys/limits.h>
#include <sys/disk.h>
#include <sys/dkio.h>
+#include <sys/stat.h>
#include "util.h"
prefix = "r"; /* character device */
if ((slash = strchr(path, '/'))) {
+ struct stat sb;
+
strlcpy(namebuf, path, sizeof(namebuf));
fd = open(namebuf, oflags);
+
+ if (fd != -1) {
+ if (fstat(fd, &sb) == -1) {
+ close(fd);
+ fd = -1;
+ } else if ((dflags & OPENDEV_BLCK) ?
+ !S_ISBLK(sb.st_mode) :
+ !S_ISCHR(sb.st_mode)) {
+ close(fd);
+ fd = -1;
+ errno = ENOTBLK;
+ }
+ }
} else if (isduid(path, dflags)) {
strlcpy(namebuf, path, sizeof(namebuf));
if ((fd = open("/dev/diskmap", oflags)) != -1) {