jcs's openbsd hax
openbsd
1.\" $OpenBSD: opendev.3,v 1.25 2025/06/06 22:01:40 schwarze Exp $
2.\"
3.\" Copyright (c) 2000, Todd C. Miller. All rights reserved.
4.\" Copyright (c) 1996, Jason Downs. All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
16.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18.\" DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
19.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25.\" SUCH DAMAGE.
26.\"
27.Dd $Mdocdate: June 6 2025 $
28.Dt OPENDEV 3
29.Os
30.Sh NAME
31.Nm opendev
32.Nd short form device open routine
33.Sh SYNOPSIS
34.Lb libutil
35.In util.h
36.Ft int
37.Fn opendev "const char *path" "int oflags" "int dflags" "char **realpath"
38.Sh DESCRIPTION
39The
40.Fn opendev
41function opens a device using a
42.Dq short form
43name or
44.Xr disklabel 8
45UID
46.Pq DUID .
47For instance
48.Dq sd0
49or
50.Dq sd0c
51will be expanded to
52.Pa /dev/rsd0c
53on most architectures.
54.Pp
55Device name lookup is done by first checking
56.Fa path
57for a
58.Sq /
59and if one is found attempting to open that file.
60If not,
61.Fa path
62is checked to see if it is a valid DUID.
63If it is, the corresponding device is obtained via
64.Xr diskmap 4 .
65If
66.Fa path
67has no
68.Sq /
69and is not a DUID,
70.Fa /dev
71is searched for a matching device.
72.Pp
73The
74.Fa oflags
75are the same as the
76.Fa flags
77passed to
78.Xr open 2 .
79.Pp
80The
81.Fa dflags
82are specified by OR'ing the following values:
83.Bd -literal -offset indent
84OPENDEV_PART attempt to open the raw partition during expansion
85OPENDEV_BLCK open the block device (default is character device)
86.Ed
87.Pp
88If
89.Fa realpath
90is not
91.Dv NULL ,
92it is modified to point at the fully expanded device name.
93.Sh RETURN VALUES
94The
95.Fn opendev
96return value and errors are the same as the return value and errors of
97.Xr open 2 .
98.Sh SEE ALSO
99.Xr open 2 ,
100.Xr getrawpartition 3 ,
101.Xr diskmap 4 ,
102.Xr disklabel 8
103.Sh HISTORY
104The
105.Fn opendev
106function first appeared in
107.Ox 1.2 .
108.Sh CAVEATS
109If
110.Fa realpath
111is not
112.Dv NULL ,
113on return it will point to internal
114static storage space that will be overwritten by subsequent calls.