MCPcopy Create free account
hub / github.com/F-Stack/f-stack / setfflags

Function setfflags

freebsd/kern/vfs_syscalls.c:2648–2684  ·  view source on GitHub ↗

* Common implementation code for chflags() and fchflags(). */

Source from the content-addressed store, hash-verified

2646 * Common implementation code for chflags() and fchflags().
2647 */
2648static int
2649setfflags(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.

Callers 2

kern_chflagsatFunction · 0.85
sys_fchflagsFunction · 0.85

Calls 5

vn_start_writeFunction · 0.85
vn_lockFunction · 0.85
mac_vnode_check_setflagsFunction · 0.85
vn_finished_writeFunction · 0.85
priv_checkFunction · 0.70

Tested by

no test coverage detected