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