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