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