1 .\" $NetBSD: rename.2,v 1.23 2010/05/31 12:16:20 njoly 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
37 .Nd change the name of a file
43 .Fn rename "const char *from" "const char *to"
52 exists, it is first removed.
57 must be of the same type (that is, both directories or both
58 non-directories), and must reside on the same file system.
61 guarantees that an instance of
63 will always exist, even if the system should crash in
64 the middle of the operation.
66 If the final component of
69 the symbolic link is renamed,
70 not the file or directory to which it points.
76 are pathnames of the same existing file in the file system's name space,
78 returns successfully and performs no other action.
80 A 0 value is returned if the operation succeeds, otherwise
82 returns \-1 and the global variable
84 indicates the reason for the failure.
87 will fail and neither of the argument files will be
90 .It Bq Er ENAMETOOLONG
91 A component of a pathname exceeded
93 characters, or an entire path name exceeded
104 A component of either path prefix denies search permission, or
105 the requested link requires writing in a directory with a mode
106 that denies write permission.
108 The directory containing
111 and neither the containing directory nor
113 are owned by the effective user ID.
117 the directory containing
120 and neither the containing directory nor
122 are owned by the effective user ID.
124 Too many symbolic links were encountered in translating either pathname.
126 A component of either path prefix is not a directory, or
139 and the file named by
141 are on different logical devices (file systems).
142 Note that this error code will not be returned if the implementation
143 permits cross-device links.
145 The directory in which the entry for the new name is being placed
146 cannot be extended because there is no space left on the file
147 system containing the directory.
149 The directory in which the entry for the new name
150 is being placed cannot be extended because the
151 user's quota of disk blocks on the file system
152 containing the directory has been exhausted.
154 An I/O error occurred while making or updating a directory entry.
156 The requested link requires writing in a directory on a read-only file
160 points outside the process's allocated address space.
163 is a parent directory of
165 or an attempt is made to rename
171 is a directory and is not empty.
176 is the mount point for a mounted file system.
184 function deviates from the semantics defined in
186 which specifies that if both
191 to the same existing file,
193 shall return successfully and performs no further action, whereas this
194 implementation will remove the file specified by
200 are pathnames of the same file in the file system's name space.
202 To retain conformance, a compatibility interface is provided by the
204 which is also be brought into scope if any of the
209 preprocessor symbols are defined at compile-time:
217 The system can deadlock if a loop in the file system graph is present.
218 This loop takes the form of an entry in directory
222 being a hard link to directory
232 When such a loop exists and two separate processes attempt to
234 .Ql rename a/foo b/bar
236 .Ql rename b/bar a/foo ,
238 the system may deadlock attempting to lock
239 both directories for modification.
240 Hard links to directories should be
241 replaced by symbolic links by the system administrator.