1.\" $NetBSD: chflags.2,v 1.28 2013/06/08 06:05:03 kardel Exp $ 2.\" 3.\" Copyright (c) 1989, 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.\" @(#)chflags.2 8.3 (Berkeley) 5/2/95 31.\" 32.Dd August 6, 2011 33.Dt CHFLAGS 2 34.Os 35.Sh NAME 36.Nm chflags , 37.Nm lchflags , 38.Nm fchflags 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.Sh DESCRIPTION 52The file whose name 53is given by 54.Fa path 55or referenced by the descriptor 56.Fa fd 57has its flags changed to 58.Fa flags . 59For 60.Fn lchflags , 61symbolic links are not traversed and thus their modes may be changed with 62this call. 63.Pp 64The flags specified are formed by 65.Em or Ns 'ing 66the following values: 67.Pp 68.Bl -tag -width "SF_IMMUTABLE" -compact -offset indent 69.It Dv UF_NODUMP 70Do not dump the file. 71.It Dv UF_IMMUTABLE 72The file may not be changed. 73.It Dv UF_APPEND 74The file may only be appended to. 75.It Dv UF_OPAQUE 76The file (if a directory) is opaque for union mounts. 77.It Dv SF_ARCHIVED 78The file is archived. 79.It Dv SF_IMMUTABLE 80The file may not be changed. 81.It Dv SF_APPEND 82The file may only be appended to. 83.El 84.Pp 85The 86.Dv UF_NODUMP , 87.Dv UF_IMMUTABLE , 88.Dv UF_APPEND , 89and 90.Dv UF_OPAQUE 91flags may be set or unset by either the owner of a file or the super-user, 92except on block and character devices, where only the super-user may set 93or unset them. 94.Pp 95The 96.Dv SF_ARCHIVED , 97.Dv SF_IMMUTABLE , 98and 99.Dv SF_APPEND 100flags may only be set or unset by the super-user. 101These flags may be set at any time, but normally may only be unset when 102the system is in single-user mode. 103(See 104.Xr init 8 105for details.) 106.Sh RETURN VALUES 107Upon successful completion, a value of 0 is returned. 108Otherwise, \-1 is returned and the global variable 109.Va errno 110is set to indicate the error. 111.Sh ERRORS 112.Fn chflags 113will fail if: 114.Bl -tag -width Er 115.It Bq Er ENOTDIR 116A component of the path prefix is not a directory. 117.It Bq Er ENAMETOOLONG 118A component of a pathname exceeded 119.Brq Dv NAME_MAX 120characters, or an entire path name exceeded 121.Brq Dv PATH_MAX 122characters. 123.It Bq Er ENOENT 124The named file does not exist. 125.It Bq Er EACCES 126Search permission is denied for a component of the path prefix. 127.It Bq Er ELOOP 128Too many symbolic links were encountered in translating the pathname. 129.It Bq Er EPERM 130The effective user ID does not match the owner of the file and 131the effective user ID is not the super-user, or 132the effective user ID is not the super-user and one or more of the 133super-user-only flags for the named file would be changed. 134.It Bq Er EOPNOTSUPP 135The named file resides on a file system that does not support file 136flags. 137.It Bq Er EROFS 138The named file resides on a read-only file system. 139.It Bq Er EFAULT 140.Fa path 141points outside the process's allocated address space. 142.It Bq Er EIO 143An 144.Tn I/O 145error occurred while reading from or writing to the file system. 146.El 147.Pp 148.Fn fchflags 149will fail if: 150.Bl -tag -width Er 151.It Bq Er EBADF 152The descriptor is not valid. 153.It Bq Er EINVAL 154.Fa fd 155refers to a socket, not to a file. 156.It Bq Er EPERM 157The effective user ID does not match the owner of the file and 158the effective user ID is not the super-user, or 159the effective user ID is not the super-user and one or more of the 160super-user-only flags for the file would be changed. 161.It Bq Er EOPNOTSUPP 162The file resides on a file system that does not support file flags. 163.It Bq Er EROFS 164The file resides on a read-only file system. 165.It Bq Er EIO 166An 167.Tn I/O 168error occurred while reading from or writing to the file system. 169.El 170.Sh SEE ALSO 171.Xr chflags 1 , 172.Xr stat 2 , 173.Xr stat_flags 3 , 174.Xr init 8 , 175.Xr mount_union 8 176.Sh HISTORY 177The 178.Fn chflags 179and 180.Fn fchflags 181functions first appeared in 182.Bx 4.4 . 183The 184.Fn lchflags 185function first appeared in 186.Nx 1.5 . 187