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