* Common implementation code for chflags() and fchflags(). */
| 2646 | * Common implementation code for chflags() and fchflags(). |
| 2647 | */ |
| 2648 | static int |
| 2649 | setfflags(struct thread *td, struct vnode *vp, u_long flags) |
| 2650 | { |
| 2651 | struct mount *mp; |
| 2652 | struct vattr vattr; |
| 2653 | int error; |
| 2654 | |
| 2655 | /* We can't support the value matching VNOVAL. */ |
| 2656 | if (flags == VNOVAL) |
| 2657 | return (EOPNOTSUPP); |
| 2658 | |
| 2659 | /* |
| 2660 | * Prevent non-root users from setting flags on devices. When |
| 2661 | * a device is reused, users can retain ownership of the device |
| 2662 | * if they are allowed to set flags and programs assume that |
| 2663 | * chown can't fail when done as root. |
| 2664 | */ |
| 2665 | if (vp->v_type == VCHR || vp->v_type == VBLK) { |
| 2666 | error = priv_check(td, PRIV_VFS_CHFLAGS_DEV); |
| 2667 | if (error != 0) |
| 2668 | return (error); |
| 2669 | } |
| 2670 | |
| 2671 | if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) |
| 2672 | return (error); |
| 2673 | VATTR_NULL(&vattr); |
| 2674 | vattr.va_flags = flags; |
| 2675 | vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); |
| 2676 | #ifdef MAC |
| 2677 | error = mac_vnode_check_setflags(td->td_ucred, vp, vattr.va_flags); |
| 2678 | if (error == 0) |
| 2679 | #endif |
| 2680 | error = VOP_SETATTR(vp, &vattr, td->td_ucred); |
| 2681 | VOP_UNLOCK(vp); |
| 2682 | vn_finished_write(mp); |
| 2683 | return (error); |
| 2684 | } |
| 2685 | |
| 2686 | /* |
| 2687 | * Change flags of a file given a path name. |
no test coverage detected