1CHMOD(2) System Calls Manual CHMOD(2)
2
3
4
6 chmod - change mode of file
7
9 chmod(path, mode)
10 char *path;
11 int mode;
12
13 fchmod(fd, mode)
14 int fd, mode;
15
17 The file whose name is given by path or referenced by the descriptor fd
18 has its mode changed to mode. Modes are constructed by or'ing together
19 some combination of the following, defined in <sys/inode.h>:
20
21 ISUID 04000 set user ID on execution
22 ISGID 02000 set group ID on execution
23 ISVTX 01000 `sticky bit' (see below)
24 IREAD 00400 read by owner
25 IWRITE 00200 write by owner
26 IEXEC 00100 execute (search on directory) by owner
27 00070 read, write, execute (search) by group
28 00007 read, write, execute (search) by others
29
30 If an executable file is set up for sharing (this is the default) then
31 mode ISVTX (the `sticky bit') prevents the system from abandoning the
32 swap-space image of the program-text portion of the file when its last
33 user terminates. Ability to set this bit on executable files is
34 restricted to the super-user.
35
36 If mode ISVTX (the `sticky bit') is set on a directory, an unprivileged
37 user may not delete or rename files of other users in that directory.
38 For more details of the properties of the sticky bit, see sticky(8).
39
40 Only the owner of a file (or the super-user) may change the mode.
41
42 Writing or changing the owner of a file turns off the set-user-id and
43 set-group-id bits unless the user is the super-user. This makes the
44 system somewhat more secure by protecting set-user-id (set-group-id)
45 files from remaining set-user-id (set-group-id) if they are modified,
46 at the expense of a degree of compatibility.
47
49 Upon successful completion, a value of 0 is returned. Otherwise, a
50 value of -1 is returned and errno is set to indicate the error.
51
53 Chmod will fail and the file mode will be unchanged if:
54
55 [ENOTDIR] A component of the path prefix is not a directory.
56
57 [EINVAL] The pathname contains a character with the high-order
58 bit set.
59
60 [ENAMETOOLONG] A component of a pathname exceeded 255 characters, or an
61 entire path name exceeded 1023 characters.
62
63 [ENOENT] The named file does not exist.
64
65 [EACCES] Search permission is denied for a component of the path
66 prefix.
67
68 [ELOOP] Too many symbolic links were encountered in translating
69 the pathname.
70
71 [EPERM] The effective user ID does not match the owner of the
72 file and the effective user ID is not the super-user.
73
74 [EROFS] The named file resides on a read-only file system.
75
76 [EFAULT] Path points outside the process's allocated address
77 space.
78
79 [EIO] An I/O error occurred while reading from or writing to
80 the file system.
81
82 Fchmod will fail if:
83
84 [EBADF] The descriptor is not valid.
85
86 [EINVAL] Fd refers to a socket, not to a file.
87
88 [EROFS] The file resides on a read-only file system.
89
90 [EIO] An I/O error occurred while reading from or writing to
91 the file system.
92
94 chmod(1), open(2), chown(2), stat(2), sticky(8)
95
96
97
984th Berkeley Distribution May 13, 1986 CHMOD(2)