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