xref: /dragonfly/lib/libc/sys/link.2 (revision b7367ef6)
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.4 2007/04/26 17:35:03 swildner 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 named file has its immutable or append-only flag set (see
121.Xr chflags 2 ) .
122.It Bq Er EPERM
123The file named by
124.Fa name1
125is a directory.
126.It Bq Er EXDEV
127The link named by
128.Fa name2
129and the file named by
130.Fa name1
131are on different file systems.
132.It Bq Er ENOSPC
133The directory in which the entry for the new link is being placed
134cannot be extended because there is no space left on the file
135system containing the directory.
136.It Bq Er EDQUOT
137The directory in which the entry for the new link
138is being placed cannot be extended because the
139user's quota of disk blocks on the file system
140containing the directory has been exhausted.
141.It Bq Er EIO
142An I/O error occurred while reading from or writing to
143the file system to make the directory entry.
144.It Bq Er EROFS
145The requested link requires writing in a directory on a read-only file
146system.
147.It Bq Er EFAULT
148One of the pathnames specified
149is outside the process's allocated address space.
150.El
151.Sh SEE ALSO
152.Xr readlink 2 ,
153.Xr symlink 2 ,
154.Xr unlink 2
155.Sh STANDARDS
156The
157.Fn link
158function call is expected to conform to
159.St -p1003.1-90 .
160.Sh HISTORY
161A
162.Fn link
163function call appeared in
164.At v7 .
165.Pp
166The
167.Fn link
168system call traditionally allows the super-user to link directories which
169corrupts the filesystem coherency.  This implementation no longer permits
170it.
171