]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/link.2
Wrapped long lines, wrapped at sentence boundaries; stripped trailing
[thirdparty/man-pages.git] / man2 / link.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\" 1993 Michael Haardt, Ian Jackson.
5 .\"
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"
26 .\" Modified 1993-07-23 by Rik Faith <faith@cs.unc.edu>
27 .\" Modified 1994-08-21 by Michael Haardt
28 .\" Modified 2004-06-23 by Michael Kerrisk <mtk-manpages@gmx.net>
29 .\" Modified 2005-04-04, as per suggestion by Michael Hardt for rename.2
30 .\"
31 .TH LINK 2 2004-06-23 "Linux 2.6.7" "Linux Programmer's Manual"
32 .SH NAME
33 link \- make a new name for a file
34 .SH SYNOPSIS
35 .B #include <unistd.h>
36 .sp
37 .BI "int link(const char *" oldpath ", const char *" newpath );
38 .SH DESCRIPTION
39 .BR link ()
40 creates a new link (also known as a hard link) to an existing file.
41
42 If
43 .I newpath
44 exists it will
45 .I not
46 be overwritten.
47
48 This new name may be used exactly as the old one for any operation;
49 both names refer to the same file (and so have the same permissions
50 and ownership) and it is impossible to tell which name was the
51 \`original'.
52 .SH "RETURN VALUE"
53 On success, zero is returned.
54 On error, \-1 is returned, and
55 .I errno
56 is set appropriately.
57 .SH ERRORS
58 .TP
59 .B EACCES
60 Write access to the directory containing
61 .I newpath
62 is denied, or search permission is denied for one of the directories
63 in the path prefix of
64 .I oldpath
65 or
66 .IR newpath .
67 (See also
68 .BR path_resolution (2).)
69 .TP
70 .B EEXIST
71 .I newpath
72 already exists.
73 .TP
74 .B EFAULT
75 .IR oldpath " or " newpath " points outside your accessible address space."
76 .TP
77 .B EIO
78 An I/O error occurred.
79 .TP
80 .B ELOOP
81 Too many symbolic links were encountered in resolving
82 .IR oldpath " or " newpath .
83 .TP
84 .B EMLINK
85 The file referred to by
86 .I oldpath
87 already has the maximum number of links to it.
88 .TP
89 .B ENAMETOOLONG
90 .IR oldpath " or " newpath " was too long."
91 .TP
92 .B ENOENT
93 A directory component in
94 .IR oldpath " or " newpath
95 does not exist or is a dangling symbolic link.
96 .TP
97 .B ENOMEM
98 Insufficient kernel memory was available.
99 .TP
100 .B ENOSPC
101 The device containing the file has no room for the new directory
102 entry.
103 .TP
104 .B ENOTDIR
105 A component used as a directory in
106 .IR oldpath " or " newpath
107 is not, in fact, a directory.
108 .TP
109 .B EPERM
110 .I oldpath
111 is a directory.
112 .TP
113 .B EPERM
114 The filesystem containing
115 .IR oldpath " and " newpath
116 does not support the creation of hard links.
117 .TP
118 .B EROFS
119 The file is on a read-only filesystem.
120 .TP
121 .B EXDEV
122 .IR oldpath " and " newpath
123 are not on the same mounted filesystem.
124 (Linux permits a filesystem to be mounted at multiple points, but
125 .BR link (2)
126 does not work across different mount points,
127 even if the same filesystem is mounted on both.)
128 .SH NOTES
129 Hard links, as created by
130 .BR link (),
131 cannot span filesystems.
132 Use
133 .BR symlink ()
134 if this is required.
135
136 POSIX.1-2001 says that
137 .BR link ()
138 should dereference
139 .I oldpath
140 if it is a symbolic link.
141 However, Linux does not do so: if
142 .I oldpath
143 is a symbolic link, then
144 .I newpath
145 is created as a (hard) link to the same symbolic link file
146 (i.e.,
147 .I newpath
148 becomes a symbolic link to the same file that
149 .I oldpath
150 refers to).
151 Some other implementations behave in the same manner as Linux.
152 .\" For example, the default Solaris compilation environment
153 .\" behaves like Linux, and contributors to a March 2005
154 .\" thread in the Austin mailing list reported that some
155 .\" other (System V) implementations did/do the same -- MTK, Apr 05
156 .SH "CONFORMING TO"
157 SVr4, 4.3BSD, POSIX.1-2001 (except as noted above).
158 .\" SVr4 documents additional ENOLINK and
159 .\" EMULTIHOP error conditions; POSIX.1 does not document ELOOP.
160 .\" X/OPEN does not document EFAULT, ENOMEM or EIO.
161 .SH BUGS
162 On NFS file systems, the return code may be wrong in case the NFS server
163 performs the link creation and dies before it can say so.
164 Use
165 .BR stat (2)
166 to find out if the link got created.
167 .SH "SEE ALSO"
168 .BR ln (1),
169 .BR linkat (2),
170 .BR open (2),
171 .BR path_resolution (2),
172 .BR rename (2),
173 .BR stat (2),
174 .BR symlink (2),
175 .BR unlink (2)