]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/man/man2/link.2
xnu-2422.115.4.tar.gz
[apple/xnu.git] / bsd / man / man2 / link.2
... / ...
CommitLineData
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.\"
36.Dd October 29, 2008
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
45.Fo link
46.Fa "const char *path1"
47.Fa "const char *path2"
48.Fc
49.Sh DESCRIPTION
50The
51.Fn link
52function call
53atomically creates the specified directory entry (hard link)
54.Fa path2
55with the attributes of the underlying object pointed at by
56.Fa path1 .
57If the link is successful,
58the link count of the underlying object is incremented;
59.Fa path1
60and
61.Fa path2
62share equal access and rights
63to the
64underlying object.
65.Pp
66If
67.Fa path1
68is removed, the file
69.Fa path2
70is not deleted and the link count of the
71underlying object is
72decremented.
73.Pp
74In order for the system call to succeed,
75.Fa path1
76must exist and both
77.Fa path1
78and
79.Fa path2
80must be in the same file system.
81As mandated by POSIX.1,
82.Fa path1
83may not be a directory.
84.Pp
85.Fn link
86will resolve and follow symbolic links contained within both
87.Fa path1
88and
89.Fa path2 .
90If the last component of
91.Fa path1
92is a symbolic link,
93.Fn link
94will point the hard link,
95.Fa path2 ,
96to the underlying object pointed to by
97.Fa path1 ,
98not to the symbolic link itself.
99.Sh RETURN VALUES
100Upon successful completion, a value of 0 is returned. Otherwise,
101a value of -1 is returned and
102.Va errno
103is set to indicate the error.
104.Sh ERRORS
105.Fn Link
106will fail and no link will be created if:
107.Bl -tag -width Er
108.\" ==========
109.It Bq Er EACCES
110A component of either path prefix denies search permission.
111.\" ==========
112.It Bq Er EACCES
113The requested link requires writing in a directory with a mode
114that denies write permission.
115.\" ==========
116.It Bq Er EACCES
117The current process cannot access the existing file.
118.\" ==========
119.It Bq Er EDQUOT
120The directory in which the entry for the new link
121is being placed cannot be extended because the
122user's quota of disk blocks on the file system
123containing the directory has been exhausted.
124.\" ==========
125.It Bq Er EEXIST
126The link named by
127.Fa path2
128already exists.
129.\" ==========
130.It Bq Er EFAULT
131One of the pathnames specified
132is outside the process's allocated address space.
133.\" ==========
134.It Bq Er EIO
135An I/O error occurs while reading from or writing to
136the file system to make the directory entry.
137.\" ==========
138.It Bq Er ELOOP
139Too many symbolic links are encountered in translating one of the pathnames.
140This is taken to be indicative of a looping symbolic link.
141.\" ==========
142.It Bq Er EMLINK
143The file already has {LINK_MAX} links.
144.\" ==========
145.It Bq Er ENAMETOOLONG
146A component of a pathname exceeds
147.Dv {NAME_MAX}
148characters, or an entire path name exceeded
149.Dv {PATH_MAX}
150characters.
151.\" ==========
152.It Bq Er ENOENT
153A component of either path prefix does not exist, or is a dangling symbolic link.
154.\" ==========
155.It Bq Er ENOENT
156The file named by
157.Fa path1
158does not exist, or is a dangling symbolic link.
159.\" ==========
160.It Bq Er ENOSPC
161The directory in which the entry for the new link is being placed
162cannot be extended because there is no space left on the file
163system containing the directory.
164.\" ==========
165.It Bq Er ENOTDIR
166A component of either path prefix is not a directory.
167.\" ==========
168.It Bq Er EPERM
169The file named by
170.Fa path1
171is a directory.
172.\" ==========
173.It Bq Er EROFS
174The requested link requires writing in a directory
175on a read-only file system.
176.\" ==========
177.It Bq Er EXDEV
178The link named by
179.Fa path2
180and the file named by
181.Fa path1
182are on different file systems.
183.El
184.Sh SEE ALSO
185.Xr symlink 2 ,
186.Xr unlink 2
187.Sh STANDARDS
188The
189.Fn link
190function is expected to conform to
191.St -p1003.1-88 .