update error messages (mostly from sun!guy)
[unix-history] / usr / src / lib / libc / sys / 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.\"
fd690c8b 5.\" @(#)rename.2 6.3 (Berkeley) %G%
786fe04f 6.\"
0e4a927e 7.TH RENAME 2 ""
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.
39.SH CAVEAT
40The system can deadlock if a loop in the file system graph is present.
41This loop takes the form of an entry in directory \*(lqa\*(rq,
42say \*(lqa/foo\*(rq,
43being a hard link to directory \*(lqb\*(rq, and an entry in
44directory \*(lqb\*(rq, say \*(lqb/bar\*(rq, being a hard link
45to directory \*(lqa\*(rq.
46When such a loop exists and two separate processes attempt to
47perform \*(lqrename a/foo b/bar\*(rq and \*(lqrename b/bar a/foo\*(rq,
48respectively,
49the system may deadlock attempting to lock
50both directories for modification.
51Hard links to directories should be
52replaced by symbolic links by the system administrator.
53.SH "RETURN VALUE"
54A 0 value is returned if the operation succeeds, otherwise
55.I rename
56returns \-1 and the global variable
57.I errno
58indicates the reason for the failure.
59.SH "ERRORS
60.I Rename
61will fail and neither of the argument files will be
62affected if any of the following are true:
63.TP 15
b5984ffe
KM
64[EINVAL]
65Either pathname contains a character with the high-order bit set.
66.TP 15
67[ENAMETOOLONG]
68A component of either pathname exceeded 255 characters,
69or the entire length of either path name exceeded 1023 characters.
786fe04f
KM
70.TP 15
71[ENOENT]
b5984ffe
KM
72A component of the \fIfrom\fP path does not exist,
73or a path prefix of \fIto\fP does not exist.
786fe04f
KM
74.TP 15
75[EACCES]
76A component of either path prefix denies search permission.
77.TP 15
b5984ffe
KM
78[EACCES]
79The requested link requires writing in a directory with a mode
80that denies write permission.
81.TP 15
fd690c8b
KM
82[EPERM]
83The directory containing \fIfrom\fP is marked sticky,
84and neither the containing directory nor \fIfrom\fP
85are owned by the effective user ID.
86.TP 15
87[EPERM]
88The \fIto\fP file exists,
89the directory containing \fIto\fP is marked sticky,
90and neither the containing directory nor \fIto\fP
91are owned by the effective user ID.
92.TP 15
b5984ffe
KM
93[ELOOP]
94Too many symbolic links were encountered in translating either pathname.
95.TP 15
96[ENOTDIR]
97A component of either path prefix is not a directory.
98.TP 15
99[ENOTDIR]
100.I From
101is a directory, but \fIto\fP is not a directory.
786fe04f 102.TP 15
b5984ffe
KM
103[EISDIR]
104.I To
105is a directory, but \fIfrom\fP is not a directory.
786fe04f
KM
106.TP 15
107[EXDEV]
108The link named by \fIto\fP and the file named by \fIfrom\fP
109are on different logical devices (file systems). Note that this error
110code will not be returned if the implementation permits cross-device
111links.
112.TP 15
fd690c8b
KM
113[ENOSPC]
114The directory in which the entry for the new name is being placed
115cannot be extended because there is no space left on the file
116system containing the directory.
117.TP 15
118[EDQUOT]
119The directory in which the entry for the new name
120is being placed cannot be extended because the
121user's quota of disk blocks on the file system
122containing the directory has been exhausted.
123.TP 15
b5984ffe
KM
124[EIO]
125An I/O error occurred while making or updating a directory entry.
786fe04f
KM
126.TP 15
127[EROFS]
128The requested link requires writing in a directory on a read-only file
129system.
130.TP 15
131[EFAULT]
132.I Path
133points outside the process's allocated address space.
134.TP 15
135[EINVAL]
136.I From
137is a parent directory of
b5984ffe
KM
138.IR to ,
139or an attempt is made to rename ``.'' or ``..''.
140.TP 15
141[ENOTEMPTY]
142.I To
143is a directory and is not empty.
786fe04f
KM
144.SH "SEE ALSO"
145open(2)