FHLINK(2)
π FHLINK(2) π β make a hard file link
okay bestie, welcome to the system calls manual β¨ today we're learning about fhlink and fhlinkat, and honestly? it's giving "make a hard file link" energy and i am obsessed π
π«Ά LIBRARY
Standard C Library (libc, -lc) β she's iconic, she's everywhere, she's literally the standard π
πΈ SYNOPSIS
#include <unistd.h>
int
fhlink(fhandle_t *fhp, const char *to);
int
fhlinkat(fhandle_t *fhp, int tofd, const char *to);
look at her. two functions. same vibe. no cap π
β¨ DESCRIPTION β¨
The fhlink() system call atomically creates the specified directory entry (a hard link, periodt) named to, with the attributes of the underlying object pointed at by fhp. and if the link works out? bestie, it's a whole glow-up:
- the link count of the underlying object gets incremented π
fhpandtonow share equal access and rights to the underlying object π«Ά
If fhp gets removed, the file to is not deleted, and the link count of the underlying object gets decremented. she stays. she's resilient. π
The object pointed at by the fhp argument must exist for the hard link to succeed, and both fhp and to must be in the same file system. also, the fhp argument may not be a directory β nope, not happening, no exceptions, don't even try it π«
The fhlinkat() system call is equivalent to fhlink except in the case where to is a relative paths. in that case, a relative path to is interpreted relative to the directory associated with the file descriptor tofd instead of the current working directory. it's giving "context matters" β¨
π the flags π
Values for flag are constructed by a bitwise-inclusive OR of flags from the following list, defined in <fcntl.h>:
AT_SYMLINK_FOLLOWβ iffhpnames a symbolic link, a new link for the target of the symbolic link is created. (she follows the plot π¦)AT_BENEATHβ only allowtolink to a file which is beneath of the topping directory. See the description of theO_BENEATHflag in theopen(2)manual page. π
If fhlinkat() is passed the special value AT_FDCWD in the tofd parameter, the current working directory is used for the to argument. and if tofd has value AT_FDCWD, the behavior is identical to a call to link(). iconic crossover event π
Unless flag contains the AT_SYMLINK_FOLLOW flag, if fhp names a symbolic link, a new link is created for the symbolic link fhp itself and not its target. iykyk β no following, no chasing, she links what she sees π
π₯ RETURN VALUES π₯
The link() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. zero = slay. negative one = bestie something went wrong π
π ERRORS π
The fhlink() system call will fail and no link will be created if:
[ENOTDIR]β a component oftoprefix is not a directory.[ENAMETOOLONG]β a component oftoexceeded255characters, or entire length oftoname exceeded1023characters. (she's too long. she's doing too much. π₯²)[ENOENT]β a component oftoprefix does not exist.[EOPNOTSUPP]β the file system containing the file pointed at byfhpdoes not support links.[EMLINK]β the link count of the file pointed at byfhpwould exceed32767.[EACCES]β a component oftoprefix denies search permission.[EACCES]β the requested link requires writing in a directory with a mode that denies write permission.[ELOOP]β too many symbolic links were encountered in translating one of the pathnames. (she's in a loop, bestie, send help π)[ENOENT]β the file pointed at byfhpdoes not exist.[EEXIST]β the link named bytodoes exist.[EPERM]β the file pointed at byfhpis a directory.[EPERM]β the file pointed at byfhphas its immutable or append-only flag set, see thechflags(2)manual page for more information.[EPERM]β the parent directory of the file named bytohas its immutable flag set.[EXDEV]β the link named bytoand the file pointed at byfhpare on different file systems. π« cross-filesystem romance is not allowed[ENOSPC]β the directory in which the entry for the new link is being placed cannot be extended because there is no space left on the file system containing the directory.[EDQUOT]β the directory in which the entry for the new link is being placed cannot be extended because the user's quota of disk blocks on the file system containing the directory has been exhausted.[EIO]β an I/O error occurred while reading from or writing to the file system to make the directory entry.[EINTEGRITY]β corrupted data was detected while reading from the file system.[EROFS]β the requested link requires writing in a directory on a read-only file system.[EFAULT]β one of the pathnames specified is outside the process's allocated address space.[ESTALE]β the file handlefhpis no longer valid
π¦ and there's more π¦
In addition to the errors returned by the fhlink(), the fhlinkat() system call may fail if:
[EBADF]β thefhportoargument does not specify an absolute path and thetofdargument, is notAT_FDCWDnor a valid file descriptor open for searching.[EINVAL]β the value of theflagargument is not valid.[ENOTDIR]β thefhportoargument is not an absolute path andtofdis notAT_FDCWDnor a file descriptor associated with a directory.
π SEE ALSO π
fhstat(2), fhreadlink(2), fhopen(2),
go read those next, bestie, they're all part of the same friend group π«Άβ¨
and that's the whole page, fr fr π this one's from the Debian crew, dated March 30, 2020, and it's filed under FHLINK(2) β no cap, you're now officially a hard-link girly. go forth and link responsibly π πΈ
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- π the page's license: BSD-2-Clause
- Copyright (c) 2018 Gandi
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms