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