]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/chmod.2
getent.1, intro.1, time.1, _exit.2, _syscall.2, accept.2, access.2, acct.2, adjtimex...
[thirdparty/man-pages.git] / man2 / chmod.2
CommitLineData
fea681da
MK
1.\" Hey Emacs! This file is -*- nroff -*- source.
2.\"
3.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
4.\"
5.\" Permission is granted to make and distribute verbatim copies of this
6.\" manual provided the copyright notice and this permission notice are
7.\" preserved on all copies.
8.\"
9.\" Permission is granted to copy and distribute modified versions of this
10.\" manual under the conditions for verbatim copying, provided that the
11.\" entire resulting derived work is distributed under the terms of a
12.\" permission notice identical to this one.
c13182ef 13.\"
fea681da
MK
14.\" Since the Linux kernel and libraries are constantly changing, this
15.\" manual page may be incorrect or out-of-date. The author(s) assume no
16.\" responsibility for errors or omissions, or for damages resulting from
17.\" the use of the information contained herein. The author(s) may not
18.\" have taken the same level of care in the production of this manual,
19.\" which is licensed free of charge, as they might when working
20.\" professionally.
c13182ef 21.\"
fea681da
MK
22.\" Formatted or processed versions of this manual, if unaccompanied by
23.\" the source, must acknowledge the copyright and authors of this work.
24.\"
25.\" Modified by Michael Haardt <michael@moria.de>
26.\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
27.\" Modified 1997-01-12 by Michael Haardt
28.\" <michael@cantor.informatik.rwth-aachen.de>: NFS details
c11b1abf 29.\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
fea681da 30.\"
7990e026 31.TH CHMOD 2 2010-09-26 "Linux" "Linux Programmer's Manual"
fea681da
MK
32.SH NAME
33chmod, fchmod \- change permissions of a file
34.SH SYNOPSIS
fea681da
MK
35.B #include <sys/stat.h>
36.sp
37.BI "int chmod(const char *" path ", mode_t " mode );
38.br
47752f33 39.BI "int fchmod(int " fd ", mode_t " mode );
cc4615cc
MK
40.sp
41.in -4n
42Feature Test Macro Requirements for glibc (see
43.BR feature_test_macros (7)):
44.in
45.sp
65d3ffd9
MK
46.ad l
47.PD 0
cc4615cc 48.BR fchmod ():
65d3ffd9 49.RS 4
65d3ffd9
MK
50_BSD_SOURCE ||
51_XOPEN_SOURCE\ >=\ 500 ||
52_XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
3ba63d80 53.br
28e7ac24 54|| /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
c9f2ff9d 55.RE
65d3ffd9
MK
56.PD
57.ad
fea681da 58.SH DESCRIPTION
0689a4da
MK
59These system calls change the permissions of a file.
60They differ only in how the file is specified:
61.IP * 2
62.BR chmod ()
63changes the permissions of the file specified whose pathname is given in
64.IR path ,
65which is dereferenced if it is a symbolic link.
66.IP *
67.BR fchmod ()
68changes the permissions of the file referred to by the open file descriptor
69.IR fd .
70.PP
71The new file permissions are specified in
72.IR mode ,
73which is a bit mask created by ORing together zero or
74more of the following:
75.TP 18
76.BR S_ISUID " (04000)"
77set-user-ID (set process effective user ID on
78.BR execve (2))
fea681da 79.TP
0689a4da
MK
80.BR S_ISGID " (02000)"
81set-group-ID (set process effective group ID on
82.BR execve (2);
83mandatory locking, as described in
84.BR fcntl (2);
85take a new file's group from parent directory, as described in
86.BR chown (2)
87and
88.BR mkdir (2))
fea681da 89.TP
0689a4da
MK
90.BR S_ISVTX " (01000)"
91sticky bit (restricted deletion flag, as described in
92.BR unlink (2))
fea681da 93.TP
0689a4da
MK
94.BR S_IRUSR " (00400)"
95read by owner
fea681da 96.TP
0689a4da
MK
97.BR S_IWUSR " (00200)"
98write by owner
fea681da 99.TP
0689a4da
MK
100.BR S_IXUSR " (00100)"
101execute/search by owner ("search" applies for directories,
102and means that entries within the directory can be accessed)
fea681da 103.TP
0689a4da
MK
104.BR S_IRGRP " (00040)"
105read by group
fea681da 106.TP
0689a4da
MK
107.BR S_IWGRP " (00020)"
108write by group
fea681da 109.TP
0689a4da
MK
110.BR S_IXGRP " (00010)"
111execute/search by group
fea681da 112.TP
0689a4da
MK
113.BR S_IROTH " (00004)"
114read by others
fea681da 115.TP
0689a4da
MK
116.BR S_IWOTH " (00002)"
117write by others
fea681da 118.TP
0689a4da
MK
119.BR S_IXOTH " (00001)"
120execute/search by others
cf0a9ace 121.PP
fea681da
MK
122The effective UID of the calling process must match the owner of the file,
123or the process must be privileged (Linux: it must have the
124.B CAP_FOWNER
125capability).
126
127If the calling process is not privileged (Linux: does not have the
128.B CAP_FSETID
129capability), and the group of the file does not match
130the effective group ID of the process or one of its
682edefb
MK
131supplementary group IDs, the
132.B S_ISGID
133bit will be turned off,
fea681da
MK
134but this will not cause an error to be returned.
135
136As a security measure, depending on the file system,
c7400a2c 137the set-user-ID and set-group-ID execution bits
fea681da
MK
138may be turned off if a file is written.
139(On Linux this occurs if the writing process does not have the
140.B CAP_FSETID
141capability.)
2c8d1c7d 142On some file systems, only the superuser can set the sticky bit,
fea681da 143which may have a special meaning.
c7400a2c 144For the sticky bit, and for set-user-ID and set-group-ID bits on
fea681da
MK
145directories, see
146.BR stat (2).
147
148On NFS file systems, restricting the permissions will immediately influence
149already open files, because the access control is done on the server, but
c13182ef
MK
150open files are maintained by the client.
151Widening the permissions may be
fea681da 152delayed for other clients if attribute caching is enabled on them.
47297adb 153.SH RETURN VALUE
c13182ef
MK
154On success, zero is returned.
155On error, \-1 is returned, and
fea681da
MK
156.I errno
157is set appropriately.
158.SH ERRORS
c13182ef
MK
159Depending on the file system, other errors can be returned.
160The more general errors for
e511ffb6 161.BR chmod ()
fea681da 162are listed below:
fea681da
MK
163.TP
164.B EACCES
165Search permission is denied on a component of the path prefix.
166(See also
ad7cc990 167.BR path_resolution (7).)
fea681da
MK
168.TP
169.B EFAULT
170.I path
171points outside your accessible address space.
172.TP
173.B EIO
174An I/O error occurred.
175.TP
176.B ELOOP
177Too many symbolic links were encountered in resolving
178.IR path .
179.TP
180.B ENAMETOOLONG
181.I path
182is too long.
183.TP
184.B ENOENT
185The file does not exist.
186.TP
187.B ENOMEM
188Insufficient kernel memory was available.
189.TP
190.B ENOTDIR
191A component of the path prefix is not a directory.
192.TP
193.B EPERM
194The effective UID does not match the owner of the file,
195and the process is not privileged (Linux: it does not have the
196.B CAP_FOWNER
197capability).
198.TP
199.B EROFS
200The named file resides on a read-only file system.
201.PP
202The general errors for
e511ffb6 203.BR fchmod ()
fea681da
MK
204are listed below:
205.TP
206.B EBADF
207The file descriptor
47752f33 208.I fd
fea681da
MK
209is not valid.
210.TP
211.B EIO
212See above.
213.TP
214.B EPERM
215See above.
216.TP
217.B EROFS
218See above.
47297adb 219.SH CONFORMING TO
97c1eac8 2204.4BSD, SVr4, POSIX.1-2001.
47297adb 221.SH SEE ALSO
fea681da
MK
222.BR chown (2),
223.BR execve (2),
22e3b8b1 224.BR fchmodat (2),
fea681da 225.BR open (2),
ad7cc990
MK
226.BR stat (2),
227.BR path_resolution (7)