Print this page
7653 tmpfs: calling unlink() on a directory which isn't empty should fail
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/man/man2/unlink.2.man.txt
+++ new/usr/src/man/man2/unlink.2.man.txt
1 1 UNLINK(2) System Calls UNLINK(2)
2 2
3 3
4 4
5 5 NAME
6 6 unlink, unlinkat - remove directory entry
7 7
8 8 SYNOPSIS
9 9 #include <unistd.h>
10 10
11 11 int unlink(const char *path);
12 12
13 13
14 14 int unlinkat(int dirfd, const char *path, int flag);
15 15
16 16
17 17 DESCRIPTION
18 18 The unlink() function removes a link to a file. If path names a
19 19 symbolic link, unlink() removes the symbolic link named by path and
20 20 does not affect any file or directory named by the contents of the
21 21 symbolic link. Otherwise, unlink() removes the link named by the
22 22 pathname pointed to by path and decrements the link count of the file
23 23 referenced by the link.
24 24
25 25
26 26 The unlinkat() function also removes a link to a file. See fsattr(5).
27 27 If the flag argument is 0, the behavior of unlinkat() is the same as
28 28 unlink() except in the processing of its path argument. If path is
29 29 absolute, unlinkat() behaves the same as unlink() and the dirfd
30 30 argument is unused. If path is relative and dirfd has the value
31 31 AT_FDCWD, defined in <fcntl.h>, unlinkat() also behaves the same as
32 32 unlink(). Otherwise, path is resolved relative to the directory
33 33 referenced by the dirfd argument.
34 34
35 35
36 36 If the flag argument is set to the value AT_REMOVEDIR, defined in
37 37 <fcntl.h>, unlinkat() behaves the same as rmdir(2) except in the
38 38 processing of the path argument as described above.
39 39
40 40
41 41 When the file's link count becomes 0 and no process has the file open,
42 42 the space occupied by the file will be freed and the file is no longer
43 43 accessible. If one or more processes have the file open when the last
44 44 link is removed, the link is removed before unlink() or unlinkat()
45 45 returns, but the removal of the file contents is postponed until all
46 46 references to the file are closed.
47 47
48 48
49 49 If the path argument is a directory and the filesystem supports
50 50 unlink() and unlinkat() on directories, the directory is unlinked from
51 51 its parent with no cleanup being performed. In UFS, the disconnected
52 52 directory will be found the next time the filesystem is checked with
53 53 fsck(1M). The unlink() and unlinkat() functions will not fail simply
54 54 because a directory is not empty. The user with appropriate privileges
55 55 can orphan a non-empty directory without generating an error message.
56 56
57 57
58 58 If the path argument is a directory and the filesystem does not support
59 59 unlink() and unlink() on directories (for example, ZFS), the call will
60 60 fail with errno set to EPERM.
61 61
62 62
63 63 Upon successful completion, unlink() and unlinkat() will mark for
64 64 update the st_ctime and st_mtime fields of the parent directory. If
65 65 the file's link count is not 0, the st_ctime field of the file will be
66 66 marked for update.
67 67
68 68 RETURN VALUES
69 69 Upon successful completion, 0 is returned. Otherwise, -1 is returned,
70 70 errno is set to indicate the error, and the file is not unlinked.
71 71
72 72 ERRORS
73 73 The unlink() and unlinkat() functions will fail if:
74 74
75 75 EACCES
76 76 Search permission is denied for a component of the path
77 77 prefix, or write permission is denied on the directory
78 78 containing the link to be removed.
79 79
80 80
81 81 EACCES
82 82 The parent directory has the sticky bit set and the
↓ open down ↓ |
82 lines elided |
↑ open up ↑ |
83 83 file is not writable by the user, the user does not own
84 84 the parent directory, the user does not own the file,
85 85 and the user is not a privileged user.
86 86
87 87
88 88 EBUSY
89 89 The entry to be unlinked is the mount point for a
90 90 mounted file system.
91 91
92 92
93 + EEXIST
94 + The entry to be unlinked is a directory which is not
95 + empty.
96 +
97 +
93 98 EFAULT
94 99 The path argument points to an illegal address.
95 100
96 101
97 102 EILSEQ
98 103 The path argument includes non-UTF8 characters and the
99 104 file system accepts only file names where all
100 105 characters are part of the UTF-8 character codeset.
101 106
102 107
103 108 EINTR
104 109 A signal was caught during the execution of the
105 110 unlink() function.
106 111
107 112
108 113 ELOOP
109 114 Too many symbolic links were encountered in translating
110 115 path.
111 116
112 117
113 118 ENAMETOOLONG
114 119 The length of the path argument exceeds PATH_MAX, or
115 120 the length of a path component exceeds NAME_MAX while
116 121 _POSIX_NO_TRUNC is in effect.
117 122
118 123
119 124 ENOENT
120 125 The named file does not exist or is a null pathname.
121 126
122 127
123 128 ENOLINK
124 129 The path argument points to a remote machine and the
125 130 link to that machine is no longer active.
126 131
127 132
128 133 ENOTDIR
129 134 A component of the path prefix is not a directory or
130 135 the provided directory descriptor for unlinkat() is not
131 136 AT_FDCWD or does not reference a directory.
132 137
133 138
134 139 EPERM
135 140 The named file is a directory and {PRIV_SYS_LINKDIR} is
136 141 not asserted in the effective set of the calling
137 142 process, or the filesystem implementation does not
138 143 support unlink() or unlinkat() on directories.
139 144
140 145
141 146 EROFS
142 147 The directory entry to be unlinked is part of a read-
143 148 only file system.
144 149
145 150
146 151
147 152 The unlink() and unlinkat() functions may fail if:
148 153
149 154 ENAMETOOLONG
150 155 Pathname resolution of a symbolic link produced an
151 156 intermediate result whose length exceeds {PATH_MAX}.
152 157
153 158
154 159 ETXTBSY
155 160 The entry to be unlinked is the last directory entry to
156 161 a pure procedure (shared text) file that is being
157 162 executed.
158 163
159 164
160 165 USAGE
161 166 Applications should use rmdir(2) to remove a directory.
162 167
163 168 ATTRIBUTES
164 169 See attributes(5) for descriptions of the following attributes:
165 170
166 171
167 172
168 173
169 174 +--------------------+----------------------------------------------+
170 175 | ATTRIBUTE TYPE | ATTRIBUTE VALUE |
171 176 +--------------------+----------------------------------------------+
172 177 |Interface Stability | unlink() is Standard; unlinkat() is Evolving |
↓ open down ↓ |
70 lines elided |
↑ open up ↑ |
173 178 +--------------------+----------------------------------------------+
174 179 |MT-Level | Async-Signal-Safe |
175 180 +--------------------+----------------------------------------------+
176 181
177 182 SEE ALSO
178 183 rm(1), close(2), link(2), open(2), rmdir(2), remove(3C), attributes(5),
179 184 privileges(5), fsattr(5)
180 185
181 186
182 187
183 - May 18, 2007 UNLINK(2)
188 + December 7, 2016 UNLINK(2)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX