FreeBSD/sys/fs/ext2fs/ext2_vnops.c
/*
 * Perform chown operation on inode ip;
 * inode must be locked prior to call.
 */
Perform chown operation on inode ip;
inode must be locked prior to call.
Perform chown operation on inode ip ; inode must be locked prior to call .
static int
ext2_chown(struct vnode *vp, uid_t uid, gid_t gid, struct ucred *cred,
    struct thread *td)
{
	struct inode *ip = VTOI(vp);
	uid_t ouid;
	gid_t ogid;
	int error = 0;
	if (uid == (uid_t)VNOVAL)
		uid = ip->i_uid;
	if (gid == (gid_t)VNOVAL)
		gid = ip->i_gid;
	if ((error = VOP_ACCESS(vp, VADMIN, cred, td)))
		return (error);
	if (uid != ip->i_uid || (gid != ip->i_gid &&
	    !groupmember(gid, cred))) {
		error = priv_check_cred(cred, PRIV_VFS_CHOWN, 0);
		if (error)
			return (error);
	}
	ogid = ip->i_gid;
	ouid = ip->i_uid;
	ip->i_gid = gid;
	ip->i_uid = uid;
	ip->i_flag |= IN_CHANGE;
	if ((ip->i_mode & (ISUID | ISGID)) && (ouid != uid || ogid != gid)) {
		if (priv_check_cred(cred, PRIV_VFS_RETAINSUGID, 0) != 0)
			ip->i_mode &= ~(ISUID | ISGID);
	}
	return (0);
}
static int ext2_chown ( struct vnode * vp , uid_t uid , gid_t gid , struct ucred * cred , struct thread * td ) { struct inode * ip = VTOI ( vp ) ; uid_t ouid ; gid_t ogid ; int error = 0 ; if ( uid == ( uid_t ) VNOVAL ) uid = ip -> i_uid ; if ( gid == ( gid_t ) VNOVAL ) gid = ip -> i_gid ; if ( ( error = VOP_ACCESS ( vp , VADMIN , cred , td ) ) ) return ( error ) ; if ( uid != ip -> i_uid || ( gid != ip -> i_gid && ! groupmember ( gid , cred ) ) ) { error = priv_check_cred ( cred , PRIV_VFS_CHOWN , 0 ) ; if ( error ) return ( error ) ; } ogid = ip -> i_gid ; ouid = ip -> i_uid ; ip -> i_gid = gid ; ip -> i_uid = uid ; ip -> i_flag |= IN_CHANGE ; if ( ( ip -> i_mode & ( ISUID | ISGID ) ) && ( ouid != uid || ogid != gid ) ) { if ( priv_check_cred ( cred , PRIV_VFS_RETAINSUGID , 0 ) != 0 ) ip -> i_mode &= ~ ( ISUID | ISGID ) ; } return ( 0 ) ; }
Perform chown operation on inode ip;
 inode must be locked prior to call.
Perform chown operation on inode ip ; inode must be locked prior to call .
/*
	 * To modify the ownership of a file, must possess VADMIN
	 * for that file.
	 */ /*
	 * To change the owner of a file, or change the group of a file
	 * to a group of which we are not a member, the caller must
	 * have privilege.
	 */