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