xref: /openbsd/lib/libutil/opendev.3 (revision 8529ddd3)
1.\"	$OpenBSD: opendev.3,v 1.22 2015/01/15 19:06:32 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: January 15 2015 $
28.Dt OPENDEV 3
29.Os
30.Sh NAME
31.Nm opendev
32.Nd short form device open routine
33.Sh SYNOPSIS
34.In util.h
35.Ft int
36.Fn opendev "const char *path" "int oflags" "int dflags" "char **realpath"
37.Sh DESCRIPTION
38The
39.Fn opendev
40function opens a device using a
41.Dq short form
42name or
43.Xr disklabel 8
44UID
45.Pq DUID .
46For instance
47.Dq sd0
48or
49.Dq sd0c
50will be expanded to
51.Pa /dev/rsd0c
52on most architectures.
53.Pp
54Device name lookup is done by first checking
55.Fa path
56for a
57.Sq /
58and if one is found attempting to open that file.
59If not,
60.Fa path
61is checked to see if it is a valid DUID.
62If it is, the corresponding device is obtained via
63.Xr diskmap 4 .
64If
65.Fa path
66has no
67.Sq /
68and is not a DUID,
69.Fa /dev
70is searched for a matching device.
71.Pp
72The
73.Fa oflags
74are the same as the
75.Fa flags
76passed to
77.Xr open 2 .
78.Pp
79The
80.Fa dflags
81are specified by OR'ing the following values:
82.Bd -literal -offset indent
83OPENDEV_PART	attempt to open the raw partition during expansion
84OPENDEV_BLCK	open the block device (default is character device)
85.Ed
86.Pp
87If
88.Fa realpath
89is not
90.Dv NULL ,
91it is modified to point at the fully expanded device name.
92.Sh RETURN VALUES
93The
94.Fn opendev
95return value and errors are the same as the return value and errors of
96.Xr open 2 .
97.Sh SEE ALSO
98.Xr open 2 ,
99.Xr getrawpartition 3 ,
100.Xr diskmap 4 ,
101.Xr disklabel 8
102.Sh HISTORY
103The
104.Fn opendev
105function first appeared in
106.Ox 1.2 .
107.Sh CAVEATS
108If
109.Fa realpath
110is not
111.Dv NULL ,
112on return it will point to internal
113static storage space that will be overwritten by subsequent calls.
114