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