xref: /openbsd-src/lib/libutil/opendev.3 (revision 531ea1fd1f29d4262dcc911182a2c7056587eb1f)
1*531ea1fdSkn.\"	$OpenBSD: opendev.3,v 1.24 2022/08/26 21:47:16 kn Exp $
2151ab52cSdownsj.\"
372ac04f0Smillert.\" Copyright (c) 2000, Todd C. Miller.  All rights reserved.
4151ab52cSdownsj.\" Copyright (c) 1996, Jason Downs.  All rights reserved.
5151ab52cSdownsj.\"
6151ab52cSdownsj.\" Redistribution and use in source and binary forms, with or without
7151ab52cSdownsj.\" modification, are permitted provided that the following conditions
8151ab52cSdownsj.\" are met:
9151ab52cSdownsj.\" 1. Redistributions of source code must retain the above copyright
10151ab52cSdownsj.\"    notice, this list of conditions and the following disclaimer.
11151ab52cSdownsj.\" 2. Redistributions in binary form must reproduce the above copyright
12151ab52cSdownsj.\"    notice, this list of conditions and the following disclaimer in the
13151ab52cSdownsj.\"    documentation and/or other materials provided with the distribution.
14151ab52cSdownsj.\"
15151ab52cSdownsj.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
16151ab52cSdownsj.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17151ab52cSdownsj.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18151ab52cSdownsj.\" DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
19151ab52cSdownsj.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20151ab52cSdownsj.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21151ab52cSdownsj.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22151ab52cSdownsj.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23151ab52cSdownsj.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24151ab52cSdownsj.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25151ab52cSdownsj.\" SUCH DAMAGE.
26151ab52cSdownsj.\"
27*531ea1fdSkn.Dd $Mdocdate: August 26 2022 $
28151ab52cSdownsj.Dt OPENDEV 3
297f3168a2Saaron.Os
30151ab52cSdownsj.Sh NAME
31151ab52cSdownsj.Nm opendev
32151ab52cSdownsj.Nd short form device open routine
33151ab52cSdownsj.Sh SYNOPSIS
3486f9d4cdStedu.In util.h
35151ab52cSdownsj.Ft int
3627ad9b61Smillert.Fn opendev "const char *path" "int oflags" "int dflags" "char **realpath"
37151ab52cSdownsj.Sh DESCRIPTION
38151ab52cSdownsjThe
39151ab52cSdownsj.Fn opendev
40b709cc0bSkrwfunction opens a device using a
4102ecd0d2Saaron.Dq short form
42b709cc0bSkrwname or
43b709cc0bSkrw.Xr disklabel 8
44b709cc0bSkrwUID
45b709cc0bSkrw.Pq DUID .
46b709cc0bSkrwFor instance
4702ecd0d2Saaron.Dq sd0
4802ecd0d2Saaronor
49b709cc0bSkrw.Dq sd0c
50b709cc0bSkrwwill be expanded to
51151ab52cSdownsj.Pa /dev/rsd0c
52151ab52cSdownsjon most architectures.
53151ab52cSdownsj.Pp
542e4bea77ShughDevice name lookup is done by first checking
552e4bea77Shugh.Fa path
562e4bea77Shughfor a
57b709cc0bSkrw.Sq /
582e4bea77Shughand if one is found attempting to open that file.
59b709cc0bSkrwIf not,
60b709cc0bSkrw.Fa path
61b709cc0bSkrwis checked to see if it is a valid DUID.
62b709cc0bSkrwIf it is, the corresponding device is obtained via
63b709cc0bSkrw.Xr diskmap 4 .
64b709cc0bSkrwIf
65b709cc0bSkrw.Fa path
66b709cc0bSkrwhas no
67b709cc0bSkrw.Sq /
68b709cc0bSkrwand is not a DUID,
692e4bea77Shugh.Fa /dev
702e4bea77Shughis searched for a matching device.
712e4bea77Shugh.Pp
72151ab52cSdownsjThe
7302ecd0d2Saaron.Fa oflags
74151ab52cSdownsjare the same as the
7502ecd0d2Saaron.Fa flags
76151ab52cSdownsjpassed to
77151ab52cSdownsj.Xr open 2 .
78151ab52cSdownsj.Pp
79151ab52cSdownsjThe
8002ecd0d2Saaron.Fa dflags
8112bc6069Sschwarzeare specified by OR'ing the following values:
82b5ceb444Sjmc.Bd -literal -offset indent
83151ab52cSdownsjOPENDEV_PART	attempt to open the raw partition during expansion
8472ac04f0SmillertOPENDEV_BLCK	open the block device (default is character device)
85151ab52cSdownsj.Ed
86151ab52cSdownsj.Pp
87679286fbSderaadtIf
8802ecd0d2Saaron.Fa realpath
8902ecd0d2Saaronis not
9002ecd0d2Saaron.Dv NULL ,
9102ecd0d2Saaronit is modified to point at the fully expanded device name.
92151ab52cSdownsj.Sh RETURN VALUES
93*531ea1fdSknThe
94151ab52cSdownsj.Fn opendev
95*531ea1fdSknreturn value and errors are the same as the return value and errors of
96*531ea1fdSkn.Xr open 2 .
97151ab52cSdownsj.Sh SEE ALSO
9872ac04f0Smillert.Xr open 2 ,
99b709cc0bSkrw.Xr getrawpartition 3 ,
100b709cc0bSkrw.Xr diskmap 4 ,
101b709cc0bSkrw.Xr disklabel 8
10202ecd0d2Saaron.Sh HISTORY
10302ecd0d2SaaronThe
10402ecd0d2Saaron.Fn opendev
10502ecd0d2Saaronfunction first appeared in
10602ecd0d2Saaron.Ox 1.2 .
1070c1bb6b5Sjmc.Sh CAVEATS
1080c1bb6b5SjmcIf
1090c1bb6b5Sjmc.Fa realpath
1100c1bb6b5Sjmcis not
1110c1bb6b5Sjmc.Dv NULL ,
1120c1bb6b5Sjmcon return it will point to internal
1130c1bb6b5Sjmcstatic storage space that will be overwritten by subsequent calls.
114