date and time created 89/07/02 15:22:51 by mckusick
[unix-history] / usr / src / lib / libc / sys / rename.2
CommitLineData
88b3ccf2
KB
1.\" Copyright (c) 1983 The Regents of the University of California.
2.\" All rights reserved.
786fe04f 3.\"
88b3ccf2
KB
4.\" Redistribution and use in source and binary forms are permitted
5.\" provided that the above copyright notice and this paragraph are
6.\" duplicated in all such forms and that any documentation,
7.\" advertising materials, and other materials related to such
8.\" distribution and use acknowledge that the software was developed
9.\" by the University of California, Berkeley. The name of the
10.\" University may not be used to endorse or promote products derived
11.\" from this software without specific prior written permission.
12.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15.\"
16.\" @(#)rename.2 6.5 (Berkeley) %G%
786fe04f 17.\"
0e4a927e 18.TH RENAME 2 ""
786fe04f
KM
19.UC 5
20.SH NAME
21rename \- change the name of a file
22.SH SYNOPSIS
23.ft B
24.nf
25rename(from, to)
26char *from, *to;
27.fi
28.ft R
29.SH DESCRIPTION
30.I Rename
31causes the link named
32.I from
33to be renamed as
34.IR to .
35If
36.I to
37exists, then it is first removed.
38Both
39.I from
40and
41.I to
42must be of the same type (that is, both directories or both
43non-directories), and must reside on the same file system.
44.PP
45.I Rename
46guarantees that an instance of
47.I to
48will always exist, even if the system should crash in
49the middle of the operation.
dbe80be1
KM
50.PP
51If the final component of
52.I from
53is a symbolic link,
54the symbolic link is renamed,
55not the file or directory to which it points.
786fe04f
KM
56.SH CAVEAT
57The system can deadlock if a loop in the file system graph is present.
58This loop takes the form of an entry in directory \*(lqa\*(rq,
59say \*(lqa/foo\*(rq,
60being a hard link to directory \*(lqb\*(rq, and an entry in
61directory \*(lqb\*(rq, say \*(lqb/bar\*(rq, being a hard link
62to directory \*(lqa\*(rq.
63When such a loop exists and two separate processes attempt to
64perform \*(lqrename a/foo b/bar\*(rq and \*(lqrename b/bar a/foo\*(rq,
65respectively,
66the system may deadlock attempting to lock
67both directories for modification.
68Hard links to directories should be
69replaced by symbolic links by the system administrator.
70.SH "RETURN VALUE"
71A 0 value is returned if the operation succeeds, otherwise
72.I rename
73returns \-1 and the global variable
74.I errno
75indicates the reason for the failure.
76.SH "ERRORS
77.I Rename
78will fail and neither of the argument files will be
79affected if any of the following are true:
80.TP 15
b5984ffe
KM
81[EINVAL]
82Either pathname contains a character with the high-order bit set.
83.TP 15
84[ENAMETOOLONG]
85A component of either pathname exceeded 255 characters,
86or the entire length of either path name exceeded 1023 characters.
786fe04f
KM
87.TP 15
88[ENOENT]
b5984ffe
KM
89A component of the \fIfrom\fP path does not exist,
90or a path prefix of \fIto\fP does not exist.
786fe04f
KM
91.TP 15
92[EACCES]
93A component of either path prefix denies search permission.
94.TP 15
b5984ffe
KM
95[EACCES]
96The requested link requires writing in a directory with a mode
97that denies write permission.
98.TP 15
fd690c8b
KM
99[EPERM]
100The directory containing \fIfrom\fP is marked sticky,
101and neither the containing directory nor \fIfrom\fP
102are owned by the effective user ID.
103.TP 15
104[EPERM]
105The \fIto\fP file exists,
106the directory containing \fIto\fP is marked sticky,
107and neither the containing directory nor \fIto\fP
108are owned by the effective user ID.
109.TP 15
b5984ffe
KM
110[ELOOP]
111Too many symbolic links were encountered in translating either pathname.
112.TP 15
113[ENOTDIR]
114A component of either path prefix is not a directory.
115.TP 15
116[ENOTDIR]
117.I From
118is a directory, but \fIto\fP is not a directory.
786fe04f 119.TP 15
b5984ffe
KM
120[EISDIR]
121.I To
122is a directory, but \fIfrom\fP is not a directory.
786fe04f
KM
123.TP 15
124[EXDEV]
125The link named by \fIto\fP and the file named by \fIfrom\fP
126are on different logical devices (file systems). Note that this error
127code will not be returned if the implementation permits cross-device
128links.
129.TP 15
fd690c8b
KM
130[ENOSPC]
131The directory in which the entry for the new name is being placed
132cannot be extended because there is no space left on the file
133system containing the directory.
134.TP 15
135[EDQUOT]
136The directory in which the entry for the new name
137is being placed cannot be extended because the
138user's quota of disk blocks on the file system
139containing the directory has been exhausted.
140.TP 15
b5984ffe
KM
141[EIO]
142An I/O error occurred while making or updating a directory entry.
786fe04f
KM
143.TP 15
144[EROFS]
145The requested link requires writing in a directory on a read-only file
146system.
147.TP 15
148[EFAULT]
149.I Path
150points outside the process's allocated address space.
151.TP 15
152[EINVAL]
153.I From
154is a parent directory of
b5984ffe
KM
155.IR to ,
156or an attempt is made to rename ``.'' or ``..''.
157.TP 15
158[ENOTEMPTY]
159.I To
160is a directory and is not empty.
786fe04f
KM
161.SH "SEE ALSO"
162open(2)