Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
CHMOD(2V)							     CHMOD(2V)

NAME
       chmod, fchmod - change mode of file

SYNOPSIS
       #include	<sys/stat.h>

       int chmod(path, mode)
       char *path;
       mode_t mode;

       int fchmod(fd, mode)
       int fd, mode;

DESCRIPTION
       chmod() sets the	mode of	the file referred to by	path or	the descriptor
       fd according to mode.  mode is the inclusive OR of the file  mode  bits
       (see stat(2V) for a description of these	bits).

       The  effective  user ID of the process must match the owner of the file
       or be super-user	to change the mode of a	file.

       If the effective	user ID	of the	process	 is  not  super-user  and  the
       process attempts	to set the set group ID	bit on a file owned by a group
       which is	not in its supplementary group IDs, the	S_ISGID	bit (set group
       ID on execution)	is cleared.

       If the S_ISVTX (sticky) bit is set on a directory, an unprivileged user
       may not delete or rename	files of other users in	that directory.

       If a user other than the	super-user writes to a file, the set  user  ID
       and  set	 group ID bits are turned off.	This makes the system somewhat
       more secure by protecting set-user-ID (set-group-ID) files from remain-
       ing  set-user-ID	(set-group-ID) if they are modified, at	the expense of
       a degree	of compatibility.

RETURN VALUES
       chmod() returns:

       0      on success.

       -1     on failure and sets errno	to indicate the	error.

ERRORS
       chmod() will fail and the file mode will	be unchanged if:

       EACCES		   Search permission is	denied for a component of  the
			   path	prefix of path.

       EFAULT		   path	points outside the process's allocated address
			   space.

       EINVAL		   fd refers to	a socket, not to a file.

       EIO		   An I/O error	occurred while reading from or writing
			   to the file system.

       ELOOP		   Too	many symbolic links were encountered in	trans-
			   lating path.

       ENAMETOOLONG	   The length of the path argument exceeds {PATH_MAX}.

			   A pathname  component  is  longer  than  {NAME_MAX}
			   while  {_POSIX_NO_TRUNC}  is	 in  effect (see path-
			   conf(2V)).

       ENOENT		   The file referred to	by path	does not exist.

       ENOTDIR		   A component of the path prefix of path is not a di-
			   rectory.

       EPERM		   The	effective  user	ID does	not match the owner of
			   the file and	the effective user ID is not  the  su-
			   per-user.

       EROFS		   The file referred to	by path	resides	on a read-only
			   file	system.

       fchmod()	will fail if:

       EBADF		   The descriptor is not valid.

       EIO		   An I/O error	occurred while reading from or writing
			   to the file system.

       EPERM		   The	effective  user	ID does	not match the owner of
			   the file and	the effective user ID is not  the  su-
			   per-user.

       EROFS		   The	file  referred to by fd	resides	on a read-only
			   file	system.

SYSTEM V ERRORS
       In addition to the above, the following may also	occur:

       ENOENT		   path	points to a null pathname.

SEE ALSO
       chown(2V), open(2V), stat(2V), sticky(8)

BUGS
       S_ISVTX,	the "sticky bit", is a misnomer, and  is  overloaded  to  mean
       different things	for different file types.

				21 January 1990			     CHMOD(2V)

NAME | SYNOPSIS | DESCRIPTION | RETURN VALUES | ERRORS | SYSTEM V ERRORS | SEE ALSO | BUGS

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=chmod&sektion=2v&manpath=SunOS+4.1.3>

home | help