1.\" $OpenBSD: chflags.2,v 1.22 2009/08/20 18:32:58 martynas Exp $ 2.\" $NetBSD: chflags.2,v 1.6 1995/02/27 12:32:03 cgd Exp $ 3.\" 4.\" Copyright (c) 1989, 1993 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. Neither the name of the University nor the names of its contributors 16.\" may be used to endorse or promote products derived from this software 17.\" without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" SUCH DAMAGE. 30.\" 31.\" @(#)chflags.2 8.1 (Berkeley) 6/9/93 32.\" 33.Dd $Mdocdate: August 20 2009 $ 34.Dt CHFLAGS 2 35.Os 36.Sh NAME 37.Nm chflags , 38.Nm fchflags 39.Nd set file flags 40.Sh SYNOPSIS 41.Fd #include <sys/stat.h> 42.Fd #include <unistd.h> 43.Ft int 44.Fn chflags "const char *path" "unsigned int flags" 45.Ft int 46.Fn fchflags "int fd" "unsigned int flags" 47.Sh DESCRIPTION 48The file whose name is given by 49.Fa path 50or referenced by the descriptor 51.Fa fd 52has its flags changed to 53.Fa flags . 54.Pp 55The flags specified are formed by 56.Tn OR Ns 'ing 57the following values: 58.Pp 59.Bl -tag -width "SF_IMMUTABLE" -compact -offset indent 60.It Dv UF_NODUMP 61Do not dump the file. 62.It Dv UF_IMMUTABLE 63The file may not be changed. 64.It Dv UF_APPEND 65The file may only be appended to. 66.It Dv SF_ARCHIVED 67The file may be archived. 68.It Dv SF_IMMUTABLE 69The file may not be changed. 70.It Dv SF_APPEND 71The file may only be appended to. 72.El 73.Pp 74The 75.Dv UF_IMMUTABLE 76and 77.Dv UF_APPEND 78flags may be set or unset by either the owner of a file or the superuser. 79.Pp 80The 81.Dv SF_ARCHIVED , 82.Dv SF_IMMUTABLE 83and 84.Dv SF_APPEND 85flags may only be set or unset by the superuser. 86They may be set at any time, but normally may only be unset when 87the system is in single-user mode. 88(See 89.Xr init 8 90for details.) 91.Sh RETURN VALUES 92Upon successful completion, a value of 0 is returned. 93Otherwise, \-1 is returned and the global variable 94.Va errno 95is set to indicate the error. 96.Sh ERRORS 97.Fn chflags 98will fail if: 99.Bl -tag -width Er 100.It Bq Er ENOTDIR 101A component of the path prefix is not a directory. 102.It Bq Er ENAMETOOLONG 103A component of a pathname exceeded 104.Dv {NAME_MAX} 105characters, or an entire path name exceeded 106.Dv {PATH_MAX} 107characters. 108.It Bq Er ENOENT 109The named file does not exist. 110.It Bq Er EACCES 111Search permission is denied for a component of the path prefix. 112.It Bq Er ELOOP 113Too many symbolic links were encountered in translating the pathname. 114.It Bq Er EPERM 115The effective user ID does not match the owner of the file and 116the effective user ID is not the superuser, or the effective user ID 117is not the superuser and at least one of the super-user-only flags 118for the named file would be changed. 119.It Bq Er EOPNOTSUPP 120The named file resides on a file system that does not support file 121flags. 122.It Bq Er EROFS 123The named file resides on a read-only file system. 124.It Bq Er EFAULT 125.Fa path 126points outside the process's allocated address space. 127.It Bq Er EIO 128An 129.Tn I/O 130error occurred while reading from or writing to the file system. 131.It Bq Er EINVAL 132The 133.Fa flags 134value is invalid. 135.It Bq Er EINVAL 136The descriptor references a block or character device and the effective 137user ID is not the superuser. 138.El 139.Pp 140.Fn fchflags 141will fail if: 142.Bl -tag -width Er 143.It Bq Er EBADF 144The descriptor is not valid. 145.It Bq Er EINVAL 146.Fa fd 147refers to a socket, not to a file. 148.It Bq Er EINVAL 149The descriptor references a block or character device and the effective 150user ID is not the superuser. 151.It Bq Er EINVAL 152The 153.Fa flags 154value is invalid. 155.It Bq Er EPERM 156The effective user ID does not match the owner of the file and 157the effective user ID is not the superuser, or the effective user ID 158is not the superuser and at least one of the super-user-only flags 159for the named file would be changed. 160.It Bq Er EOPNOTSUPP 161The named file resides on a file system that does not support file 162flags. 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 init 8 173.Sh HISTORY 174The 175.Fn chflags 176and 177.Fn fchflags 178functions first appeared in 179.Bx 4.4 . 180