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