1*8269e767SBrooks Davis.\" SPDX-License-Identifier: BSD-2-Clause 2*8269e767SBrooks Davis.\" 3*8269e767SBrooks Davis.\" Copyright (c) 2018 Gandi 4*8269e767SBrooks Davis.\" 5*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without 6*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions 7*8269e767SBrooks Davis.\" are met: 8*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright 9*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer. 10*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright 11*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer in the 12*8269e767SBrooks Davis.\" documentation and/or other materials provided with the distribution. 13*8269e767SBrooks Davis.\" 14*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*8269e767SBrooks Davis.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*8269e767SBrooks Davis.\" SUCH DAMAGE. 25*8269e767SBrooks Davis.\" 26*8269e767SBrooks Davis.Dd November 30, 2022 27*8269e767SBrooks Davis.Dt FHLINK 2 28*8269e767SBrooks Davis.Os 29*8269e767SBrooks Davis.Sh NAME 30*8269e767SBrooks Davis.Nm fhlink , 31*8269e767SBrooks Davis.Nm fhlinkat 32*8269e767SBrooks Davis.Nd make a hard file link 33*8269e767SBrooks Davis.Sh LIBRARY 34*8269e767SBrooks Davis.Lb libc 35*8269e767SBrooks Davis.Sh SYNOPSIS 36*8269e767SBrooks Davis.In unistd.h 37*8269e767SBrooks Davis.Ft int 38*8269e767SBrooks Davis.Fn fhlink "fhandle_t *fhp" "const char *to" 39*8269e767SBrooks Davis.Ft int 40*8269e767SBrooks Davis.Fn fhlinkat "fhandle_t *fhp" "int tofd" "const char *to" 41*8269e767SBrooks Davis.Sh DESCRIPTION 42*8269e767SBrooks DavisThe 43*8269e767SBrooks Davis.Fn fhlink 44*8269e767SBrooks Davissystem call 45*8269e767SBrooks Davisatomically creates the specified directory entry (hard link) 46*8269e767SBrooks Davis.Fa to 47*8269e767SBrooks Daviswith the attributes of the underlying object pointed at by 48*8269e767SBrooks Davis.Fa fhp . 49*8269e767SBrooks DavisIf the link is successful: the link count of the underlying object 50*8269e767SBrooks Davisis incremented; 51*8269e767SBrooks Davis.Fa fhp 52*8269e767SBrooks Davisand 53*8269e767SBrooks Davis.Fa to 54*8269e767SBrooks Davisshare equal access and rights 55*8269e767SBrooks Davisto the 56*8269e767SBrooks Davisunderlying object. 57*8269e767SBrooks Davis.Pp 58*8269e767SBrooks DavisIf 59*8269e767SBrooks Davis.Fa fhp 60*8269e767SBrooks Davisis removed, the file 61*8269e767SBrooks Davis.Fa to 62*8269e767SBrooks Davisis not deleted and the link count of the 63*8269e767SBrooks Davisunderlying object is 64*8269e767SBrooks Davisdecremented. 65*8269e767SBrooks Davis.Pp 66*8269e767SBrooks DavisThe object pointed at by the 67*8269e767SBrooks Davis.Fa fhp 68*8269e767SBrooks Davisargument 69*8269e767SBrooks Davismust exist for the hard link to 70*8269e767SBrooks Davissucceed and 71*8269e767SBrooks Davisboth 72*8269e767SBrooks Davis.Fa fhp 73*8269e767SBrooks Davisand 74*8269e767SBrooks Davis.Fa to 75*8269e767SBrooks Davismust be in the same file system. 76*8269e767SBrooks DavisThe 77*8269e767SBrooks Davis.Fa fhp 78*8269e767SBrooks Davisargument 79*8269e767SBrooks Davismay not be a directory. 80*8269e767SBrooks Davis.Pp 81*8269e767SBrooks DavisThe 82*8269e767SBrooks Davis.Fn fhlinkat 83*8269e767SBrooks Davissystem call is equivalent to 84*8269e767SBrooks Davis.Fa fhlink 85*8269e767SBrooks Davisexcept in the case where 86*8269e767SBrooks Davis.Fa to 87*8269e767SBrooks Davisis a relative paths. 88*8269e767SBrooks DavisIn this case a relative path 89*8269e767SBrooks Davis.Fa to 90*8269e767SBrooks Davisis interpreted relative to 91*8269e767SBrooks Davisthe directory associated with the file descriptor 92*8269e767SBrooks Davis.Fa tofd 93*8269e767SBrooks Davisinstead of the current working directory. 94*8269e767SBrooks Davis.Pp 95*8269e767SBrooks DavisIf 96*8269e767SBrooks Davis.Fn fhlinkat 97*8269e767SBrooks Davisis passed the special value 98*8269e767SBrooks Davis.Dv AT_FDCWD 99*8269e767SBrooks Davisin the 100*8269e767SBrooks Davis.Fa tofd 101*8269e767SBrooks Davisparameter, the current working directory is used for the 102*8269e767SBrooks Davis.Fa to 103*8269e767SBrooks Davisargument. 104*8269e767SBrooks DavisIf 105*8269e767SBrooks Davis.Fa tofd 106*8269e767SBrooks Davishas value 107*8269e767SBrooks Davis.Dv AT_FDCWD , 108*8269e767SBrooks Davisthe behavior is identical to a call to 109*8269e767SBrooks Davis.Fn link . 110*8269e767SBrooks DavisUnless 111*8269e767SBrooks Davis.Fa flag 112*8269e767SBrooks Daviscontains the 113*8269e767SBrooks Davis.Dv AT_SYMLINK_FOLLOW 114*8269e767SBrooks Davisflag, if 115*8269e767SBrooks Davis.Fa fhp 116*8269e767SBrooks Davisnames a symbolic link, a new link is created for the symbolic link 117*8269e767SBrooks Davis.Fa fhp 118*8269e767SBrooks Davisand not its target. 119*8269e767SBrooks Davis.Sh RETURN VALUES 120*8269e767SBrooks Davis.Rv -std link 121*8269e767SBrooks Davis.Sh ERRORS 122*8269e767SBrooks DavisThe 123*8269e767SBrooks Davis.Fn fhlink 124*8269e767SBrooks Davissystem call 125*8269e767SBrooks Daviswill fail and no link will be created if: 126*8269e767SBrooks Davis.Bl -tag -width Er 127*8269e767SBrooks Davis.It Bq Er ENOTDIR 128*8269e767SBrooks DavisA component of 129*8269e767SBrooks Davis.Fa to 130*8269e767SBrooks Davisprefix is not a directory. 131*8269e767SBrooks Davis.It Bq Er ENAMETOOLONG 132*8269e767SBrooks DavisA component of 133*8269e767SBrooks Davis.Fa to 134*8269e767SBrooks Davisexceeded 255 characters, 135*8269e767SBrooks Davisor entire length of 136*8269e767SBrooks Davis.Fa to 137*8269e767SBrooks Davisname exceeded 1023 characters. 138*8269e767SBrooks Davis.It Bq Er ENOENT 139*8269e767SBrooks DavisA component of 140*8269e767SBrooks Davis.Fa to 141*8269e767SBrooks Davisprefix does not exist. 142*8269e767SBrooks Davis.It Bq Er EOPNOTSUPP 143*8269e767SBrooks DavisThe file system containing the file pointed at by 144*8269e767SBrooks Davis.Fa fhp 145*8269e767SBrooks Davisdoes not support links. 146*8269e767SBrooks Davis.It Bq Er EMLINK 147*8269e767SBrooks DavisThe link count of the file pointed at by 148*8269e767SBrooks Davis.Fa fhp 149*8269e767SBrooks Daviswould exceed 32767. 150*8269e767SBrooks Davis.It Bq Er EACCES 151*8269e767SBrooks DavisA component of 152*8269e767SBrooks Davis.Fa to 153*8269e767SBrooks Davisprefix denies search permission. 154*8269e767SBrooks Davis.It Bq Er EACCES 155*8269e767SBrooks DavisThe requested link requires writing in a directory with a mode 156*8269e767SBrooks Davisthat denies write permission. 157*8269e767SBrooks Davis.It Bq Er ELOOP 158*8269e767SBrooks DavisToo many symbolic links were encountered in translating one of the pathnames. 159*8269e767SBrooks Davis.It Bq Er ENOENT 160*8269e767SBrooks DavisThe file pointed at by 161*8269e767SBrooks Davis.Fa fhp 162*8269e767SBrooks Davisdoes not exist. 163*8269e767SBrooks Davis.It Bq Er EEXIST 164*8269e767SBrooks DavisThe link named by 165*8269e767SBrooks Davis.Fa to 166*8269e767SBrooks Davisdoes exist. 167*8269e767SBrooks Davis.It Bq Er EPERM 168*8269e767SBrooks DavisThe file pointed at by 169*8269e767SBrooks Davis.Fa fhp 170*8269e767SBrooks Davisis a directory. 171*8269e767SBrooks Davis.It Bq Er EPERM 172*8269e767SBrooks DavisThe file pointed at by 173*8269e767SBrooks Davis.Fa fhp 174*8269e767SBrooks Davishas its immutable or append-only flag set, see the 175*8269e767SBrooks Davis.Xr chflags 2 176*8269e767SBrooks Davismanual page for more information. 177*8269e767SBrooks Davis.It Bq Er EPERM 178*8269e767SBrooks DavisThe parent directory of the file named by 179*8269e767SBrooks Davis.Fa to 180*8269e767SBrooks Davishas its immutable flag set. 181*8269e767SBrooks Davis.It Bq Er EXDEV 182*8269e767SBrooks DavisThe link named by 183*8269e767SBrooks Davis.Fa to 184*8269e767SBrooks Davisand the file pointed at by 185*8269e767SBrooks Davis.Fa fhp 186*8269e767SBrooks Davisare on different file systems. 187*8269e767SBrooks Davis.It Bq Er ENOSPC 188*8269e767SBrooks DavisThe directory in which the entry for the new link is being placed 189*8269e767SBrooks Daviscannot be extended because there is no space left on the file 190*8269e767SBrooks Davissystem containing the directory. 191*8269e767SBrooks Davis.It Bq Er EDQUOT 192*8269e767SBrooks DavisThe directory in which the entry for the new link 193*8269e767SBrooks Davisis being placed cannot be extended because the 194*8269e767SBrooks Davisuser's quota of disk blocks on the file system 195*8269e767SBrooks Daviscontaining the directory has been exhausted. 196*8269e767SBrooks Davis.It Bq Er EIO 197*8269e767SBrooks DavisAn I/O error occurred while reading from or writing to 198*8269e767SBrooks Davisthe file system to make the directory entry. 199*8269e767SBrooks Davis.It Bq Er EINTEGRITY 200*8269e767SBrooks DavisCorrupted data was detected while reading from the file system. 201*8269e767SBrooks Davis.It Bq Er EROFS 202*8269e767SBrooks DavisThe requested link requires writing in a directory on a read-only file 203*8269e767SBrooks Davissystem. 204*8269e767SBrooks Davis.It Bq Er EFAULT 205*8269e767SBrooks DavisOne of the pathnames specified 206*8269e767SBrooks Davisis outside the process's allocated address space. 207*8269e767SBrooks Davis.It Bq Er ESTALE 208*8269e767SBrooks DavisThe file handle 209*8269e767SBrooks Davis.Fa fhp 210*8269e767SBrooks Davisis no longer valid 211*8269e767SBrooks Davis.El 212*8269e767SBrooks Davis.Pp 213*8269e767SBrooks DavisIn addition to the errors returned by the 214*8269e767SBrooks Davis.Fn fhlink , 215*8269e767SBrooks Davisthe 216*8269e767SBrooks Davis.Fn fhlinkat 217*8269e767SBrooks Davissystem call may fail if: 218*8269e767SBrooks Davis.Bl -tag -width Er 219*8269e767SBrooks Davis.It Bq Er EBADF 220*8269e767SBrooks DavisThe 221*8269e767SBrooks Davis.Fa fhp 222*8269e767SBrooks Davisor 223*8269e767SBrooks Davis.Fa to 224*8269e767SBrooks Davisargument does not specify an absolute path and the 225*8269e767SBrooks Davis.Fa tofd 226*8269e767SBrooks Davisargument, is not 227*8269e767SBrooks Davis.Dv AT_FDCWD 228*8269e767SBrooks Davisnor a valid file descriptor open for searching. 229*8269e767SBrooks Davis.It Bq Er EINVAL 230*8269e767SBrooks DavisThe value of the 231*8269e767SBrooks Davis.Fa flag 232*8269e767SBrooks Davisargument is not valid. 233*8269e767SBrooks Davis.It Bq Er ENOTDIR 234*8269e767SBrooks DavisThe 235*8269e767SBrooks Davis.Fa fhp 236*8269e767SBrooks Davisor 237*8269e767SBrooks Davis.Fa to 238*8269e767SBrooks Davisargument is not an absolute path and 239*8269e767SBrooks Davis.Fa tofd 240*8269e767SBrooks Davisis not 241*8269e767SBrooks Davis.Dv AT_FDCWD 242*8269e767SBrooks Davisnor a file descriptor associated with a directory. 243*8269e767SBrooks Davis.El 244*8269e767SBrooks Davis.Sh SEE ALSO 245*8269e767SBrooks Davis.Xr fhopen 2 , 246*8269e767SBrooks Davis.Xr fhreadlink 2 , 247*8269e767SBrooks Davis.Xr fhstat 2 248*8269e767SBrooks Davis.Sh HISTORY 249*8269e767SBrooks DavisThe 250*8269e767SBrooks Davis.Fn fhlink 251*8269e767SBrooks Davisand 252*8269e767SBrooks Davis.Fn fhlinkat 253*8269e767SBrooks Davissystem calls first appeared in 254*8269e767SBrooks Davis.Fx 12.1 . 255