RFS | XFS

link()

PROTOTYPE

#include <posix.h>

int link(const char *current, const char *new);

DESCRIPTION

link() creates a new directory entry, specified by the path new, that references the same data, timestamps, user/group IDs, and permissions as the regular file specified by the path current. The paths must refer to the same volume and neither can end with ‘/’. Paths starting with ‘/’ are absolute. Otherwise they are relative to the CWD.

The caller needs write-access to the new parent directory and execute-access to every directory in both paths. The file’s status change timestamp and the new parent directory’s status change and data modification timestamps are updated.

If successful, link() returns 0. Otherwise, it sets errno and returns -1.

ERROR CODES

EACCES No execute access to a directory in either path prefix or no write access to the new parent directory.
EEXIST new specifies an existing file.
EFAULT current or new equals NULL.
EINVAL current or new end with ‘/’.
EMLINK There are already LINK_MAX links to the existing file.
ENAMETOOLONG A path component exceeds the effective maximum file name length.
ENOENT current or new is the empty string, or a file in current or the new prefix was not found.
ENOSPC No space is left on volume to create link.
ENOTDIR One of the non-leaf path components is not a directory.
EPERM new specifies a directory, links to directories are prohibited.
EROFS The volume is read-only.
EXDEV new is on a different volume than current.

EXAMPLE

if (link(old, new))
  return -1;