1.\" $OpenBSD: chflags.2,v 1.21 2007/05/31 19:19:32 jmc 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: May 31 2007 $ 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 ARCHIVED 67.\"File is 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_IMMUTABLE 82and 83.Dv SF_APPEND 84flags may only be set or unset by the superuser. 85They may be set at any time, but normally may only be unset when 86the system is in single-user mode. 87(See 88.Xr init 8 89for details.) 90.Sh RETURN VALUES 91Upon successful completion, a value of 0 is returned. 92Otherwise, \-1 is returned and the global variable 93.Va errno 94is set to indicate the error. 95.Sh ERRORS 96.Fn chflags 97will fail if: 98.Bl -tag -width Er 99.It Bq Er ENOTDIR 100A component of the path prefix is not a directory. 101.It Bq Er ENAMETOOLONG 102A component of a pathname exceeded 103.Dv {NAME_MAX} 104characters, or an entire path name exceeded 105.Dv {PATH_MAX} 106characters. 107.It Bq Er ENOENT 108The named file does not exist. 109.It Bq Er EACCES 110Search permission is denied for a component of the path prefix. 111.It Bq Er ELOOP 112Too many symbolic links were encountered in translating the pathname. 113.It Bq Er EPERM 114The effective user ID does not match the owner of the file and 115the effective user ID is not the superuser, or the effective user ID 116is not the superuser and at least one of the super-user-only flags 117for the named file would be changed. 118.It Bq Er EOPNOTSUPP 119The named file resides on a file system that does not support file 120flags. 121.It Bq Er EROFS 122The named file resides on a read-only file system. 123.It Bq Er EFAULT 124.Fa path 125points outside the process's allocated address space. 126.It Bq Er EIO 127An 128.Tn I/O 129error occurred while reading from or writing to the file system. 130.It Bq Er EINVAL 131The 132.Fa flags 133value is invalid. 134.It Bq Er EINVAL 135The descriptor references a block or character device and the effective 136user ID is not the superuser. 137.El 138.Pp 139.Fn fchflags 140will fail if: 141.Bl -tag -width Er 142.It Bq Er EBADF 143The descriptor is not valid. 144.It Bq Er EINVAL 145.Fa fd 146refers to a socket, not to a file. 147.It Bq Er EINVAL 148The descriptor references a block or character device and the effective 149user ID is not the superuser. 150.It Bq Er EINVAL 151The 152.Fa flags 153value is invalid. 154.It Bq Er EPERM 155The effective user ID does not match the owner of the file and 156the effective user ID is not the superuser, or the effective user ID 157is not the superuser and at least one of the super-user-only flags 158for the named file would be changed. 159.It Bq Er EOPNOTSUPP 160The named file resides on a file system that does not support file 161flags. 162.It Bq Er EROFS 163The file resides on a read-only file system. 164.It Bq Er EIO 165An 166.Tn I/O 167error occurred while reading from or writing to the file system. 168.El 169.Sh SEE ALSO 170.Xr chflags 1 , 171.Xr init 8 172.Sh HISTORY 173The 174.Fn chflags 175and 176.Fn fchflags 177functions first appeared in 178.Bx 4.4 . 179