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