1.\" $OpenBSD: opendev.3,v 1.21 2013/06/05 03:40:26 tedu Exp $ 2.\" 3.\" Copyright (c) 2000, Todd C. Miller. All rights reserved. 4.\" Copyright (c) 1996, Jason Downs. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS 16.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18.\" DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, 19.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25.\" SUCH DAMAGE. 26.\" 27.Dd $Mdocdate: June 5 2013 $ 28.Dt OPENDEV 3 29.Os 30.Sh NAME 31.Nm opendev 32.Nd short form device open routine 33.Sh SYNOPSIS 34.In util.h 35.Ft int 36.Fn opendev "const char *path" "int oflags" "int dflags" "char **realpath" 37.Sh DESCRIPTION 38The 39.Fn opendev 40function opens a device using a 41.Dq short form 42name or 43.Xr disklabel 8 44UID 45.Pq DUID . 46For instance 47.Dq sd0 48or 49.Dq sd0c 50will be expanded to 51.Pa /dev/rsd0c 52on most architectures. 53.Pp 54Device name lookup is done by first checking 55.Fa path 56for a 57.Sq / 58and if one is found attempting to open that file. 59If not, 60.Fa path 61is checked to see if it is a valid DUID. 62If it is, the corresponding device is obtained via 63.Xr diskmap 4 . 64If 65.Fa path 66has no 67.Sq / 68and is not a DUID, 69.Fa /dev 70is searched for a matching device. 71.Pp 72The 73.Fa oflags 74are the same as the 75.Fa flags 76passed to 77.Xr open 2 . 78.Pp 79The 80.Fa dflags 81are specified by 82.Tn OR Ns 'ing 83the following values: 84.Bd -literal -offset indent 85OPENDEV_PART attempt to open the raw partition during expansion 86OPENDEV_BLCK open the block device (default is character device) 87.Ed 88.Pp 89If 90.Fa realpath 91is not 92.Dv NULL , 93it is modified to point at the fully expanded device name. 94.Sh RETURN VALUES 95The 96.Fn opendev 97return value and errors are the same as the return value and errors of 98.Xr open 2 . 99.Sh SEE ALSO 100.Xr open 2 , 101.Xr getrawpartition 3 , 102.Xr diskmap 4 , 103.Xr disklabel 8 104.Sh HISTORY 105The 106.Fn opendev 107function first appeared in 108.Ox 1.2 . 109.Sh CAVEATS 110If 111.Fa realpath 112is not 113.Dv NULL , 114on return it will point to internal 115static storage space that will be overwritten by subsequent calls. 116