1.\" Copyright (c) 1980, 1991 Regents of the University of California. 2.\" 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.\" from: @(#)link.2 6.4 (Berkeley) 3/10/91 33.\" $Id: link.2,v 1.6 1994/04/22 00:13:36 jtc Exp $ 34.\" 35.Dd March 10, 1991 36.Dt LINK 2 37.Os BSD 4 38.Sh NAME 39.Nm link 40.Nd make a hard file link 41.Sh SYNOPSIS 42.Fd #include <unistd.h> 43.Ft int 44.Fn link "const char *name1" "const char *name2" 45.Sh DESCRIPTION 46The 47.Fn link 48function call 49atomically creates the specified directory entry (hard link) 50.Fa name2 51with the attributes of the underlying object pointed at by 52.Fa name1 53If the link is successful: the link count of the underlying object 54is incremented; 55.Fa name1 56and 57.Fa name2 58share equal access and rights 59to the 60underlying object. 61.Pp 62If 63.Fa name1 64is removed, the file 65.Fa name2 66is not deleted and the link count of the 67underlying object is 68decremented. 69.Pp 70.Fa Name1 71must exist for the hard link to 72succeed and 73both 74.Fa name1 75and 76.Fa name2 77must be in the same file system. 78Unless the caller is the super-user, 79.Fa name1 80may not be a directory. 81.Sh RETURN VALUES 82Upon successful completion, a value of 0 is returned. Otherwise, 83a value of -1 is returned and 84.Va errno 85is set to indicate the error. 86.Sh ERRORS 87.Fn Link 88will fail and no link will be created if: 89are true: 90.Bl -tag -width Er 91.It Bq Er ENOTDIR 92A component of either path prefix is not a directory. 93.It Bq Er ENAMETOOLONG 94A component of a pathname exceeded 95.Dv {NAME_MAX} 96characters, or an entire path name exceeded 97.Dv {PATH_MAX} 98characters. 99.It Bq Er ENOENT 100A component of either path prefix does not exist. 101.It Bq Er EACCES 102A component of either path prefix denies search permission. 103.It Bq Er EACCES 104The requested link requires writing in a directory with a mode 105that denies write permission. 106.It Bq Er ELOOP 107Too many symbolic links were encountered in translating one of the pathnames. 108.It Bq Er ENOENT 109The file named by 110.Fa name1 111does not exist. 112.It Bq Er EEXIST 113The link named by 114.Fa name2 115does exist. 116.It Bq Er EPERM 117The file named by 118.Fa name1 119is a directory and the effective 120user ID is not super-user. 121.It Bq Er EXDEV 122The link named by 123.Fa name2 124and the file named by 125.Fa name1 126are on different file systems. 127.It Bq Er ENOSPC 128The directory in which the entry for the new link is being placed 129cannot be extended because there is no space left on the file 130system containing the directory. 131.It Bq Er EDQUOT 132The directory in which the entry for the new link 133is being placed cannot be extended because the 134user's quota of disk blocks on the file system 135containing the directory has been exhausted. 136.It Bq Er EIO 137An I/O error occurred while reading from or writing to 138the file system to make the directory entry. 139.It Bq Er EROFS 140The requested link requires writing in a directory on a read-only file 141system. 142.It Bq Er EFAULT 143One of the pathnames specified 144is outside the process's allocated address space. 145.El 146.Sh SEE ALSO 147.Xr symlink 2 , 148.Xr unlink 2 149.Sh STANDARDS 150The 151.Fn link 152function is expected to conform to 153.St -p1003.1-88 . 154