xref: /freebsd/lib/libsys/getfh.2 (revision 650056363baddb83c61c85b0539ee536f3d4b56c)
18269e767SBrooks Davis.\" Copyright (c) 1989, 1991, 1993
28269e767SBrooks Davis.\"	The Regents of the University of California.  All rights reserved.
38269e767SBrooks Davis.\" Copyright (c) 2018 Gandi
48269e767SBrooks Davis.\"
58269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
68269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
78269e767SBrooks Davis.\" are met:
88269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
98269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
108269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
118269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
128269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
138269e767SBrooks Davis.\" 3. Neither the name of the University nor the names of its contributors
148269e767SBrooks Davis.\"    may be used to endorse or promote products derived from this software
158269e767SBrooks Davis.\"    without specific prior written permission.
168269e767SBrooks Davis.\"
178269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
188269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
198269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
208269e767SBrooks Davis.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
218269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
228269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
238269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
248269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
258269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
268269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
278269e767SBrooks Davis.\" SUCH DAMAGE.
288269e767SBrooks Davis.\"
298269e767SBrooks Davis.Dd November 30, 2022
308269e767SBrooks Davis.Dt GETFH 2
318269e767SBrooks Davis.Os
328269e767SBrooks Davis.Sh NAME
338269e767SBrooks Davis.Nm getfh ,
348269e767SBrooks Davis.Nm lgetfh ,
358269e767SBrooks Davis.Nm getfhat
368269e767SBrooks Davis.Nd get file handle
378269e767SBrooks Davis.Sh LIBRARY
388269e767SBrooks Davis.Lb libc
398269e767SBrooks Davis.Sh SYNOPSIS
408269e767SBrooks Davis.In sys/param.h
418269e767SBrooks Davis.In sys/mount.h
428269e767SBrooks Davis.Ft int
438269e767SBrooks Davis.Fn getfh "const char *path" "fhandle_t *fhp"
448269e767SBrooks Davis.Ft int
458269e767SBrooks Davis.Fn lgetfh "const char *path" "fhandle_t *fhp"
468269e767SBrooks Davis.Ft int
478269e767SBrooks Davis.Fn getfhat "int fd" "const char *path" "fhandle_t *fhp" "int flag"
488269e767SBrooks Davis.Sh DESCRIPTION
498269e767SBrooks DavisThe
508269e767SBrooks Davis.Fn getfh
518269e767SBrooks Davissystem call
528269e767SBrooks Davisreturns a file handle for the specified file or directory
538269e767SBrooks Davisin the file handle pointed to by
548269e767SBrooks Davis.Fa fhp .
558269e767SBrooks Davis.Pp
568269e767SBrooks DavisThe
578269e767SBrooks Davis.Fn lgetfh
588269e767SBrooks Davissystem call is like
598269e767SBrooks Davis.Fn getfh
608269e767SBrooks Davisexcept in the case where the named file is a symbolic link,
618269e767SBrooks Davisin which case
628269e767SBrooks Davis.Fn lgetfh
638269e767SBrooks Davisreturns information about the link,
648269e767SBrooks Daviswhile
658269e767SBrooks Davis.Fn getfh
668269e767SBrooks Davisreturns information about the file the link references.
678269e767SBrooks Davis.Pp
688269e767SBrooks DavisThe
698269e767SBrooks Davis.Fn getfhat
708269e767SBrooks Davissystem call is equivalent to
718269e767SBrooks Davis.Fn getfh
728269e767SBrooks Davisand
738269e767SBrooks Davis.Fn lgetfh
748269e767SBrooks Davisexcept when the
758269e767SBrooks Davis.Fa path
768269e767SBrooks Davisspecifies a relative path.
778269e767SBrooks DavisFor
788269e767SBrooks Davis.Fn getfhat
798269e767SBrooks Davisand relative
808269e767SBrooks Davis.Fa path ,
818269e767SBrooks Davisthe status is retrieved from a file relative to
828269e767SBrooks Davisthe directory associated with the file descriptor
838269e767SBrooks Davis.Fa fd
848269e767SBrooks Davisinstead of the current working directory.
858269e767SBrooks Davis.Pp
868269e767SBrooks DavisThe values for the
878269e767SBrooks Davis.Fa flag
888269e767SBrooks Davisare constructed by a bitwise-inclusive OR of flags from this list,
898269e767SBrooks Davisdefined in
908269e767SBrooks Davis.In fcntl.h :
918269e767SBrooks Davis.Bl -tag -width indent
928269e767SBrooks Davis.It Dv AT_SYMLINK_NOFOLLOW
938269e767SBrooks DavisIf
948269e767SBrooks Davis.Fa path
958269e767SBrooks Davisnames a symbolic link, the status of the symbolic link is returned.
968269e767SBrooks Davis.It Dv AT_RESOLVE_BENEATH
978269e767SBrooks DavisOnly walk paths below the directory specified by the
988269e767SBrooks Davis.Ar fd
998269e767SBrooks Davisdescriptor.
1008269e767SBrooks DavisSee the description of the
1018269e767SBrooks Davis.Dv O_RESOLVE_BENEATH
1028269e767SBrooks Davisflag in the
1038269e767SBrooks Davis.Xr open 2
1048269e767SBrooks Davismanual page.
1058269e767SBrooks Davis.El
1068269e767SBrooks Davis.Pp
1078269e767SBrooks DavisIf
1088269e767SBrooks Davis.Fn getfhat
1098269e767SBrooks Davisis passed the special value
1108269e767SBrooks Davis.Dv AT_FDCWD
1118269e767SBrooks Davisin the
1128269e767SBrooks Davis.Fa fd
1138269e767SBrooks Davisparameter, the current working directory is used and the behavior is
1148269e767SBrooks Davisidentical to a call to
1158269e767SBrooks Davis.Fn getfth
1168269e767SBrooks Davisor
1178269e767SBrooks Davis.Fn lgetfh
1188269e767SBrooks Davisrespectively, depending on whether or not the
1198269e767SBrooks Davis.Dv AT_SYMLINK_NOFOLLOW
1208269e767SBrooks Davisbit is set in
1218269e767SBrooks Davis.Fa flag .
1228269e767SBrooks Davis.Pp
1238269e767SBrooks DavisWhen
1248269e767SBrooks Davis.Fn getfhat
1258269e767SBrooks Davisis called with an absolute
1268269e767SBrooks Davis.Fa path ,
1278269e767SBrooks Davisit ignores the
1288269e767SBrooks Davis.Fa fd
1298269e767SBrooks Davisargument.
1308269e767SBrooks Davis.Pp
1318269e767SBrooks DavisThese system calls are restricted to the superuser.
1328269e767SBrooks Davis.Sh RETURN VALUES
1338269e767SBrooks Davis.Rv -std
1348269e767SBrooks Davis.Sh ERRORS
1358269e767SBrooks DavisThe
1368269e767SBrooks Davis.Fn getfh
1378269e767SBrooks Davisand
1388269e767SBrooks Davis.Fn lgetfh
1398269e767SBrooks Davissystem calls
1408269e767SBrooks Davisfail if one or more of the following are true:
1418269e767SBrooks Davis.Bl -tag -width Er
1428269e767SBrooks Davis.It Bq Er EPERM
1438269e767SBrooks DavisThe caller does not have appropriate privilege to perform the operation.
1448269e767SBrooks Davis.It Bq Er ENOTDIR
1458269e767SBrooks DavisA component of the path prefix of
1468269e767SBrooks Davis.Fa path
1478269e767SBrooks Davisis not a directory.
1488269e767SBrooks Davis.It Bq Er ENAMETOOLONG
1498269e767SBrooks DavisThe length of a component of
1508269e767SBrooks Davis.Fa path
1518269e767SBrooks Davisexceeds 255 characters,
1528269e767SBrooks Davisor the length of
1538269e767SBrooks Davis.Fa path
1548269e767SBrooks Davisexceeds 1023 characters.
1558269e767SBrooks Davis.It Bq Er ENOENT
1568269e767SBrooks DavisThe file referred to by
1578269e767SBrooks Davis.Fa path
1588269e767SBrooks Davisdoes not exist.
1598269e767SBrooks Davis.It Bq Er EACCES
1608269e767SBrooks DavisSearch permission is denied for a component of the path prefix of
1618269e767SBrooks Davis.Fa path .
1628269e767SBrooks Davis.It Bq Er ELOOP
1638269e767SBrooks DavisToo many symbolic links were encountered in translating
1648269e767SBrooks Davis.Fa path .
1658269e767SBrooks Davis.It Bq Er EFAULT
1668269e767SBrooks DavisThe
1678269e767SBrooks Davis.Fa fhp
1688269e767SBrooks Davisargument
1698269e767SBrooks Davispoints to an invalid address.
1708269e767SBrooks Davis.It Bq Er EFAULT
1718269e767SBrooks DavisThe
1728269e767SBrooks Davis.Fa path
1738269e767SBrooks Davisargument
1748269e767SBrooks Davispoints to an invalid address.
1758269e767SBrooks Davis.It Bq Er EIO
1768269e767SBrooks DavisAn
1778269e767SBrooks Davis.Tn I/O
1788269e767SBrooks Daviserror occurred while reading from or writing to the file system.
1798269e767SBrooks Davis.It Bq Er EINTEGRITY
1808269e767SBrooks DavisCorrupted data was detected while reading from the file system.
1818269e767SBrooks Davis.It Bq Er ESTALE
1828269e767SBrooks DavisThe file handle
1838269e767SBrooks Davis.Fa fhp
1848269e767SBrooks Davisis no longer valid.
1858269e767SBrooks Davis.El
1868269e767SBrooks Davis.Pp
1878269e767SBrooks DavisIn addition to the errors returned by
1888269e767SBrooks Davis.Fn getfh ,
1898269e767SBrooks Davisand
1908269e767SBrooks Davis.Fn lgetfh ,
1918269e767SBrooks Davisthe
1928269e767SBrooks Davis.Fn getfhat
1938269e767SBrooks Davissystem call may fail if:
1948269e767SBrooks Davis.Bl -tag -width Er
1958269e767SBrooks Davis.It Bq Er EBADF
1968269e767SBrooks DavisThe
1978269e767SBrooks Davis.Fa path
1988269e767SBrooks Davisargument does not specify an absolute path and the
1998269e767SBrooks Davis.Fa fd
2008269e767SBrooks Davisargument, is neither
2018269e767SBrooks Davis.Dv AT_FDCWD
2028269e767SBrooks Davisnor a valid file descriptor open for searching.
2038269e767SBrooks Davis.It Bq Er EINVAL
2048269e767SBrooks DavisThe value of the
2058269e767SBrooks Davis.Fa flag
2068269e767SBrooks Davisargument is not valid.
2078269e767SBrooks Davis.It Bq Er ENOTDIR
2088269e767SBrooks DavisThe
2098269e767SBrooks Davis.Fa path
2108269e767SBrooks Davisargument is not an absolute path and
2118269e767SBrooks Davis.Fa fd
2128269e767SBrooks Davisis neither
2138269e767SBrooks Davis.Dv AT_FDCWD
2148269e767SBrooks Davisnor a file descriptor associated with a directory.
215*65005636SGraham Percival.El
2168269e767SBrooks Davis.Sh SEE ALSO
2178269e767SBrooks Davis.Xr fhopen 2 ,
2188269e767SBrooks Davis.Xr open 2 ,
2198269e767SBrooks Davis.Xr stat 2
2208269e767SBrooks Davis.Sh HISTORY
2218269e767SBrooks DavisThe
2228269e767SBrooks Davis.Fn getfh
2238269e767SBrooks Davissystem call first appeared in
2248269e767SBrooks Davis.Bx 4.4 .
2258269e767SBrooks DavisThe
2268269e767SBrooks Davis.Fn lgetfh
2278269e767SBrooks Davissystem call first appeared in
2288269e767SBrooks Davis.Fx 5.3 .
2298269e767SBrooks DavisThe
2308269e767SBrooks Davis.Fn getfhat
2318269e767SBrooks Davissystem call first appeared in
2328269e767SBrooks Davis.Fx 12.1 .
233