xref: /trueos/lib/libc/sys/unlink.2 (revision ede42824618710ffa9ac08c805d8bf39bd5661ce)
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.\" 4. 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 April 25, 2010
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
47The
48.Fn unlink
49system call
50removes the link named by
51.Fa path
52from its directory and decrements the link count of the
53file which was referenced by the link.
54If that decrement reduces the link count of the file
55to zero,
56and no process has the file open, then
57all resources associated with the file are reclaimed.
58If one or more process have the file open when the last link is removed,
59the link is removed, but the removal of the file is delayed until
60all references to it have been closed.
61The
62.Fa path
63argument
64may not be a directory.
65.Pp
66The
67.Fn unlinkat
68system call is equivalent to
69.Fn unlink
70or
71.Fn rmdir
72except in the case where
73.Fa path
74specifies a relative path.
75In this case the directory entry to be removed is determined
76relative to the directory associated with the file descriptor
77.Fa fd
78instead of the current working directory.
79.Pp
80The values for
81.Fa flag
82are constructed by a bitwise-inclusive OR of flags from the following list,
83defined in
84.In fcntl.h :
85.Bl -tag -width indent
86.It Dv AT_REMOVEDIR
87Remove the directory entry specified by
88.Fa fd
89and
90.Fa path
91as a directory, not a normal file.
92.El
93.Pp
94If
95.Fn unlinkat
96is passed the special value
97.Dv AT_FDCWD
98in the
99.Fa fd
100parameter, the current working directory is used and the behavior is
101identical to a call to
102.Fa unlink
103or
104.Fa rmdir
105respectively, depending on whether or not the
106.Dv AT_REMOVEDIR
107bit is set in flag.
108.Sh RETURN VALUES
109.Rv -std unlink
110.Sh ERRORS
111The
112.Fn unlink
113succeeds unless:
114.Bl -tag -width Er
115.It Bq Er ENOTDIR
116A component of the path prefix is not a directory.
117.It Bq Er EISDIR
118The named file is a directory.
119.It Bq Er ENAMETOOLONG
120A component of a pathname exceeded 255 characters,
121or an entire path name exceeded 1023 characters.
122.It Bq Er ENOENT
123The named file does not exist.
124.It Bq Er EACCES
125Search permission is denied for a component of the path prefix.
126.It Bq Er EACCES
127Write permission is denied on the directory containing the link
128to be removed.
129.It Bq Er ELOOP
130Too many symbolic links were encountered in translating the pathname.
131.It Bq Er EPERM
132The named file is a directory.
133.It Bq Er EPERM
134The named file has its immutable, undeletable or append-only flag set, see the
135.Xr chflags 2
136manual page for more information.
137.It Bq Er EPERM
138The parent directory of the named file has its immutable or append-only flag
139set.
140.It Bq Er EPERM
141The directory containing the file is marked sticky,
142and neither the containing directory nor the file to be removed
143are owned by the effective user ID.
144.It Bq Er EIO
145An I/O error occurred while deleting the directory entry
146or deallocating the inode.
147.It Bq Er EROFS
148The named file resides on a read-only file system.
149.It Bq Er EFAULT
150The
151.Fa path
152argument
153points outside the process's allocated address space.
154.El
155.Pp
156In addition to the errors returned by the
157.Fn unlink ,
158the
159.Fn unlinkat
160may fail if:
161.Bl -tag -width Er
162.It Bq Er EBADF
163The
164.Fa path
165argument does not specify an absolute path and the
166.Fa fd
167argument is neither
168.Dv AT_FDCWD
169nor a valid file descriptor open for searching.
170.It Bq Er ENOTEMPTY
171The
172.Fa flag
173parameter has the
174.Dv AT_REMOVEDIR
175bit set and the
176.Fa path
177argument names a directory that is not an empty directory,
178or there are hard links to the directory other than dot or
179a single entry in dot-dot.
180.It Bq Er ENOTDIR
181The
182.Fa flag
183parameter has the
184.Dv AT_REMOVEDIR
185bit set and
186.Fa path
187does not name a directory.
188.It Bq Er EINVAL
189The value of the
190.Fa flag
191argument is not valid.
192.It Bq Er ENOTDIR
193The
194.Fa path
195argument is not an absolute path and
196.Fa fd
197is neither
198.Dv AT_FDCWD
199nor a file descriptor associated with a directory.
200.El
201.Sh SEE ALSO
202.Xr chflags 2 ,
203.Xr close 2 ,
204.Xr link 2 ,
205.Xr rmdir 2 ,
206.Xr symlink 7
207.Sh STANDARDS
208The
209.Fn unlinkat
210system call follows The Open Group Extended API Set 2 specification.
211.Sh HISTORY
212The
213.Fn unlink
214function appeared in
215.At v6 .
216The
217.Fn unlinkat
218system call appeared in
219.Fx 8.0 .
220.Pp
221The
222.Fn unlink
223system call traditionally allows the super-user to unlink directories which
224can damage the file system integrity.
225This implementation no longer permits it.
226