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 | .\"
|
---|
5 | .\" @(#)chmod.2 6.5 (Berkeley) 5/13/86
|
---|
6 | .\"
|
---|
7 | .TH CHMOD 2 "May 13, 1986"
|
---|
8 | .UC 4
|
---|
9 | .SH NAME
|
---|
10 | chmod \- change mode of file
|
---|
11 | .SH SYNOPSIS
|
---|
12 | .nf
|
---|
13 | .ft B
|
---|
14 | #include <sys/types.h>
|
---|
15 | #include <sys/stat.h>
|
---|
16 |
|
---|
17 | int chmod(const char *\fIpath\fP, mode_t \fImode\fP)
|
---|
18 | .ig \" You never know
|
---|
19 | .PP
|
---|
20 | .ft B
|
---|
21 | int fchmod(int \fIfd\fP, mode_t \fImode\fP)
|
---|
22 | ..
|
---|
23 | .fi
|
---|
24 | .SH DESCRIPTION
|
---|
25 | The file whose name
|
---|
26 | is given by \fIpath\fP
|
---|
27 | .ig
|
---|
28 | or referenced by the descriptor
|
---|
29 | .I fd
|
---|
30 | ..
|
---|
31 | has its mode changed to
|
---|
32 | .IR mode .
|
---|
33 | Modes are constructed by
|
---|
34 | .IR or 'ing
|
---|
35 | together some
|
---|
36 | combination of the following, defined in
|
---|
37 | .IR <sys/stat.h> :
|
---|
38 | .PP
|
---|
39 | .RS
|
---|
40 | .nf
|
---|
41 | .ta \w'S_ISUID\ \ 'u +\w'04000\ \ \ 'u
|
---|
42 | S_ISUID 04000 set user ID on execution
|
---|
43 | S_ISGID 02000 set group ID on execution
|
---|
44 | S_ISVTX 01000 `sticky bit' (see below)
|
---|
45 | S_IRWXU 00700 read, write, execute by owner
|
---|
46 | S_IRUSR 00400 read by owner
|
---|
47 | S_IWUSR 00200 write by owner
|
---|
48 | S_IXUSR 00100 execute (search on directory) by owner
|
---|
49 | S_IRWXG 00070 read, write, execute by group
|
---|
50 | S_IRGRP 00040 read by group
|
---|
51 | S_IWGRP 00020 write by group
|
---|
52 | S_IXGRP 00010 execute (search on directory) by group
|
---|
53 | S_IRWXO 00007 read, write, execute by others
|
---|
54 | S_IROTH 00004 read by others
|
---|
55 | S_IWOTH 00002 write by others
|
---|
56 | S_IXOTH 00001 execute (search on directory) by others
|
---|
57 | .fi
|
---|
58 | .RE
|
---|
59 | .PP
|
---|
60 | If mode ISVTX (the `sticky bit') is set on a directory,
|
---|
61 | an unprivileged user may not delete or rename
|
---|
62 | files of other users in that directory. (Minix-vmd)
|
---|
63 | .PP
|
---|
64 | Only the owner of a file (or the super-user) may change the mode.
|
---|
65 | .PP
|
---|
66 | Writing or changing the owner of a file
|
---|
67 | turns off the set-user-id and set-group-id bits
|
---|
68 | unless the user is the super-user.
|
---|
69 | This makes the system somewhat more secure
|
---|
70 | by protecting set-user-id (set-group-id) files
|
---|
71 | from remaining set-user-id (set-group-id) if they are modified,
|
---|
72 | at the expense of a degree of compatibility.
|
---|
73 | .SH "RETURN VALUE
|
---|
74 | Upon successful completion, a value of 0 is returned.
|
---|
75 | Otherwise, a value of \-1 is returned and
|
---|
76 | .B errno
|
---|
77 | is set to indicate the error.
|
---|
78 | .SH "ERRORS
|
---|
79 | .B Chmod
|
---|
80 | will fail and the file mode will be unchanged if:
|
---|
81 | .TP 15
|
---|
82 | [ENOTDIR]
|
---|
83 | A component of the path prefix is not a directory.
|
---|
84 | .TP 15
|
---|
85 | [ENAMETOOLONG]
|
---|
86 | The path name exceeds PATH_MAX characters.
|
---|
87 | .TP 15
|
---|
88 | [ENOENT]
|
---|
89 | The named file does not exist.
|
---|
90 | .TP 15
|
---|
91 | [EACCES]
|
---|
92 | Search permission is denied for a component of the path prefix.
|
---|
93 | .TP 15
|
---|
94 | [ELOOP]
|
---|
95 | Too many symbolic links were encountered in translating the pathname.
|
---|
96 | (Minix-vmd)
|
---|
97 | .TP 15
|
---|
98 | [EPERM]
|
---|
99 | The effective user ID does not match the owner of the file and
|
---|
100 | the effective user ID is not the super-user.
|
---|
101 | .TP 15
|
---|
102 | [EROFS]
|
---|
103 | The named file resides on a read-only file system.
|
---|
104 | .TP 15
|
---|
105 | [EFAULT]
|
---|
106 | .I Path
|
---|
107 | points outside the process's allocated address space.
|
---|
108 | .TP 15
|
---|
109 | [EIO]
|
---|
110 | An I/O error occurred while reading from or writing to the file system.
|
---|
111 | .ig
|
---|
112 | .PP
|
---|
113 | .I Fchmod
|
---|
114 | will fail if:
|
---|
115 | .TP 15
|
---|
116 | [EBADF]
|
---|
117 | The descriptor is not valid.
|
---|
118 | .TP 15
|
---|
119 | [EROFS]
|
---|
120 | The file resides on a read-only file system.
|
---|
121 | .TP 15
|
---|
122 | [EIO]
|
---|
123 | An I/O error occurred while reading from or writing to the file system.
|
---|
124 | ..
|
---|
125 | .SH "SEE ALSO"
|
---|
126 | .BR chmod (1),
|
---|
127 | .BR open (2),
|
---|
128 | .BR chown (2),
|
---|
129 | .BR stat (2).
|
---|
130 | .SH NOTES
|
---|
131 | The sticky bit was historically used to lock important executables into
|
---|
132 | memory.
|
---|