]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/unlink.2
Update bmake to version 20180919
[FreeBSD/FreeBSD.git] / lib / libc / sys / unlink.2
1 .\" Copyright (c) 1980, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)unlink.2    8.1 (Berkeley) 6/4/93
29 .\" $FreeBSD$
30 .\"
31 .Dd November 11, 2018
32 .Dt UNLINK 2
33 .Os
34 .Sh NAME
35 .Nm unlink ,
36 .Nm unlinkat
37 .Nd remove directory entry
38 .Sh LIBRARY
39 .Lb libc
40 .Sh SYNOPSIS
41 .In unistd.h
42 .Ft int
43 .Fn unlink "const char *path"
44 .Ft int
45 .Fn unlinkat "int fd" "const char *path" "int flag"
46 .Sh DESCRIPTION
47 The
48 .Fn unlink
49 system call
50 removes the link named by
51 .Fa path
52 from its directory and decrements the link count of the
53 file which was referenced by the link.
54 If that decrement reduces the link count of the file
55 to zero,
56 and no process has the file open, then
57 all resources associated with the file are reclaimed.
58 If one or more process have the file open when the last link is removed,
59 the link is removed, but the removal of the file is delayed until
60 all references to it have been closed.
61 The
62 .Fa path
63 argument
64 may not be a directory.
65 .Pp
66 The
67 .Fn unlinkat
68 system call is equivalent to
69 .Fn unlink
70 or
71 .Fn rmdir
72 except in the case where
73 .Fa path
74 specifies a relative path.
75 In this case the directory entry to be removed is determined
76 relative to the directory associated with the file descriptor
77 .Fa fd
78 instead of the current working directory.
79 .Pp
80 The values for
81 .Fa flag
82 are constructed by a bitwise-inclusive OR of flags from the following list,
83 defined in
84 .In fcntl.h :
85 .Bl -tag -width indent
86 .It Dv AT_REMOVEDIR
87 Remove the directory entry specified by
88 .Fa fd
89 and
90 .Fa path
91 as a directory, not a normal file.
92 .It Dv AT_BENEATH
93 Only unlink files and directories which are beneath of the topping
94 directory.
95 See the description of the
96 .Dv O_BENEATH
97 flag in the
98 .Xr open 2
99 manual page.
100 .El
101 .Pp
102 If
103 .Fn unlinkat
104 is passed the special value
105 .Dv AT_FDCWD
106 in the
107 .Fa fd
108 parameter, the current working directory is used and the behavior is
109 identical to a call to
110 .Fa unlink
111 or
112 .Fa rmdir
113 respectively, depending on whether or not the
114 .Dv AT_REMOVEDIR
115 bit is set in flag.
116 .Sh RETURN VALUES
117 .Rv -std unlink
118 .Sh ERRORS
119 The
120 .Fn unlink
121 succeeds unless:
122 .Bl -tag -width Er
123 .It Bq Er ENOTDIR
124 A component of the path prefix is not a directory.
125 .It Bq Er EISDIR
126 The named file is a directory.
127 .It Bq Er ENAMETOOLONG
128 A component of a pathname exceeded 255 characters,
129 or an entire path name exceeded 1023 characters.
130 .It Bq Er ENOENT
131 The named file does not exist.
132 .It Bq Er EACCES
133 Search permission is denied for a component of the path prefix.
134 .It Bq Er EACCES
135 Write permission is denied on the directory containing the link
136 to be removed.
137 .It Bq Er ELOOP
138 Too many symbolic links were encountered in translating the pathname.
139 .It Bq Er EPERM
140 The named file is a directory.
141 .It Bq Er EPERM
142 The named file has its immutable, undeletable or append-only flag set, see the
143 .Xr chflags 2
144 manual page for more information.
145 .It Bq Er EPERM
146 The parent directory of the named file has its immutable or append-only flag
147 set.
148 .It Bq Er EPERM
149 The directory containing the file is marked sticky,
150 and neither the containing directory nor the file to be removed
151 are owned by the effective user ID.
152 .It Bq Er EIO
153 An I/O error occurred while deleting the directory entry
154 or deallocating the inode.
155 .It Bq Er EROFS
156 The named file resides on a read-only file system.
157 .It Bq Er EFAULT
158 The
159 .Fa path
160 argument
161 points outside the process's allocated address space.
162 .It Bq Er ENOSPC
163 On file systems supporting copy-on-write or snapshots, there was not enough
164 free space to record metadata for the delete operation of the file.
165 .El
166 .Pp
167 In addition to the errors returned by the
168 .Fn unlink ,
169 the
170 .Fn unlinkat
171 may fail if:
172 .Bl -tag -width Er
173 .It Bq Er EBADF
174 The
175 .Fa path
176 argument does not specify an absolute path and the
177 .Fa fd
178 argument is neither
179 .Dv AT_FDCWD
180 nor a valid file descriptor open for searching.
181 .It Bq Er ENOTEMPTY
182 The
183 .Fa flag
184 parameter has the
185 .Dv AT_REMOVEDIR
186 bit set and the
187 .Fa path
188 argument names a directory that is not an empty directory,
189 or there are hard links to the directory other than dot or
190 a single entry in dot-dot.
191 .It Bq Er ENOTDIR
192 The
193 .Fa flag
194 parameter has the
195 .Dv AT_REMOVEDIR
196 bit set and
197 .Fa path
198 does not name a directory.
199 .It Bq Er EINVAL
200 The value of the
201 .Fa flag
202 argument is not valid.
203 .It Bq Er ENOTDIR
204 The
205 .Fa path
206 argument is not an absolute path and
207 .Fa fd
208 is neither
209 .Dv AT_FDCWD
210 nor a file descriptor associated with a directory.
211 .It Bq Er ENOTCAPABLE
212 .Fa path
213 is an absolute path,
214 or contained a ".." component leading to a
215 directory outside of the directory hierarchy specified by
216 .Fa fd ,
217 and the process is in capability mode.
218 .It Bq Er ENOTCAPABLE
219 The
220 .Dv AT_BENEATH
221 flag was provided to
222 .Fn unlinkat ,
223 and the absolute
224 .Fa path
225 does not have its tail fully contained under the topping directory,
226 or the relative
227 .Fa path
228 escapes it.
229 .El
230 .Sh SEE ALSO
231 .Xr chflags 2 ,
232 .Xr close 2 ,
233 .Xr link 2 ,
234 .Xr rmdir 2 ,
235 .Xr symlink 7
236 .Sh STANDARDS
237 The
238 .Fn unlinkat
239 system call follows The Open Group Extended API Set 2 specification.
240 .Sh HISTORY
241 The
242 .Fn unlink
243 function appeared in
244 .At v1 .
245 The
246 .Fn unlinkat
247 system call appeared in
248 .Fx 8.0 .
249 .Pp
250 The
251 .Fn unlink
252 system call traditionally allows the super-user to unlink directories which
253 can damage the file system integrity.
254 This implementation no longer permits it.