xref: /netbsd/lib/libc/sys/chflags.2 (revision c4a72b64)
1.\"	$NetBSD: chflags.2,v 1.20 2002/07/07 14:59:49 bjh21 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 lchflags ,
42.Nm fchflags
43.Nd set file flags
44.Sh LIBRARY
45.Lb libc
46.Sh SYNOPSIS
47.Fd #include \*[Lt]sys/stat.h\*[Gt]
48.Fd #include \*[Lt]unistd.h\*[Gt]
49.Ft int
50.Fn chflags "const char *path"  "u_long flags"
51.Ft int
52.Fn lchflags "const char *path"  "u_long flags"
53.Ft int
54.Fn fchflags "int fd" "u_long flags"
55.Sh DESCRIPTION
56The file whose name
57is given by
58.Fa path
59or referenced by the descriptor
60.Fa fd
61has its flags changed to
62.Fa flags .
63For
64.Fn lchflags ,
65symbolic links are not traversed and thus their modes may be changed with
66this call.
67.Pp
68The flags specified are formed by
69.Em or Ns 'ing
70the following values:
71.Pp
72.Bl -tag -width "SF_IMMUTABLE" -compact -offset indent
73.It Dv UF_NODUMP
74Do not dump the file.
75.It Dv UF_IMMUTABLE
76The file may not be changed.
77.It Dv UF_APPEND
78The file may only be appended to.
79.It Dv UF_OPAQUE
80The file (if a directory) is opaque for union mounts.
81.It Dv SF_ARCHIVED
82The file is archived.
83.It Dv SF_IMMUTABLE
84The file may not be changed.
85.It Dv SF_APPEND
86The file may only be appended to.
87.El
88.Pp
89The
90.Dv UF_NODUMP ,
91.Dv UF_IMMUTABLE ,
92.Dv UF_APPEND ,
93and
94.Dv UF_OPAQUE
95flags may be set or unset by either the owner of a file or the super-user,
96except on block and character devices, where only the super-user may set
97or unset them.
98.Pp
99The
100.Dv SF_ARCHIVED ,
101.Dv SF_IMMUTABLE ,
102and
103.Dv SF_APPEND
104flags may only be set or unset by the super-user.
105Attempts by the non-super-user to set the super-user only flags
106are silently ignored.
107These flags may be set at any time, but normally may only be unset when
108the system is in single-user mode.
109(See
110.Xr init 8
111for details.)
112.Sh RETURN VALUES
113Upon successful completion, a value of 0 is returned.
114Otherwise, -1 is returned and the global variable
115.Va errno
116is set to indicate the error.
117.Sh ERRORS
118.Fn chflags
119will fail if:
120.Bl -tag -width Er
121.It Bq Er ENOTDIR
122A component of the path prefix is not a directory.
123.It Bq Er ENAMETOOLONG
124A component of a pathname exceeded
125.Dv {NAME_MAX}
126characters, or an entire path name exceeded
127.Dv {PATH_MAX}
128characters.
129.It Bq Er ENOENT
130The named file does not exist.
131.It Bq Er EACCES
132Search permission is denied for a component of the path prefix.
133.It Bq Er ELOOP
134Too many symbolic links were encountered in translating the pathname.
135.It Bq Er EPERM
136The effective user ID does not match the owner of the file and
137the effective user ID is not the super-user, or
138the effective user ID is not the super-user and one or more of the
139super-user-only flags for the named file would be changed.
140.It Bq Er EOPNOTSUPP
141The named file resides on a file system that does not support file
142flags.
143.It Bq Er EROFS
144The named file resides on a read-only file system.
145.It Bq Er EFAULT
146.Fa path
147points outside the process's allocated address space.
148.It Bq Er EIO
149An
150.Tn I/O
151error occurred while reading from or writing to the file system.
152.El
153.Pp
154.Fn fchflags
155will fail if:
156.Bl -tag -width Er
157.It Bq Er EBADF
158The descriptor is not valid.
159.It Bq Er EINVAL
160.Fa fd
161refers to a socket, not to a file.
162.It Bq Er EPERM
163The effective user ID does not match the owner of the file and
164the effective user ID is not the super-user, or
165the effective user ID is not the super-user and one or more of the
166super-user-only flags for the file would be changed.
167.It Bq Er EOPNOTSUPP
168The file resides on a file system that does not support file flags.
169.It Bq Er EROFS
170The file resides on a read-only file system.
171.It Bq Er EIO
172An
173.Tn I/O
174error occurred while reading from or writing to the file system.
175.El
176.Sh SEE ALSO
177.Xr chflags 1 ,
178.Xr init 8 ,
179.Xr mount_union 8
180.Sh HISTORY
181The
182.Fn chflags
183and
184.Fn fchflags
185functions first appeared in
186.Bx 4.4 .
187The
188.Fn lchflags
189function first appeared in
190.Nx 1.5 .
191