xref: /freebsd/lib/libsys/chflags.2 (revision 8269e7673cf033aba67dab8264fe719920c70f87)
1*8269e767SBrooks Davis.\" Copyright (c) 1989, 1993
2*8269e767SBrooks Davis.\"	The Regents of the University of California.  All rights reserved.
3*8269e767SBrooks Davis.\"
4*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
5*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
6*8269e767SBrooks Davis.\" are met:
7*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
8*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
9*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
10*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
11*8269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
12*8269e767SBrooks Davis.\" 3. Neither the name of the University nor the names of its contributors
13*8269e767SBrooks Davis.\"    may be used to endorse or promote products derived from this software
14*8269e767SBrooks Davis.\"    without specific prior written permission.
15*8269e767SBrooks Davis.\"
16*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*8269e767SBrooks Davis.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*8269e767SBrooks Davis.\" SUCH DAMAGE.
27*8269e767SBrooks Davis.\"
28*8269e767SBrooks Davis.Dd March 30, 2021
29*8269e767SBrooks Davis.Dt CHFLAGS 2
30*8269e767SBrooks Davis.Os
31*8269e767SBrooks Davis.Sh NAME
32*8269e767SBrooks Davis.Nm chflags ,
33*8269e767SBrooks Davis.Nm lchflags ,
34*8269e767SBrooks Davis.Nm fchflags ,
35*8269e767SBrooks Davis.Nm chflagsat
36*8269e767SBrooks Davis.Nd set file flags
37*8269e767SBrooks Davis.Sh LIBRARY
38*8269e767SBrooks Davis.Lb libc
39*8269e767SBrooks Davis.Sh SYNOPSIS
40*8269e767SBrooks Davis.In sys/stat.h
41*8269e767SBrooks Davis.In unistd.h
42*8269e767SBrooks Davis.Ft int
43*8269e767SBrooks Davis.Fn chflags "const char *path" "unsigned long flags"
44*8269e767SBrooks Davis.Ft int
45*8269e767SBrooks Davis.Fn lchflags "const char *path" "unsigned long flags"
46*8269e767SBrooks Davis.Ft int
47*8269e767SBrooks Davis.Fn fchflags "int fd" "unsigned long flags"
48*8269e767SBrooks Davis.Ft int
49*8269e767SBrooks Davis.Fn chflagsat "int fd" "const char *path" "unsigned long flags" "int atflag"
50*8269e767SBrooks Davis.Sh DESCRIPTION
51*8269e767SBrooks DavisThe file whose name
52*8269e767SBrooks Davisis given by
53*8269e767SBrooks Davis.Fa path
54*8269e767SBrooks Davisor referenced by the descriptor
55*8269e767SBrooks Davis.Fa fd
56*8269e767SBrooks Davishas its flags changed to
57*8269e767SBrooks Davis.Fa flags .
58*8269e767SBrooks Davis.Pp
59*8269e767SBrooks DavisThe
60*8269e767SBrooks Davis.Fn lchflags
61*8269e767SBrooks Davissystem call is like
62*8269e767SBrooks Davis.Fn chflags
63*8269e767SBrooks Davisexcept in the case where the named file is a symbolic link,
64*8269e767SBrooks Davisin which case
65*8269e767SBrooks Davis.Fn lchflags
66*8269e767SBrooks Daviswill change the flags of the link itself,
67*8269e767SBrooks Davisrather than the file it points to.
68*8269e767SBrooks Davis.Pp
69*8269e767SBrooks DavisThe
70*8269e767SBrooks Davis.Fn chflagsat
71*8269e767SBrooks Davisis equivalent to either
72*8269e767SBrooks Davis.Fn chflags
73*8269e767SBrooks Davisor
74*8269e767SBrooks Davis.Fn lchflags
75*8269e767SBrooks Davisdepending on the
76*8269e767SBrooks Davis.Fa atflag
77*8269e767SBrooks Davisexcept in the case where
78*8269e767SBrooks Davis.Fa path
79*8269e767SBrooks Davisspecifies a relative path.
80*8269e767SBrooks DavisIn this case the file to be changed is determined relative to the directory
81*8269e767SBrooks Davisassociated with the file descriptor
82*8269e767SBrooks Davis.Fa fd
83*8269e767SBrooks Davisinstead of the current working directory.
84*8269e767SBrooks DavisThe values for the
85*8269e767SBrooks Davis.Fa atflag
86*8269e767SBrooks Davisare constructed by a bitwise-inclusive OR of flags from the following list,
87*8269e767SBrooks Davisdefined in
88*8269e767SBrooks Davis.In fcntl.h :
89*8269e767SBrooks Davis.Bl -tag -width indent
90*8269e767SBrooks Davis.It Dv AT_SYMLINK_NOFOLLOW
91*8269e767SBrooks DavisIf
92*8269e767SBrooks Davis.Fa path
93*8269e767SBrooks Davisnames a symbolic link, then the flags of the symbolic link are changed.
94*8269e767SBrooks Davis.It Dv AT_RESOLVE_BENEATH
95*8269e767SBrooks DavisOnly walk paths below the directory specified by the
96*8269e767SBrooks Davis.Ar fd
97*8269e767SBrooks Davisdescriptor.
98*8269e767SBrooks DavisSee the description of the
99*8269e767SBrooks Davis.Dv O_RESOLVE_BENEATH
100*8269e767SBrooks Davisflag in the
101*8269e767SBrooks Davis.Xr open 2
102*8269e767SBrooks Davismanual page.
103*8269e767SBrooks Davis.It Dv AT_EMPTY_PATH
104*8269e767SBrooks DavisIf the
105*8269e767SBrooks Davis.Fa path
106*8269e767SBrooks Davisargument is an empty string, operate on the file or directory
107*8269e767SBrooks Davisreferenced by the descriptor
108*8269e767SBrooks Davis.Fa fd .
109*8269e767SBrooks DavisIf
110*8269e767SBrooks Davis.Fa fd
111*8269e767SBrooks Davisis equal to
112*8269e767SBrooks Davis.Dv AT_FDCWD ,
113*8269e767SBrooks Davisoperate on the current working directory.
114*8269e767SBrooks Davis.El
115*8269e767SBrooks Davis.Pp
116*8269e767SBrooks DavisIf
117*8269e767SBrooks Davis.Fn chflagsat
118*8269e767SBrooks Davisis passed the special value
119*8269e767SBrooks Davis.Dv AT_FDCWD
120*8269e767SBrooks Davisin the
121*8269e767SBrooks Davis.Fa fd
122*8269e767SBrooks Davisparameter, the current working directory is used.
123*8269e767SBrooks DavisIf also
124*8269e767SBrooks Davis.Fa atflag
125*8269e767SBrooks Davisis zero, the behavior is identical to a call to
126*8269e767SBrooks Davis.Fn chflags .
127*8269e767SBrooks Davis.Pp
128*8269e767SBrooks DavisThe flags specified are formed by
129*8269e767SBrooks Davis.Em or Ns 'ing
130*8269e767SBrooks Davisthe following values
131*8269e767SBrooks Davis.Pp
132*8269e767SBrooks Davis.Bl -tag -width ".Dv SF_IMMUTABLE" -compact -offset indent
133*8269e767SBrooks Davis.It Dv SF_APPEND
134*8269e767SBrooks DavisThe file may only be appended to.
135*8269e767SBrooks Davis.It Dv SF_ARCHIVED
136*8269e767SBrooks DavisThe file has been archived.
137*8269e767SBrooks DavisThis flag means the opposite of the DOS, Windows and CIFS
138*8269e767SBrooks DavisFILE_ATTRIBUTE_ARCHIVE attribute.
139*8269e767SBrooks DavisThis flag has been deprecated, and may be removed in a future release.
140*8269e767SBrooks Davis.It Dv SF_IMMUTABLE
141*8269e767SBrooks DavisThe file may not be changed.
142*8269e767SBrooks Davis.It Dv SF_NOUNLINK
143*8269e767SBrooks DavisThe file may not be renamed or deleted.
144*8269e767SBrooks Davis.It Dv SF_SNAPSHOT
145*8269e767SBrooks DavisThe file is a snapshot file.
146*8269e767SBrooks Davis.It Dv UF_APPEND
147*8269e767SBrooks DavisThe file may only be appended to.
148*8269e767SBrooks Davis.It Dv UF_ARCHIVE
149*8269e767SBrooks DavisThe file needs to be archived.
150*8269e767SBrooks DavisThis flag has the same meaning as the DOS, Windows and CIFS
151*8269e767SBrooks DavisFILE_ATTRIBUTE_ARCHIVE attribute.
152*8269e767SBrooks DavisFilesystems in FreeBSD may or may not have special handling for this flag.
153*8269e767SBrooks DavisFor instance, ZFS tracks changes to files and will set this bit when a
154*8269e767SBrooks Davisfile is updated.
155*8269e767SBrooks DavisUFS only stores the flag, and relies on the application to change it when
156*8269e767SBrooks Davisneeded.
157*8269e767SBrooks Davis.It Dv UF_HIDDEN
158*8269e767SBrooks DavisThe file may be hidden from directory listings at the application's
159*8269e767SBrooks Davisdiscretion.
160*8269e767SBrooks DavisThe file has the DOS, Windows and CIFS FILE_ATTRIBUTE_HIDDEN attribute.
161*8269e767SBrooks Davis.It Dv UF_IMMUTABLE
162*8269e767SBrooks DavisThe file may not be changed.
163*8269e767SBrooks Davis.It Dv UF_NODUMP
164*8269e767SBrooks DavisDo not dump the file.
165*8269e767SBrooks Davis.It Dv UF_NOUNLINK
166*8269e767SBrooks DavisThe file may not be renamed or deleted.
167*8269e767SBrooks Davis.It Dv UF_OFFLINE
168*8269e767SBrooks DavisThe file is offline, or has the Windows and CIFS FILE_ATTRIBUTE_OFFLINE
169*8269e767SBrooks Davisattribute.
170*8269e767SBrooks DavisFilesystems in FreeBSD store and display this flag, but do not provide any
171*8269e767SBrooks Davisspecial handling when it is set.
172*8269e767SBrooks Davis.It Dv UF_OPAQUE
173*8269e767SBrooks DavisThe directory is opaque when viewed through a union stack.
174*8269e767SBrooks Davis.It Dv UF_READONLY
175*8269e767SBrooks DavisThe file is read only, and may not be written or appended.
176*8269e767SBrooks DavisFilesystems may use this flag to maintain compatibility with the DOS, Windows
177*8269e767SBrooks Davisand CIFS FILE_ATTRIBUTE_READONLY attribute.
178*8269e767SBrooks Davis.It Dv UF_REPARSE
179*8269e767SBrooks DavisThe file contains a Windows reparse point and has the Windows and CIFS
180*8269e767SBrooks DavisFILE_ATTRIBUTE_REPARSE_POINT attribute.
181*8269e767SBrooks Davis.It Dv UF_SPARSE
182*8269e767SBrooks DavisThe file has the Windows FILE_ATTRIBUTE_SPARSE_FILE attribute.
183*8269e767SBrooks DavisThis may also be used by a filesystem to indicate a sparse file.
184*8269e767SBrooks Davis.It Dv UF_SYSTEM
185*8269e767SBrooks DavisThe file has the DOS, Windows and CIFS FILE_ATTRIBUTE_SYSTEM attribute.
186*8269e767SBrooks DavisFilesystems in FreeBSD may store and display this flag, but do not provide
187*8269e767SBrooks Davisany special handling when it is set.
188*8269e767SBrooks Davis.El
189*8269e767SBrooks Davis.Pp
190*8269e767SBrooks DavisIf one of
191*8269e767SBrooks Davis.Dv SF_IMMUTABLE , SF_APPEND ,
192*8269e767SBrooks Davisor
193*8269e767SBrooks Davis.Dv SF_NOUNLINK
194*8269e767SBrooks Davisis set a non-super-user cannot change any flags and even the super-user
195*8269e767SBrooks Daviscan change flags only if securelevel is 0.
196*8269e767SBrooks Davis(See
197*8269e767SBrooks Davis.Xr init 8
198*8269e767SBrooks Davisfor details.)
199*8269e767SBrooks Davis.Pp
200*8269e767SBrooks DavisThe
201*8269e767SBrooks Davis.Dv UF_IMMUTABLE , UF_APPEND , UF_NOUNLINK , UF_NODUMP ,
202*8269e767SBrooks Davisand
203*8269e767SBrooks Davis.Dv UF_OPAQUE
204*8269e767SBrooks Davisflags may be set or unset by either the owner of a file or the super-user.
205*8269e767SBrooks Davis.Pp
206*8269e767SBrooks DavisThe
207*8269e767SBrooks Davis.Dv SF_IMMUTABLE , SF_APPEND , SF_NOUNLINK ,
208*8269e767SBrooks Davisand
209*8269e767SBrooks Davis.Dv SF_ARCHIVED
210*8269e767SBrooks Davisflags may only be set or unset by the super-user.
211*8269e767SBrooks DavisAttempts to toggle these flags by non-super-users are rejected.
212*8269e767SBrooks DavisThese flags may be set at any time, but normally may only be unset when
213*8269e767SBrooks Davisthe system is in single-user mode.
214*8269e767SBrooks Davis(See
215*8269e767SBrooks Davis.Xr init 8
216*8269e767SBrooks Davisfor details.)
217*8269e767SBrooks Davis.Pp
218*8269e767SBrooks DavisThe implementation of all flags is filesystem-dependent.
219*8269e767SBrooks DavisSee the description of the
220*8269e767SBrooks Davis.Dv UF_ARCHIVE
221*8269e767SBrooks Davisflag above for one example of the differences in behavior.
222*8269e767SBrooks DavisCare should be exercised when writing applications to account for
223*8269e767SBrooks Davissupport or lack of support of these flags in various filesystems.
224*8269e767SBrooks Davis.Pp
225*8269e767SBrooks DavisThe
226*8269e767SBrooks Davis.Dv SF_SNAPSHOT
227*8269e767SBrooks Davisflag is maintained by the system and cannot be toggled.
228*8269e767SBrooks Davis.Sh RETURN VALUES
229*8269e767SBrooks Davis.Rv -std
230*8269e767SBrooks Davis.Sh ERRORS
231*8269e767SBrooks DavisThe
232*8269e767SBrooks Davis.Fn chflags
233*8269e767SBrooks Davissystem call will fail if:
234*8269e767SBrooks Davis.Bl -tag -width Er
235*8269e767SBrooks Davis.It Bq Er ENOTDIR
236*8269e767SBrooks DavisA component of the path prefix is not a directory.
237*8269e767SBrooks Davis.It Bq Er ENAMETOOLONG
238*8269e767SBrooks DavisA component of a pathname exceeded 255 characters,
239*8269e767SBrooks Davisor an entire path name exceeded 1023 characters.
240*8269e767SBrooks Davis.It Bq Er ENOENT
241*8269e767SBrooks DavisThe named file does not exist.
242*8269e767SBrooks Davis.It Bq Er EACCES
243*8269e767SBrooks DavisSearch permission is denied for a component of the path prefix.
244*8269e767SBrooks Davis.It Bq Er ELOOP
245*8269e767SBrooks DavisToo many symbolic links were encountered in translating the pathname.
246*8269e767SBrooks Davis.It Bq Er EPERM
247*8269e767SBrooks DavisThe effective user ID does not match the owner of the file and
248*8269e767SBrooks Davisthe effective user ID is not the super-user.
249*8269e767SBrooks Davis.It Bq Er EPERM
250*8269e767SBrooks DavisOne of
251*8269e767SBrooks Davis.Dv SF_IMMUTABLE , SF_APPEND ,
252*8269e767SBrooks Davisor
253*8269e767SBrooks Davis.Dv SF_NOUNLINK
254*8269e767SBrooks Davisis set and the user is either not the super-user or
255*8269e767SBrooks Davissecurelevel is greater than 0.
256*8269e767SBrooks Davis.It Bq Er EPERM
257*8269e767SBrooks DavisA non-super-user attempted to toggle one of
258*8269e767SBrooks Davis.Dv SF_ARCHIVED , SF_IMMUTABLE , SF_APPEND ,
259*8269e767SBrooks Davisor
260*8269e767SBrooks Davis.Dv SF_NOUNLINK .
261*8269e767SBrooks Davis.It Bq Er EPERM
262*8269e767SBrooks DavisAn attempt was made to toggle the
263*8269e767SBrooks Davis.Dv SF_SNAPSHOT
264*8269e767SBrooks Davisflag.
265*8269e767SBrooks Davis.It Bq Er EROFS
266*8269e767SBrooks DavisThe named file resides on a read-only file system.
267*8269e767SBrooks Davis.It Bq Er EFAULT
268*8269e767SBrooks DavisThe
269*8269e767SBrooks Davis.Fa path
270*8269e767SBrooks Davisargument
271*8269e767SBrooks Davispoints outside the process's allocated address space.
272*8269e767SBrooks Davis.It Bq Er EIO
273*8269e767SBrooks DavisAn
274*8269e767SBrooks Davis.Tn I/O
275*8269e767SBrooks Daviserror occurred while reading from or writing to the file system.
276*8269e767SBrooks Davis.It Bq Er EINTEGRITY
277*8269e767SBrooks DavisCorrupted data was detected while reading from the file system.
278*8269e767SBrooks Davis.It Bq Er EOPNOTSUPP
279*8269e767SBrooks DavisThe underlying file system does not support file flags, or
280*8269e767SBrooks Davisdoes not support all of the flags set in
281*8269e767SBrooks Davis.Fa flags .
282*8269e767SBrooks Davis.El
283*8269e767SBrooks Davis.Pp
284*8269e767SBrooks DavisThe
285*8269e767SBrooks Davis.Fn fchflags
286*8269e767SBrooks Davissystem call will fail if:
287*8269e767SBrooks Davis.Bl -tag -width Er
288*8269e767SBrooks Davis.It Bq Er EBADF
289*8269e767SBrooks DavisThe descriptor is not valid.
290*8269e767SBrooks Davis.It Bq Er EINVAL
291*8269e767SBrooks DavisThe
292*8269e767SBrooks Davis.Fa fd
293*8269e767SBrooks Davisargument
294*8269e767SBrooks Davisrefers to a socket, not to a file.
295*8269e767SBrooks Davis.It Bq Er EPERM
296*8269e767SBrooks DavisThe effective user ID does not match the owner of the file and
297*8269e767SBrooks Davisthe effective user ID is not the super-user.
298*8269e767SBrooks Davis.It Bq Er EPERM
299*8269e767SBrooks DavisOne of
300*8269e767SBrooks Davis.Dv SF_IMMUTABLE , SF_APPEND ,
301*8269e767SBrooks Davisor
302*8269e767SBrooks Davis.Dv SF_NOUNLINK
303*8269e767SBrooks Davisis set and the user is either not the super-user or
304*8269e767SBrooks Davissecurelevel is greater than 0.
305*8269e767SBrooks Davis.It Bq Er EPERM
306*8269e767SBrooks DavisA non-super-user attempted to toggle one of
307*8269e767SBrooks Davis.Dv SF_ARCHIVED , SF_IMMUTABLE , SF_APPEND ,
308*8269e767SBrooks Davisor
309*8269e767SBrooks Davis.Dv SF_NOUNLINK .
310*8269e767SBrooks Davis.It Bq Er EPERM
311*8269e767SBrooks DavisAn attempt was made to toggle the
312*8269e767SBrooks Davis.Dv SF_SNAPSHOT
313*8269e767SBrooks Davisflag.
314*8269e767SBrooks Davis.It Bq Er EROFS
315*8269e767SBrooks DavisThe file resides on a read-only file system.
316*8269e767SBrooks Davis.It Bq Er EIO
317*8269e767SBrooks DavisAn
318*8269e767SBrooks Davis.Tn I/O
319*8269e767SBrooks Daviserror occurred while reading from or writing to the file system.
320*8269e767SBrooks Davis.It Bq Er EINTEGRITY
321*8269e767SBrooks DavisCorrupted data was detected while reading from the file system.
322*8269e767SBrooks Davis.It Bq Er EOPNOTSUPP
323*8269e767SBrooks DavisThe underlying file system does not support file flags, or
324*8269e767SBrooks Davisdoes not support all of the flags set in
325*8269e767SBrooks Davis.Fa flags .
326*8269e767SBrooks Davis.It Bq Er ENOTCAPABLE
327*8269e767SBrooks Davis.Fa path
328*8269e767SBrooks Davisis an absolute path,
329*8269e767SBrooks Davisor contained a ".." component leading to a
330*8269e767SBrooks Davisdirectory outside of the directory hierarchy specified by
331*8269e767SBrooks Davis.Fa fd ,
332*8269e767SBrooks Davisand the process is in capability mode or the
333*8269e767SBrooks Davis.Dv AT_RESOLVE_BENEATH
334*8269e767SBrooks Davisflag was specified.
335*8269e767SBrooks Davis.El
336*8269e767SBrooks Davis.Sh SEE ALSO
337*8269e767SBrooks Davis.Xr chflags 1 ,
338*8269e767SBrooks Davis.Xr fflagstostr 3 ,
339*8269e767SBrooks Davis.Xr strtofflags 3 ,
340*8269e767SBrooks Davis.Xr init 8 ,
341*8269e767SBrooks Davis.Xr mount_unionfs 8
342*8269e767SBrooks Davis.Sh HISTORY
343*8269e767SBrooks DavisThe
344*8269e767SBrooks Davis.Fn chflags
345*8269e767SBrooks Davisand
346*8269e767SBrooks Davis.Fn fchflags
347*8269e767SBrooks Davissystem calls first appeared in
348*8269e767SBrooks Davis.Bx 4.4 .
349*8269e767SBrooks DavisThe
350*8269e767SBrooks Davis.Fn lchflags
351*8269e767SBrooks Davissystem call first appeared in
352*8269e767SBrooks Davis.Fx 5.0 .
353*8269e767SBrooks DavisThe
354*8269e767SBrooks Davis.Fn chflagsat
355*8269e767SBrooks Davissystem call first appeared in
356*8269e767SBrooks Davis.Fx 10.0 .
357