1.\" $NetBSD: opendisk.3,v 1.9 2002/02/07 07:00:52 ross 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 December 11, 2001 38.Dt OPENDISK 3 39.Os 40.Sh NAME 41.Nm opendisk 42.Nd open a disk partition 43.Sh LIBRARY 44.Lb libutil 45.Sh SYNOPSIS 46.Fd #include \*[Lt]util.h\*[Gt] 47.Ft int 48.Fo opendisk 49.Fa "const char *path" 50.Fa "int flags" 51.Fa "char *buf" 52.Fa "size_t buflen" 53.Fa "int iscooked" 54.Fc 55.Sh DESCRIPTION 56.Fn opendisk 57opens 58.Fa path , 59for reading and/or writing as specified by the argument 60.Fa flags 61using 62.Xr open 2 , 63and the file descriptor is returned to the caller. 64.Fa buf 65is used to store the resultant filename. 66.Fa buflen 67is the size, in bytes, of the array referenced by 68.Fa buf 69(usually 70.Dv MAXPATHLEN 71bytes). 72.Fa iscooked 73controls which paths in 74.Pa /dev 75are tried. 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 path 98does not contain a 99slash 100.Pq Dq / , 101the following variations are attempted: 102.Pp 103.Bl -dash -offset indent 104.It 105If 106.Fa iscooked 107is zero: 108.Pp 109.Bl -tag -width "/dev/rpathX" 110.It Pa /dev/rpath 111.Fa path 112with a prefix of 113.Dq Pa /dev/r . 114.It Pa /dev/rpath Ns Em X 115.Fa path 116with a prefix of 117.Dq Pa /dev/r 118and a suffix of 119.Sq Em X 120(q.v.). 121.El 122.It 123If 124.Fa iscooked 125is non-zero: 126.Bl -tag -width "/dev/rpathX" 127.It Pa /dev/path 128.Fa path 129with a prefix of 130.Dq Pa /dev/ . 131.It Pa /dev/path Ns Em X 132.Fa path 133with a prefix of 134.Dq Pa /dev/ 135and a suffix of 136.Sq Em X 137(q.v.). 138.El 139.El 140.Sh RETURN VALUES 141An open file descriptor, or -1 if the 142.Xr open 2 143failed. 144.Sh ERRORS 145.Fn opendisk 146may set 147.Va errno 148to one of the following values: 149.Bl -tag -width Er 150.It Bq Er EINVAL 151.Dv O_CREAT 152was set in 153.Fa flags , 154or 155.Xr getrawpartition 3 156didn't return a valid partition. 157.It Bq Er EFAULT 158.Fa buf 159was the 160.Dv NULL 161pointer. 162.El 163.Pp 164The 165.Fn opendisk 166function 167may also set 168.Va errno 169to any value specified by the 170.Xr open 2 171function. 172.Sh SEE ALSO 173.Xr open 2 , 174.Xr getrawpartition 3 175.Sh HISTORY 176The 177.Fn opendisk 178function first appeared in 179.Nx 1.3 . 180