1 .\" $NetBSD: rename.2,v 1.33 2015/01/27 10:11:20 wiz 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. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)rename.2 8.1 (Berkeley) 6/4/93
38 .Nd change the name of a file
44 .Fn rename "const char *from" "const char *to"
47 .Fn renameat "int fromfd" "const char *from" "int tofd" "const char *to"
56 exists, it is first removed.
61 must be of the same type (that is, both directories or both
62 non-directories), and must reside on the same file system.
65 guarantees that an instance of
67 will always exist, even if the system should crash in
68 the middle of the operation.
70 If the final component of
73 the symbolic link is renamed,
74 not the file or directory to which it points.
80 are pathnames of the same existing file in the file system's name space,
82 returns successfully and performs no other action.
92 In that case, it is looked up from a directory whose file
93 descriptor was passed as
97 Search permission is required on the directories named by
101 .\" (These alternatives await a decision about the semantics of O_SEARCH)
102 .\" Search permission is required on the directories named by
106 .\" unless they were opened with the
110 .\" The directories named by
114 .\" must have been opened with the
122 in order to specify the current directory.
124 .Rv -std rename renameat
129 will fail and neither of the argument files will be
133 A component of either path prefix denies search permission, or
134 the requested link requires writing in a directory with a mode
135 that denies write permission.
140 is the mount point for a mounted file system.
142 The directory in which the entry for the new name
143 is being placed cannot be extended because the
144 user's quota of disk blocks on the file system
145 containing the directory has been exhausted.
150 points outside the process's allocated address space.
153 is a parent directory of
155 or an attempt is made to rename
160 An I/O error occurred while making or updating a directory entry.
167 Too many symbolic links were encountered in translating either pathname.
168 .It Bq Er ENAMETOOLONG
169 A component of a pathname exceeded
171 characters, or an entire path name exceeded
182 The directory in which the entry for the new name is being placed
183 cannot be extended because there is no space left on the file
184 system containing the directory.
186 A component of either path prefix is not a directory, or
193 is a directory and is not empty.
195 The directory containing
198 and neither the containing directory nor
200 are owned by the effective user ID.
204 the directory containing
207 and neither the containing directory nor
209 are owned by the effective user ID.
211 The requested link requires writing in a directory on a read-only file
216 and the file named by
218 are on different logical devices (file systems).
219 Note that this error code will not be returned if the implementation
220 permits cross-device links.
231 does not specify an absolute path and
235 respectively, is neither
237 nor a valid file descriptor open for reading or searching.
242 is not an absolute path and
246 respectively, is a file descriptor associated with a non-directory file.
254 function deviates from the semantics defined in
256 which specifies that if both
261 to the same existing file,
263 shall return successfully and performs no further action, whereas this
264 implementation will remove the file specified by
270 are pathnames of the same file in the file system's name space.
272 To retain conformance, a compatibility interface is provided by the
274 which is also be brought into scope if any of the
279 preprocessor symbols are defined at compile-time:
290 The system can deadlock if a loop in the file system graph is present.
291 This loop takes the form of an entry in directory
295 being a hard link to directory
305 When such a loop exists and two separate processes attempt to
307 .Ql rename a/foo b/bar
309 .Ql rename b/bar a/foo ,
311 the system may deadlock attempting to lock
312 both directories for modification.
313 Hard links to directories should be
314 replaced by symbolic links by the system administrator.