FreeBSD/sys/fs/tmpfs/tmpfs_subr.c
/*
 * Change access mode on the given vnode.
 * Caller should execute tmpfs_update on vp after a successful execution.
 * The vnode must be locked on entry and remain locked on exit.
 */
Change access mode on the given vnode.
Caller should execute tmpfs_update on vp after a successful execution.
The vnode must be locked on entry and remain locked on exit.
Change access mode on the given vnode . Caller should execute tmpfs_update on vp after a successful execution . The vnode must be locked on entry and remain locked on exit .
int
tmpfs_chmod(struct vnode *vp, mode_t mode, struct ucred *cred, struct thread *p)
{
	int error;
	struct tmpfs_node *node;
	MPASS(VOP_ISLOCKED(vp));
	node = VP_TO_TMPFS_NODE(vp);
	if (vp->v_mount->mnt_flag & MNT_RDONLY)
		return EROFS;
	if (node->tn_flags & (IMMUTABLE | APPEND))
		return EPERM;
	if ((error = VOP_ACCESS(vp, VADMIN, cred, p)))
		return (error);
	if (vp->v_type != VDIR && (mode & S_ISTXT)) {
		if (priv_check_cred(cred, PRIV_VFS_STICKYFILE, 0))
			return (EFTYPE);
	}
	if (!groupmember(node->tn_gid, cred) && (mode & S_ISGID)) {
		error = priv_check_cred(cred, PRIV_VFS_SETGID, 0);
		if (error)
			return (error);
	}
	node->tn_mode &= ~ALLPERMS;
	node->tn_mode |= mode & ALLPERMS;
	node->tn_status |= TMPFS_NODE_CHANGED;
	MPASS(VOP_ISLOCKED(vp));
	return 0;
}
int tmpfs_chmod ( struct vnode * vp , mode_t mode , struct ucred * cred , struct thread * p ) { int error ; struct tmpfs_node * node ; MPASS ( VOP_ISLOCKED ( vp ) ) ; node = VP_TO_TMPFS_NODE ( vp ) ; if ( vp -> v_mount -> mnt_flag & MNT_RDONLY ) return EROFS ; if ( node -> tn_flags & ( IMMUTABLE | APPEND ) ) return EPERM ; if ( ( error = VOP_ACCESS ( vp , VADMIN , cred , p ) ) ) return ( error ) ; if ( vp -> v_type != VDIR && ( mode & S_ISTXT ) ) { if ( priv_check_cred ( cred , PRIV_VFS_STICKYFILE , 0 ) ) return ( EFTYPE ) ; } if ( ! groupmember ( node -> tn_gid , cred ) && ( mode & S_ISGID ) ) { error = priv_check_cred ( cred , PRIV_VFS_SETGID , 0 ) ; if ( error ) return ( error ) ; } node -> tn_mode &= ~ ALLPERMS ; node -> tn_mode |= mode & ALLPERMS ; node -> tn_status |= TMPFS_NODE_CHANGED ; MPASS ( VOP_ISLOCKED ( vp ) ) ; return 0 ; }
Change access mode on the given vnode.
Change access mode on the given vnode .
/* Disallow this operation if the file system is mounted read-only. */ /* Immutable or append-only files cannot be modified, either. */ /*
	 * To modify the permissions on a file, must possess VADMIN
	 * for that file.
	 */ /*
	 * Privileged processes may set the sticky bit on non-directories,
	 * as well as set the setgid bit on a file with a group that the
	 * process is not a member of.
	 */