xref: /openbsd/lib/libc/sys/chflags.2 (revision 4bdff4be)
1.\"	$OpenBSD: chflags.2,v 1.29 2022/08/04 06:20:24 jsg 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 4 2022 $
34.Dt CHFLAGS 2
35.Os
36.Sh NAME
37.Nm chflags ,
38.Nm chflagsat ,
39.Nm fchflags
40.Nd set file flags
41.Sh SYNOPSIS
42.In sys/stat.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.In sys/stat.h
48.In fcntl.h
49.Ft int
50.Fn chflagsat "int fd" "const char *path"  "unsigned int flags" "int atflags"
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 are the bitwise OR of zero or more of the following values:
60.Pp
61.Bl -tag -width "SF_IMMUTABLE" -compact -offset indent
62.It Dv UF_NODUMP
63Do not dump the file.
64.It Dv UF_IMMUTABLE
65The file may not be changed.
66.It Dv UF_APPEND
67The file may only be appended to.
68.It Dv SF_ARCHIVED
69The file may be archived.
70.It Dv SF_IMMUTABLE
71The file may not be changed.
72.It Dv SF_APPEND
73The file may only be appended to.
74.El
75.Pp
76The
77.Dv UF_IMMUTABLE
78and
79.Dv UF_APPEND
80flags may be set or unset by either the owner of a file or the superuser.
81.Pp
82The
83.Dv SF_ARCHIVED ,
84.Dv SF_IMMUTABLE
85and
86.Dv SF_APPEND
87flags may only be set or unset by the superuser.
88They may be set at any time, but normally may only be unset when
89the system is in single-user mode.
90(See
91.Xr init 8
92for details.)
93.Pp
94The
95.Fn chflagsat
96function is equivalent to
97.Fn chflags
98except in the case where
99.Fa path
100specifies a relative path.
101In this case the file to be changed is determined relative to the directory
102associated with the file descriptor
103.Fa fd
104instead of the current working directory.
105.Pp
106If
107.Fn chflagsat
108is passed the special value
109.Dv AT_FDCWD
110(defined in
111.In fcntl.h )
112in the
113.Fa fd
114parameter, the current working directory is used.
115If
116.Fa atflags
117is also zero, the behavior is identical to a call to
118.Fn chflags .
119.Pp
120The
121.Fa atflags
122argument is the bitwise OR of zero or more of the following values:
123.Pp
124.Bl -tag -width AT_SYMLINK_NOFOLLOW -offset indent -compact
125.It Dv AT_SYMLINK_NOFOLLOW
126If
127.Fa path
128names a symbolic link, then the flags of the symbolic link are changed.
129.El
130.Pp
131The
132.Fn fchflags
133function is equivalent to
134.Fn chflags
135except that the file whose flags are changed is specified
136by the file descriptor
137.Fa fd .
138.Sh RETURN VALUES
139.Rv -std
140.Sh ERRORS
141.Fn chflags
142will fail if:
143.Bl -tag -width Er
144.It Bq Er ENOTDIR
145A component of the path prefix is not a directory.
146.It Bq Er ENAMETOOLONG
147A component of a pathname exceeded
148.Dv NAME_MAX
149characters, or an entire pathname (including the terminating NUL)
150exceeded
151.Dv PATH_MAX
152bytes.
153.It Bq Er ENOENT
154The named file does not exist.
155.It Bq Er EACCES
156Search permission is denied for a component of the path prefix.
157.It Bq Er ELOOP
158Too many symbolic links were encountered in translating the pathname.
159.It Bq Er EPERM
160The effective user ID does not match the owner of the file and
161the effective user ID is not the superuser, or the effective user ID
162is not the superuser and at least one of the super-user-only flags
163for the named file would be changed.
164.It Bq Er EOPNOTSUPP
165The named file resides on a file system that does not support file
166flags.
167.It Bq Er EROFS
168The named file resides on a read-only file system.
169.It Bq Er EFAULT
170.Fa path
171points outside the process's allocated address space.
172.It Bq Er EIO
173An I/O error occurred while reading from or writing to the file system.
174.It Bq Er EINVAL
175The
176.Fa flags
177value is invalid.
178.It Bq Er EINVAL
179The descriptor references a block or character device and the effective
180user ID is not the superuser.
181.El
182.Pp
183.Fn fchflags
184will fail if:
185.Bl -tag -width Er
186.It Bq Er EBADF
187The descriptor is not valid.
188.It Bq Er EINVAL
189.Fa fd
190refers to a socket, not to a file.
191.It Bq Er EINVAL
192The descriptor references a block or character device and the effective
193user ID is not the superuser.
194.It Bq Er EINVAL
195The
196.Fa flags
197value is invalid.
198.It Bq Er EPERM
199The effective user ID does not match the owner of the file and
200the effective user ID is not the superuser, or the effective user ID
201is not the superuser and at least one of the super-user-only flags
202for the named file would be changed.
203.It Bq Er EOPNOTSUPP
204The named file resides on a file system that does not support file
205flags.
206.It Bq Er EROFS
207The file resides on a read-only file system.
208.It Bq Er EIO
209An I/O error occurred while reading from or writing to the file system.
210.El
211.Sh SEE ALSO
212.Xr chflags 1 ,
213.Xr init 8
214.Sh HISTORY
215The
216.Fn chflags
217and
218.Fn fchflags
219functions first appeared in
220.Bx 4.3 Reno .
221The
222.Fn chflagsat
223function first appeared in
224.Fx 10.0 .
225It was added to
226.Ox
227in
228.Ox 5.7 .
229