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