1 '\" te 2 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved. 3 .\" Copyright 1989 AT&T 4 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved. 5 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at 6 .\" http://www.opengroup.org/bookstore/. 7 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html. 8 .\" This notice shall appear on any product containing this material. 9 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. 10 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. 11 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] 12 .TH UNLINK 2 "May 18, 2007" 13 .SH NAME 14 unlink, unlinkat \- remove directory entry 15 .SH SYNOPSIS 16 .LP 17 .nf 18 #include <unistd.h> 19 20 \fBint\fR \fBunlink\fR(\fBconst char *\fR\fIpath\fR); 21 .fi 22 23 .LP 24 .nf 25 \fBint\fR \fBunlinkat\fR(\fBint\fR \fIdirfd\fR, \fBconst char *\fR\fIpath\fR, \fBint\fR \fIflag\fR); 26 .fi 27 28 .SH DESCRIPTION 29 .sp 30 .LP 31 The \fBunlink()\fR function removes a link to a file. If \fIpath\fR names a 32 symbolic link, \fBunlink()\fR removes the symbolic link named by \fIpath\fR and 33 does not affect any file or directory named by the contents of the symbolic 34 link. Otherwise, \fBunlink()\fR removes the link named by the pathname pointed 35 to by \fIpath\fR and decrements the link count of the file referenced by the 36 link. 37 .sp 38 .LP 39 The \fBunlinkat()\fR function also removes a link to a file. See 40 \fBfsattr\fR(5). If the \fIflag\fR argument is 0, the behavior of 41 \fBunlinkat()\fR is the same as \fBunlink()\fR except in the processing of its 42 \fIpath\fR argument. If \fIpath\fR is absolute, \fBunlinkat()\fR behaves the 43 same as \fBunlink()\fR and the \fIdirfd\fR argument is unused. If \fIpath\fR is 44 relative and \fIdirfd\fR has the value \fBAT_FDCWD\fR, defined in 45 <\fBfcntl.h\fR>, \fBunlinkat()\fR also behaves the same as \fBunlink()\fR. 46 Otherwise, \fIpath\fR is resolved relative to the directory referenced by the 47 \fIdirfd\fR argument. 48 .sp 49 .LP 50 If the \fIflag\fR argument is set to the value \fBAT_REMOVEDIR\fR, defined in 51 <\fBfcntl.h\fR>, \fBunlinkat()\fR behaves the same as \fBrmdir\fR(2) except in 52 the processing of the \fIpath\fR argument as described above. 53 .sp 54 .LP 55 When the file's link count becomes 0 and no process has the file open, the 56 space occupied by the file will be freed and the file is no longer accessible. 57 If one or more processes have the file open when the last link is removed, the 58 link is removed before \fBunlink()\fR or \fBunlinkat()\fR returns, but the 59 removal of the file contents is postponed until all references to the file are 60 closed. 61 .sp 62 .LP 63 If the \fIpath\fR argument is a directory and the filesystem supports 64 \fBunlink()\fR and \fBunlinkat()\fR on directories, the directory is unlinked 65 from its parent with no cleanup being performed. In UFS, the disconnected 66 directory will be found the next time the filesystem is checked with 67 \fBfsck\fR(1M). The \fBunlink()\fR and \fBunlinkat()\fR functions will not fail 68 simply because a directory is not empty. The user with appropriate privileges 69 can orphan a non-empty directory without generating an error message. 70 .sp 71 .LP 72 If the \fIpath\fR argument is a directory and the filesystem does not support 73 \fBunlink()\fR and \fBunlink()\fR on directories (for example, ZFS), the call 74 will fail with \fBerrno\fR set to \fBEPERM\fR. 75 .sp 76 .LP 77 Upon successful completion, \fBunlink()\fR and \fBunlinkat()\fR will mark for 78 update the \fBst_ctime\fR and \fBst_mtime\fR fields of the parent directory. 79 If the file's link count is not 0, the \fBst_ctime\fR field of the file will be 80 marked for update. 81 .SH RETURN VALUES 82 .sp 83 .LP 84 Upon successful completion, \fB0\fR is returned. Otherwise, \fB\(mi1\fR is 85 returned, \fBerrno\fR is set to indicate the error, and the file is not 86 unlinked. 87 .SH ERRORS 88 .sp 89 .LP 90 The \fBunlink()\fR and \fBunlinkat()\fR functions will fail if: 91 .sp 92 .ne 2 93 .na 94 \fB\fBEACCES\fR\fR 95 .ad 96 .RS 16n 97 Search permission is denied for a component of the \fIpath\fR prefix, or write 98 permission is denied on the directory containing the link to be removed. 99 .RE 100 101 .sp 102 .ne 2 103 .na 104 \fB\fBEACCES\fR\fR 105 .ad 106 .RS 16n 107 The parent directory has the sticky bit set and the file is not writable by the 108 user, the user does not own the parent directory, the user does not own the 109 file, and the user is not a privileged user. 110 .RE 111 112 .sp 113 .ne 2 114 .na 115 \fB\fBEBUSY\fR\fR 116 .ad 117 .RS 16n 118 The entry to be unlinked is the mount point for a mounted file system. 119 .RE 120 121 .sp 122 .ne 2 123 .na 124 \fB\fBEFAULT\fR\fR 125 .ad 126 .RS 16n 127 The \fIpath\fR argument points to an illegal address. 128 .RE 129 130 .sp 131 .ne 2 132 .na 133 \fB\fBEILSEQ\fR\fR 134 .ad 135 .RS 16n 136 The path argument includes non-UTF8 characters and the file system accepts only 137 file names where all characters are part of the UTF-8 character codeset. 138 .RE 139 140 .sp 141 .ne 2 142 .na 143 \fB\fBEINTR\fR\fR 144 .ad 145 .RS 16n 146 A signal was caught during the execution of the \fBunlink()\fR function. 147 .RE 148 149 .sp 150 .ne 2 151 .na 152 \fB\fBELOOP\fR\fR 153 .ad 154 .RS 16n 155 Too many symbolic links were encountered in translating \fIpath\fR. 156 .RE 157 158 .sp 159 .ne 2 160 .na 161 \fB\fBENAMETOOLONG\fR\fR 162 .ad 163 .RS 16n 164 The length of the \fIpath\fR argument exceeds \fBPATH_MAX\fR, or the length of 165 a \fIpath\fR component exceeds \fBNAME_MAX\fR while \fB_POSIX_NO_TRUNC\fR is in 166 effect. 167 .RE 168 169 .sp 170 .ne 2 171 .na 172 \fB\fBENOENT\fR\fR 173 .ad 174 .RS 16n 175 The named file does not exist or is a null pathname. 176 .RE 177 178 .sp 179 .ne 2 180 .na 181 \fB\fBENOLINK\fR\fR 182 .ad 183 .RS 16n 184 The \fIpath\fR argument points to a remote machine and the link to that machine 185 is no longer active. 186 .RE 187 188 .sp 189 .ne 2 190 .na 191 \fB\fBENOTDIR\fR\fR 192 .ad 193 .RS 16n 194 A component of the \fIpath\fR prefix is not a directory or the provided 195 directory descriptor for \fBunlinkat()\fR is not \fBAT_FDCWD\fR or does not 196 reference a directory. 197 .RE 198 199 .sp 200 .ne 2 201 .na 202 \fB\fBEPERM\fR\fR 203 .ad 204 .RS 16n 205 The named file is a directory and {\fBPRIV_SYS_LINKDIR\fR} is not asserted in 206 the effective set of the calling process, or the filesystem implementation does 207 not support \fBunlink()\fR or \fBunlinkat()\fR on directories. 208 .RE 209 210 .sp 211 .ne 2 212 .na 213 \fB\fBEROFS\fR\fR 214 .ad 215 .RS 16n 216 The directory entry to be unlinked is part of a read-only file system. 217 .RE 218 219 .sp 220 .LP 221 The \fBunlink()\fR and \fBunlinkat()\fR functions may fail if: 222 .sp 223 .ne 2 224 .na 225 \fB\fBENAMETOOLONG\fR\fR 226 .ad 227 .RS 16n 228 Pathname resolution of a symbolic link produced an intermediate result whose 229 length exceeds {\fBPATH_MAX\fR}. 230 .RE 231 232 .sp 233 .ne 2 234 .na 235 \fB\fBETXTBSY\fR\fR 236 .ad 237 .RS 16n 238 The entry to be unlinked is the last directory entry to a pure procedure 239 (shared text) file that is being executed. 240 .RE 241 242 .SH USAGE 243 .sp 244 .LP 245 Applications should use \fBrmdir\fR(2) to remove a directory. 246 .SH ATTRIBUTES 247 .sp 248 .LP 249 See \fBattributes\fR(5) for descriptions of the following attributes: 250 .sp 251 252 .sp 253 .TS 254 box; 255 c | c 256 l | l . 257 ATTRIBUTE TYPE ATTRIBUTE VALUE 258 _ 259 Interface Stability T{ 260 \fBunlink()\fR is Standard; \fBunlinkat()\fR is Evolving 261 T} 262 _ 263 MT-Level Async-Signal-Safe 264 .TE 265 266 .SH SEE ALSO 267 .sp 268 .LP 269 \fBrm\fR(1), \fBclose\fR(2), \fBlink\fR(2), \fBopen\fR(2), \fBrmdir\fR(2), 270 \fBremove\fR(3C), \fBattributes\fR(5), \fBprivileges\fR(5), \fBfsattr\fR(5)