]>
Commit | Line | Data |
---|---|---|
9bccf70c A |
1 | .\" $NetBSD: link.2,v 1.7 1995/02/27 12:34:01 cgd Exp $ |
2 | .\" | |
3 | .\" Copyright (c) 1980, 1991, 1993 | |
4 | .\" The Regents of the University of California. All rights reserved. | |
5 | .\" | |
6 | .\" Redistribution and use in source and binary forms, with or without | |
7 | .\" modification, are permitted provided that the following conditions | |
8 | .\" are met: | |
9 | .\" 1. Redistributions of source code must retain the above copyright | |
10 | .\" notice, this list of conditions and the following disclaimer. | |
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
12 | .\" notice, this list of conditions and the following disclaimer in the | |
13 | .\" documentation and/or other materials provided with the distribution. | |
14 | .\" 3. All advertising materials mentioning features or use of this software | |
15 | .\" must display the following acknowledgement: | |
16 | .\" This product includes software developed by the University of | |
17 | .\" California, Berkeley and its contributors. | |
18 | .\" 4. Neither the name of the University nor the names of its contributors | |
19 | .\" may be used to endorse or promote products derived from this software | |
20 | .\" without specific prior written permission. | |
21 | .\" | |
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | .\" SUCH DAMAGE. | |
33 | .\" | |
34 | .\" @(#)link.2 8.3 (Berkeley) 1/12/94 | |
35 | .\" | |
b0d623f7 | 36 | .Dd October 29, 2008 |
9bccf70c A |
37 | .Dt LINK 2 |
38 | .Os BSD 4 | |
39 | .Sh NAME | |
40 | .Nm link | |
41 | .Nd make a hard file link | |
42 | .Sh SYNOPSIS | |
43 | .Fd #include <unistd.h> | |
44 | .Ft int | |
2d21ac55 A |
45 | .Fo link |
46 | .Fa "const char *path1" | |
47 | .Fa "const char *path2" | |
48 | .Fc | |
9bccf70c A |
49 | .Sh DESCRIPTION |
50 | The | |
51 | .Fn link | |
52 | function call | |
53 | atomically creates the specified directory entry (hard link) | |
2d21ac55 | 54 | .Fa path2 |
9bccf70c | 55 | with the attributes of the underlying object pointed at by |
2d21ac55 A |
56 | .Fa path1 . |
57 | If the link is successful, | |
58 | the link count of the underlying object is incremented; | |
59 | .Fa path1 | |
9bccf70c | 60 | and |
2d21ac55 | 61 | .Fa path2 |
9bccf70c A |
62 | share equal access and rights |
63 | to the | |
64 | underlying object. | |
65 | .Pp | |
66 | If | |
2d21ac55 | 67 | .Fa path1 |
9bccf70c | 68 | is removed, the file |
2d21ac55 | 69 | .Fa path2 |
9bccf70c A |
70 | is not deleted and the link count of the |
71 | underlying object is | |
72 | decremented. | |
73 | .Pp | |
2d21ac55 A |
74 | In order for the system call to succeed, |
75 | .Fa path1 | |
76 | must exist and both | |
77 | .Fa path1 | |
9bccf70c | 78 | and |
2d21ac55 | 79 | .Fa path2 |
9bccf70c | 80 | must be in the same file system. |
2d21ac55 A |
81 | As mandated by POSIX.1, |
82 | .Fa path1 | |
9bccf70c | 83 | may not be a directory. |
b0d623f7 A |
84 | .Pp |
85 | .Fn link | |
86 | will resolve and follow symbolic links contained within both | |
87 | .Fa path1 | |
88 | and | |
89 | .Fa path2 . | |
90 | If the last component of | |
91 | .Fa path1 | |
92 | is a symbolic link, | |
93 | .Fn link | |
94 | will point the hard link, | |
95 | .Fa path2 , | |
96 | to the underlying object pointed to by | |
97 | .Fa path1 , | |
98 | not to the symbolic link itself. | |
9bccf70c A |
99 | .Sh RETURN VALUES |
100 | Upon successful completion, a value of 0 is returned. Otherwise, | |
101 | a value of -1 is returned and | |
102 | .Va errno | |
103 | is set to indicate the error. | |
104 | .Sh ERRORS | |
105 | .Fn Link | |
106 | will fail and no link will be created if: | |
107 | .Bl -tag -width Er | |
2d21ac55 A |
108 | .\" ========== |
109 | .It Bq Er EACCES | |
110 | A component of either path prefix denies search permission. | |
111 | .\" ========== | |
112 | .It Bq Er EACCES | |
113 | The requested link requires writing in a directory with a mode | |
114 | that denies write permission. | |
115 | .\" ========== | |
116 | .It Bq Er EACCES | |
117 | The current process cannot access the existing file. | |
118 | .\" ========== | |
119 | .It Bq Er EDQUOT | |
120 | The directory in which the entry for the new link | |
121 | is being placed cannot be extended because the | |
122 | user's quota of disk blocks on the file system | |
123 | containing the directory has been exhausted. | |
124 | .\" ========== | |
125 | .It Bq Er EEXIST | |
126 | The link named by | |
127 | .Fa path2 | |
128 | already exists. | |
129 | .\" ========== | |
130 | .It Bq Er EFAULT | |
131 | One of the pathnames specified | |
132 | is outside the process's allocated address space. | |
133 | .\" ========== | |
134 | .It Bq Er EIO | |
135 | An I/O error occurs while reading from or writing to | |
136 | the file system to make the directory entry. | |
137 | .\" ========== | |
138 | .It Bq Er ELOOP | |
139 | Too many symbolic links are encountered in translating one of the pathnames. | |
140 | This is taken to be indicative of a looping symbolic link. | |
141 | .\" ========== | |
142 | .It Bq Er EMLINK | |
143 | The file already has {LINK_MAX} links. | |
144 | .\" ========== | |
9bccf70c | 145 | .It Bq Er ENAMETOOLONG |
2d21ac55 | 146 | A component of a pathname exceeds |
9bccf70c A |
147 | .Dv {NAME_MAX} |
148 | characters, or an entire path name exceeded | |
149 | .Dv {PATH_MAX} | |
150 | characters. | |
2d21ac55 | 151 | .\" ========== |
9bccf70c | 152 | .It Bq Er ENOENT |
b0d623f7 | 153 | A component of either path prefix does not exist, or is a dangling symbolic link. |
2d21ac55 | 154 | .\" ========== |
9bccf70c A |
155 | .It Bq Er ENOENT |
156 | The file named by | |
2d21ac55 | 157 | .Fa path1 |
b0d623f7 | 158 | does not exist, or is a dangling symbolic link. |
2d21ac55 A |
159 | .\" ========== |
160 | .It Bq Er ENOSPC | |
161 | The directory in which the entry for the new link is being placed | |
162 | cannot be extended because there is no space left on the file | |
163 | system containing the directory. | |
164 | .\" ========== | |
165 | .It Bq Er ENOTDIR | |
166 | A component of either path prefix is not a directory. | |
167 | .\" ========== | |
9bccf70c A |
168 | .It Bq Er EPERM |
169 | The file named by | |
2d21ac55 | 170 | .Fa path1 |
9bccf70c | 171 | is a directory. |
2d21ac55 A |
172 | .\" ========== |
173 | .It Bq Er EROFS | |
174 | The requested link requires writing in a directory | |
175 | on a read-only file system. | |
176 | .\" ========== | |
9bccf70c A |
177 | .It Bq Er EXDEV |
178 | The link named by | |
2d21ac55 | 179 | .Fa path2 |
9bccf70c | 180 | and the file named by |
2d21ac55 | 181 | .Fa path1 |
9bccf70c | 182 | are on different file systems. |
9bccf70c A |
183 | .El |
184 | .Sh SEE ALSO | |
185 | .Xr symlink 2 , | |
186 | .Xr unlink 2 | |
187 | .Sh STANDARDS | |
188 | The | |
189 | .Fn link | |
190 | function is expected to conform to | |
191 | .St -p1003.1-88 . |