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