1.\" $NetBSD: getfh.2,v 1.21 2006/10/30 18:53:42 mjf Exp $ 2.\" 3.\" Copyright (c) 1989, 1991, 1993 4.\" The Regents of the University of California. 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.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.\" @(#)getfh.2 8.1 (Berkeley) 6/9/93 31.\" 32.Dd October 30, 2006 33.Dt GETFH 2 34.Os 35.Sh NAME 36.Nm getfh 37.Nd get file handle 38.Sh LIBRARY 39.Lb libc 40.Sh SYNOPSIS 41.In sys/types.h 42.In sys/mount.h 43.Ft int 44.Fn getfh "const char *path" "void *fhp" "size_t *fh_size" 45.Sh DESCRIPTION 46.Fn getfh 47returns a file handle for the specified file or directory 48in the file handle pointed to by 49.Fa fhp . 50The variable pointed to by 51.Fa fh_size 52has to be initialized to the memory allocated for the variable sized file 53handle. 54On return the value will be replaced by the actual size 55needed (which will vary depending on the file system the path is on). 56This system call is restricted to the superuser. 57To query the necessary size for the filehandle, a 58.Dv NULL 59pointer may 60be passed as 61.Fa fhp , 62and the value pointed to by 63.Fa fh_size 64should be initialized to zero. 65.Sh RETURN VALUES 66Upon successful completion, a value of 0 is returned. 67Otherwise, \-1 is returned and the global variable 68.Va errno 69is set to indicate the error. 70.Sh ERRORS 71.Fn getfh 72fails if one or more of the following are true: 73.Bl -tag -width Er 74.It Bq Er ENOTDIR 75A component of the path prefix of 76.Fa path 77is not a directory. 78.It Bq Er ENAMETOOLONG 79The length of a component of 80.Fa path 81exceeds 82.Brq Dv NAME_MAX 83characters, or the length of 84.Fa path 85exceeds 86.Brq Dv PATH_MAX 87characters. 88.It Bq Er ENOENT 89The file referred to by 90.Fa path 91does not exist. 92.It Bq Er EACCES 93Search permission is denied for a component of the path prefix of 94.Fa path . 95.It Bq Er ELOOP 96Too many symbolic links were encountered in translating 97.Fa path . 98.It Bq Er EFAULT 99.Fa fhp 100points to an invalid address. 101.It Bq Er EIO 102An 103.Tn I/O 104error occurred while reading from or writing to the file system. 105.It Bq Er E2BIG 106The memory allocated for the file handle is too small. 107The size needed has been written to the variable pointed to by 108.Fa fh_size . 109.It Bq Er ENOMEM 110The kernel failed to allocate temporary memory to create a filehandle of the 111requested size. 112.El 113.Sh SEE ALSO 114.Xr fhstat 2 , 115.Xr fhstatvfs 2 , 116.Xr fhstatvfs1 2 117.Sh HISTORY 118The 119.Fn getfh 120function 121first appeared in 122.Bx 4.4 . 123