Commit | Line | Data |
---|---|---|
931b8415 CL |
1 | .\" Copyright (c) 1980, 1991 Regents of the University of California. |
2 | .\" All rights reserved. | |
d149e2aa | 3 | .\" |
931b8415 | 4 | .\" %sccs.include.redist.man% |
d149e2aa | 5 | .\" |
931b8415 CL |
6 | .\" @(#)chmod.2 6.6 (Berkeley) %G% |
7 | .\" | |
8 | .Dd | |
9 | .Dt CHMOD 2 | |
10 | .Os BSD 4 | |
11 | .Sh NAME | |
12 | .Nm chmod , | |
13 | .Nm fchmod | |
14 | .Nd change mode of file | |
15 | .Sh SYNOPSIS | |
16 | .Fd #include <sys/stat.h> | |
17 | .Ft int | |
18 | .Fn chmod "const char *path" "mode_t mode" | |
19 | .Ft int | |
20 | .Fn fchmod "int fd" "mode_t mode" | |
21 | .Sh DESCRIPTION | |
22 | The function | |
23 | .Fn chmod | |
24 | sets the file permission bits | |
25 | of the file | |
26 | specified by the pathname | |
27 | .Fa path | |
28 | to | |
29 | .Fa mode . | |
30 | .Fn Fchmod | |
31 | sets the permission bits of the specified | |
32 | file descriptor | |
33 | .Fa fd . | |
34 | .Fn Chmod | |
35 | verifies that the process owner (user) either owns | |
36 | the file specified by | |
37 | .Fa path | |
38 | (or | |
39 | .Fa fd ) , | |
40 | or | |
41 | is the super-user. | |
42 | A mode is created from | |
43 | .Em or'd | |
44 | permission bit masks | |
45 | defined in | |
46 | .Aq Pa sys/stat.h : | |
47 | .Bd -literal -offset indent -compact | |
48 | #define S_IRWXU 0000700 /* RWX mask for owner */ | |
49 | #define S_IRUSR 0000400 /* R for owner */ | |
50 | #define S_IWUSR 0000200 /* W for owner */ | |
51 | #define S_IXUSR 0000100 /* X for owner */ | |
52 | ||
53 | #define S_IRWXG 0000070 /* RWX mask for group */ | |
54 | #define S_IRGRP 0000040 /* R for group */ | |
55 | #define S_IWGRP 0000020 /* W for group */ | |
56 | #define S_IXGRP 0000010 /* X for group */ | |
57 | ||
58 | #define S_IRWXO 0000007 /* RWX mask for other */ | |
59 | #define S_IROTH 0000004 /* R for other */ | |
60 | #define S_IWOTH 0000002 /* W for other */ | |
61 | #define S_IXOTH 0000001 /* X for other */ | |
62 | ||
63 | #define S_ISUID 0004000 /* set user id on execution */ | |
64 | #define S_ISGID 0002000 /* set group id on execution */ | |
65 | #define S_ISVTX 0001000 /* save swapped text even after use */ | |
66 | .Ed | |
67 | .Pp | |
68 | The | |
69 | .Dv ISVTX | |
70 | (the | |
71 | .Em sticky bit ) | |
72 | indicates to the system which executable files are shareable (the | |
73 | default) and the system maintains the program text of the files | |
74 | in the swap area. The sticky bit may only be set by the super user | |
75 | on shareable executable files. | |
76 | .Pp | |
77 | If mode | |
78 | .Dv ISVTX | |
79 | (the `sticky bit') is set on a directory, | |
31d564b9 | 80 | an unprivileged user may not delete or rename |
931b8415 CL |
81 | files of other users in that directory. The sticky bit may be |
82 | set by any user on a directory which the user owns or has appropriate | |
83 | permissions. | |
31d564b9 | 84 | For more details of the properties of the sticky bit, see |
931b8415 CL |
85 | .Xr sticky 8 . |
86 | .Pp | |
7656e522 | 87 | Writing or changing the owner of a file |
ed77f7df MK |
88 | turns off the set-user-id and set-group-id bits |
89 | unless the user is the super-user. | |
d149e2aa | 90 | This makes the system somewhat more secure |
7656e522 KM |
91 | by protecting set-user-id (set-group-id) files |
92 | from remaining set-user-id (set-group-id) if they are modified, | |
d149e2aa | 93 | at the expense of a degree of compatibility. |
931b8415 | 94 | .Sh RETURN VALUES |
7656e522 | 95 | Upon successful completion, a value of 0 is returned. |
931b8415 CL |
96 | Otherwise, a value of -1 is returned and |
97 | .Va errno | |
7656e522 | 98 | is set to indicate the error. |
931b8415 CL |
99 | .Sh ERRORS |
100 | .Fn Chmod | |
7656e522 | 101 | will fail and the file mode will be unchanged if: |
931b8415 CL |
102 | .Bl -tag -width Er |
103 | .It Bq Er ENOTDIR | |
7656e522 | 104 | A component of the path prefix is not a directory. |
931b8415 | 105 | .It Bq Er EINVAL |
b5984ffe | 106 | The pathname contains a character with the high-order bit set. |
931b8415 | 107 | .It Bq Er ENAMETOOLONG |
b5984ffe KM |
108 | A component of a pathname exceeded 255 characters, |
109 | or an entire path name exceeded 1023 characters. | |
931b8415 | 110 | .It Bq Er ENOENT |
7656e522 | 111 | The named file does not exist. |
931b8415 | 112 | .It Bq Er EACCES |
b5984ffe | 113 | Search permission is denied for a component of the path prefix. |
931b8415 | 114 | .It Bq Er ELOOP |
b5984ffe | 115 | Too many symbolic links were encountered in translating the pathname. |
931b8415 | 116 | .It Bq Er EPERM |
7656e522 KM |
117 | The effective user ID does not match the owner of the file and |
118 | the effective user ID is not the super-user. | |
931b8415 | 119 | .It Bq Er EROFS |
7656e522 | 120 | The named file resides on a read-only file system. |
931b8415 CL |
121 | .It Bq Er EFAULT |
122 | .Fa Path | |
7656e522 | 123 | points outside the process's allocated address space. |
931b8415 | 124 | .It Bq Er EIO |
fd690c8b | 125 | An I/O error occurred while reading from or writing to the file system. |
931b8415 CL |
126 | .El |
127 | .Pp | |
128 | .Fn Fchmod | |
7656e522 | 129 | will fail if: |
931b8415 CL |
130 | .Bl -tag -width Er |
131 | .It Bq Er EBADF | |
7656e522 | 132 | The descriptor is not valid. |
931b8415 CL |
133 | .It Bq Er EINVAL |
134 | .Fa Fd | |
7656e522 | 135 | refers to a socket, not to a file. |
931b8415 | 136 | .It Bq Er EROFS |
7656e522 | 137 | The file resides on a read-only file system. |
931b8415 | 138 | .It Bq Er EIO |
fd690c8b | 139 | An I/O error occurred while reading from or writing to the file system. |
931b8415 CL |
140 | .El |
141 | .Sh SEE ALSO | |
142 | .Xr chmod 1 , | |
143 | .Xr open 2 , | |
144 | .Xr chown 2 , | |
145 | .Xr stat 2 , | |
146 | .Xr sticky 8 | |
147 | .Sh STANDARDS | |
148 | .Fn Chmod | |
149 | is expected to conform to IEEE Std 1003.1-1988 | |
150 | .Pq Dq Tn POSIX . | |
151 | .Sh HISTORY | |
152 | The | |
153 | .Fn fchmod | |
154 | function call | |
155 | appeared in | |
156 | .Bx 4.2 . |