920c6bbd4eacaa10e98afd8f1200e8302158e46c
[dragonfly.git] / lib / libc / sys / chflags.2
1 .\" Copyright (c) 1989, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)chflags.2   8.3 (Berkeley) 5/2/95
29 .\" $FreeBSD: src/lib/libc/sys/chflags.2,v 1.11.2.7 2001/12/14 18:34:00 ru Exp $
30 .\"
31 .Dd February 13, 2015
32 .Dt CHFLAGS 2
33 .Os
34 .Sh NAME
35 .Nm chflags ,
36 .Nm lchflags ,
37 .Nm fchflags ,
38 .Nm chflagsat
39 .Nd set file flags
40 .Sh LIBRARY
41 .Lb libc
42 .Sh SYNOPSIS
43 .In sys/stat.h
44 .In unistd.h
45 .Ft int
46 .Fn chflags "const char *path" "u_long flags"
47 .Ft int
48 .Fn lchflags "const char *path" "u_long flags"
49 .Ft int
50 .Fn fchflags "int fd" "u_long flags"
51 .Ft int
52 .Fn chflagsat "int fd" "const char *path" "u_long flags" "int atflag"
53 .Sh DESCRIPTION
54 The file whose name
55 is given by
56 .Fa path
57 or referenced by the descriptor
58 .Fa fd
59 has its flags changed to
60 .Fa flags .
61 .Pp
62 The
63 .Fn lchflags
64 system call is like
65 .Fn chflags
66 except in the case where the named file is a symbolic link,
67 in which case
68 .Fn lchflags
69 will change the flags of the link itself,
70 rather than the file it points to.
71 .Pp
72 The
73 .Fn chflagsat
74 is equivalent to either
75 .Fn chflags
76 or
77 .Fn lchflags
78 depending on the
79 .Fa atflag
80 except in the case where
81 .Fa path
82 specifies a relative path.
83 In this case the file to be changed is determined relative to the directory
84 associated with the file descriptor
85 .Fa fd
86 instead of the current working directory.
87 The values for the
88 .Fa atflag
89 are constructed by a bitwise-inclusive OR of flags from the following list,
90 defined in
91 .In fcntl.h :
92 .Bl -tag -width indent
93 .It Dv AT_SYMLINK_NOFOLLOW
94 If
95 .Fa path
96 names a symbolic link, then the flags of the symbolic link are changed.
97 .El
98 .Pp
99 If
100 .Fn chflagsat
101 is passed the special value
102 .Dv AT_FDCWD
103 in the
104 .Fa fd
105 parameter, the current working directory is used.
106 If also
107 .Fa atflag
108 is zero, the behavior is identical to a call to
109 .Fn chflags .
110 .Pp
111 The flags specified are formed by
112 .Em or Ns 'ing
113 the following values
114 .Pp
115 .Bl -tag -width "SF_IMMUTABLE" -compact -offset indent
116 .It UF_NODUMP
117 Do not dump the file.
118 .It UF_IMMUTABLE
119 The file may not be changed.
120 .It UF_APPEND
121 The file may only be appended to.
122 .It UF_OPAQUE
123 The directory is opaque when viewed through a union stack.
124 .It UF_NOUNLINK
125 The file may not be renamed or deleted.
126 .It UF_NOHISTORY
127 Do not retain history for file.
128 .It UF_CACHE
129 Enable
130 .Xr swapcache 8
131 data caching.
132 The flag is recursive and need only be set on a top-level directory.
133 .It SF_ARCHIVED
134 The file may be archived.
135 .It SF_IMMUTABLE
136 The file may not be changed.
137 .It SF_APPEND
138 The file may only be appended to.
139 .It SF_NOUNLINK
140 The file may not be renamed or deleted.
141 .It SF_NOHISTORY
142 Do not retain history for file.
143 .It SF_NOCACHE
144 Disable
145 .Xr swapcache 8
146 data caching.
147 The flag is recursive and need only be set on a top-level directory.
148 .El
149 .Pp
150 The
151 .Dq UF_
152 prefixed
153 flags may be set or unset by either the owner of a file or the super-user.
154 .Pp
155 The
156 .Dq SF_
157 prefixed
158 flags may only be set or unset by the super-user.
159 Attempts by the non-super-user to set the super-user only flags
160 are silently ignored.
161 These flags may be set at any time, but normally may only be unset when
162 the system is in single-user mode.
163 (See
164 .Xr init 8
165 for details.)
166 .Sh RETURN VALUES
167 .Rv -std
168 .Sh ERRORS
169 .Fn Chflags
170 will fail if:
171 .Bl -tag -width Er
172 .It Bq Er ENOTDIR
173 A component of the path prefix is not a directory.
174 .It Bq Er ENAMETOOLONG
175 A component of a pathname exceeded 255 characters,
176 or an entire path name exceeded 1023 characters.
177 .It Bq Er ENOENT
178 The named file does not exist.
179 .It Bq Er EACCES
180 Search permission is denied for a component of the path prefix.
181 .It Bq Er ELOOP
182 Too many symbolic links were encountered in translating the pathname.
183 .It Bq Er EPERM
184 The effective user ID does not match the owner of the file and
185 the effective user ID is not the super-user.
186 .It Bq Er EROFS
187 The named file resides on a read-only file system.
188 .It Bq Er EFAULT
189 .Fa Path
190 points outside the process's allocated address space.
191 .It Bq Er EIO
192 An
193 .Tn I/O
194 error occurred while reading from or writing to the file system.
195 .It Bq Er EOPNOTSUPP
196 The underlying file system does not support file flags.
197 .El
198 .Pp
199 .Fn Fchflags
200 will fail if:
201 .Bl -tag -width Er
202 .It Bq Er EBADF
203 The descriptor is not valid.
204 .It Bq Er EINVAL
205 .Fa fd
206 refers to a socket, not to a file.
207 .It Bq Er EPERM
208 The effective user ID does not match the owner of the file and
209 the effective user ID is not the super-user.
210 .It Bq Er EROFS
211 The file resides on a read-only file system.
212 .It Bq Er EIO
213 An
214 .Tn I/O
215 error occurred while reading from or writing to the file system.
216 .It Bq Er EOPNOTSUPP
217 The underlying file system does not support file flags.
218 .El
219 .Sh SEE ALSO
220 .Xr chflags 1 ,
221 .Xr fflagstostr 3 ,
222 .Xr strtofflags 3 ,
223 .Xr init 8 ,
224 .Xr mount_union 8 ,
225 .Xr swapcache 8
226 .Sh HISTORY
227 The
228 .Nm chflags
229 and
230 .Nm fchflags
231 functions first appeared in
232 .Bx 4.4 .