-
Notifications
You must be signed in to change notification settings - Fork 0
/
unlink.html
466 lines (330 loc) · 12 KB
/
unlink.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
<!-- Creator : groff version 1.22.4 -->
<!-- CreationDate: Wed Jan 29 11:26:02 2020 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>UNLINK</title>
</head>
<body>
<h1 align="center">UNLINK</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#RETURN VALUE">RETURN VALUE</a><br>
<a href="#ERRORS">ERRORS</a><br>
<a href="#VERSIONS">VERSIONS</a><br>
<a href="#CONFORMING TO">CONFORMING TO</a><br>
<a href="#NOTES">NOTES</a><br>
<a href="#BUGS">BUGS</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<a href="#COLOPHON">COLOPHON</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">unlink,
unlinkat - delete a name and possibly the file it refers
to</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>#include
<unistd.h></b></p>
<p style="margin-left:11%; margin-top: 1em"><b>int
unlink(const char *</b><i>pathname</i><b>);</b></p>
<p style="margin-left:11%; margin-top: 1em"><b>#include
<fcntl.h></b> /* Definition of AT_* constants */
<b><br>
#include <unistd.h></b></p>
<p style="margin-left:11%; margin-top: 1em"><b>int
unlinkat(int</b> <i>dirfd</i><b>, const char
*</b><i>pathname</i><b>, int</b> <i>flags</i><b>);</b></p>
<p style="margin-left:5%; margin-top: 1em">Feature Test
Macro Requirements for glibc (see
<b>feature_test_macros</b>(7)):</p>
<p style="margin-left:11%; margin-top: 1em"><b>unlinkat</b>():</p>
<p style="margin-left:17%;">Since glibc 2.10:</p>
<p style="margin-left:23%;">_POSIX_C_SOURCE >= 200809L</p>
<p style="margin-left:17%;">Before glibc 2.10:</p>
<p style="margin-left:23%;">_ATFILE_SOURCE</p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>unlink</b>()
deletes a name from the filesystem. If that name was the
last link to a file and no processes have the file open, the
file is deleted and the space it was using is made available
for reuse.</p>
<p style="margin-left:11%; margin-top: 1em">If the name was
the last link to a file but any processes still have the
file open, the file will remain in existence until the last
file descriptor referring to it is closed.</p>
<p style="margin-left:11%; margin-top: 1em">If the name
referred to a symbolic link, the link is removed.</p>
<p style="margin-left:11%; margin-top: 1em">If the name
referred to a socket, FIFO, or device, the name for it is
removed but processes which have the object open may
continue to use it.</p>
<p style="margin-left:11%; margin-top: 1em"><b>unlinkat()</b>
<br>
The <b>unlinkat</b>() system call operates in exactly the
same way as either <b>unlink</b>() or <b>rmdir</b>(2)
(depending on whether or not <i>flags</i> includes the
<b>AT_REMOVEDIR</b> flag) except for the differences
described here.</p>
<p style="margin-left:11%; margin-top: 1em">If the pathname
given in <i>pathname</i> is relative, then it is interpreted
relative to the directory referred to by the file descriptor
<i>dirfd</i> (rather than relative to the current working
directory of the calling process, as is done by
<b>unlink</b>() and <b>rmdir</b>(2) for a relative
pathname).</p>
<p style="margin-left:11%; margin-top: 1em">If the pathname
given in <i>pathname</i> is relative and <i>dirfd</i> is the
special value <b>AT_FDCWD</b>, then <i>pathname</i> is
interpreted relative to the current working directory of the
calling process (like <b>unlink</b>() and
<b>rmdir</b>(2)).</p>
<p style="margin-left:11%; margin-top: 1em">If the pathname
given in <i>pathname</i> is absolute, then <i>dirfd</i> is
ignored.</p>
<p style="margin-left:11%; margin-top: 1em"><i>flags</i> is
a bit mask that can either be specified as 0, or by ORing
together flag values that control the operation of
<b>unlinkat</b>(). Currently, only one such flag is defined:
<b><br>
AT_REMOVEDIR</b></p>
<p style="margin-left:22%;">By default, <b>unlinkat</b>()
performs the equivalent of <b>unlink</b>() on
<i>pathname</i>. If the <b>AT_REMOVEDIR</b> flag is
specified, then performs the equivalent of <b>rmdir</b>(2)
on <i>pathname</i>.</p>
<p style="margin-left:11%; margin-top: 1em">See
<b>openat</b>(2) for an explanation of the need for
<b>unlinkat</b>().</p>
<h2>RETURN VALUE
<a name="RETURN VALUE"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">On success,
zero is returned. On error, -1 is returned, and <i>errno</i>
is set appropriately.</p>
<h2>ERRORS
<a name="ERRORS"></a>
</h2>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p style="margin-top: 1em"><b>EACCES</b></p></td>
<td width="2%"></td>
<td width="78%">
<p style="margin-top: 1em">Write access to the directory
containing <i>pathname</i> is not allowed for the
process’s effective UID, or one of the directories in
<i>pathname</i> did not allow search permission. (See also
<b>path_resolution</b>(7).)</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EBUSY</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The file <i>pathname</i> cannot be unlinked because it
is being used by the system or another process; for example,
it is a mount point or the NFS client software created it to
represent an active but otherwise nameless inode ("NFS
silly renamed").</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EFAULT</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><i>pathname</i> points outside your accessible address
space.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EIO</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>An I/O error occurred.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EISDIR</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><i>pathname</i> refers to a directory. (This is the
non-POSIX value returned by Linux since 2.1.132.)</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ELOOP</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>Too many symbolic links were encountered in translating
<i>pathname</i>.</p> </td></tr>
</table>
<p style="margin-left:11%;"><b>ENAMETOOLONG</b></p>
<p style="margin-left:22%;"><i>pathname</i> was too
long.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ENOENT</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>A component in <i>pathname</i> does not exist or is a
dangling symbolic link, or <i>pathname</i> is empty.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ENOMEM</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>Insufficient kernel memory was available.</p></td></tr>
</table>
<p style="margin-left:11%;"><b>ENOTDIR</b></p>
<p style="margin-left:22%;">A component used as a directory
in <i>pathname</i> is not, in fact, a directory.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="7%">
<p><b>EPERM</b></p></td>
<td width="4%"></td>
<td width="78%">
<p>The system does not allow unlinking of directories, or
unlinking of directories requires privileges that the
calling process doesn’t have. (This is the POSIX
prescribed error return; as noted above, Linux returns
<b>EISDIR</b> for this case.)</p></td></tr>
</table>
<p style="margin-left:11%;"><b>EPERM</b> (Linux only)</p>
<p style="margin-left:22%;">The filesystem does not allow
unlinking of files.</p>
<p style="margin-left:11%;"><b>EPERM</b> or
<b>EACCES</b></p>
<p style="margin-left:22%;">The directory containing
<i>pathname</i> has the sticky bit (<b>S_ISVTX</b>) set and
the process’s effective UID is neither the UID of the
file to be deleted nor that of the directory containing it,
and the process is not privileged (Linux: does not have the
<b>CAP_FOWNER</b> capability).</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="7%">
<p><b>EPERM</b></p></td>
<td width="4%"></td>
<td width="78%">
<p>The file to be unlinked is marked immutable or
append-only. (See <b>ioctl_iflags</b>(2).)</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="7%">
<p><b>EROFS</b></p></td>
<td width="4%"></td>
<td width="78%">
<p><i>pathname</i> refers to a file on a read-only
filesystem.</p> </td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em">The same errors
that occur for <b>unlink</b>() and <b>rmdir</b>(2) can also
occur for <b>unlinkat</b>(). The following additional errors
can occur for <b>unlinkat</b>():</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p style="margin-top: 1em"><b>EBADF</b></p></td>
<td width="2%"></td>
<td width="78%">
<p style="margin-top: 1em"><i>dirfd</i> is not a valid file
descriptor.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>An invalid flag value was specified in <i>flags</i>.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EISDIR</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><i>pathname</i> refers to a directory, and
<b>AT_REMOVEDIR</b> was not specified in <i>flags</i>.</p></td></tr>
</table>
<p style="margin-left:11%;"><b>ENOTDIR</b></p>
<p style="margin-left:22%;"><i>pathname</i> is relative and
<i>dirfd</i> is a file descriptor referring to a file other
than a directory.</p>
<h2>VERSIONS
<a name="VERSIONS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>unlinkat</b>()
was added to Linux in kernel 2.6.16; library support was
added to glibc in version 2.4.</p>
<h2>CONFORMING TO
<a name="CONFORMING TO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>unlink</b>():
SVr4, 4.3BSD, POSIX.1-2001, POSIX.1-2008.</p>
<p style="margin-left:11%; margin-top: 1em"><b>unlinkat</b>():
POSIX.1-2008.</p>
<h2>NOTES
<a name="NOTES"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>Glibc
notes</b> <br>
On older kernels where <b>unlinkat</b>() is unavailable, the
glibc wrapper function falls back to the use of
<b>unlink</b>() or <b>rmdir</b>(2). When <i>pathname</i> is
a relative pathname, glibc constructs a pathname based on
the symbolic link in <i>/proc/self/fd</i> that corresponds
to the <i>dirfd</i> argument.</p>
<h2>BUGS
<a name="BUGS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">Infelicities in
the protocol underlying NFS can cause the unexpected
disappearance of files which are still being used.</p>
<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>rm</b>(1),
<b>unlink</b>(1), <b>chmod</b>(2), <b>link</b>(2),
<b>mknod</b>(2), <b>open</b>(2), <b>rename</b>(2),
<b>rmdir</b>(2), <b>mkfifo</b>(3), <b>remove</b>(3),
<b>path_resolution</b>(7), <b>symlink</b>(7)</p>
<h2>COLOPHON
<a name="COLOPHON"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">This page is
part of release 5.02 of the Linux <i>man-pages</i> project.
A description of the project, information about reporting
bugs, and the latest version of this page, can be found at
https://www.kernel.org/doc/man-pages/.</p>
<hr>
</body>
</html>