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