Print this page
7656 unlinking directory on tmpfs can cause kernel panic
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
↓ open down ↓ |
39 lines elided |
↑ open up ↑ |
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 - unlink() and unlinkat() on directories, the directory is unlinked from
51 - its parent with no cleanup being performed. In UFS, the disconnected
52 - directory will be found the next time the filesystem is checked with
53 - fsck(1M). The unlink() and unlinkat() functions will not fail simply
54 - because a directory is not empty. The user with appropriate privileges
55 - can orphan a non-empty directory without generating an error message.
50 + unlink() and unlinkat() on directories the behaviour is dependent on
51 + the filesystem.
56 52
57 53
58 54 If the path argument is a directory and the filesystem does not support
59 55 unlink() and unlink() on directories (for example, ZFS), the call will
60 56 fail with errno set to EPERM.
61 57
62 58
63 59 Upon successful completion, unlink() and unlinkat() will mark for
64 60 update the st_ctime and st_mtime fields of the parent directory. If
65 61 the file's link count is not 0, the st_ctime field of the file will be
66 62 marked for update.
67 63
68 64 RETURN VALUES
69 65 Upon successful completion, 0 is returned. Otherwise, -1 is returned,
70 66 errno is set to indicate the error, and the file is not unlinked.
71 67
72 68 ERRORS
73 69 The unlink() and unlinkat() functions will fail if:
74 70
75 71 EACCES
76 72 Search permission is denied for a component of the path
77 73 prefix, or write permission is denied on the directory
78 74 containing the link to be removed.
79 75
80 76
81 77 EACCES
82 78 The parent directory has the sticky bit set and the
83 79 file is not writable by the user, the user does not own
84 80 the parent directory, the user does not own the file,
85 81 and the user is not a privileged user.
86 82
87 83
88 84 EBUSY
89 85 The entry to be unlinked is the mount point for a
90 86 mounted file system.
91 87
92 88
93 89 EFAULT
94 90 The path argument points to an illegal address.
95 91
96 92
97 93 EILSEQ
98 94 The path argument includes non-UTF8 characters and the
99 95 file system accepts only file names where all
100 96 characters are part of the UTF-8 character codeset.
101 97
102 98
103 99 EINTR
104 100 A signal was caught during the execution of the
105 101 unlink() function.
106 102
107 103
108 104 ELOOP
109 105 Too many symbolic links were encountered in translating
110 106 path.
111 107
112 108
113 109 ENAMETOOLONG
114 110 The length of the path argument exceeds PATH_MAX, or
115 111 the length of a path component exceeds NAME_MAX while
116 112 _POSIX_NO_TRUNC is in effect.
117 113
118 114
119 115 ENOENT
120 116 The named file does not exist or is a null pathname.
121 117
122 118
123 119 ENOLINK
124 120 The path argument points to a remote machine and the
125 121 link to that machine is no longer active.
126 122
127 123
128 124 ENOTDIR
129 125 A component of the path prefix is not a directory or
130 126 the provided directory descriptor for unlinkat() is not
131 127 AT_FDCWD or does not reference a directory.
132 128
133 129
134 130 EPERM
135 131 The named file is a directory and {PRIV_SYS_LINKDIR} is
136 132 not asserted in the effective set of the calling
137 133 process, or the filesystem implementation does not
138 134 support unlink() or unlinkat() on directories.
139 135
140 136
141 137 EROFS
142 138 The directory entry to be unlinked is part of a read-
143 139 only file system.
144 140
145 141
146 142
147 143 The unlink() and unlinkat() functions may fail if:
148 144
149 145 ENAMETOOLONG
150 146 Pathname resolution of a symbolic link produced an
151 147 intermediate result whose length exceeds {PATH_MAX}.
152 148
153 149
154 150 ETXTBSY
155 151 The entry to be unlinked is the last directory entry to
156 152 a pure procedure (shared text) file that is being
157 153 executed.
158 154
159 155
160 156 USAGE
161 157 Applications should use rmdir(2) to remove a directory.
162 158
163 159 ATTRIBUTES
164 160 See attributes(5) for descriptions of the following attributes:
165 161
166 162
167 163
168 164
169 165 +--------------------+----------------------------------------------+
170 166 | ATTRIBUTE TYPE | ATTRIBUTE VALUE |
171 167 +--------------------+----------------------------------------------+
172 168 |Interface Stability | unlink() is Standard; unlinkat() is Evolving |
↓ open down ↓ |
107 lines elided |
↑ open up ↑ |
173 169 +--------------------+----------------------------------------------+
174 170 |MT-Level | Async-Signal-Safe |
175 171 +--------------------+----------------------------------------------+
176 172
177 173 SEE ALSO
178 174 rm(1), close(2), link(2), open(2), rmdir(2), remove(3C), attributes(5),
179 175 privileges(5), fsattr(5)
180 176
181 177
182 178
183 - May 18, 2007 UNLINK(2)
179 + December 15, 2016 UNLINK(2)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX