1.\" Copyright (c) 1989, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" Copyright (c) 2018 Gandi 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice, this list of conditions and the following disclaimer. 10.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" notice, this list of conditions and the following disclaimer in the 12.\" documentation and/or other materials provided with the distribution. 13.\" 3. Neither the name of the University nor the names of its contributors 14.\" may be used to endorse or promote products derived from this software 15.\" without specific prior written permission. 16.\" 17.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27.\" SUCH DAMAGE. 28.\" 29.\" @(#)getfh.2 8.1 (Berkeley) 6/9/93 30.\" $FreeBSD$ 31.\" 32.Dd September 23, 2020 33.Dt GETFH 2 34.Os 35.Sh NAME 36.Nm getfh , 37.Nm lgetfh , 38.Nm getfhat 39.Nd get file handle 40.Sh LIBRARY 41.Lb libc 42.Sh SYNOPSIS 43.In sys/param.h 44.In sys/mount.h 45.Ft int 46.Fn getfh "const char *path" "fhandle_t *fhp" 47.Ft int 48.Fn lgetfh "const char *path" "fhandle_t *fhp" 49.Ft int 50.Fn getfhat "int fd" "const char *path" "fhandle_t *fhp" "int flag" 51.Sh DESCRIPTION 52The 53.Fn getfh 54system call 55returns a file handle for the specified file or directory 56in the file handle pointed to by 57.Fa fhp . 58.Pp 59The 60.Fn lgetfh 61system call is like 62.Fn getfh 63except in the case where the named file is a symbolic link, 64in which case 65.Fn lgetfh 66returns information about the link, 67while 68.Fn getfh 69returns information about the file the link references. 70.Pp 71The 72.Fn getfhat 73system call is equivalent to 74.Fn getfh 75and 76.Fn lgetfh 77except when the 78.Fa path 79specifies a relative path, or the 80.Dv AT_BENEATH 81flag is provided. 82For 83.Fn getfhat 84and relative 85.Fa path , 86the status is retrieved from a file relative to 87the directory associated with the file descriptor 88.Fa fd 89instead of the current working directory. 90For 91.Dv AT_BENEATH 92and absolute 93.Fa path , 94the status is retrieved from a file specified by the 95.Fa path , 96but additional permission checks are performed, see below. 97.Pp 98The values for the 99.Fa flag 100are constructed by a bitwise-inclusive OR of flags from this list, 101defined in 102.In fcntl.h : 103.Bl -tag -width indent 104.It Dv AT_SYMLINK_NOFOLLOW 105If 106.Fa path 107names a symbolic link, the status of the symbolic link is returned. 108.It Dv AT_BENEATH 109Only stat files and directories below the topping directory. 110See the description of the 111.Dv O_BENEATH 112flag in the 113.Xr open 2 114manual page. 115.It Dv AT_RESOLVE_BENEATH 116Only walks paths below the topping directory. 117See the description of the 118.Dv O_RESOLVE_BENEATH 119flag in the 120.Xr open 2 121manual page. 122.El 123.Pp 124If 125.Fn getfhat 126is passed the special value 127.Dv AT_FDCWD 128in the 129.Fa fd 130parameter, the current working directory is used and the behavior is 131identical to a call to 132.Fn getfth 133or 134.Fn lgetfh 135respectively, depending on whether or not the 136.Dv AT_SYMLINK_NOFOLLOW 137bit is set in 138.Fa flag . 139.Pp 140When 141.Fn getfhat 142is called with an absolute 143.Fa path 144without the 145.Dv AT_BENEATH 146flag, it ignores the 147.Fa fd 148argument. 149When 150.Dv AT_BENEATH 151is specified with an absolute 152.Fa path , 153a directory passed by the 154.Fa fd 155argument is used as the topping point for the resolution. 156These system calls are restricted to the superuser. 157.Sh RETURN VALUES 158.Rv -std 159.Sh ERRORS 160The 161.Fn getfh 162and 163.Fn lgetfh 164system calls 165fail if one or more of the following are true: 166.Bl -tag -width Er 167.It Bq Er ENOTDIR 168A component of the path prefix of 169.Fa path 170is not a directory. 171.It Bq Er ENAMETOOLONG 172The length of a component of 173.Fa path 174exceeds 255 characters, 175or the length of 176.Fa path 177exceeds 1023 characters. 178.It Bq Er ENOENT 179The file referred to by 180.Fa path 181does not exist. 182.It Bq Er EACCES 183Search permission is denied for a component of the path prefix of 184.Fa path . 185.It Bq Er ELOOP 186Too many symbolic links were encountered in translating 187.Fa path . 188.It Bq Er EFAULT 189The 190.Fa fhp 191argument 192points to an invalid address. 193.It Bq Er EFAULT 194The 195.Fa path 196argument 197points to an invalid address. 198.It Bq Er EIO 199An 200.Tn I/O 201error occurred while reading from or writing to the file system. 202.It Bq Er EINTEGRITY 203Corrupted data was detected while reading from the file system. 204.It Bq Er ESTALE 205The file handle 206.Fa fhp 207is no longer valid. 208.El 209.Pp 210In addition to the errors returned by 211.Fn getfh , 212and 213.Fn lgetfh , 214the 215.Fn getfhat 216system call may fail if: 217.Bl -tag -width Er 218.It Bq Er EBADF 219The 220.Fa path 221argument does not specify an absolute path and the 222.Fa fd 223argument, is neither 224.Dv AT_FDCWD 225nor a valid file descriptor open for searching. 226.It Bq Er EINVAL 227The value of the 228.Fa flag 229argument is not valid. 230.It Bq Er ENOTDIR 231The 232.Fa path 233argument is not an absolute path and 234.Fa fd 235is neither 236.Dv AT_FDCWD 237nor a file descriptor associated with a directory. 238.Sh SEE ALSO 239.Xr fhopen 2 , 240.Xr open 2 , 241.Xr stat 2 242.Sh HISTORY 243The 244.Fn getfh 245system call first appeared in 246.Bx 4.4 . 247