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