Commit | Line | Data |
---|---|---|
d149e2aa KM |
1 | .\" Copyright (c) 1980 Regents of the University of California. |
2 | .\" All rights reserved. The Berkeley software License Agreement | |
3 | .\" specifies the terms and conditions for redistribution. | |
4 | .\" | |
31d564b9 | 5 | .\" @(#)chmod.2 6.4 (Berkeley) %G% |
d149e2aa | 6 | .\" |
3efa6125 | 7 | .TH CHMOD 2 "" |
d149e2aa KM |
8 | .UC 4 |
9 | .SH NAME | |
10 | chmod \- change mode of file | |
11 | .SH SYNOPSIS | |
12 | .nf | |
7656e522 KM |
13 | .ft B |
14 | chmod(path, mode) | |
15 | char *path; | |
16 | int mode; | |
17 | .PP | |
18 | .ft B | |
19 | fchmod(fd, mode) | |
20 | int fd, mode; | |
d149e2aa KM |
21 | .fi |
22 | .SH DESCRIPTION | |
23 | The file whose name | |
7656e522 KM |
24 | is given by \fIpath\fP |
25 | or referenced by the descriptor | |
26 | .I fd | |
d149e2aa KM |
27 | has its mode changed to |
28 | .IR mode . | |
29 | Modes are constructed by | |
7656e522 | 30 | .IR or 'ing |
d149e2aa KM |
31 | together some |
32 | combination of the following: | |
33 | .PP | |
34 | .RS | |
35 | 04000 set user ID on execution | |
36 | 02000 set group ID on execution | |
31d564b9 | 37 | 01000 `sticky bit' (see below) |
d149e2aa KM |
38 | 00400 read by owner |
39 | 00200 write by owner | |
40 | 00100 execute (search on directory) by owner | |
41 | 00070 read, write, execute (search) by group | |
42 | 00007 read, write, execute (search) by others | |
43 | .RE | |
44 | .PP | |
45 | If an executable file is set up for sharing (this is the default) | |
31d564b9 | 46 | then mode 01000 (the `sticky bit') prevents the system from |
d149e2aa | 47 | abandoning the swap-space image of the program-text portion |
31d564b9 DS |
48 | of the file when its last user terminates. |
49 | Ability to set this bit on executable files is restricted to the super-user. | |
50 | .PP | |
51 | If mode 01000 (the `sticky bit') is set on a directory, | |
52 | an unprivileged user may not delete or rename | |
53 | files of other users in that directory. | |
54 | For more details of the properties of the sticky bit, see | |
55 | .IR sticky (8). | |
d149e2aa KM |
56 | .PP |
57 | Only the owner of a file (or the super-user) may change the mode. | |
d149e2aa | 58 | .PP |
7656e522 KM |
59 | Writing or changing the owner of a file |
60 | turns off the set-user-id and set-group-id bits. | |
d149e2aa | 61 | This makes the system somewhat more secure |
7656e522 KM |
62 | by protecting set-user-id (set-group-id) files |
63 | from remaining set-user-id (set-group-id) if they are modified, | |
d149e2aa | 64 | at the expense of a degree of compatibility. |
7656e522 KM |
65 | .SH "RETURN VALUE |
66 | Upon successful completion, a value of 0 is returned. | |
67 | Otherwise, a value of \-1 is returned and | |
68 | .I errno | |
69 | is set to indicate the error. | |
70 | .SH "ERRORS | |
71 | .I Chmod | |
72 | will fail and the file mode will be unchanged if: | |
73 | .TP 15 | |
7656e522 KM |
74 | [ENOTDIR] |
75 | A component of the path prefix is not a directory. | |
76 | .TP 15 | |
b5984ffe KM |
77 | [EINVAL] |
78 | The pathname contains a character with the high-order bit set. | |
79 | .TP 15 | |
80 | [ENAMETOOLONG] | |
81 | A component of a pathname exceeded 255 characters, | |
82 | or an entire path name exceeded 1023 characters. | |
7656e522 KM |
83 | .TP 15 |
84 | [ENOENT] | |
85 | The named file does not exist. | |
86 | .TP 15 | |
87 | [EACCES] | |
b5984ffe KM |
88 | Search permission is denied for a component of the path prefix. |
89 | .TP 15 | |
90 | [ELOOP] | |
91 | Too many symbolic links were encountered in translating the pathname. | |
7656e522 KM |
92 | .TP 15 |
93 | [EPERM] | |
94 | The effective user ID does not match the owner of the file and | |
95 | the effective user ID is not the super-user. | |
96 | .TP 15 | |
97 | [EROFS] | |
98 | The named file resides on a read-only file system. | |
99 | .TP 15 | |
100 | [EFAULT] | |
101 | .I Path | |
102 | points outside the process's allocated address space. | |
fd690c8b KM |
103 | .TP 15 |
104 | [EIO] | |
105 | An I/O error occurred while reading from or writing to the file system. | |
7656e522 KM |
106 | .PP |
107 | .I Fchmod | |
108 | will fail if: | |
109 | .TP 15 | |
110 | [EBADF] | |
111 | The descriptor is not valid. | |
112 | .TP 15 | |
113 | [EINVAL] | |
114 | .I Fd | |
115 | refers to a socket, not to a file. | |
116 | .TP 15 | |
117 | [EROFS] | |
118 | The file resides on a read-only file system. | |
fd690c8b KM |
119 | .TP 15 |
120 | [EIO] | |
121 | An I/O error occurred while reading from or writing to the file system. | |
d149e2aa | 122 | .SH "SEE ALSO" |
31d564b9 | 123 | chmod(1), open(2), chown(2), stat(2), sticky(8) |