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