1.\" $NetBSD: sticky.7,v 1.7 2024/02/08 20:11:55 andvar Exp $ 2.\" 3.\" Copyright (c) 1980, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.\" @(#)sticky.8 8.1 (Berkeley) 6/5/93 31.\" 32.Dd May 10, 2011 33.Dt STICKY 7 34.Os 35.Sh NAME 36.Nm sticky 37.Nd Description of the `sticky' (S_ISVTX) bit functionality 38.Sh DESCRIPTION 39A special file mode, called the 40.Em sticky bit 41(mode 42.Dv S_ISVTX ) , 43is used to indicate special treatment for directories. 44See 45.Xr chmod 2 46or the file 47.Pa /usr/include/sys/stat.h 48.Ss Sticky files 49For regular files, the use of mode 50.Dv S_ISVTX 51is reserved and can be set only by the super-user. 52.Nx 53does not currently treat regular files that have the sticky bit set 54specially, but this behavior might change in the future. 55.Ss Sticky directories 56A directory whose 57.Dq sticky bit 58is set becomes a 59directory in which the deletion of files is restricted. 60A file in a sticky directory may only be removed or renamed 61by a user if the user has write permission for the directory and 62the user is the owner of the file, the owner of the directory, 63or the super-user. 64This feature is usefully applied to directories such as 65.Pa /tmp 66which must be publicly writable but should deny users the license 67to arbitrarily delete or rename each others' files. 68.Pp 69Any user may create a sticky directory. 70See 71.Xr chmod 1 72for details about modifying file modes. 73.Sh HISTORY 74The sticky bit first appeared in V7, and this manual page appeared 75in section 8. 76Its initial use was to mark shareable executables 77that were frequently used so that they would stay in swap after 78the process exited. 79Shareable executables were compiled in a special way so their text 80and read-only data could be shared amongst processes. 81.Xr vi 1 82and 83.Xr sh 1 84were such executables. 85This is where the term 86.Dq sticky 87comes from - the program would stick around in swap, and it would 88not have to be fetched again from the file system. 89Of course as long as there was a copy in the swap area, the file 90was marked busy so it could not be overwritten. 91On V7 this meant that the file could not be removed either, because 92busy executables could not be removed, but this restriction was 93lifted in BSD releases. 94.Pp 95To replace such executables was a cumbersome process. 96One had first to remove the sticky bit, then execute the binary so 97that the copy from swap was flushed, overwrite the executable, and 98finally reset the sticky bit. 99.Pp 100Later, on SunOS 4, the sticky bit got an additional meaning for 101files that had the bit set and were not executable: read and write 102operations from and to those files would go directly to the disk 103and bypass the buffer cache. 104This was typically used on swap files for NFS clients on an NFS 105server, so that swap I/O generated by the clients on the servers 106would not evict useful data from the server's buffer cache. 107.Sh BUGS 108Neither 109.Xr open 2 110nor 111.Xr mkdir 2 112will create a file with the sticky bit set. 113