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/types.h>
10       #include <sys/stat.h>
11
12       int chmod(const char *path, mode_t mode);
13       int fchmod(int fildes, mode_t mode);
14

DESCRIPTION

16       The mode of the file given by path or referenced by fildes is changed.
17
18       Modes are specified by or'ing the following:
19
20
21              S_ISUID   04000 set user ID on execution
22
23              S_ISGID   02000 set group ID on execution
24
25              S_ISVTX   01000 sticky bit
26
27              S_IRUSR   00400 read by owner
28
29              S_IWUSR   00200 write by owner
30
31              S_IXUSR   00100 execute/search by owner
32
33              S_IRGRP   00040 read by group
34
35              S_IWGRP   00020 write by group
36
37              S_IXGRP   00010 execute/search by group
38
39              S_IROTH   00004 read by others
40
41              S_IWOTH   00002 write by others
42
43              S_IXOTH   00001 execute/search by others
44
45
46       The  effective  UID  of the calling process must match the owner of the
47       file, or the process must  be  privileged  (Linux:  it  must  have  the
48       CAP_FOWNER capability).
49
50       If  the  calling  process  is  not privileged (Linux: does not have the
51       CAP_FSETID capability), and the group of the file does  not  match  the
52       effective  group  ID  of  the process or one of its supplementary group
53       IDs, the S_ISGID bit will be turned off, but this  will  not  cause  an
54       error to be returned.
55
56       As  a  security  measure, depending on the file system, the set-user-ID
57       and set-group-ID execution bits may be turned off if a file is written.
58       (On  Linux  this  occurs  if  the  writing  process  does  not have the
59       CAP_FSETID capability.)  On some file systems, only the  superuser  can
60       set  the  sticky bit, which may have a special meaning.  For the sticky
61       bit, and for set-user-ID and  set-group-ID  bits  on  directories,  see
62       stat(2).
63
64       On  NFS  file  systems,  restricting  the  permissions will immediately
65       influence already open files, because the access control is done on the
66       server, but open files are maintained by the client.  Widening the per‐
67       missions may be delayed for  other  clients  if  attribute  caching  is
68       enabled on them.
69

RETURN VALUE

71       On  success,  zero is returned.  On error, -1 is returned, and errno is
72       set appropriately.
73

ERRORS

75       Depending on the file system, other errors can be returned.   The  more
76       general errors for chmod() are listed below:
77
78
79       EACCES Search  permission  is denied on a component of the path prefix.
80              (See also path_resolution(2).)
81
82       EFAULT path points outside your accessible address space.
83
84       EIO    An I/O error occurred.
85
86       ELOOP  Too many symbolic links were encountered in resolving path.
87
88       ENAMETOOLONG
89              path is too long.
90
91       ENOENT The file does not exist.
92
93       ENOMEM Insufficient kernel memory was available.
94
95       ENOTDIR
96              A component of the path prefix is not a directory.
97
98       EPERM  The effective UID does not match the owner of the file, and  the
99              process   is  not  privileged  (Linux:  it  does  not  have  the
100              CAP_FOWNER capability).
101
102       EROFS  The named file resides on a read-only file system.
103
104       The general errors for fchmod() are listed below:
105
106       EBADF  The file descriptor fildes is not valid.
107
108       EIO    See above.
109
110       EPERM  See above.
111
112       EROFS  See above.
113

CONFORMING TO

115       4.4BSD, SVr4, POSIX.1-2001.
116

SEE ALSO

118       chown(2), execve(2), fchmodat(2), open(2), path_resolution(2), stat(2)
119
120
121
122Linux 2.6.7                       2004-06-23                          CHMOD(2)
Impressum