xref: /openbsd/lib/libutil/opendisk.3 (revision e34c0550)
1.\"	$OpenBSD: opendisk.3,v 1.9 2015/09/10 15:16:43 schwarze 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: September 10 2015 $
32.Dt OPENDISK 3
33.Os
34.Sh NAME
35.Nm opendisk
36.Nd open a disk's raw partition
37.Sh SYNOPSIS
38.In sys/types.h
39.In util.h
40.Ft int
41.Fo opendisk
42.Fa "const char *path"
43.Fa "int flags"
44.Fa "char *buf"
45.Fa "size_t buflen"
46.Fa "int iscooked"
47.Fc
48.Sh DESCRIPTION
49.Fn opendisk
50opens
51.Fa path ,
52for reading and/or writing as specified by the argument
53.Fa flags
54using
55.Xr open 2 ,
56and the file descriptor is returned to the caller.
57.Fa buf
58is used to store the resultant filename.
59.Fa buflen
60is the size, in bytes, of the array referenced by
61.Fa buf
62(usually
63.Dv MAXPATHLEN
64bytes).
65If
66.Fa iscooked
67is non zero, the
68.Dq cooked
69partition (block device) is opened, rather than the
70.Dq raw
71partition (character device).
72.Pp
73.Fn opendisk
74attempts to open the following variations of
75.Fa path ,
76in order:
77.Bl -tag -width "/dev/rpathX"
78.It Fa path
79The pathname as given.
80.It Fa path Ns Em X
81.Fa path
82with a suffix of
83.Sq Em X ,
84where
85.Sq Em X
86represents the raw partition of the device, as determined by
87.Xr getrawpartition 3 ,
88usually
89.Dq c .
90.El
91.Pp
92If
93.Fa iscooked
94is zero, then the following two variations are attempted:
95.Bl -tag -width "/dev/rpathX"
96.It Pa /dev/r Ns Fa path
97.Fa path
98with a prefix of
99.Dq Pa /dev/r .
100.It Pa /dev/r Ns Fa path Ns Em X
101.Fa path
102with a prefix of
103.Dq Pa /dev/r
104and a suffix of
105.Sq Em X
106(q.v.).
107.El
108.Pp
109Otherwise (i.e.,
110.Fa iscooked
111is non-zero), the following variations are attempted:
112.Bl -tag -width "/dev/rpathX"
113.It Pa /dev/ Ns Fa path
114.Fa path
115with a prefix of
116.Dq Pa /dev/ .
117.It Pa /dev/ Ns Fa path Ns Em X
118.Fa path
119with a prefix of
120.Dq Pa /dev/
121and a suffix of
122.Sq Em X
123(q.v.).
124.El
125.Sh RETURN VALUES
126An open file descriptor, or -1 if the
127.Xr open 2
128failed.
129.Sh ERRORS
130.Fn opendisk
131may set
132.Va errno
133to one of the following values:
134.Bl -tag -width Er
135.It Bq Er EINVAL
136.Dv O_CREAT
137was set in
138.Fa flags ,
139or
140.Xr getrawpartition 3
141didn't return a valid partition.
142.El
143.Pp
144The
145.Fn opendisk
146function
147may also set
148.Va errno
149to any value specified by the
150.Xr open 2
151function.
152.Sh SEE ALSO
153.Xr open 2 ,
154.Xr getrawpartition 3
155.Sh HISTORY
156The
157.Fn opendisk
158function first appeared in
159.Nx 1.3 .
160