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 October 6, 2019 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" "unsigned long flags" 47.Ft int 48.Fn lchflags "const char *path" "unsigned long flags" 49.Ft int 50.Fn fchflags "int fd" "unsigned long flags" 51.Ft int 52.Fn chflagsat "int fd" "const char *path" "unsigned long flags" "int atflag" 53.Sh DESCRIPTION 54The file whose name 55is given by 56.Fa path 57or referenced by the descriptor 58.Fa fd 59has its flags changed to 60.Fa flags . 61.Pp 62The 63.Fn lchflags 64system call is like 65.Fn chflags 66except in the case where the named file is a symbolic link, 67in which case 68.Fn lchflags 69will change the flags of the link itself, 70rather than the file it points to. 71.Pp 72The 73.Fn chflagsat 74is equivalent to either 75.Fn chflags 76or 77.Fn lchflags 78depending on the 79.Fa atflag 80except in the case where 81.Fa path 82specifies a relative path. 83In this case the file to be changed is determined relative to the directory 84associated with the file descriptor 85.Fa fd 86instead of the current working directory. 87The values for the 88.Fa atflag 89are constructed by a bitwise-inclusive OR of flags from the following list, 90defined in 91.In fcntl.h : 92.Bl -tag -width indent 93.It Dv AT_SYMLINK_NOFOLLOW 94If 95.Fa path 96names a symbolic link, then the flags of the symbolic link are changed. 97.El 98.Pp 99If 100.Fn chflagsat 101is passed the special value 102.Dv AT_FDCWD 103in the 104.Fa fd 105parameter, the current working directory is used. 106If also 107.Fa atflag 108is zero, the behavior is identical to a call to 109.Fn chflags . 110.Pp 111The flags specified are formed by 112.Em or Ns 'ing 113the following values 114.Pp 115.Bl -tag -width ".Dv SF_IMMUTABLE" -compact -offset indent 116.It Dv UF_NODUMP 117Do not dump the file. 118.It Dv UF_IMMUTABLE 119The file may not be changed. 120.It Dv UF_APPEND 121The file may only be appended to. 122.It Dv UF_OPAQUE 123The directory is opaque when viewed through a union stack. 124.It Dv UF_NOUNLINK 125The file may not be renamed or deleted. 126.It Dv UF_NOHISTORY 127Do not retain history for file. 128.It Dv UF_CACHE 129Enable 130.Xr swapcache 8 131data caching. 132The flag is recursive and need only be set on a top-level directory. 133.It Dv SF_ARCHIVED 134The file may be archived. 135.It Dv SF_IMMUTABLE 136The file may not be changed. 137.It Dv SF_APPEND 138The file may only be appended to. 139.It Dv SF_NOUNLINK 140The file may not be renamed or deleted. 141.It Dv SF_NOHISTORY 142Do not retain history for file. 143.It Dv SF_NOCACHE 144Disable 145.Xr swapcache 8 146data caching. 147The flag is recursive and need only be set on a top-level directory. 148.El 149.Pp 150The 151.Dq UF_ 152prefixed 153flags may be set or unset by either the owner of a file or the super-user. 154.Pp 155The 156.Dq SF_ 157prefixed 158flags may only be set or unset by the super-user. 159Attempts by the non-super-user to set the super-user only flags 160are silently ignored. 161These flags may be set at any time, but normally may only be unset when 162the system is in single-user mode. 163(See 164.Xr init 8 165for details.) 166.Sh RETURN VALUES 167.Rv -std 168.Sh ERRORS 169.Fn Chflags 170will fail if: 171.Bl -tag -width Er 172.It Bq Er ENOTDIR 173A component of the path prefix is not a directory. 174.It Bq Er ENAMETOOLONG 175A component of a pathname exceeded 255 characters, 176or an entire path name exceeded 1023 characters. 177.It Bq Er ENOENT 178The named file does not exist. 179.It Bq Er EACCES 180Search permission is denied for a component of the path prefix. 181.It Bq Er ELOOP 182Too many symbolic links were encountered in translating the pathname. 183.It Bq Er EPERM 184The effective user ID does not match the owner of the file and 185the effective user ID is not the super-user. 186.It Bq Er EROFS 187The named file resides on a read-only file system. 188.It Bq Er EFAULT 189.Fa Path 190points outside the process's allocated address space. 191.It Bq Er EIO 192An 193.Tn I/O 194error occurred while reading from or writing to the file system. 195.It Bq Er EOPNOTSUPP 196The underlying file system does not support file flags. 197.El 198.Pp 199.Fn Fchflags 200will fail if: 201.Bl -tag -width Er 202.It Bq Er EBADF 203The descriptor is not valid. 204.It Bq Er EINVAL 205.Fa fd 206refers to a socket, not to a file. 207.It Bq Er EPERM 208The effective user ID does not match the owner of the file and 209the effective user ID is not the super-user. 210.It Bq Er EROFS 211The file resides on a read-only file system. 212.It Bq Er EIO 213An 214.Tn I/O 215error occurred while reading from or writing to the file system. 216.It Bq Er EOPNOTSUPP 217The 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 swapcache 8 225.Sh HISTORY 226The 227.Nm chflags 228and 229.Nm fchflags 230functions first appeared in 231.Bx 4.4 . 232