O nás     Inzerce     KontaktSpolehlivé informace o IT již od roku 2011
Nepřehlédněte: Usnadní vám práci: Pozoruhodné IT produkty pro rok 2024
Správa dokumentů
Digitální transformace
Informační systémy
Hlavní rubriky: Informační systémy, Mobilní technologie, Datová centra, Sítě, IT bezpečnost, Software, Hardware, Zkušenosti a názory, Speciály

Pozoruhodné IT produkty 2024
E-knihy o IT zdarma
Manuál Linux
[Linux manuál]

link: odkaz na soubor

Originální popis anglicky: link - link to a file

Návod, kniha: POSIX Programmer's Manual


#include <unistd.h>
int link(const char * path1, const char *path2 );


The link() function shall create a new link (directory entry) for the existing file, path1.
The path1 argument points to a pathname naming an existing file. The path2 argument points to a pathname naming the new directory entry to be created. The link() function shall atomically create a new link for the existing file and the link count of the file shall be incremented by one.
If path1 names a directory, link() shall fail unless the process has appropriate privileges and the implementation supports using link() on directories.
Upon successful completion, link() shall mark for update the st_ctime field of the file. Also, the st_ctime and st_mtime fields of the directory that contains the new entry shall be marked for update.
If link() fails, no link shall be created and the link count of the file shall remain unchanged.
The implementation may require that the calling process has permission to access the existing file.


Upon successful completion, 0 shall be returned. Otherwise, -1 shall be returned and errno set to indicate the error.


The link() function shall fail if:
A component of either path prefix denies search permission, or the requested link requires writing in a directory that denies write permission, or the calling process does not have permission to access the existing file and this is required by the implementation.
The path2 argument resolves to an existing file or refers to a symbolic link.
A loop exists in symbolic links encountered during resolution of the path1 or path2 argument.
The number of links to the file named by path1 would exceed {LINK_MAX}.
The length of the path1 or path2 argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.
A component of either path prefix does not exist; the file named by path1 does not exist; or path1 or path2 points to an empty string.
The directory to contain the link cannot be extended.
A component of either path prefix is not a directory.
The file named by path1 is a directory and either the calling process does not have appropriate privileges or the implementation prohibits using link() on directories.
The requested link requires writing in a directory on a read-only file system.
The link named by path2 and the file named by path1 are on different file systems and the implementation does not support links between file systems.
path1 refers to a named STREAM.
The link() function may fail if:
More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the path1 or path2 argument.
As a result of encountering a symbolic link in resolution of the path1 or path2 argument, the length of the substituted pathname string exceeded {PATH_MAX}.
The following sections are informative.


The following example shows how to create a link to a file named /home/cnd/mod1 by creating a new directory entry named /modules/pass1.
#include <unistd.h>
char *path1 = "/home/cnd/mod1"; char *path2 = "/modules/pass1"; int status; ... status = link (path1, path2);
In the following program example, the link() function links the /etc/passwd file (defined as PASSWDFILE) to a file named /etc/opasswd (defined as SAVEFILE), which is used to save the current password file. Then, after removing the current password file (defined as PASSWDFILE), the new password file is saved as the current password file using the link() function again.
#include <unistd.h>
#define LOCKFILE "/etc/ptmp" #define PASSWDFILE "/etc/passwd" #define SAVEFILE "/etc/opasswd" ... /* Save current password file */ link (PASSWDFILE, SAVEFILE);
/* Remove current password file. */ unlink (PASSWDFILE);
/* Save new password file as current password file. */ link (LOCKFILE,PASSWDFILE);


Some implementations do allow links between file systems.


Linking to a directory is restricted to the superuser in most historical implementations because this capability may produce loops in the file hierarchy or otherwise corrupt the file system. This volume of IEEE Std 1003.1-2001 continues that philosophy by prohibiting link() and unlink() from doing this. Other functions could do it if the implementor designed such an extension.
Some historical implementations allow linking of files on different file systems. Wording was added to explicitly allow this optional behavior.
The exception for cross-file system links is intended to apply only to links that are programmatically indistinguishable from "hard" links.




symlink() , unlink() , the Base Definitions volume of IEEE Std 1003.1-2001, <unistd.h> Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
2003 IEEE/The Open Group
©2011-2024 BusinessIT.cz, ISSN 1805-0522 | Názvy použité v textech mohou být ochrannými známkami příslušných vlastníků.
Provozovatel: Bispiral, s.r.o., kontakt: BusinessIT(at)Bispiral.com | Inzerce: Best Online Media, s.r.o., zuzana@online-media.cz
O vydavateli | Pravidla webu BusinessIT.cz a ochrana soukromí | Používáme účetní program Money S3 | pg(9275)