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