1 .\" $NetBSD: rename.2,v 1.7 1995/02/27 12:36:15 cgd Exp $
3 .\" Copyright (c) 1983, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)rename.2 8.1 (Berkeley) 6/4/93
36 .Dd September 18, 2008
44 .Nd change the name of a file
46 .Fd #include <stdio.h>
53 .Fn renameat "int fromfd" "const char *from" "int tofd" "const char *to"
55 .Fn renamex_np "const char *from" "const char *to" "unsigned int flags"
57 .Fn renameatx_np "int fromfd" "const char *from" "int tofd" "const char *to" "unsigned int flags"
61 system call causes the link named
67 exists, it is first removed.
72 must be of the same type
73 (that is, both must be either directories or non-directories)
74 and must reside on the same file system.
78 system call guarantees that an instance of
81 even if the system should crash in the middle of the operation.
83 If the final component of
86 the symbolic link is renamed,
87 not the file or directory to which it points.
91 system call is equivalent to
93 except in the case where either
97 specifies a relative path.
100 is a relative path, the file to be renamed is located
101 relative to the directory associated with the file descriptor
103 instead of the current working directory.
106 is a relative path, the same happens only relative to the directory associated
111 is passed the special value
117 parameter, the current working directory is used in the determination
118 of the file for the respective path parameter.
124 system calls are similar to their counterparts except that they take a
129 are constructed with below bits set:
130 .Bl -tag -offset indent
132 On file systems that support it (see
134 .Dv VOL_CAP_INT_RENAME_SWAP Ns ),
135 it will cause the source and target to be atomically swapped. Source and target need not be of
136 the same type, i.e. it is possible to swap a file with a directory.
137 EINVAL is returned in case of bitwise-inclusive OR with
140 On file systems that support it (see
142 .Dv VOL_CAP_INT_RENAME_EXCL Ns ),
145 to be returned if the destination already exists. EINVAL is returned in case of bitwise-inclusive OR with
149 The system can deadlock if a loop is present in the file system graph.
150 This loop takes the form of an entry in directory
154 being a hard link to directory
164 When such a loop exists and two separate processes attempt to
166 .Ql rename a/foo b/bar
168 .Ql rename b/bar a/foo ,
170 the system may deadlock attempting to lock
171 both directories for modification.
173 Whether or not hard links to directories are supported is specific to
174 the underlying filesystem implementation.
176 It is recommended that any hard links to directories in an underlying
177 filesystem should be replaced by symbolic links by the system administrator
178 to avoid the possibility of deadlocks.
180 Moving or renaming a file or directory into a directory with inheritable ACLs does not result in ACLs being set on the file or directory. Use
184 to set ACLs on the file or directory.
186 A 0 value is returned if the operation succeeds, otherwise
188 returns -1 and the global variable
190 indicates the reason for the failure.
194 system call will fail and neither of the argument files will be
199 A component of either path prefix denies search permission.
202 The requested operation requires writing in a directory
205 new/.., or old/..) whose modes disallow this.
209 is a directory and it, or some descendent in the namespace, is open
210 and the file system format does does not support renaming a directory
211 with open descendents (see
213 .Dv VOL_CAP_INT_RENAME_OPENFAIL Ns ).
216 The directory in which the entry for the new name
217 is being placed cannot be extended because the
218 user's quota of disk blocks on the file system
219 containing the directory has been exhausted.
231 points outside the process's allocated address space.
235 is a parent directory of
237 or an attempt is made to rename
245 will also be returned if
247 is a parent directory of
249 If both RENAME_SWAP and RENAME_EXCL bits are set in
257 has an invalid value.
260 An I/O error occurs while making or updating a directory entry.
269 Too many symbolic links are encountered in translating either pathname.
270 This is taken to be indicative of a looping symbolic link.
272 .It Bq Er ENAMETOOLONG
273 A component of a pathname exceeds
275 characters, or an entire path name exceeds
296 The directory in which the entry for the new name is being placed
297 cannot be extended because there is no space left on the file
298 system containing the directory.
301 A component of either path prefix is not a directory.
311 is a directory and is not empty.
315 has a value that is not supported by the file system.
318 The directory containing
321 and neither the containing directory nor
323 are owned by the effective user ID.
329 the directory containing
332 and neither the containing directory nor
334 are owned by the effective user ID.
337 The requested link requires writing in a directory on a read-only file
343 and the file named by
345 are on different logical devices (file systems).
346 Note that this error code will not be returned
347 if the implementation permits cross-device links.
354 calls may also fail with:
359 argument does not specify an absolute path and the
363 nor a valid file descriptor open for searching, or the
365 argument does not specify an absolute path and the
369 nor a valid file descriptor open for searching.
373 argument is not an absolute path and
377 nor a file descriptor associated with a directory, or the
379 argument is not an absolute path and
383 nor a file descriptor associated with a directory.
386 The restriction on renaming a directory whose permissions disallow writing
387 is based on the fact that UFS directories contain a ".." entry.
388 If renaming a directory would move it to another parent directory,
389 this entry needs to be changed.
391 This restriction has been generalized to disallow renaming
392 of any write-disabled directory,
393 even when this would not require a change to the ".." entry.
394 For consistency, HFS+ directories emulate this behavior.
405 system call is expected to conform to POSIX.1-2008 .