OSDN Git Service

Update release for LDP 3.67
[linuxjm/LDP_man-pages.git] / release / man2 / link.2
1 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
2 .\"             and Copyright (C) 1993 Michael Haardt, Ian Jackson.
3 .\" and Copyright (C) 2006, 2014 Michael Kerrisk
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
26 .\"
27 .\" Modified 1993-07-23 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified 1994-08-21 by Michael Haardt
29 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
30 .\" Modified 2005-04-04, as per suggestion by Michael Hardt for rename.2
31 .\"
32 .\"*******************************************************************
33 .\"
34 .\" This file was generated with po4a. Translate the source file.
35 .\"
36 .\"*******************************************************************
37 .\"
38 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
39 .\"         all rights reserved.
40 .\" Translated Thu Dec 11 23:47:55 JST 1997
41 .\"         by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
42 .\" Updated & Modified Tue Feb  8 06:36:08 JST 2005
43 .\"         by Yuichi SATO <ysato444@yahoo.co.jp>
44 .\" Updated & Modified Fri Apr 22 02:05:00 JST 2005 by Yuichi SATO
45 .\" Updated 2008-09-07, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.08
46 .\" Updated 2013-05-06, Akihiro MOTOKI <amotoki@gmail.com>
47 .\"
48 .TH LINK 2 2014\-05\-10 Linux "Linux Programmer's Manual"
49 .SH 名前
50 link, linkat \- ファイルの新しい名前を作成する
51 .SH 書式
52 .nf
53 \fB#include <unistd.h>\fP
54 .sp
55 \fBint link(const char *\fP\fIoldpath\fP\fB, const char *\fP\fInewpath\fP\fB);\fP
56 .sp
57 \fB#include <fcntl.h>           \fP/* AT_* 定数の定義 */
58 \fB#include <unistd.h>\fP
59 .sp
60 \fBint linkat(int \fP\fIolddirfd\fP\fB, const char *\fP\fIoldpath\fP\fB,\fP
61 \fB           int \fP\fInewdirfd\fP\fB, const char *\fP\fInewpath\fP\fB, int \fP\fIflags\fP\fB);\fP
62 .fi
63 .sp
64 .in -4n
65 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
66 .in
67 .sp
68 \fBlinkat\fP():
69 .PD 0
70 .ad l
71 .RS 4
72 .TP  4
73 glibc 2.10 以降:
74 _XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L
75 .TP 
76 glibc 2.10 より前:
77 _ATFILE_SOURCE
78 .RE
79 .ad
80 .PD
81 .SH 説明
82 \fBlink\fP()  は存在するファイルへの新しいリンク (link)  (ハードリンク (hard link) ともいう) を作成する。
83
84 \fInewpath\fP が存在する場合には、上書きは\fIされない\fP。
85
86 この新しい名前は全ての操作において古い名前と完全に同じように使用される; 両方の名前は同じファイルを参照しており (それで同じ許可
87 (permission) や所有者 (ownership) となるので)、 どちらの名前が本来のものであるか判別できない。
88 .SS linkat()
89 \fBlinkat\fP() システムコールは \fBlink\fP() と全く同様に動作するが、以下で説明する点が異なる。
90
91 \fIoldpath\fP で指定されたパス名が相対パスの場合、このパス名はファイルディスクリプター \fIolddirfd\fP
92 が参照するディレクトリに対する相対パスと解釈される (\fBlink\fP(2)
93 に相対パス名を渡した場合のように、呼び出したプロセスのカレントワーキングディレクトリに対する相対パスではない)。
94
95 \fIoldpath\fP で指定されたパス名が相対パスで、 \fIolddirfd\fP が特別な値 \fBAT_FDCWD\fP の場合、 (\fBlink\fP(2)
96 と同様に) \fIoldpath\fP は呼び出したプロセスのカレントワーキングディレクトリに対する相対パスと解釈される。
97
98 \fIoldpath\fP で指定されたパス名が絶対パスの場合、 \fIolddirfd\fP は無視される。
99
100 \fInewpath\fP の解釈は \fIoldpath\fP と同じである。 相対パスのパス名がファイルディスクリプター \fInewdirfd\fP
101 が参照するディレクトリと解釈される点だけが異なる。
102
103 以下の値のビット単位の論理和を \fIflags\fP に指定できる。
104 .TP 
105 \fBAT_EMPTY_PATH\fP (Linux 2.6.39 以降)
106 .\" commit 11a7b371b64ef39fc5fb1b6f2218eef7c4d035e3
107 .\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
108 If \fIoldpath\fP is an empty string, create a link to the file referenced by
109 \fIolddirfd\fP (which may have been obtained using the \fBopen\fP(2)  \fBO_PATH\fP
110 flag).  In this case, \fIolddirfd\fP can refer to any type of file, not just a
111 directory.  This will generally not work if the file has a link count of
112 zero (files created with \fBO_TMPFILE\fP and without \fBO_EXCL\fP are an
113 exception).  The caller must have the \fBCAP_DAC_READ_SEARCH\fP capability in
114 order to use this flag.  This flag is Linux\-specific; define \fB_GNU_SOURCE\fP
115 to obtain its definition.
116 .TP 
117 \fBAT_SYMLINK_FOLLOW\fP (Linux 2.6.18 以降)
118 By default, \fBlinkat\fP(), does not dereference \fIoldpath\fP if it is a symbolic
119 link (like \fBlink\fP()).  The flag \fBAT_SYMLINK_FOLLOW\fP can be specified in
120 \fIflags\fP to cause \fIoldpath\fP to be dereferenced if it is a symbolic link.
121 If procfs is mounted, this can be used as an alternative to
122 \fBAT_EMPTY_PATH\fP, like this:
123
124 .nf
125 .in +4n
126 linkat(AT_FDCWD, "/proc/self/fd/<fd>", newdirfd,
127        newname, AT_SYMLINK_FOLLOW);
128 .in
129 .fi
130 .PP
131 カーネル 2.6.18 より前では、 \fIflags\fP 引き数は未使用で、 0 を指定しなければならなかった。
132 .PP
133 \fBlinkat\fP() の必要性についての説明については \fBopenat\fP(2) を参照。
134 .SH 返り値
135 成功した場合は 0 が返される。エラーの場合は \-1 が返され、 \fIerrno\fP が適切に設定される。
136 .SH エラー
137 .TP 
138 \fBEACCES\fP
139 \fInewpath\fP を含んでいるディレクトリへの書き込みが許されていないか、 \fIoldpath\fP または \fInewpath\fP
140 へのディレクトリのどれかに検索許可がない (\fBpath_resolution\fP(7)  を参照)。
141 .TP 
142 \fBEDQUOT\fP
143 ディスクブロックか inode がそのファイルシステムのユーザクォータに達していた。
144 .TP 
145 \fBEEXIST\fP
146 \fInewpath\fP が既に存在する。
147 .TP 
148 \fBEFAULT\fP
149 \fIoldpath\fP や \fInewpath\fP がアクセス可能なアドレス空間の外を指している。
150 .TP 
151 \fBEIO\fP
152 I/O エラーが発生した。
153 .TP 
154 \fBELOOP\fP
155 \fIoldpath\fP または \fInewpath\fP を解決する際に遭遇したシンボリックリンクが多過ぎる。
156 .TP 
157 \fBEMLINK\fP
158 \fIoldpath\fP によって参照されるファイルは 既に最大数までのリンクを持っている。
159 .TP 
160 \fBENAMETOOLONG\fP
161 \fIoldpath\fP または \fInewpath\fP が長過ぎる。
162 .TP 
163 \fBENOENT\fP
164 \fIoldpath\fP または \fInewpath\fP のディレクトリ部分が存在しないか、 壊れた(dangling)シンボリックリンクである。
165 .TP 
166 \fBENOMEM\fP
167 十分なカーネルメモリーがない。
168 .TP 
169 \fBENOSPC\fP
170 そのファイルを含んでいるデバイスに新しいディレクトリエントリを 作成するための空きがない。
171 .TP 
172 \fBENOTDIR\fP
173 \fIoldpath\fP または \fInewpath\fP のディレクトリ部分が、実際には、ディレクトリでない。
174 .TP 
175 \fBEPERM\fP
176 \fIoldpath\fP がディレクトリである。
177 .TP 
178 \fBEPERM\fP
179 \fIoldpath\fP と \fInewpath\fP を含んでいるファイルシステムがハードリンクをサポートしていない。
180 .TP 
181 \fBEPERM\fP (Linux 3.6 以降)
182 呼び出し元にこのファイルへのハードリンクを作成する許可がなかった (\fBproc\fP(5) の
183 \fI/proc/sys/fs/protected_hardlinks\fP の説明を参照)。
184 .TP 
185 \fBEROFS\fP
186 ファイルが読み込み専用のファイルシステムに存在する。
187 .TP 
188 \fBEXDEV\fP
189 \fIoldpath\fP と \fInewpath\fP が同じマウントされたファイルシステムに存在しない。 (Linux は 1
190 つのファイルシステムを複数のマウント位置に マウントすることを許可している。 しかし \fBlink\fP()  は、たとえ同じファイルシステムであっても、
191 別々のマウント位置を跨いでは動作しない。)
192 .PP
193 \fBlinkat\fP() では以下のエラーも発生する。
194 .TP 
195 \fBEBADF\fP
196 \fIolddirfd\fP か \fInewdirfd\fP が有効なファイルディスクリプタでない。
197 .TP 
198 \fBEINVAL\fP
199 無効なフラグ値が \fIflags\fP に指定された。
200 .TP 
201 \fBENOENT\fP
202 \fBAT_EMPTY_PATH\fP が \fIflags\fP に指定されたが、呼び出し元が \fBCAP_DAC_READ_SEARCH\fP
203 ケーパビリティを持っていなかった。
204 .TP 
205 \fBENOENT\fP
206 以下の呼び出しで作成されたファイルディスクリプターに対応する \fI/proc/self/fd/NN\fP ファイルに対してリンクを行おおうとした。
207
208     open(path, O_TMPFILE | O_EXCL, mode);
209
210 \fBopen\fP(2) 参照。
211 .TP 
212 \fBENOENT\fP
213 \fIoldpath\fP is a relative pathname and \fIolddirfd\fP refers to a directory that
214 has been deleted, or \fInewpath\fP is a relative pathname and \fInewdirfd\fP
215 refers to a directory that has been deleted.
216 .TP 
217 \fBENOTDIR\fP
218 \fIoldpath\fP が相対パスで、 \fIolddirfd\fP がディレクトリ以外のファイルを参照している。または \fInewpath\fP と
219 \fInewdirfd\fP に関して同じ状況である。
220 .TP 
221 \fBEPERM\fP
222 \fIflags\fP に \fBAT_EMPTY_PATH\fP が指定され、 \fIoldpath\fP が空文字列で、 \fIolddirfd\fP
223 がディレクトリを参照している。
224 .SH バージョン
225 \fBlinkat\fP()  はカーネル 2.6.16 で Linux に追加された。 ライブラリによるサポートはバージョン 2.4 で glibc
226 に追加された。
227 .SH 準拠
228 .\" SVr4 documents additional ENOLINK and
229 .\" EMULTIHOP error conditions; POSIX.1 does not document ELOOP.
230 .\" X/OPEN does not document EFAULT, ENOMEM or EIO.
231 \fBlink\fP(): SVr4, 4.3BSD, POSIX.1\-2001 (但し「注意」を参照), POSIX.1\-2008.
232
233 \fBlinkat\fP(): POSIX.1\-2008.
234 .SH 注意
235 \fBlink\fP()  でファイルシステムを超えてハードリンクを作成することはできない。 このような場合は \fBsymlink\fP(2)  を使用すること。
236
237 .\" more precisely: since kernel 1.3.56
238 .\" For example, the default Solaris compilation environment
239 .\" behaves like Linux, and contributors to a March 2005
240 .\" thread in the Austin mailing list reported that some
241 .\" other (System V) implementations did/do the same -- MTK, Apr 05
242 POSIX.1\-2001 では、 \fIoldpath\fP がシンボリックリンクである場合、 \fBlink\fP()  は \fIoldpath\fP
243 の参照を解決すべきであると記述されている。 しかし、カーネル 2.0 以降の Linux ではそのようになっていない。 \fIoldpath\fP
244 がシンボリックリンクである場合、 \fInewpath\fP は同じシンボリックリンクファイルへの (ハード) リンクとして作成される (つまり
245 \fInewpath\fP は \fIoldpath\fP が参照していた同じファイルへのシンボリックリンクになる)。 他のいくつかの実装でも Linux
246 と同じように動作する。 POSIX.1\-2008 では \fBlink\fP()  の仕様が変更され、 \fIoldpath\fP
247 がシンボリックリンクの場合にシンボリックリンクの参照を 解決するかどうかは実装依存となった。
248 リンク作成時のシンボリックリンクの扱いについての詳細な制御を行う場合には \fBlinkat\fP(2) を使用すること。
249 .SH バグ
250 NFS ファイルシステムでは、NFS サーバーがリンクを作成した後に、 それを伝える前に死んだ場合には返り値が不正な場合がある。
251 リンクが作成できたかどうか見つけるためには \fBstat\fP(2)  を使用すること。
252 .SH 関連項目
253 \fBln\fP(1), \fBopen\fP(2), \fBrename\fP(2), \fBstat\fP(2), \fBsymlink\fP(2), \fBunlink\fP(2),
254 \fBpath_resolution\fP(7), \fBsymlink\fP(7)
255 .SH この文書について
256 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.67 の一部
257 である。プロジェクトの説明とバグ報告に関する情報は
258 http://www.kernel.org/doc/man\-pages/ に書かれている。