]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/link.2
procctl(2): Add PROC_WXMAP_CTL/STATUS
[FreeBSD/FreeBSD.git] / lib / libc / sys / link.2
1 .\" Copyright (c) 1980, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)link.2      8.3 (Berkeley) 1/12/94
29 .\" $FreeBSD$
30 .\"
31 .Dd March 30, 2021
32 .Dt LINK 2
33 .Os
34 .Sh NAME
35 .Nm link ,
36 .Nm linkat
37 .Nd make a hard file link
38 .Sh LIBRARY
39 .Lb libc
40 .Sh SYNOPSIS
41 .In unistd.h
42 .Ft int
43 .Fn link "const char *name1" "const char *name2"
44 .Ft int
45 .Fo linkat
46 .Fa "int fd1" "const char *name1" "int fd2" "const char *name2" "int flag"
47 .Fc
48 .Sh DESCRIPTION
49 The
50 .Fn link
51 system call
52 atomically creates the specified directory entry (hard link)
53 .Fa name2
54 with the attributes of the underlying object pointed at by
55 .Fa name1 .
56 If the link is successful: the link count of the underlying object
57 is incremented;
58 .Fa name1
59 and
60 .Fa name2
61 share equal access and rights
62 to the
63 underlying object.
64 .Pp
65 If
66 .Fa name1
67 is removed, the file
68 .Fa name2
69 is not deleted and the link count of the
70 underlying object is
71 decremented.
72 .Pp
73 The object pointed at by the
74 .Fa name1
75 argument
76 must exist for the hard link to
77 succeed and
78 both
79 .Fa name1
80 and
81 .Fa name2
82 must be in the same file system.
83 The
84 .Fa name1
85 argument
86 may not be a directory.
87 .Pp
88 The
89 .Fn linkat
90 system call is equivalent to
91 .Fa link
92 except in the case where either
93 .Fa name1
94 or
95 .Fa name2
96 or both are relative paths.
97 In this case a relative path
98 .Fa name1
99 is interpreted relative to
100 the directory associated with the file descriptor
101 .Fa fd1
102 instead of the current working directory and similarly for
103 .Fa name2
104 and the file descriptor
105 .Fa fd2 .
106 .Pp
107 Values for
108 .Fa flag
109 are constructed by a bitwise-inclusive OR of flags from the following
110 list, defined in
111 .In fcntl.h :
112 .Bl -tag -width indent
113 .It Dv AT_SYMLINK_FOLLOW
114 If
115 .Fa name1
116 names a symbolic link, a new link for the target of the symbolic link is
117 created.
118 .It Dv AT_RESOLVE_BENEATH
119 Only walk paths below the directory specified by the
120 .Ar fd1
121 descriptor.
122 See the description of the
123 .Dv O_RESOLVE_BENEATH
124 flag in the
125 .Xr open 2
126 manual page.
127 .It Dv AT_EMPTY_PATH
128 If the
129 .Fa path2
130 argument is an empty string, link the file referenced by the descriptor
131 .Fa fd2 .
132 The operation requires that the calling process has the
133 .Dv PRIV_VFS_FHOPEN
134 privilege, effectively being executed with effective user
135 .Dv root .
136 .El
137 .Pp
138 If
139 .Fn linkat
140 is passed the special value
141 .Dv AT_FDCWD
142 in the
143 .Fa fd1
144 or
145 .Fa fd2
146 parameter, the current working directory is used for the respective
147 .Fa name
148 argument.
149 If both
150 .Fa fd1
151 and
152 .Fa fd2
153 have value
154 .Dv AT_FDCWD ,
155 the behavior is identical to a call to
156 .Fn link .
157 Unless
158 .Fa flag
159 contains the
160 .Dv AT_SYMLINK_FOLLOW
161 flag, if
162 .Fa name1
163 names a symbolic link, a new link is created for the symbolic link
164 .Fa name1
165 and not its target.
166 .Sh RETURN VALUES
167 .Rv -std link
168 .Sh ERRORS
169 The
170 .Fn link
171 system call
172 will fail and no link will be created if:
173 .Bl -tag -width Er
174 .It Bq Er ENOTDIR
175 A component of either path prefix is not a directory.
176 .It Bq Er ENAMETOOLONG
177 A component of either pathname exceeded 255 characters,
178 or entire length of either path name exceeded 1023 characters.
179 .It Bq Er ENOENT
180 A component of either path prefix does not exist.
181 .It Bq Er EOPNOTSUPP
182 The file system containing the file named by
183 .Fa name1
184 does not support links.
185 .It Bq Er EMLINK
186 The link count of the file named by
187 .Fa name1
188 would exceed 32767.
189 .It Bq Er EACCES
190 A component of either path prefix denies search permission.
191 .It Bq Er EACCES
192 The requested link requires writing in a directory with a mode
193 that denies write permission.
194 .It Bq Er ELOOP
195 Too many symbolic links were encountered in translating one of the pathnames.
196 .It Bq Er ENOENT
197 The file named by
198 .Fa name1
199 does not exist.
200 .It Bq Er EEXIST
201 The link named by
202 .Fa name2
203 does exist.
204 .It Bq Er EPERM
205 The file named by
206 .Fa name1
207 is a directory.
208 .It Bq Er EPERM
209 The file named by
210 .Fa name1
211 has its immutable or append-only flag set, see the
212 .Xr chflags 2
213 manual page for more information.
214 .It Bq Er EPERM
215 The parent directory of the file named by
216 .Fa name2
217 has its immutable flag set.
218 .It Bq Er EXDEV
219 The link named by
220 .Fa name2
221 and the file named by
222 .Fa name1
223 are on different file systems.
224 .It Bq Er ENOSPC
225 The directory in which the entry for the new link is being placed
226 cannot be extended because there is no space left on the file
227 system containing the directory.
228 .It Bq Er EDQUOT
229 The directory in which the entry for the new link
230 is being placed cannot be extended because the
231 user's quota of disk blocks on the file system
232 containing the directory has been exhausted.
233 .It Bq Er EIO
234 An I/O error occurred while reading from or writing to
235 the file system to make the directory entry.
236 .It Bq Er EINTEGRITY
237 Corrupted data was detected while reading from the file system.
238 .It Bq Er EROFS
239 The requested link requires writing in a directory on a read-only file
240 system.
241 .It Bq Er EFAULT
242 One of the pathnames specified
243 is outside the process's allocated address space.
244 .El
245 .Pp
246 In addition to the errors returned by the
247 .Fn link ,
248 the
249 .Fn linkat
250 system call may fail if:
251 .Bl -tag -width Er
252 .It Bq Er EBADF
253 The
254 .Fa name1
255 or
256 .Fa name2
257 argument does not specify an absolute path and the
258 .Fa fd1
259 or
260 .Fa fd2
261 argument, respectively, is neither
262 .Dv AT_FDCWD
263 nor a valid file descriptor open for searching.
264 .It Bq Er EINVAL
265 The value of the
266 .Fa flag
267 argument is not valid.
268 .It Bq Er ENOTDIR
269 The
270 .Fa name1
271 or
272 .Fa name2
273 argument is not an absolute path and
274 .Fa fd1
275 or
276 .Fa fd2 ,
277 respectively, is neither
278 .Dv AT_FDCWD
279 nor a file descriptor associated with a directory.
280 .It Bq Er ENOTCAPABLE
281 .Fa name1
282 is not strictly relative to the starting directory.
283 For example,
284 .Fa name1
285 is absolute or includes a ".." component that escapes
286 the directory hierarchy specified by
287 .Fa fd ,
288 and the process is in capability mode or the
289 .Dv AT_RESOLVE_BENEATH
290 flag was specified.
291 .El
292 .Sh SEE ALSO
293 .Xr chflags 2 ,
294 .Xr readlink 2 ,
295 .Xr symlink 2 ,
296 .Xr unlink 2
297 .Sh STANDARDS
298 The
299 .Fn link
300 system call is expected to conform to
301 .St -p1003.1-90 .
302 The
303 .Fn linkat
304 system call follows The Open Group Extended API Set 2 specification.
305 .Sh HISTORY
306 The
307 .Fn link
308 function appeared in
309 .At v1 .
310 The
311 .Fn linkat
312 system call appeared in
313 .Fx 8.0 .
314 .Pp
315 The
316 .Fn link
317 system call traditionally allows the super-user to link directories which
318 corrupts the file system coherency.
319 This implementation no longer permits it.