2 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
3 .\" Copyright 1989 AT&T
4 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
5 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
6 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
7 .TH RENAME 2 "Oct 4, 2007"
9 rename, renameat \- change the name of a file
15 \fBint\fR \fBrename\fR(\fBconst char *\fR\fIold\fR, \fBconst char *\fR\fInew\fR);
22 \fBint\fR \fBrenameat\fR(\fBint\fR \fIfromfd\fR, \fBconst char *\fR\fIold\fR, \fBint\fR \fItofd\fR,
23 \fBconst char *\fR\fInew\fR);
31 \fBint\fR \fBrename\fR(\fBconst char *\fR\fIold\fR, \fBconst char *\fR\fInew\fR);
37 The \fBrename()\fR function changes the name of a file. The \fIold\fR argument
38 points to the pathname of the file to be renamed. The \fInew\fR argument points
39 to the new path name of the file.
42 The \fBrenameat()\fR function renames an entry in a directory, possibly moving
43 the entry into a different directory. See \fBfsattr\fR(5). If the \fIold\fR
44 argument is an absolute path, the \fIfromfd\fR is ignored. Otherwise it is
45 resolved relative to the \fIfromfd\fR argument rather than the current working
46 directory. Similarly, if the \fInew\fR argument is not absolute, it is
47 resolved relative to the \fItofd\fR argument. If either \fIfromfd\fR or
48 \fItofd\fR have the value \fBAT_FDCWD\fR, defined in <\fBfcntl.h\fR>, and their
49 respective paths are relative, the path is resolved relative to the current
53 Current implementation restrictions will cause the \fBrenameat()\fR function to
54 return an error if an attempt is made to rename an extended attribute file to a
55 regular (non-attribute) file, or to rename a regular file to an extended
59 If \fIold\fR and \fInew\fR both refer to the same existing file, the
60 \fBrename()\fR and \fBrenameat()\fR functions return successfully and performs
64 If \fIold\fR points to the pathname of a file that is not a directory,
65 \fInew\fR must not point to the pathname of a directory. If the link named by
66 \fInew\fR exists, it will be removed and \fIold\fR will be renamed to
67 \fInew\fR. In this case, a link named \fInew\fR must remain visible to other
68 processes throughout the renaming operation and will refer to either the file
69 referred to by \fInew\fR or the file referred to as \fIold\fR before the
73 If \fIold\fR points to the pathname of a directory, \fInew\fR must not point
74 to the pathname of a file that is not a directory. If the directory named by
75 \fInew\fR exists, it will be removed and \fIold\fR will be renamed to
76 \fInew\fR. In this case, a link named \fInew\fR will exist throughout the
77 renaming operation and will refer to either the file referred to by \fInew\fR
78 or the file referred to as \fIold\fR before the operation began. Thus, if
79 \fInew\fR names an existing directory, it must be an empty directory.
82 The \fInew\fR pathname must not contain a path prefix that names \fIold\fR.
83 Write access permission is required for both the directory containing \fIold\fR
84 and the directory containing \fInew\fR. If \fIold\fR points to the pathname of
85 a directory, write access permission is required for the directory named by
86 \fIold\fR, and, if it exists, the directory named by \fInew\fR.
89 If the directory containing \fIold\fR has the sticky bit set, at least one of
90 the following conditions listed below must be true:
95 the user must own \fIold\fR
101 the user must own the directory containing \fIold\fR
107 \fIold\fR must be writable by the user
113 the user must be a privileged user
117 If \fInew\fR exists, and the directory containing \fInew\fR is writable and has
118 the sticky bit set, at least one of the following conditions must be true:
123 the user must own \fInew\fR
129 the user must own the directory containing \fInew\fR
135 \fInew\fR must be writable by the user
141 the user must be a privileged user
145 If the link named by \fInew\fR exists, the file's link count becomes zero when
146 it is removed, and no process has the file open, then the space occupied by
147 the file will be freed and the file will no longer be accessible. If one or
148 more processes have the file open when the last link is removed, the link will
149 be removed before \fBrename()\fR or \fBrenameat()\fR returns, but the removal
150 of the file contents will be postponed until all references to the file have
154 Upon successful completion, the \fBrename()\fR and \fBrenameat()\fR functions
155 will mark for update the \fBst_ctime\fR and \fBst_mtime\fR fields of the parent
156 directory of each file.
160 Upon successful completion, \fB0\fR is returned. Otherwise, \fB\(mi1\fR is
161 returned and \fBerrno\fR is set to indicate an error.
165 The \fBrename()\fR function will fail if:
172 A component of either path prefix denies search permission; one of the
173 directories containing \fIold\fR and \fInew\fR denies write permissions; or
174 write permission is denied by a directory pointed to by \fIold\fR or \fInew\fR.
183 The \fInew\fR argument is a directory and the mount point for a mounted file
193 The directory where the new name entry is being placed cannot be extended
194 because the user's quota of disk blocks on that file system has been exhausted.
203 The link named by \fInew\fR is a directory containing entries other than
204 `\fB\&.\fR' (the directory itself) and `\fB\&..\fR' (the parent directory).
213 Either \fIold\fR or \fInew\fR references an invalid address.
222 The path argument includes non-UTF8 characters and the file system accepts only
223 file names where all characters are part of the UTF-8 character codeset.
232 The \fInew\fR argument directory pathname contains a path prefix that names the
233 \fIold\fR directory, or an attempt was made to rename a regular file to an
234 extended attribute or from an extended attribute to a regular file.
243 An I/O error occurred while making or updating a directory entry.
252 The \fInew\fR argument points to a directory but \fIold\fR points to a file
253 that is not a directory.
262 Too many symbolic links were encountered in translating the pathname.
268 \fB\fBENAMETOOLONG\fR\fR
271 The length of \fIold\fR or \fInew\fR exceeds \fBPATH_MAX\fR, or a pathname
272 component is longer than \fBNAME_MAX\fR while \fB_POSIX_NO_TRUNC\fR is in
282 The file named by \fIold\fR is a directory, and the link count of the parent
283 directory of \fInew\fR would exceed \fBLINK_MAX\fR.
292 The link named by \fIold\fR does not name an existing file, a component of the
293 path prefix of \fInew\fR does not exist, or either \fIold\fR or \fInew\fR
294 points to an empty string.
303 The directory that would contain \fInew\fR cannot be extended.
312 A component of either path prefix is not a directory, or \fIold\fR names a
313 directory and \fInew\fR names a file that is not a directory, or \fItofd\fR and
314 \fIdirfd\fR in \fBrenameat()\fR do not reference a directory.
323 The requested operation requires writing in a directory on a read-only file
333 The links named by \fIold\fR and \fInew\fR are on different file systems.
338 The \fBrenameat()\fR functions will fail if:
345 An attempt was made to rename a regular file as an attribute file or to rename
346 an attribute file as a regular file.
352 See \fBattributes\fR(5) for descriptions of the following attributes:
360 ATTRIBUTE TYPE ATTRIBUTE VALUE
362 Interface Stability Committed
364 MT-Level Async-Signal-Safe
366 Standard For \fBrename()\fR, see \fBstandards\fR(5).
372 \fBchmod\fR(2), \fBlink\fR(2), \fBunlink\fR(2), \fBattributes\fR(5),
373 \fBfsattr\fR(5), \fBstandards\fR(5)
377 The system can deadlock if there is a loop in the file system graph. Such a
378 loop can occur if there is an entry in directory \fBa\fR, \fBa/name1\fR, that
379 is a hard link to directory \fBb\fR, and an entry in directory \fBb\fR,
380 \fBb/name2\fR, that is a hard link to directory \fBa\fR. When such a loop
381 exists and two separate processes attempt to rename \fBa/name1\fR to
382 \fBb/name2\fR and \fBb/name2\fR to \fBa/name1\fR, the system may deadlock
383 attempting to lock both directories for modification. Use symbolic links
384 instead of hard links for directories.