1*47208Scael.\" Copyright (c) 1980, 1991 Regents of the University of California. 2*47208Scael.\" All rights reserved. 320035Smckusick.\" 4*47208Scael.\" %sccs.include.redist.man% 520035Smckusick.\" 6*47208Scael.\" @(#)link.2 6.4 (Berkeley) 03/10/91 7*47208Scael.\" 8*47208Scael.Dd 9*47208Scael.Dt LINK 2 10*47208Scael.Os BSD 4 11*47208Scael.Sh NAME 12*47208Scael.Nm link 13*47208Scael.Nd make a hard file link 14*47208Scael.Sh SYNOPSIS 15*47208Scael.Fd #include <unistd.h> 16*47208Scael.Ft int 17*47208Scael.Fn link "const char *name1" "const char *name2" 18*47208Scael.Sh DESCRIPTION 19*47208ScaelThe 20*47208Scael.Fn link 21*47208Scaelfunction call 22*47208Scaelatomically creates the specified directory entry (hard link) 23*47208Scael.Fa name2 24*47208Scaelwith the attributes of the underlying object pointed at by 25*47208Scael.Fa name1 26*47208ScaelIf the link is successful: the link count of the underlying object 27*47208Scaelis incremented; 28*47208Scael.Fa name1 29*47208Scaeland 30*47208Scael.Fa name2 31*47208Scaelshare equal access and rights 32*47208Scaelto the 33*47208Scaelunderlying object. 34*47208Scael.Pp 35*47208ScaelIf 36*47208Scael.Fa name1 37*47208Scaelis removed, the file 38*47208Scael.Fa name2 39*47208Scaelis not deleted and the link count of the 40*47208Scaelunderlying object is 41*47208Scaeldecremented. 42*47208Scael.Pp 43*47208Scael.Fa Name1 44*47208Scaelmust exist for the hard link to 45*47208Scaelsucceed and 4620036Smckusickboth 47*47208Scael.Fa name1 4820036Smckusickand 49*47208Scael.Fa name2 5020036Smckusickmust be in the same file system. 5120036SmckusickUnless the caller is the super-user, 52*47208Scael.Fa name1 53*47208Scaelmay not be a directory. 54*47208Scael.Sh RETURN VALUES 5520036SmckusickUpon successful completion, a value of 0 is returned. Otherwise, 56*47208Scaela value of -1 is returned and 57*47208Scael.Va errno 5820036Smckusickis set to indicate the error. 59*47208Scael.Sh ERRORS 60*47208Scael.Fn Link 61*47208Scaelwill fail and no link will be created if: 6220036Smckusickare true: 63*47208Scael.Bl -tag -width Ar 64*47208Scael.It Bq Er ENOTDIR 6520036SmckusickA component of either path prefix is not a directory. 66*47208Scael.It Bq Er EINVAL 6721003SmckusickEither pathname contains a character with the high-order bit set. 68*47208Scael.It Bq Er ENAMETOOLONG 6921003SmckusickA component of either pathname exceeded 255 characters, 7021003Smckusickor entire length of either path name exceeded 1023 characters. 71*47208Scael.It Bq Er ENOENT 7220036SmckusickA component of either path prefix does not exist. 73*47208Scael.It Bq Er EACCES 7420036SmckusickA component of either path prefix denies search permission. 75*47208Scael.It Bq Er EACCES 7621003SmckusickThe requested link requires writing in a directory with a mode 7721003Smckusickthat denies write permission. 78*47208Scael.It Bq Er ELOOP 7921003SmckusickToo many symbolic links were encountered in translating one of the pathnames. 80*47208Scael.It Bq Er ENOENT 81*47208ScaelThe file named by 82*47208Scael.Fa name1 83*47208Scaeldoes not exist. 84*47208Scael.It Bq Er EEXIST 85*47208ScaelThe link named by 86*47208Scael.Fa name2 87*47208Scaeldoes exist. 88*47208Scael.It Bq Er EPERM 89*47208ScaelThe file named by 90*47208Scael.Fa name1 91*47208Scaelis a directory and the effective 9220036Smckusickuser ID is not super-user. 93*47208Scael.It Bq Er EXDEV 94*47208ScaelThe link named by 95*47208Scael.Fa name2 96*47208Scaeland the file named by 97*47208Scael.Fa name1 9820036Smckusickare on different file systems. 99*47208Scael.It Bq Er ENOSPC 10024439SmckusickThe directory in which the entry for the new link is being placed 10124439Smckusickcannot be extended because there is no space left on the file 10224439Smckusicksystem containing the directory. 103*47208Scael.It Bq Er EDQUOT 10424439SmckusickThe directory in which the entry for the new link 10524439Smckusickis being placed cannot be extended because the 10624439Smckusickuser's quota of disk blocks on the file system 10724439Smckusickcontaining the directory has been exhausted. 108*47208Scael.It Bq Er EIO 10924439SmckusickAn I/O error occurred while reading from or writing to 11024439Smckusickthe file system to make the directory entry. 111*47208Scael.It Bq Er EROFS 11220036SmckusickThe requested link requires writing in a directory on a read-only file 11320036Smckusicksystem. 114*47208Scael.It Bq Er EFAULT 11520036SmckusickOne of the pathnames specified 11620036Smckusickis outside the process's allocated address space. 117*47208Scael.El 118*47208Scael.Sh SEE ALSO 119*47208Scael.Xr symlink 2 , 120*47208Scael.Xr unlink 2 121*47208Scael.Sh STANDARDS 122*47208Scael.Fn Link 123*47208Scaelis expected to 124*47208Scaelconform to IEEE Std 1003.1-1988 125*47208Scael.Pq Dq Tn POSIX . 126