1RENAME(2) System Calls Manual RENAME(2)
2
3
4
6 rename - change the name of a file
7
9 rename(from, to)
10 char *from, *to;
11
13 Rename causes the link named from to be renamed as to. If to exists,
14 then it is first removed. Both from and to must be of the same type
15 (that is, both directories or both non-directories), and must reside on
16 the same file system.
17
18 Rename guarantees that an instance of to will always exist, even if the
19 system should crash in the middle of the operation.
20
21 If the final component of from is a symbolic link, the symbolic link is
22 renamed, not the file or directory to which it points.
23
25 The system can deadlock if a loop in the file system graph is present.
26 This loop takes the form of an entry in directory “a”, say “a/foo”,
27 being a hard link to directory “b”, and an entry in directory “b”, say
28 “b/bar”, being a hard link to directory “a”. When such a loop exists
29 and two separate processes attempt to perform “rename a/foo b/bar” and
30 “rename b/bar a/foo”, respectively, the system may deadlock attempting
31 to lock both directories for modification. Hard links to directories
32 should be replaced by symbolic links by the system administrator.
33
35 A 0 value is returned if the operation succeeds, otherwise rename
36 returns -1 and the global variable errno indicates the reason for the
37 failure.
38
40 Rename will fail and neither of the argument files will be affected if
41 any of the following are true:
42
43 [EINVAL] Either pathname contains a character with the high-order
44 bit set.
45
46 [ENAMETOOLONG] A component of either pathname exceeded 255 characters,
47 or the entire length of either path name exceeded 1023
48 characters.
49
50 [ENOENT] A component of the from path does not exist, or a path
51 prefix of to does not exist.
52
53 [EACCES] A component of either path prefix denies search permis‐
54 sion.
55
56 [EACCES] The requested link requires writing in a directory with
57 a mode that denies write permission.
58
59 [EPERM] The directory containing from is marked sticky, and nei‐
60 ther the containing directory nor from are owned by the
61 effective user ID.
62
63 [EPERM] The to file exists, the directory containing to is
64 marked sticky, and neither the containing directory nor
65 to are owned by the effective user ID.
66
67 [ELOOP] Too many symbolic links were encountered in translating
68 either pathname.
69
70 [ENOTDIR] A component of either path prefix is not a directory.
71
72 [ENOTDIR] From is a directory, but to is not a directory.
73
74 [EISDIR] To is a directory, but from is not a directory.
75
76 [EXDEV] The link named by to and the file named by from are on
77 different logical devices (file systems). Note that
78 this error code will not be returned if the implementa‐
79 tion permits cross-device links.
80
81 [ENOSPC] The directory in which the entry for the new name is
82 being placed cannot be extended because there is no
83 space left on the file system containing the directory.
84
85 [EDQUOT] The directory in which the entry for the new name is
86 being placed cannot be extended because the user's quota
87 of disk blocks on the file system containing the direc‐
88 tory has been exhausted.
89
90 [EIO] An I/O error occurred while making or updating a direc‐
91 tory entry.
92
93 [EROFS] The requested link requires writing in a directory on a
94 read-only file system.
95
96 [EFAULT] Path points outside the process's allocated address
97 space.
98
99 [EINVAL] From is a parent directory of to, or an attempt is made
100 to rename ``.'' or ``..''.
101
102 [ENOTEMPTY] To is a directory and is not empty.
103
105 open(2)
106
107
108
1094.2 Berkeley Distribution May 22, 1986 RENAME(2)