xref: /dragonfly/lib/libc/sys/link.2 (revision 2cd2d2b5)
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.\" $FreeBSD: src/lib/libc/sys/link.2,v 1.11.2.7 2001/12/14 18:34:01 ru Exp $
34.\" $DragonFly: src/lib/libc/sys/link.2,v 1.2 2003/06/17 04:26:47 dillon Exp $
35.\"
36.Dd March 5, 1999
37.Dt LINK 2
38.Os
39.Sh NAME
40.Nm link
41.Nd make a hard file link
42.Sh LIBRARY
43.Lb libc
44.Sh SYNOPSIS
45.In unistd.h
46.Ft int
47.Fn link "const char *name1" "const char *name2"
48.Sh DESCRIPTION
49The
50.Fn link
51function call
52atomically creates the specified directory entry (hard link)
53.Fa name2
54with the attributes of the underlying object pointed at by
55.Fa name1 .
56If the link is successful: the link count of the underlying object
57is incremented;
58.Fa name1
59and
60.Fa name2
61share equal access and rights
62to the
63underlying object.
64.Pp
65If
66.Fa name1
67is removed, the file
68.Fa name2
69is not deleted and the link count of the
70underlying object is
71decremented.
72.Pp
73.Fa Name1
74must exist for the hard link to
75succeed and
76both
77.Fa name1
78and
79.Fa name2
80must be in the same file system.
81.Fa name1
82may not be a directory.
83.Sh RETURN VALUES
84.Rv -std link
85.Sh ERRORS
86.Fn Link
87will fail and no link will be created if:
88.Bl -tag -width Er
89.It Bq Er ENOTDIR
90A component of either path prefix is not a directory.
91.It Bq Er ENAMETOOLONG
92A component of either pathname exceeded 255 characters,
93or entire length of either path name exceeded 1023 characters.
94.It Bq Er ENOENT
95A component of either path prefix does not exist.
96.It Bq Er EOPNOTSUPP
97The file system containing the file named by
98.Fa name1
99does not support links.
100.It Bq Er EMLINK
101The link count of the file named by
102.Fa name1
103would exceed 32767.
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.
123.It Bq Er EXDEV
124The link named by
125.Fa name2
126and the file named by
127.Fa name1
128are on different file systems.
129.It Bq Er ENOSPC
130The directory in which the entry for the new link is being placed
131cannot be extended because there is no space left on the file
132system containing the directory.
133.It Bq Er EDQUOT
134The directory in which the entry for the new link
135is being placed cannot be extended because the
136user's quota of disk blocks on the file system
137containing the directory has been exhausted.
138.It Bq Er EIO
139An I/O error occurred while reading from or writing to
140the file system to make the directory entry.
141.It Bq Er EROFS
142The requested link requires writing in a directory on a read-only file
143system.
144.It Bq Er EFAULT
145One of the pathnames specified
146is outside the process's allocated address space.
147.El
148.Sh SEE ALSO
149.Xr readlink 2 ,
150.Xr symlink 2 ,
151.Xr unlink 2
152.Sh STANDARDS
153The
154.Fn link
155function call is expected to conform to
156.St -p1003.1-90 .
157.Sh HISTORY
158A
159.Fn link
160function call appeared in
161.At v7 .
162.Pp
163The
164.Fn link
165system call traditionally allows the super-user to link directories which
166corrupts the filesystem coherency.  This implementation no longer permits
167it.
168