xref: /netbsd-src/lib/libutil/opendisk.3 (revision 8a8f936f250a330d54f8a24ed0e92aadf9743a7b)
1.\"	$NetBSD: opendisk.3,v 1.5 2001/09/26 07:21:42 lukem Exp $
2.\"
3.\" Copyright (c) 1997, 2001 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Luke Mewburn.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.Dd September 26, 2001
38.Dt OPENDISK 3
39.Os
40.Sh NAME
41.Nm opendisk
42.Nd open a disk's
43.Dq raw
44partition
45.Sh LIBRARY
46.Lb libutil
47.Sh SYNOPSIS
48.Fd #include <util.h>
49.Ft int
50.Fo opendisk
51.Fa "const char *path"
52.Fa "int flags"
53.Fa "char *buf"
54.Fa "size_t buflen"
55.Fa "int iscooked"
56.Fc
57.Sh DESCRIPTION
58.Fn opendisk
59opens
60.Fa path ,
61for reading and/or writing as specified by the argument
62.Fa flags
63using
64.Xr open 2 ,
65and the file descriptor is returned to the caller.
66.Fa buf
67is used to store the resultant filename.
68.Fa buflen
69is the size, in bytes, of the array referenced by
70.Fa buf
71(usually
72.Dv MAXPATHLEN
73bytes).
74If
75.Fa iscooked
76is non zero, the
77.Dq cooked
78partition (block device) is opened, rather than the
79.Dq raw
80partition (character device).
81.Pp
82.Fn opendisk
83attempts to open the following variations of
84.Fa path ,
85in order:
86.Bl -tag -width "/dev/rpathX"
87.It Pa path
88The pathname as given.
89.It Pa path Ns Em X
90.Fa path
91with a suffix of
92.Sq Em X ,
93where
94.Sq Em X
95represents the raw partition of the device, as determined by
96.Xr getrawpartition 3 ,
97usually
98.Dq c .
99.El
100.Pp
101If
102.Fa path
103does not contain a
104slash
105.Pq Dq / ,
106the following variations are attempted:
107.Pp
108.Bl -dash -offset indent
109.It
110If
111.Fa iscooked
112is zero:
113.Pp
114.Bl -tag -width "/dev/rpathX"
115.It Pa /dev/rpath
116.Fa path
117with a prefix of
118.Dq Pa /dev/r .
119.It Pa /dev/rpath Ns Em X
120.Fa path
121with a prefix of
122.Dq Pa /dev/r
123and a suffix of
124.Sq Em X
125(q.v.).
126.El
127.It
128If
129.Fa iscooked
130is non-zero:
131.Bl -tag -width "/dev/rpathX"
132.It Pa /dev/path
133.Fa path
134with a prefix of
135.Dq Pa /dev/ .
136.It Pa /dev/path Ns Em X
137.Fa path
138with a prefix of
139.Dq Pa /dev/
140and a suffix of
141.Sq Em X
142(q.v.).
143.El
144.El
145.Sh RETURN VALUES
146An open file descriptor, or -1 if the
147.Xr open 2
148failed.
149.Sh ERRORS
150.Fn opendisk
151may set
152.Va errno
153to one of the following values:
154.Bl -tag -width Er
155.It Bq Er EINVAL
156.Dv O_CREAT
157was set in
158.Fa flags ,
159or
160.Xr getrawpartition 3
161didn't return a valid partition.
162.It Bq Er EFAULT
163.Fa buf
164was the
165.Dv NULL
166pointer.
167.El
168.Pp
169The
170.Fn opendisk
171function
172may also set
173.Va errno
174to any value specified by the
175.Xr open 2
176function.
177.Sh SEE ALSO
178.Xr open 2 ,
179.Xr getrawpartition 3
180.Sh HISTORY
181The
182.Fn opendisk
183function first appeared in
184.Nx 1.3 .
185