OSDN Git Service

e3a84316998b362f692740ef8784a428c075220b
[linuxjm/LDP_man-pages.git] / draft / man2 / rename.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\"                               1993 Michael Haardt;
5 .\"                          1993,1995 Ian Jackson.
6 .\"
7 .\" Permission is granted to make and distribute verbatim copies of this
8 .\" manual provided the copyright notice and this permission notice are
9 .\" preserved on all copies.
10 .\"
11 .\" Permission is granted to copy and distribute modified versions of this
12 .\" manual under the conditions for verbatim copying, provided that the
13 .\" entire resulting derived work is distributed under the terms of a
14 .\" permission notice identical to this one.
15 .\"
16 .\" Since the Linux kernel and libraries are constantly changing, this
17 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
18 .\" responsibility for errors or omissions, or for damages resulting from
19 .\" the use of the information contained herein.  The author(s) may not
20 .\" have taken the same level of care in the production of this manual,
21 .\" which is licensed free of charge, as they might when working
22 .\" professionally.
23 .\"
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
26 .\"
27 .\" Modified Sat Jul 24 00:35:52 1993 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified Thu Jun  4 12:21:13 1998 by Andries Brouwer <aeb@cwi.nl>
29 .\" Modified Thu Mar  3 09:49:35 2005 by Michael Haardt <michael@moria.de>
30 .\" 2007-03-25, mtk, added various text to DESCRIPTION.
31 .\"
32 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
33 .\"         all rights reserved.
34 .\" Translated Fri Dec 12 00:15:52 JST 1997
35 .\"         by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
36 .\" Updated & Modified Thu Feb 10 07:23:59 JST 2005
37 .\"         by Yuichi SATO <ysato444@yahoo.co.jp>
38 .\" Updated & Modified Fri Apr 22 03:21:04 JST 2005 by Yuichi SATO
39 .\" Updated 2007-05-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.44
40 .\" Updated 2009-04-24, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.20
41 .\"
42 .\"WORD:        directory               ディレクトリ
43 .\"WORD:        hard link               ハード・リンク
44 .\"WORD:        overwrite               上書き(overwrite)
45 .\"WORD:        process                 プロセス
46 .\"WORD:        crash                   クラッシュ
47 .\"WORD:        symbolic link           シンボリック・リンク
48 .\"WORD:        working directory       ワーキング・ディレクトリ
49 .\"WORD:        root directory          ルート・ディレクトリ
50 .\"WORD:        effective uid           実効ユーザーID
51 .\"WORD:        sticky bit              スティッキー・ビット
52 .\"WORD:        memory                  メモリ
53 .\"WORD:        read-only               読み込み専用
54 .\"WORD:        uid                     ユーザーID
55 .\"WORD:        dangling symbolic link  壊れたシンボリック・リンク
56 .\"WORD:        server                  サーバー
57 .\"
58 .TH RENAME 2 2009-03-30 "Linux" "Linux Programmer's Manual"
59 .\"O .SH NAME
60 .SH 名前
61 .\"O rename \- change the name or location of a file
62 rename \- ファイルの名前や位置を変更する
63 .\"O .SH SYNOPSIS
64 .SH 書式
65 .B #include <stdio.h>
66 .sp
67 .BI "int rename(const char *" oldpath ", const char *" newpath );
68 .\"O .SH DESCRIPTION
69 .SH 説明
70 .\"O .BR rename ()
71 .\"O renames a file, moving it between directories if required.
72 .BR rename ()
73 はファイルの名前を変更し、必要ならばディレクトリ間の移動を行なう。
74 .\"O Any other hard links to the file (as created using
75 .\"O .BR link (2))
76 .\"O are unaffected.
77 そのファイルに対する
78 .RB ( link (2)
79 を使用して作られた) 他のハードリンク (hard link) には影響はない。
80 .\"O Open file descriptors for
81 .\"O .I oldpath
82 .\"O are also unaffected.
83 オープン済の
84 .I oldpath
85 に対するファイルディスクリプタにも影響はない。
86
87 .\"O If
88 .\"O .I newpath
89 .\"O already exists it will be atomically replaced (subject to
90 .\"O a few conditions; see ERRORS below), so that there is
91 .\"O no point at which another process attempting to access
92 .\"O .I newpath
93 .\"O will find it missing.
94 .I newpath
95 が既に存在する場合、それは不可分操作で (atomically) 置き換えられる
96 (ただし、いくつかの条件がある; 以下の「エラー」のセクションを参照)。
97 そのため、
98 .I newpath
99 にアクセスしようとしている他のプロセスがファイルを見失うことはない
100 (訳註: 常にアクセス可能である)。
101
102 .\"O If
103 .\"O .I oldpath
104 .\"O and
105 .\"O .I newpath
106 .\"O are existing hard links referring to the same file, then
107 .\"O .BR rename ()
108 .\"O does nothing, and returns a success status.
109 .I oldpath
110
111 .I newpath
112 がどちらも既存のハードリンクで、同じファイルを参照している場合、
113 .BR rename ()
114 は何も行わず、ステータスとして成功を返す。
115
116 .\"O If
117 .\"O .I newpath
118 .\"O exists but the operation fails for some reason
119 .\"O .BR rename ()
120 .\"O guarantees to leave an instance of
121 .\"O .I newpath
122 .\"O in place.
123 .I newpath
124 が存在し、何らかの理由で操作が失敗した場合、
125 .BR rename ()
126
127 .I newpath
128 の実体を元のまま残すことを保証する。
129
130 .\"O .I oldpath
131 .\"O can specify a directory.
132 .\"O In this case,
133 .\"O .I newpath
134 .\"O must either not exist, or it must specify an empty directory.
135 .I oldpath
136 にはディレクトリを指定することもできる。
137 この場合、
138 .I newpath
139 は存在しないか、空のディレクトリでなければならない。
140
141 .\"O However, when overwriting there will probably be a window in which
142 .\"O both
143 .\"O .I oldpath
144 .\"O and
145 .\"O .I newpath
146 .\"O refer to the file being renamed.
147 一方で、上書きを行なう場合は、rename が行なわれるファイルを
148 .I oldpath
149
150 .I newpath
151 の両方で参照できる瞬間がおそらく存在する。
152
153 .\"O If
154 .\"O .I oldpath
155 .\"O refers to a symbolic link the link is renamed; if
156 .\"O .I newpath
157 .\"O refers to a symbolic link the link will be overwritten.
158 .I oldpath
159 がシンボリック・リンク (symbolic link) を参照している場合は、
160 リンクの名前が変更される。
161 また、
162 .I newpath
163 がシンボリック・リンクを参照している場合は、リンクが上書きされる。
164 .\"O .SH "RETURN VALUE"
165 .SH 返り値
166 .\"O On success, zero is returned.
167 .\"O On error, \-1 is returned, and
168 .\"O .I errno
169 .\"O is set appropriately.
170 成功した場合は 0 を返す。エラーの場合は \-1 を返し、
171 .I errno
172 を適切に設定する。
173 .\"O .SH ERRORS
174 .SH エラー
175 .TP
176 .B EACCES
177 .\"O Write permission is denied for the directory containing
178 .\"O .I oldpath
179 .\"O or
180 .\"O .IR newpath ,
181 .\"O or, search permission is denied for one of the directories
182 .\"O in the path prefix of
183 .\"O .I oldpath
184 .\"O or
185 .\"O .IR newpath ,
186 .\"O or
187 .\"O .I oldpath
188 .\"O is a directory and does not allow write permission (needed to update
189 .\"O the
190 .\"O .I ..
191 .\"O entry).
192 .\"O (See also
193 .\"O .BR path_resolution (7).)
194 .IR oldpath " または " newpath
195 を含んでいるディレクトリの書き込み許可がない。
196 または、
197 .IR oldpath " または " newpath
198 のディレクトリ部分のどれかに検索許可がない。
199 または、
200 .I oldpath
201 がディレクトリで
202 .RI ( ..
203 エントリを更新するのに必要な) 書き込み許可がない
204 .RB ( path_resolution (7)
205 も参照)。
206 .TP
207 .B EBUSY
208 .\"O The rename fails because
209 .\"O .IR oldpath " or " newpath
210 .\"O is a directory that is in use by some process (perhaps as
211 .\"O current working directory, or as root directory, or because
212 .\"O it was open for reading) or is in use by the system
213 .\"O (for example as mount point), while the system considers
214 .\"O this an error.
215 .IR oldpath " または " newpath
216 がディレクトリで、何らかのプロセスが使用中
217 (多分、カレント・ワーキング・ディレクトリか、ルートディレクトリか、
218 読み込みのためにオープンされているかでろう)
219 もしくは、システムが使用中 (例えばマウント・ポイントである)
220 であり、システムがこれをエラーであると判断したために rename が失敗した。
221 .\"O (Note that there is no requirement to return
222 .\"O .B EBUSY
223 .\"O in such
224 .\"O cases\(emthere is nothing wrong with doing the rename anyway\(embut
225 .\"O it is allowed to return
226 .\"O .B EBUSY
227 .\"O if the system cannot otherwise
228 .\"O handle such situations.)
229 (このような場合に
230 .B EBUSY
231 を返すことは規格では要求されていない点に注意すること。
232 このような場合に、rename をとにかく実行してみるのは何の問題もない。
233 ただし、そのような状況で、システムが他に返すエラーがない場合には
234 .B EBUSY
235 を返すことが許されている。)
236 .TP
237 .B EFAULT
238 .\"O .IR oldpath " or " newpath " points outside your accessible address space."
239 .IR oldpath " または " newpath
240 がアクセス可能なアドレス空間の外を指している。
241 .TP
242 .B EINVAL
243 .\"O The new pathname contained a path prefix of the old, or, more generally,
244 .\"O an attempt was made to make a directory a subdirectory of itself.
245 .IR newpath " が " oldpath
246 のパス部分を含んでいる。ディレクトリを自分自身のサブディレクトリに
247 変更しようとした場合がほとんどである。
248 .TP
249 .B EISDIR
250 .\"O .I newpath
251 .\"O is an existing directory, but
252 .\"O .I oldpath
253 .\"O is not a directory.
254 .I newpath
255 は存在しているディレクトリであるが、
256 .I oldpath
257 はディレクトリでない。
258 .TP
259 .B ELOOP
260 .\"O Too many symbolic links were encountered in resolving
261 .\"O .IR oldpath " or " newpath .
262 .IR oldpath " または " newpath
263 を解決する際に遭遇したシンボリック・リンクが多過ぎる。
264 .TP
265 .B EMLINK
266 .\"O .I oldpath
267 .\"O already has the maximum number of links to it, or
268 .\"O it was a directory and the directory containing
269 .\"O .I newpath
270 .\"O has the maximum number of links.
271 .I oldpath
272 は既に最大数までのリンクを持っているか、それがディレクトリで
273 .I newpath
274 を含んでいるディレクトリが最大数までのリンクを持っている。
275 .TP
276 .B ENAMETOOLONG
277 .\"O .IR oldpath " or " newpath " was too long."
278 .IR oldpath " または " newpath " が長過ぎる。"
279 .TP
280 .B ENOENT
281 .\"O The link named by
282 .\"O .I oldpath
283 .\"O does not exist;
284 .\"O or, a directory component in
285 .\"O .I newpath
286 .\"O does not exist;
287 .\"O or,
288 .\"O .I oldpath
289 .\"O or
290 .\"O .I newpath
291 .\"O is an empty string.
292 .I oldpath
293 という名前のリンクが存在しない。
294 または、
295 .I newpath
296 というディレクトリが存在しない。
297 または、
298 .I oldpath
299
300 .I newpath
301 が空の文字列である。
302 .TP
303 .B ENOMEM
304 .\"O Insufficient kernel memory was available.
305 カーネルに十分なメモリが存在しない。
306 .TP
307 .B ENOSPC
308 .\"O The device containing the file has no room for the new directory
309 .\"O entry.
310 ファイルを含んでいるデバイスに新しいディレクトリ・エントリを
311 作成するための空きがない。
312 .TP
313 .B ENOTDIR
314 .\"O A component used as a directory in
315 .\"O .IR oldpath " or " newpath
316 .\"O is not, in fact, a directory.
317 .IR oldpath " か " newpath
318 に含まれているディレクトリ部分が
319 実際にはディレクトリでない。
320 .\"O Or,
321 .\"O .I oldpath
322 .\"O is a directory, and
323 .\"O .I newpath
324 .\"O exists but is not a directory.
325 または
326 .I oldpath
327 がディレクトリで、
328 .I newpath
329 が存在してディレクトリでない。
330 .TP
331 .\"O .BR ENOTEMPTY " or " EEXIST
332 .B ENOTEMPTY " または " EEXIST
333 .\"O .I newpath
334 .\"O is a nonempty directory, that is, contains entries other than "." and "..".
335 .I newpath
336 が空でないディレクトリである。すなわち "." と ".." 以外を含んでいる。
337 .TP
338 .\"O .BR EPERM " or " EACCES
339 .BR EPERM " または " EACCES
340 .\"O The directory containing
341 .\"O .I oldpath
342 .\"O has the sticky bit
343 .\"O .RB ( S_ISVTX )
344 .\"O set and the process's effective user ID is neither
345 .\"O the user ID of the file to be deleted nor that of the directory
346 .\"O containing it, and the process is not privileged
347 .\"O (Linux: does not have the
348 .\"O .B CAP_FOWNER
349 .\"O capability);
350 .I oldpath
351 のあるディレクトリにスティッキー・ビット (sticky bit)
352 .RB ( S_ISVTX )
353 が設定されており、
354 プロセスの実効ユーザー ID が
355 削除しようとするファイルのユーザー ID と
356 そのファイルを含むディレクトリのユーザー ID のいずれとも一致せず、かつ
357 プロセスに特権がない (Linux では
358 .B CAP_FOWNER
359 ケーパビリティ (capability) がない)。
360 .\"O or
361 .\"O .I newpath
362 .\"O is an existing file and the directory containing it has the sticky bit set
363 .\"O and the process's effective user ID is neither the user ID of the file
364 .\"O to be replaced nor that of the directory containing it,
365 .\"O and the process is not privileged
366 .\"O (Linux: does not have the
367 .\"O .B CAP_FOWNER
368 .\"O capability);
369 または、
370 .I newpath
371 がすでに存在するファイルで、親ディレクトリにスティッキービットが設定されており、
372 プロセスの実効ユーザー ID が
373 置き換えようとするファイルのユーザー ID と
374 そのファイルを含むディレクトリのユーザー ID のいずれとも一致せず、かつ
375 プロセスに特権がない (Linux では
376 .B CAP_FOWNER
377 ケーパビリティがない)。
378 .\"O or the file system containing
379 .\"O .I pathname
380 .\"O does not support renaming of the type requested.
381 または
382 .IR oldpath " と " newpath
383 が存在するファイル・システムが、要求された種類の名前の変更を
384 サポートしていない。
385 .TP
386 .B EROFS
387 .\"O The file is on a read-only file system.
388 ファイルが読み込み専用 (read-only) ファイル・システムにある。
389 .TP
390 .B EXDEV
391 .\"O .IR oldpath " and " newpath
392 .\"O are not on the same mounted file system.
393 .IR oldpath " と " newpath
394 が同じマウントされたファイル・システムに存在しない。
395 .\"O (Linux permits a file system to be mounted at multiple points, but
396 .\"O .BR rename ()
397 .\"O does not work across different mount points,
398 .\"O even if the same file system is mounted on both.)
399 (Linux は 1 つのファイル・システムを複数のマウント位置に
400 マウントすることを許可している。
401 しかし
402 .BR rename ()
403 は、たとえ同じファイル・システムであっても、
404 別々のマウント位置を跨いでは動作しない。)
405 .\"O .SH "CONFORMING TO"
406 .SH 準拠
407 4.3BSD, C89, C99, POSIX.1-2001.
408 .\"O .SH BUGS
409 .SH バグ
410 .\"O On NFS file systems, you can not assume that if the operation
411 .\"O failed the file was not renamed.
412 .\"O If the server does the rename operation
413 .\"O and then crashes, the retransmitted RPC which will be processed when the
414 .\"O server is up again causes a failure.
415 .\"O The application is expected to
416 .\"O deal with this.
417 .\"O See
418 .\"O .BR link (2)
419 .\"O for a similar problem.
420 NFS ファイル・システムでは、操作が失敗したからといって、
421 ファイルの名前が変更できなかったと決めてかかることはできない。
422 サーバが rename 操作を終えてからクラッシュした場合、
423 サーバが再び立ち上がったときに、
424 再送信された RPC が処理されるが、これは失敗となる。
425 アプリケーションはこの問題を正しく取り扱うことが期待されている。
426 同様の問題について
427 .BR link (2)
428 にも書かれている。
429 .\"O .SH "SEE ALSO"
430 .SH 関連項目
431 .BR mv (1),
432 .BR chmod (2),
433 .BR link (2),
434 .BR renameat (2),
435 .BR symlink (2),
436 .BR unlink (2),
437 .BR path_resolution (7),
438 .BR symlink (7)