]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/link.2
Document EINTEGRITY errors for many system calls.
[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, 2020
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_BENEATH
119 Only allow to link to a file which is beneath of the topping directory.
120 See the description of the
121 .Dv O_BENEATH
122 flag in the
123 .Xr open 2
124 manual page.
125 .El
126 .Pp
127 If
128 .Fn linkat
129 is passed the special value
130 .Dv AT_FDCWD
131 in the
132 .Fa fd1
133 or
134 .Fa fd2
135 parameter, the current working directory is used for the respective
136 .Fa name
137 argument.
138 If both
139 .Fa fd1
140 and
141 .Fa fd2
142 have value
143 .Dv AT_FDCWD ,
144 the behavior is identical to a call to
145 .Fn link .
146 Unless
147 .Fa flag
148 contains the
149 .Dv AT_SYMLINK_FOLLOW
150 flag, if
151 .Fa name1
152 names a symbolic link, a new link is created for the symbolic link
153 .Fa name1
154 and not its target.
155 .Sh RETURN VALUES
156 .Rv -std link
157 .Sh ERRORS
158 The
159 .Fn link
160 system call
161 will fail and no link will be created if:
162 .Bl -tag -width Er
163 .It Bq Er ENOTDIR
164 A component of either path prefix is not a directory.
165 .It Bq Er ENAMETOOLONG
166 A component of either pathname exceeded 255 characters,
167 or entire length of either path name exceeded 1023 characters.
168 .It Bq Er ENOENT
169 A component of either path prefix does not exist.
170 .It Bq Er EOPNOTSUPP
171 The file system containing the file named by
172 .Fa name1
173 does not support links.
174 .It Bq Er EMLINK
175 The link count of the file named by
176 .Fa name1
177 would exceed 32767.
178 .It Bq Er EACCES
179 A component of either path prefix denies search permission.
180 .It Bq Er EACCES
181 The requested link requires writing in a directory with a mode
182 that denies write permission.
183 .It Bq Er ELOOP
184 Too many symbolic links were encountered in translating one of the pathnames.
185 .It Bq Er ENOENT
186 The file named by
187 .Fa name1
188 does not exist.
189 .It Bq Er EEXIST
190 The link named by
191 .Fa name2
192 does exist.
193 .It Bq Er EPERM
194 The file named by
195 .Fa name1
196 is a directory.
197 .It Bq Er EPERM
198 The file named by
199 .Fa name1
200 has its immutable or append-only flag set, see the
201 .Xr chflags 2
202 manual page for more information.
203 .It Bq Er EPERM
204 The parent directory of the file named by
205 .Fa name2
206 has its immutable flag set.
207 .It Bq Er EXDEV
208 The link named by
209 .Fa name2
210 and the file named by
211 .Fa name1
212 are on different file systems.
213 .It Bq Er ENOSPC
214 The directory in which the entry for the new link is being placed
215 cannot be extended because there is no space left on the file
216 system containing the directory.
217 .It Bq Er EDQUOT
218 The directory in which the entry for the new link
219 is being placed cannot be extended because the
220 user's quota of disk blocks on the file system
221 containing the directory has been exhausted.
222 .It Bq Er EIO
223 An I/O error occurred while reading from or writing to
224 the file system to make the directory entry.
225 .It Bq Er EINTEGRITY
226 Corrupted data was detected while reading from the file system.
227 .It Bq Er EROFS
228 The requested link requires writing in a directory on a read-only file
229 system.
230 .It Bq Er EFAULT
231 One of the pathnames specified
232 is outside the process's allocated address space.
233 .El
234 .Pp
235 In addition to the errors returned by the
236 .Fn link ,
237 the
238 .Fn linkat
239 system call may fail if:
240 .Bl -tag -width Er
241 .It Bq Er EBADF
242 The
243 .Fa name1
244 or
245 .Fa name2
246 argument does not specify an absolute path and the
247 .Fa fd1
248 or
249 .Fa fd2
250 argument, respectively, is neither
251 .Dv AT_FDCWD
252 nor a valid file descriptor open for searching.
253 .It Bq Er EINVAL
254 The value of the
255 .Fa flag
256 argument is not valid.
257 .It Bq Er ENOTDIR
258 The
259 .Fa name1
260 or
261 .Fa name2
262 argument is not an absolute path and
263 .Fa fd1
264 or
265 .Fa fd2 ,
266 respectively, is neither
267 .Dv AT_FDCWD
268 nor a file descriptor associated with a directory.
269 .It Bq Er ENOTCAPABLE
270 .Fa name1
271 is not strictly relative to the starting directory.
272 For example,
273 .Fa name1
274 is absolute or includes a ".." component that escapes
275 the directory hierarchy specified by
276 .Fa fd ,
277 and the process is in capability mode.
278 .It Bq Er ENOTCAPABLE
279 The
280 .Dv AT_BENEATH
281 flag was provided to
282 .Fa linkat
283 and the absolute path
284 .Fa name1
285 does not have its tail fully contained under the topping directory,
286 or the relative path
287 .Fa name1
288 escapes it.
289 .El
290 .Sh SEE ALSO
291 .Xr chflags 2 ,
292 .Xr readlink 2 ,
293 .Xr symlink 2 ,
294 .Xr unlink 2
295 .Sh STANDARDS
296 The
297 .Fn link
298 system call is expected to conform to
299 .St -p1003.1-90 .
300 The
301 .Fn linkat
302 system call follows The Open Group Extended API Set 2 specification.
303 .Sh HISTORY
304 The
305 .Fn link
306 function appeared in
307 .At v1 .
308 The
309 .Fn linkat
310 system call appeared in
311 .Fx 8.0 .
312 .Pp
313 The
314 .Fn link
315 system call traditionally allows the super-user to link directories which
316 corrupts the file system coherency.
317 This implementation no longer permits it.