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