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():
17           _BSD_SOURCE || _XOPEN_SOURCE >= 500 ||
18           _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
19           || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
20

DESCRIPTION

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

RETURN VALUE

90       On  success,  zero is returned.  On error, -1 is returned, and errno is
91       set appropriately.
92

ERRORS

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

CONFORMING TO

133       4.4BSD, SVr4, POSIX.1-2001.
134

SEE ALSO

136       chown(2), execve(2), fchmodat(2), open(2), stat(2), path_resolution(7)
137

COLOPHON

139       This page is part of release 3.53 of the Linux  man-pages  project.   A
140       description  of  the project, and information about reporting bugs, can
141       be found at http://www.kernel.org/doc/man-pages/.
142
143
144
145Linux                             2010-09-26                          CHMOD(2)
Impressum