xref: /freebsd/lib/libsys/fhlink.2 (revision 96190b4fef3b4a0cc3ca0606b0c4e3e69a5e6717)
1.\" SPDX-License-Identifier: BSD-2-Clause
2.\"
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.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.Dd November 30, 2022
27.Dt FHLINK 2
28.Os
29.Sh NAME
30.Nm fhlink ,
31.Nm fhlinkat
32.Nd make a hard file link
33.Sh LIBRARY
34.Lb libc
35.Sh SYNOPSIS
36.In unistd.h
37.Ft int
38.Fn fhlink "fhandle_t *fhp" "const char *to"
39.Ft int
40.Fn fhlinkat "fhandle_t *fhp" "int tofd" "const char *to"
41.Sh DESCRIPTION
42The
43.Fn fhlink
44system call
45atomically creates the specified directory entry (hard link)
46.Fa to
47with the attributes of the underlying object pointed at by
48.Fa fhp .
49If the link is successful: the link count of the underlying object
50is incremented;
51.Fa fhp
52and
53.Fa to
54share equal access and rights
55to the
56underlying object.
57.Pp
58If
59.Fa fhp
60is removed, the file
61.Fa to
62is not deleted and the link count of the
63underlying object is
64decremented.
65.Pp
66The object pointed at by the
67.Fa fhp
68argument
69must exist for the hard link to
70succeed and
71both
72.Fa fhp
73and
74.Fa to
75must be in the same file system.
76The
77.Fa fhp
78argument
79may not be a directory.
80.Pp
81The
82.Fn fhlinkat
83system call is equivalent to
84.Fa fhlink
85except in the case where
86.Fa to
87is a relative paths.
88In this case a relative path
89.Fa to
90is interpreted relative to
91the directory associated with the file descriptor
92.Fa tofd
93instead of the current working directory.
94.Pp
95If
96.Fn fhlinkat
97is passed the special value
98.Dv AT_FDCWD
99in the
100.Fa tofd
101parameter, the current working directory is used for the
102.Fa to
103argument.
104If
105.Fa tofd
106has value
107.Dv AT_FDCWD ,
108the behavior is identical to a call to
109.Fn link .
110Unless
111.Fa flag
112contains the
113.Dv AT_SYMLINK_FOLLOW
114flag, if
115.Fa fhp
116names a symbolic link, a new link is created for the symbolic link
117.Fa fhp
118and not its target.
119.Sh RETURN VALUES
120.Rv -std link
121.Sh ERRORS
122The
123.Fn fhlink
124system call
125will fail and no link will be created if:
126.Bl -tag -width Er
127.It Bq Er ENOTDIR
128A component of
129.Fa to
130prefix is not a directory.
131.It Bq Er ENAMETOOLONG
132A component of
133.Fa to
134exceeded 255 characters,
135or entire length of
136.Fa to
137name exceeded 1023 characters.
138.It Bq Er ENOENT
139A component of
140.Fa to
141prefix does not exist.
142.It Bq Er EOPNOTSUPP
143The file system containing the file pointed at by
144.Fa fhp
145does not support links.
146.It Bq Er EMLINK
147The link count of the file pointed at by
148.Fa fhp
149would exceed 32767.
150.It Bq Er EACCES
151A component of
152.Fa to
153prefix denies search permission.
154.It Bq Er EACCES
155The requested link requires writing in a directory with a mode
156that denies write permission.
157.It Bq Er ELOOP
158Too many symbolic links were encountered in translating one of the pathnames.
159.It Bq Er ENOENT
160The file pointed at by
161.Fa fhp
162does not exist.
163.It Bq Er EEXIST
164The link named by
165.Fa to
166does exist.
167.It Bq Er EPERM
168The file pointed at by
169.Fa fhp
170is a directory.
171.It Bq Er EPERM
172The file pointed at by
173.Fa fhp
174has its immutable or append-only flag set, see the
175.Xr chflags 2
176manual page for more information.
177.It Bq Er EPERM
178The parent directory of the file named by
179.Fa to
180has its immutable flag set.
181.It Bq Er EXDEV
182The link named by
183.Fa to
184and the file pointed at by
185.Fa fhp
186are on different file systems.
187.It Bq Er ENOSPC
188The directory in which the entry for the new link is being placed
189cannot be extended because there is no space left on the file
190system containing the directory.
191.It Bq Er EDQUOT
192The directory in which the entry for the new link
193is being placed cannot be extended because the
194user's quota of disk blocks on the file system
195containing the directory has been exhausted.
196.It Bq Er EIO
197An I/O error occurred while reading from or writing to
198the file system to make the directory entry.
199.It Bq Er EINTEGRITY
200Corrupted data was detected while reading from the file system.
201.It Bq Er EROFS
202The requested link requires writing in a directory on a read-only file
203system.
204.It Bq Er EFAULT
205One of the pathnames specified
206is outside the process's allocated address space.
207.It Bq Er ESTALE
208The file handle
209.Fa fhp
210is no longer valid
211.El
212.Pp
213In addition to the errors returned by the
214.Fn fhlink ,
215the
216.Fn fhlinkat
217system call may fail if:
218.Bl -tag -width Er
219.It Bq Er EBADF
220The
221.Fa fhp
222or
223.Fa to
224argument does not specify an absolute path and the
225.Fa tofd
226argument, is not
227.Dv AT_FDCWD
228nor a valid file descriptor open for searching.
229.It Bq Er EINVAL
230The value of the
231.Fa flag
232argument is not valid.
233.It Bq Er ENOTDIR
234The
235.Fa fhp
236or
237.Fa to
238argument is not an absolute path and
239.Fa tofd
240is not
241.Dv AT_FDCWD
242nor a file descriptor associated with a directory.
243.El
244.Sh SEE ALSO
245.Xr fhopen 2 ,
246.Xr fhreadlink 2 ,
247.Xr fhstat 2
248.Sh HISTORY
249The
250.Fn fhlink
251and
252.Fn fhlinkat
253system calls first appeared in
254.Fx 12.1 .
255