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.4 1993/11/29 21:25:17 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 EINVAL 94Either pathname contains a character with the high-order bit set. 95.It Bq Er ENAMETOOLONG 96A component of either pathname exceeded 255 characters, 97or entire length of either path name exceeded 1023 characters. 98.It Bq Er ENOENT 99A component of either path prefix does not exist. 100.It Bq Er EACCES 101A component of either path prefix denies search permission. 102.It Bq Er EACCES 103The requested link requires writing in a directory with a mode 104that denies write permission. 105.It Bq Er ELOOP 106Too many symbolic links were encountered in translating one of the pathnames. 107.It Bq Er ENOENT 108The file named by 109.Fa name1 110does not exist. 111.It Bq Er EEXIST 112The link named by 113.Fa name2 114does exist. 115.It Bq Er EPERM 116The file named by 117.Fa name1 118is a directory and the effective 119user ID is not super-user. 120.It Bq Er EXDEV 121The link named by 122.Fa name2 123and the file named by 124.Fa name1 125are on different file systems. 126.It Bq Er ENOSPC 127The directory in which the entry for the new link is being placed 128cannot be extended because there is no space left on the file 129system containing the directory. 130.It Bq Er EDQUOT 131The directory in which the entry for the new link 132is being placed cannot be extended because the 133user's quota of disk blocks on the file system 134containing the directory has been exhausted. 135.It Bq Er EIO 136An I/O error occurred while reading from or writing to 137the file system to make the directory entry. 138.It Bq Er EROFS 139The requested link requires writing in a directory on a read-only file 140system. 141.It Bq Er EFAULT 142One of the pathnames specified 143is outside the process's allocated address space. 144.El 145.Sh SEE ALSO 146.Xr symlink 2 , 147.Xr unlink 2 148.Sh STANDARDS 149The 150.Fn link 151function is expected to conform to 152.St -p1003.1-88 . 153