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