1*47208Scael.\" Copyright (c) 1980, 1991 Regents of the University of California. 2*47208Scael.\" All rights reserved. 320014Smckusick.\" 4*47208Scael.\" %sccs.include.redist.man% 520014Smckusick.\" 6*47208Scael.\" @(#)chmod.2 6.6 (Berkeley) 03/10/91 7*47208Scael.\" 8*47208Scael.Dd 9*47208Scael.Dt CHMOD 2 10*47208Scael.Os BSD 4 11*47208Scael.Sh NAME 12*47208Scael.Nm chmod , 13*47208Scael.Nm fchmod 14*47208Scael.Nd change mode of file 15*47208Scael.Sh SYNOPSIS 16*47208Scael.Fd #include <sys/stat.h> 17*47208Scael.Ft int 18*47208Scael.Fn chmod "const char *path" "mode_t mode" 19*47208Scael.Ft int 20*47208Scael.Fn fchmod "int fd" "mode_t mode" 21*47208Scael.Sh DESCRIPTION 22*47208ScaelThe function 23*47208Scael.Fn chmod 24*47208Scaelsets the file permission bits 25*47208Scaelof the file 26*47208Scaelspecified by the pathname 27*47208Scael.Fa path 28*47208Scaelto 29*47208Scael.Fa mode . 30*47208Scael.Fn Fchmod 31*47208Scaelsets the permission bits of the specified 32*47208Scaelfile descriptor 33*47208Scael.Fa fd . 34*47208Scael.Fn Chmod 35*47208Scaelverifies that the process owner (user) either owns 36*47208Scaelthe file specified by 37*47208Scael.Fa path 38*47208Scael(or 39*47208Scael.Fa fd ) , 40*47208Scaelor 41*47208Scaelis the super-user. 42*47208ScaelA mode is created from 43*47208Scael.Em or'd 44*47208Scaelpermission bit masks 45*47208Scaeldefined in 46*47208Scael.Aq Pa sys/stat.h : 47*47208Scael.Bd -literal -offset indent -compact 48*47208Scael#define S_IRWXU 0000700 /* RWX mask for owner */ 49*47208Scael#define S_IRUSR 0000400 /* R for owner */ 50*47208Scael#define S_IWUSR 0000200 /* W for owner */ 51*47208Scael#define S_IXUSR 0000100 /* X for owner */ 52*47208Scael 53*47208Scael#define S_IRWXG 0000070 /* RWX mask for group */ 54*47208Scael#define S_IRGRP 0000040 /* R for group */ 55*47208Scael#define S_IWGRP 0000020 /* W for group */ 56*47208Scael#define S_IXGRP 0000010 /* X for group */ 57*47208Scael 58*47208Scael#define S_IRWXO 0000007 /* RWX mask for other */ 59*47208Scael#define S_IROTH 0000004 /* R for other */ 60*47208Scael#define S_IWOTH 0000002 /* W for other */ 61*47208Scael#define S_IXOTH 0000001 /* X for other */ 62*47208Scael 63*47208Scael#define S_ISUID 0004000 /* set user id on execution */ 64*47208Scael#define S_ISGID 0002000 /* set group id on execution */ 65*47208Scael#define S_ISVTX 0001000 /* save swapped text even after use */ 66*47208Scael.Ed 67*47208Scael.Pp 68*47208ScaelThe 69*47208Scael.Dv ISVTX 70*47208Scael(the 71*47208Scael.Em sticky bit ) 72*47208Scaelindicates to the system which executable files are shareable (the 73*47208Scaeldefault) and the system maintains the program text of the files 74*47208Scaelin the swap area. The sticky bit may only be set by the super user 75*47208Scaelon shareable executable files. 76*47208Scael.Pp 77*47208ScaelIf mode 78*47208Scael.Dv ISVTX 79*47208Scael(the `sticky bit') is set on a directory, 8026028Sdonnan unprivileged user may not delete or rename 81*47208Scaelfiles of other users in that directory. The sticky bit may be 82*47208Scaelset by any user on a directory which the user owns or has appropriate 83*47208Scaelpermissions. 8426028SdonnFor more details of the properties of the sticky bit, see 85*47208Scael.Xr sticky 8 . 86*47208Scael.Pp 8720015SmckusickWriting or changing the owner of a file 8828061Skarelsturns off the set-user-id and set-group-id bits 8928061Skarelsunless the user is the super-user. 9020014SmckusickThis makes the system somewhat more secure 9120015Smckusickby protecting set-user-id (set-group-id) files 9220015Smckusickfrom remaining set-user-id (set-group-id) if they are modified, 9320014Smckusickat the expense of a degree of compatibility. 94*47208Scael.Sh RETURN VALUES 9520015SmckusickUpon successful completion, a value of 0 is returned. 96*47208ScaelOtherwise, a value of -1 is returned and 97*47208Scael.Va errno 9820015Smckusickis set to indicate the error. 99*47208Scael.Sh ERRORS 100*47208Scael.Fn Chmod 10120015Smckusickwill fail and the file mode will be unchanged if: 102*47208Scael.Bl -tag -width Er 103*47208Scael.It Bq Er ENOTDIR 10420015SmckusickA component of the path prefix is not a directory. 105*47208Scael.It Bq Er EINVAL 10621003SmckusickThe pathname contains a character with the high-order bit set. 107*47208Scael.It Bq Er ENAMETOOLONG 10821003SmckusickA component of a pathname exceeded 255 characters, 10921003Smckusickor an entire path name exceeded 1023 characters. 110*47208Scael.It Bq Er ENOENT 11120015SmckusickThe named file does not exist. 112*47208Scael.It Bq Er EACCES 11321003SmckusickSearch permission is denied for a component of the path prefix. 114*47208Scael.It Bq Er ELOOP 11521003SmckusickToo many symbolic links were encountered in translating the pathname. 116*47208Scael.It Bq Er EPERM 11720015SmckusickThe effective user ID does not match the owner of the file and 11820015Smckusickthe effective user ID is not the super-user. 119*47208Scael.It Bq Er EROFS 12020015SmckusickThe named file resides on a read-only file system. 121*47208Scael.It Bq Er EFAULT 122*47208Scael.Fa Path 12320015Smckusickpoints outside the process's allocated address space. 124*47208Scael.It Bq Er EIO 12524439SmckusickAn I/O error occurred while reading from or writing to the file system. 126*47208Scael.El 127*47208Scael.Pp 128*47208Scael.Fn Fchmod 12920015Smckusickwill fail if: 130*47208Scael.Bl -tag -width Er 131*47208Scael.It Bq Er EBADF 13220015SmckusickThe descriptor is not valid. 133*47208Scael.It Bq Er EINVAL 134*47208Scael.Fa Fd 13520015Smckusickrefers to a socket, not to a file. 136*47208Scael.It Bq Er EROFS 13720015SmckusickThe file resides on a read-only file system. 138*47208Scael.It Bq Er EIO 13924439SmckusickAn I/O error occurred while reading from or writing to the file system. 140*47208Scael.El 141*47208Scael.Sh SEE ALSO 142*47208Scael.Xr chmod 1 , 143*47208Scael.Xr open 2 , 144*47208Scael.Xr chown 2 , 145*47208Scael.Xr stat 2 , 146*47208Scael.Xr sticky 8 147*47208Scael.Sh STANDARDS 148*47208Scael.Fn Chmod 149*47208Scaelis expected to conform to IEEE Std 1003.1-1988 150*47208Scael.Pq Dq Tn POSIX . 151*47208Scael.Sh HISTORY 152*47208ScaelThe 153*47208Scael.Fn fchmod 154*47208Scaelfunction call 155*47208Scaelappeared in 156*47208Scael.Bx 4.2 . 157