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