* Common implementation code for chmod(), lchmod() and fchmod(). */
| 2790 | * Common implementation code for chmod(), lchmod() and fchmod(). |
| 2791 | */ |
| 2792 | int |
| 2793 | setfmode(struct thread *td, struct ucred *cred, struct vnode *vp, int mode) |
| 2794 | { |
| 2795 | struct mount *mp; |
| 2796 | struct vattr vattr; |
| 2797 | int error; |
| 2798 | |
| 2799 | if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) |
| 2800 | return (error); |
| 2801 | vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); |
| 2802 | VATTR_NULL(&vattr); |
| 2803 | vattr.va_mode = mode & ALLPERMS; |
| 2804 | #ifdef MAC |
| 2805 | error = mac_vnode_check_setmode(cred, vp, vattr.va_mode); |
| 2806 | if (error == 0) |
| 2807 | #endif |
| 2808 | error = VOP_SETATTR(vp, &vattr, cred); |
| 2809 | VOP_UNLOCK(vp); |
| 2810 | vn_finished_write(mp); |
| 2811 | return (error); |
| 2812 | } |
| 2813 | |
| 2814 | /* |
| 2815 | * Change mode of a file given path name. |
no test coverage detected