Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

link(2) [osx man page]

LINK(2) 						      BSD System Calls Manual							   LINK(2)

NAME
link -- make a hard file link SYNOPSIS
#include <unistd.h> int link(const char *path1, const char *path2); DESCRIPTION
The link() function call atomically creates the specified directory entry (hard link) path2 with the attributes of the underlying object pointed at by path1. If the link is successful, the link count of the underlying object is incremented; path1 and path2 share equal access and rights to the underlying object. If path1 is removed, the file path2 is not deleted and the link count of the underlying object is decremented. In order for the system call to succeed, path1 must exist and both path1 and path2 must be in the same file system. As mandated by POSIX.1, path1 may not be a directory. link() will resolve and follow symbolic links contained within both path1 and path2. If the last component of path1 is a symbolic link, link() will point the hard link, path2, to the underlying object pointed to by path1, not to the symbolic link itself. RETURN VALUES
Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error. ERRORS
Link() will fail and no link will be created if: [EACCES] A component of either path prefix denies search permission. [EACCES] The requested link requires writing in a directory with a mode that denies write permission. [EACCES] The current process cannot access the existing file. [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. [EEXIST] The link named by path2 already exists. [EFAULT] One of the pathnames specified is outside the process's allocated address space. [EIO] An I/O error occurs while reading from or writing to the file system to make the directory entry. [ELOOP] Too many symbolic links are encountered in translating one of the pathnames. This is taken to be indicative of a looping symbolic link. [EMLINK] The file already has {LINK_MAX} links. [ENAMETOOLONG] A component of a pathname exceeds {NAME_MAX} characters, or an entire path name exceeded {PATH_MAX} characters. [ENOENT] A component of either path prefix does not exist, or is a dangling symbolic link. [ENOENT] The file named by path1 does not exist, or is a dangling symbolic link. [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. [ENOTDIR] A component of either path prefix is not a directory. [EPERM] The file named by path1 is a directory. [EROFS] The requested link requires writing in a directory on a read-only file system. [EXDEV] The link named by path2 and the file named by path1 are on different file systems. SEE ALSO
symlink(2), unlink(2) STANDARDS
The link() function is expected to conform to IEEE Std 1003.1-1988 (``POSIX.1''). 4th Berkeley Distribution October 29, 2008 4th Berkeley Distribution

Check Out this Related Man Page

link(2) 							System Calls Manual							   link(2)

NAME
link - Creates a hard link to an existing file on the local file system SYNOPSIS
#include <unistd.h> int link ( const char *path1, const char *path2 ); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: link(): XSH5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Points to the pathname of an existing file. Points to the pathname for the directory entry to be created. If the path2 parameter names a symbolic link, an error is returned. DESCRIPTION
The link() function creates an additional hard link (directory entry) for an existing file. The old and the new link share equal access rights to the underlying object. The link() function atomically creates a new link for the existing file and increments the link count of the file by one. Both the path1 and path2 parameters must reside on the same file system. A hard link to a directory cannot be created. Upon successful completion, the link() function marks the st_ctime field of the file for update, and marks the st_ctime and st_mtime fields of the directory containing the new entry for update. A process must have write permission in the target directory with respect to all access control policies configured on the system. See symlink(2) for information about making symbolic links, including Context Dependent Symbolic Links (CDSLs). RETURN VALUES
Upon successful completion, the link() function returns a value of 0 (zero). If the link() function fails, a value of -1 is returned, no link is created, and errno is set to indicate the error. ERRORS
If the link() function fails, errno may be set to one of the following values: The requested link requires writing in a directory with a mode that denies write permission, or a component of either the path1 or path2 parameter denies search permission. The requested link requires writing in a directory to which the process does not have write access with respect to one or more of the system's configured access policies. 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. The link named by the path2 parameter already exists. The path1 or path2 parameter is an invalid address. [Tru64 UNIX] An I/O error occurred when updating the directory. Too many links were encountered in translating path1 or path2. The number of links to the file named by path1 would exceed LINK_MAX. The length of the path1 or path2 string exceeds PATH_MAX or a pathname component is longer than NAME_MAX. The file named by the path1 parameter does not exist or the path1 or path2 parameter is an empty string. 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. A component of either path prefix is not a directory. The file named by the path1 parameter is a directory. The requested link requires writing in a directory on a read-only file system. The link named by the path2 parameter and the file named by the path1 parameter are on different file systems. [Tru64 UNIX] For NFS file access, if the link() function fails, errno may also be set to one of the following values: Indicates that the system file table is full or there are too many files currently open in the system. Indicates a stale NFS file handle. An opened file was deleted by the server or another client; a client cannot open a file because the server has unmounted or unexported the remote directory; or the directory that contains an opened file was unmounted or unexported by the server. RELATED INFORMATION
Commands: link(1), unlink(1) Functions: unlink(2), symlink(2) Standards: standards(5) delim off link(2)
Man Page