Print this page
7656 unlinking directory on tmpfs can cause kernel panic
   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


  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


   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 .\" Copyright 2016 RackTop Systems.
   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
   7 .\" http://www.opengroup.org/bookstore/.
   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.
   9 .\"  This notice shall appear on any product containing this material.
  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.
  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.
  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]
  13 .TH UNLINK 2 "Dec 15, 2016"
  14 .SH NAME
  15 unlink, unlinkat \- remove directory entry
  16 .SH SYNOPSIS
  17 .LP
  18 .nf
  19 #include <unistd.h>
  20 
  21 \fBint\fR \fBunlink\fR(\fBconst char *\fR\fIpath\fR);
  22 .fi
  23 
  24 .LP
  25 .nf
  26 \fBint\fR \fBunlinkat\fR(\fBint\fR \fIdirfd\fR, \fBconst char *\fR\fIpath\fR, \fBint\fR \fIflag\fR);
  27 .fi
  28 
  29 .SH DESCRIPTION
  30 .sp
  31 .LP
  32 The \fBunlink()\fR function removes a link to a file. If \fIpath\fR names a
  33 symbolic link, \fBunlink()\fR removes the symbolic link named by \fIpath\fR and


  45 relative and \fIdirfd\fR has the value \fBAT_FDCWD\fR, defined in
  46 <\fBfcntl.h\fR>, \fBunlinkat()\fR also behaves the same as \fBunlink()\fR.
  47 Otherwise, \fIpath\fR is resolved relative to the directory referenced by the
  48 \fIdirfd\fR argument.
  49 .sp
  50 .LP
  51 If the \fIflag\fR argument is set to the value \fBAT_REMOVEDIR\fR, defined in
  52 <\fBfcntl.h\fR>, \fBunlinkat()\fR behaves the same as \fBrmdir\fR(2) except in
  53 the processing of the \fIpath\fR argument as described above.
  54 .sp
  55 .LP
  56 When the file's link count becomes 0 and no process has the file open, the
  57 space occupied by the file will be freed and the file is no longer accessible.
  58 If one or more processes have the file open when the last link is removed, the
  59 link is removed before \fBunlink()\fR or \fBunlinkat()\fR returns, but the
  60 removal of the file contents is postponed until all references to the file are
  61 closed.
  62 .sp
  63 .LP
  64 If the \fIpath\fR argument is a directory and the filesystem supports
  65 \fBunlink()\fR and \fBunlinkat()\fR on directories the behaviour is dependent
  66 on the filesystem.




  67 .sp
  68 .LP
  69 If the \fIpath\fR argument is a directory and the filesystem does not support
  70 \fBunlink()\fR and \fBunlink()\fR on directories (for example, ZFS), the call
  71 will fail with \fBerrno\fR set to \fBEPERM\fR.
  72 .sp
  73 .LP
  74 Upon successful completion, \fBunlink()\fR and \fBunlinkat()\fR will mark for
  75 update the \fBst_ctime\fR and \fBst_mtime\fR fields of the parent directory.
  76 If the file's link count is not 0, the \fBst_ctime\fR field of the file will be
  77 marked for update.
  78 .SH RETURN VALUES
  79 .sp
  80 .LP
  81 Upon successful completion, \fB0\fR is returned.  Otherwise, \fB\(mi1\fR is
  82 returned, \fBerrno\fR is set to indicate the error, and the file is not
  83 unlinked.
  84 .SH ERRORS
  85 .sp
  86 .LP