xref: /netbsd-src/share/man/man7/sticky.7 (revision a5175f1e986253dff5bbe596a6ad8c22a091e4b6)
1*a5175f1eSandvar.\"	$NetBSD: sticky.7,v 1.7 2024/02/08 20:11:55 andvar Exp $
2a3b53d29Schristos.\"
3a3b53d29Schristos.\" Copyright (c) 1980, 1991, 1993
4a3b53d29Schristos.\"	The Regents of the University of California.  All rights reserved.
5a3b53d29Schristos.\"
6a3b53d29Schristos.\" Redistribution and use in source and binary forms, with or without
7a3b53d29Schristos.\" modification, are permitted provided that the following conditions
8a3b53d29Schristos.\" are met:
9a3b53d29Schristos.\" 1. Redistributions of source code must retain the above copyright
10a3b53d29Schristos.\"    notice, this list of conditions and the following disclaimer.
11a3b53d29Schristos.\" 2. Redistributions in binary form must reproduce the above copyright
12a3b53d29Schristos.\"    notice, this list of conditions and the following disclaimer in the
13a3b53d29Schristos.\"    documentation and/or other materials provided with the distribution.
14a3b53d29Schristos.\" 3. Neither the name of the University nor the names of its contributors
15a3b53d29Schristos.\"    may be used to endorse or promote products derived from this software
16a3b53d29Schristos.\"    without specific prior written permission.
17a3b53d29Schristos.\"
18a3b53d29Schristos.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19a3b53d29Schristos.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20a3b53d29Schristos.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21a3b53d29Schristos.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22a3b53d29Schristos.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23a3b53d29Schristos.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24a3b53d29Schristos.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25a3b53d29Schristos.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26a3b53d29Schristos.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27a3b53d29Schristos.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28a3b53d29Schristos.\" SUCH DAMAGE.
29a3b53d29Schristos.\"
30a3b53d29Schristos.\"     @(#)sticky.8	8.1 (Berkeley) 6/5/93
31a3b53d29Schristos.\"
3288152d88Sjruoho.Dd May 10, 2011
33193f31efSwiz.Dt STICKY 7
34a3b53d29Schristos.Os
35a3b53d29Schristos.Sh NAME
36a3b53d29Schristos.Nm sticky
37193f31efSwiz.Nd Description of the `sticky' (S_ISVTX) bit functionality
38a3b53d29Schristos.Sh DESCRIPTION
39a3b53d29SchristosA special file mode, called the
40a3b53d29Schristos.Em sticky bit
41193f31efSwiz(mode
42193f31efSwiz.Dv S_ISVTX ) ,
43a3b53d29Schristosis used to indicate special treatment for directories.
44a3b53d29SchristosSee
45a3b53d29Schristos.Xr chmod 2
46193f31efSwizor the file
47a3b53d29Schristos.Pa /usr/include/sys/stat.h
4888152d88Sjruoho.Ss Sticky files
49f59fec0dSrilligFor regular files, the use of mode
50193f31efSwiz.Dv S_ISVTX
51193f31efSwizis reserved and can be set only by the super-user.
52976cdb2bSchristos.Nx
53f59fec0dSrilligdoes not currently treat regular files that have the sticky bit set
54d48b7858Swizspecially, but this behavior might change in the future.
5588152d88Sjruoho.Ss Sticky directories
56193f31efSwizA directory whose
57193f31efSwiz.Dq sticky bit
58f59fec0dSrilligis set becomes a
59193f31efSwizdirectory in which the deletion of files is restricted.
60a3b53d29SchristosA file in a sticky directory may only be removed or renamed
61a3b53d29Schristosby a user if the user has write permission for the directory and
62a3b53d29Schristosthe user is the owner of the file, the owner of the directory,
63a3b53d29Schristosor the super-user.
64a3b53d29SchristosThis feature is usefully applied to directories such as
65a3b53d29Schristos.Pa /tmp
66193f31efSwizwhich must be publicly writable but should deny users the license
67193f31efSwizto arbitrarily delete or rename each others' files.
68a3b53d29Schristos.Pp
69a3b53d29SchristosAny user may create a sticky directory.
70a3b53d29SchristosSee
71a3b53d29Schristos.Xr chmod 1
72a3b53d29Schristosfor details about modifying file modes.
73193f31efSwiz.Sh HISTORY
74976cdb2bSchristosThe sticky bit first appeared in V7, and this manual page appeared
75d48b7858Swizin section 8.
76*a5175f1eSandvarIts initial use was to mark shareable executables
77976cdb2bSchristosthat were frequently used so that they would stay in swap after
78d48b7858Swizthe process exited.
79*a5175f1eSandvarShareable executables were compiled in a special way so their text
80d48b7858Swizand read-only data could be shared amongst processes.
81976cdb2bSchristos.Xr vi 1
82976cdb2bSchristosand
83976cdb2bSchristos.Xr sh 1
84976cdb2bSchristoswere such executables.
85193f31efSwizThis is where the term
86193f31efSwiz.Dq sticky
87d48b7858Swizcomes from - the program would stick around in swap, and it would
88d48b7858Swiznot have to be fetched again from the file system.
89d48b7858SwizOf course as long as there was a copy in the swap area, the file
90d48b7858Swizwas marked busy so it could not be overwritten.
91d48b7858SwizOn V7 this meant that the file could not be removed either, because
92d48b7858Swizbusy executables could not be removed, but this restriction was
93d48b7858Swizlifted in BSD releases.
94976cdb2bSchristos.Pp
95d48b7858SwizTo replace such executables was a cumbersome process.
96d48b7858SwizOne had first to remove the sticky bit, then execute the binary so
97d48b7858Swizthat the copy from swap was flushed, overwrite the executable, and
98d48b7858Swizfinally reset the sticky bit.
99193f31efSwiz.Pp
100193f31efSwizLater, on SunOS 4, the sticky bit got an additional meaning for
101193f31efSwizfiles that had the bit set and were not executable: read and write
102193f31efSwizoperations from and to those files would go directly to the disk
103193f31efSwizand bypass the buffer cache.
104193f31efSwizThis was typically used on swap files for NFS clients on an NFS
105193f31efSwizserver, so that swap I/O generated by the clients on the servers
106193f31efSwizwould not evict useful data from the server's buffer cache.
107a3b53d29Schristos.Sh BUGS
108a3b53d29SchristosNeither
109a3b53d29Schristos.Xr open 2
110a3b53d29Schristosnor
111a3b53d29Schristos.Xr mkdir 2
112a3b53d29Schristoswill create a file with the sticky bit set.
113