1CHMOD(2)                   Linux Programmer's Manual                  CHMOD(2)
2
3
4

NAME

6       chmod, fchmod - change permissions of a file
7

SYNOPSIS

9       #include <sys/stat.h>
10
11       int chmod(const char *path, mode_t mode);
12       int fchmod(int fd, mode_t mode);
13
14   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
15
16       fchmod(): _BSD_SOURCE || _XOPEN_SOURCE >= 500
17

DESCRIPTION

19       These  system calls change the permissions of a file.  They differ only
20       in how the file is specified:
21
22       * chmod() changes the permissions of the file specified whose  pathname
23         is given in path, which is dereferenced if it is a symbolic link.
24
25       * fchmod()  changes the permissions of the file referred to by the open
26         file descriptor fd.
27
28       The new file permissions are specified in mode, which  is  a  bit  mask
29       created by ORing together zero or more of the following:
30
31       S_ISUID  (04000)  set-user-ID   (set   process  effective  user  ID  on
32                         execve(2))
33
34       S_ISGID  (02000)  set-group-ID  (set  process  effective  group  ID  on
35                         execve(2);   mandatory   locking,   as  described  in
36                         fcntl(2); take a new file's group from parent  direc‐
37                         tory, as described in chown(2) and mkdir(2))
38
39       S_ISVTX  (01000)  sticky bit (restricted deletion flag, as described in
40                         unlink(2))
41
42       S_IRUSR  (00400)  read by owner
43
44       S_IWUSR  (00200)  write by owner
45
46       S_IXUSR  (00100)  execute/search by owner ("search" applies for  direc‐
47                         tories,  and  means that entries within the directory
48                         can be accessed)
49
50       S_IRGRP  (00040)  read by group
51
52       S_IWGRP  (00020)  write by group
53
54       S_IXGRP  (00010)  execute/search by group
55
56       S_IROTH  (00004)  read by others
57
58       S_IWOTH  (00002)  write by others
59
60       S_IXOTH  (00001)  execute/search by others
61
62       The effective UID of the calling process must match the  owner  of  the
63       file,  or  the  process  must  be  privileged  (Linux: it must have the
64       CAP_FOWNER capability).
65
66       If the calling process is not privileged  (Linux:  does  not  have  the
67       CAP_FSETID  capability),  and  the group of the file does not match the
68       effective group ID of the process or one  of  its  supplementary  group
69       IDs,  the  S_ISGID  bit  will be turned off, but this will not cause an
70       error to be returned.
71
72       As a security measure, depending on the file  system,  the  set-user-ID
73       and set-group-ID execution bits may be turned off if a file is written.
74       (On Linux this  occurs  if  the  writing  process  does  not  have  the
75       CAP_FSETID  capability.)   On some file systems, only the superuser can
76       set the sticky bit, which may have a special meaning.  For  the  sticky
77       bit,  and  for  set-user-ID  and  set-group-ID bits on directories, see
78       stat(2).
79
80       On NFS file  systems,  restricting  the  permissions  will  immediately
81       influence already open files, because the access control is done on the
82       server, but open files are maintained by the client.  Widening the per‐
83       missions  may  be  delayed  for  other  clients if attribute caching is
84       enabled on them.
85

RETURN VALUE

87       On success, zero is returned.  On error, -1 is returned, and  errno  is
88       set appropriately.
89

ERRORS

91       Depending  on  the file system, other errors can be returned.  The more
92       general errors for chmod() are listed below:
93
94       EACCES Search permission is denied on a component of the  path  prefix.
95              (See also path_resolution(7).)
96
97       EFAULT path points outside your accessible address space.
98
99       EIO    An I/O error occurred.
100
101       ELOOP  Too many symbolic links were encountered in resolving path.
102
103       ENAMETOOLONG
104              path is too long.
105
106       ENOENT The file does not exist.
107
108       ENOMEM Insufficient kernel memory was available.
109
110       ENOTDIR
111              A component of the path prefix is not a directory.
112
113       EPERM  The  effective UID does not match the owner of the file, and the
114              process  is  not  privileged  (Linux:  it  does  not  have   the
115              CAP_FOWNER capability).
116
117       EROFS  The named file resides on a read-only file system.
118
119       The general errors for fchmod() are listed below:
120
121       EBADF  The file descriptor fd is not valid.
122
123       EIO    See above.
124
125       EPERM  See above.
126
127       EROFS  See above.
128

CONFORMING TO

130       4.4BSD, SVr4, POSIX.1-2001.
131

SEE ALSO

133       chown(2), execve(2), fchmodat(2), open(2), stat(2), path_resolution(7)
134

COLOPHON

136       This  page  is  part of release 3.25 of the Linux man-pages project.  A
137       description of the project, and information about reporting  bugs,  can
138       be found at http://www.kernel.org/doc/man-pages/.
139
140
141
142Linux                             2008-05-26                          CHMOD(2)
Impressum