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