2 * Copyright (c) 1982, 1986, 1989, 1993, 1995
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)ufs_vnops.c 8.27 (Berkeley) 5/27/95
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
40 #include "opt_quota.h"
41 #include "opt_suiddir.h"
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/malloc.h>
48 #include <sys/namei.h>
49 #include <sys/kernel.h>
50 #include <sys/fcntl.h>
51 #include <sys/filio.h>
55 #include <sys/mount.h>
57 #include <sys/refcount.h>
58 #include <sys/unistd.h>
59 #include <sys/vnode.h>
60 #include <sys/dirent.h>
61 #include <sys/lockf.h>
65 #include <security/mac/mac_framework.h>
67 #include <sys/file.h> /* XXX */
70 #include <vm/vm_extern.h>
72 #include <ufs/ufs/acl.h>
73 #include <ufs/ufs/extattr.h>
74 #include <ufs/ufs/quota.h>
75 #include <ufs/ufs/inode.h>
76 #include <ufs/ufs/dir.h>
77 #include <ufs/ufs/ufsmount.h>
78 #include <ufs/ufs/ufs_extern.h>
80 #include <ufs/ufs/dirhash.h>
83 #include <ufs/ufs/gjournal.h>
84 FEATURE(ufs_gjournal, "Journaling support through GEOM for UFS");
88 FEATURE(ufs_quota, "UFS disk quotas support");
89 FEATURE(ufs_quota64, "64bit UFS disk quotas support");
94 "Give all new files in directory the same ownership as the directory");
98 #include <ufs/ffs/ffs_extern.h>
100 static vop_accessx_t ufs_accessx;
101 static int ufs_chmod(struct vnode *, int, struct ucred *, struct thread *);
102 static int ufs_chown(struct vnode *, uid_t, gid_t, struct ucred *, struct thread *);
103 static vop_close_t ufs_close;
104 static vop_create_t ufs_create;
105 static vop_getattr_t ufs_getattr;
106 static vop_ioctl_t ufs_ioctl;
107 static vop_link_t ufs_link;
108 static int ufs_makeinode(int mode, struct vnode *, struct vnode **, struct componentname *);
109 static vop_markatime_t ufs_markatime;
110 static vop_mkdir_t ufs_mkdir;
111 static vop_mknod_t ufs_mknod;
112 static vop_open_t ufs_open;
113 static vop_pathconf_t ufs_pathconf;
114 static vop_print_t ufs_print;
115 static vop_readlink_t ufs_readlink;
116 static vop_remove_t ufs_remove;
117 static vop_rename_t ufs_rename;
118 static vop_rmdir_t ufs_rmdir;
119 static vop_setattr_t ufs_setattr;
120 static vop_strategy_t ufs_strategy;
121 static vop_symlink_t ufs_symlink;
122 static vop_whiteout_t ufs_whiteout;
123 static vop_close_t ufsfifo_close;
124 static vop_kqfilter_t ufsfifo_kqfilter;
125 static vop_pathconf_t ufsfifo_pathconf;
127 SYSCTL_NODE(_vfs, OID_AUTO, ufs, CTLFLAG_RD, 0, "UFS filesystem");
130 * A virgin directory (no blushing please).
132 static struct dirtemplate mastertemplate = {
133 0, 12, DT_DIR, 1, ".",
134 0, DIRBLKSIZ - 12, DT_DIR, 2, ".."
136 static struct odirtemplate omastertemplate = {
138 0, DIRBLKSIZ - 12, 2, ".."
142 ufs_itimes_locked(struct vnode *vp)
147 ASSERT_VI_LOCKED(vp, __func__);
152 if ((ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) == 0)
155 if ((vp->v_type == VBLK || vp->v_type == VCHR) && !DOINGSOFTDEP(vp))
156 ip->i_flag |= IN_LAZYMOD;
157 else if (((vp->v_mount->mnt_kern_flag &
158 (MNTK_SUSPENDED | MNTK_SUSPEND)) == 0) ||
159 (ip->i_flag & (IN_CHANGE | IN_UPDATE)))
160 ip->i_flag |= IN_MODIFIED;
161 else if (ip->i_flag & IN_ACCESS)
162 ip->i_flag |= IN_LAZYACCESS;
164 if (ip->i_flag & IN_ACCESS) {
165 DIP_SET(ip, i_atime, ts.tv_sec);
166 DIP_SET(ip, i_atimensec, ts.tv_nsec);
168 if (ip->i_flag & IN_UPDATE) {
169 DIP_SET(ip, i_mtime, ts.tv_sec);
170 DIP_SET(ip, i_mtimensec, ts.tv_nsec);
172 if (ip->i_flag & IN_CHANGE) {
173 DIP_SET(ip, i_ctime, ts.tv_sec);
174 DIP_SET(ip, i_ctimensec, ts.tv_nsec);
175 DIP_SET(ip, i_modrev, DIP(ip, i_modrev) + 1);
179 ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE);
183 ufs_itimes(struct vnode *vp)
187 ufs_itimes_locked(vp);
192 * Create a regular file
196 struct vop_create_args /* {
198 struct vnode **a_vpp;
199 struct componentname *a_cnp;
206 ufs_makeinode(MAKEIMODE(ap->a_vap->va_type, ap->a_vap->va_mode),
207 ap->a_dvp, ap->a_vpp, ap->a_cnp);
219 struct vop_mknod_args /* {
221 struct vnode **a_vpp;
222 struct componentname *a_cnp;
226 struct vattr *vap = ap->a_vap;
227 struct vnode **vpp = ap->a_vpp;
232 error = ufs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode),
233 ap->a_dvp, vpp, ap->a_cnp);
237 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
238 if (vap->va_rdev != VNOVAL) {
240 * Want to be able to use this to make badblock
241 * inodes, so don't truncate the dev number.
243 DIP_SET(ip, i_rdev, vap->va_rdev);
246 * Remove inode, then reload it through VFS_VGET so it is
247 * checked to see if it is an alias of an existing entry in
248 * the inode cache. XXX I don't believe this is necessary now.
250 (*vpp)->v_type = VNON;
251 ino = ip->i_number; /* Save this before vgone() invalidates ip. */
254 error = VFS_VGET(ap->a_dvp->v_mount, ino, LK_EXCLUSIVE, vpp);
267 ufs_open(struct vop_open_args *ap)
269 struct vnode *vp = ap->a_vp;
272 if (vp->v_type == VCHR || vp->v_type == VBLK)
277 * Files marked append-only must be opened for appending.
279 if ((ip->i_flags & APPEND) &&
280 (ap->a_mode & (FWRITE | O_APPEND)) == FWRITE)
282 vnode_create_vobject(vp, DIP(ip, i_size), ap->a_td);
289 * Update the times on the inode.
294 struct vop_close_args /* {
297 struct ucred *a_cred;
301 struct vnode *vp = ap->a_vp;
305 usecount = vp->v_usecount;
307 ufs_itimes_locked(vp);
314 struct vop_accessx_args /* {
317 struct ucred *a_cred;
321 struct vnode *vp = ap->a_vp;
322 struct inode *ip = VTOI(vp);
323 accmode_t accmode = ap->a_accmode;
334 * Disallow write attempts on read-only filesystems;
335 * unless the file is a socket, fifo, or a block or
336 * character device resident on the filesystem.
338 if (accmode & VMODIFY_PERMS) {
339 switch (vp->v_type) {
343 if (vp->v_mount->mnt_flag & MNT_RDONLY)
347 * Inode is accounted in the quotas only if struct
348 * dquot is attached to it. VOP_ACCESS() is called
349 * from vn_open_cred() and provides a convenient
350 * point to call getinoquota().
352 if (VOP_ISLOCKED(vp) != LK_EXCLUSIVE) {
355 * Upgrade vnode lock, since getinoquota()
356 * requires exclusive lock to modify inode.
360 vn_lock(vp, LK_UPGRADE | LK_RETRY);
362 if (vp->v_iflag & VI_DOOMED) {
370 error = getinoquota(ip);
373 vn_lock(vp, LK_DOWNGRADE | LK_RETRY);
384 * If immutable bit set, nobody gets to write it. "& ~VADMIN_PERMS"
385 * is here, because without it, * it would be impossible for the owner
386 * to remove the IMMUTABLE flag.
388 if ((accmode & (VMODIFY_PERMS & ~VADMIN_PERMS)) &&
389 (ip->i_flags & (IMMUTABLE | SF_SNAPSHOT)))
393 if ((vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS)) != 0) {
394 if (vp->v_mount->mnt_flag & MNT_NFS4ACLS)
395 type = ACL_TYPE_NFS4;
397 type = ACL_TYPE_ACCESS;
399 acl = acl_alloc(M_WAITOK);
400 if (type == ACL_TYPE_NFS4)
401 error = ufs_getacl_nfs4_internal(vp, acl, ap->a_td);
403 error = VOP_GETACL(vp, type, acl, ap->a_cred, ap->a_td);
406 if (type == ACL_TYPE_NFS4) {
407 error = vaccess_acl_nfs4(vp->v_type, ip->i_uid,
408 ip->i_gid, acl, accmode, ap->a_cred, NULL);
410 error = vfs_unixify_accmode(&accmode);
412 error = vaccess_acl_posix1e(vp->v_type, ip->i_uid,
413 ip->i_gid, acl, accmode, ap->a_cred, NULL);
417 if (error != EOPNOTSUPP)
419 "ufs_accessx(): Error retrieving ACL on object (%d).\n",
422 * XXX: Fall back until debugged. Should
423 * eventually possibly log an error, and return
426 error = vfs_unixify_accmode(&accmode);
428 error = vaccess(vp->v_type, ip->i_mode, ip->i_uid,
429 ip->i_gid, accmode, ap->a_cred, NULL);
435 #endif /* !UFS_ACL */
436 error = vfs_unixify_accmode(&accmode);
438 error = vaccess(vp->v_type, ip->i_mode, ip->i_uid, ip->i_gid,
439 accmode, ap->a_cred, NULL);
446 struct vop_getattr_args /* {
449 struct ucred *a_cred;
452 struct vnode *vp = ap->a_vp;
453 struct inode *ip = VTOI(vp);
454 struct vattr *vap = ap->a_vap;
457 ufs_itimes_locked(vp);
458 if (ip->i_ump->um_fstype == UFS1) {
459 vap->va_atime.tv_sec = ip->i_din1->di_atime;
460 vap->va_atime.tv_nsec = ip->i_din1->di_atimensec;
462 vap->va_atime.tv_sec = ip->i_din2->di_atime;
463 vap->va_atime.tv_nsec = ip->i_din2->di_atimensec;
467 * Copy from inode table
469 vap->va_fsid = dev2udev(ip->i_dev);
470 vap->va_fileid = ip->i_number;
471 vap->va_mode = ip->i_mode & ~IFMT;
472 vap->va_nlink = ip->i_effnlink;
473 vap->va_uid = ip->i_uid;
474 vap->va_gid = ip->i_gid;
475 if (ip->i_ump->um_fstype == UFS1) {
476 vap->va_rdev = ip->i_din1->di_rdev;
477 vap->va_size = ip->i_din1->di_size;
478 vap->va_mtime.tv_sec = ip->i_din1->di_mtime;
479 vap->va_mtime.tv_nsec = ip->i_din1->di_mtimensec;
480 vap->va_ctime.tv_sec = ip->i_din1->di_ctime;
481 vap->va_ctime.tv_nsec = ip->i_din1->di_ctimensec;
482 vap->va_bytes = dbtob((u_quad_t)ip->i_din1->di_blocks);
483 vap->va_filerev = ip->i_din1->di_modrev;
485 vap->va_rdev = ip->i_din2->di_rdev;
486 vap->va_size = ip->i_din2->di_size;
487 vap->va_mtime.tv_sec = ip->i_din2->di_mtime;
488 vap->va_mtime.tv_nsec = ip->i_din2->di_mtimensec;
489 vap->va_ctime.tv_sec = ip->i_din2->di_ctime;
490 vap->va_ctime.tv_nsec = ip->i_din2->di_ctimensec;
491 vap->va_birthtime.tv_sec = ip->i_din2->di_birthtime;
492 vap->va_birthtime.tv_nsec = ip->i_din2->di_birthnsec;
493 vap->va_bytes = dbtob((u_quad_t)ip->i_din2->di_blocks);
494 vap->va_filerev = ip->i_din2->di_modrev;
496 vap->va_flags = ip->i_flags;
497 vap->va_gen = ip->i_gen;
498 vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
499 vap->va_type = IFTOVT(ip->i_mode);
504 * Set attribute vnode op. called from several syscalls
508 struct vop_setattr_args /* {
511 struct ucred *a_cred;
514 struct vattr *vap = ap->a_vap;
515 struct vnode *vp = ap->a_vp;
516 struct inode *ip = VTOI(vp);
517 struct ucred *cred = ap->a_cred;
518 struct thread *td = curthread;
522 * Check for unsettable attributes.
524 if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
525 (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
526 (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
527 ((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
530 if (vap->va_flags != VNOVAL) {
531 if ((vap->va_flags & ~(UF_NODUMP | UF_IMMUTABLE | UF_APPEND |
532 UF_OPAQUE | UF_NOUNLINK | SF_ARCHIVED | SF_IMMUTABLE |
533 SF_APPEND | SF_NOUNLINK | SF_SNAPSHOT)) != 0)
535 if (vp->v_mount->mnt_flag & MNT_RDONLY)
538 * Callers may only modify the file flags on objects they
539 * have VADMIN rights for.
541 if ((error = VOP_ACCESS(vp, VADMIN, cred, td)))
544 * Unprivileged processes are not permitted to unset system
545 * flags, or modify flags if any system flags are set.
546 * Privileged non-jail processes may not modify system flags
547 * if securelevel > 0 and any existing system flags are set.
548 * Privileged jail processes behave like privileged non-jail
549 * processes if the security.jail.chflags_allowed sysctl is
550 * is non-zero; otherwise, they behave like unprivileged
553 if (!priv_check_cred(cred, PRIV_VFS_SYSFLAGS, 0)) {
555 (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND)) {
556 error = securelevel_gt(cred, 0);
560 /* The snapshot flag cannot be toggled. */
561 if ((vap->va_flags ^ ip->i_flags) & SF_SNAPSHOT)
565 (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND) ||
566 ((vap->va_flags ^ ip->i_flags) & SF_SETTABLE))
569 ip->i_flags = vap->va_flags;
570 DIP_SET(ip, i_flags, vap->va_flags);
571 ip->i_flag |= IN_CHANGE;
572 error = UFS_UPDATE(vp, 0);
573 if (ip->i_flags & (IMMUTABLE | APPEND))
577 * If immutable or append, no one can change any of its attributes
578 * except the ones already handled (in some cases, file flags
579 * including the immutability flags themselves for the superuser).
581 if (ip->i_flags & (IMMUTABLE | APPEND))
584 * Go through the fields and update iff not VNOVAL.
586 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
587 if (vp->v_mount->mnt_flag & MNT_RDONLY)
589 if ((error = ufs_chown(vp, vap->va_uid, vap->va_gid, cred,
593 if (vap->va_size != VNOVAL) {
595 * XXX most of the following special cases should be in
596 * callers instead of in N filesystems. The VDIR check
599 switch (vp->v_type) {
605 * Truncation should have an effect in these cases.
606 * Disallow it if the filesystem is read-only or
607 * the file is being snapshotted.
609 if (vp->v_mount->mnt_flag & MNT_RDONLY)
611 if ((ip->i_flags & SF_SNAPSHOT) != 0)
616 * According to POSIX, the result is unspecified
617 * for file types other than regular files,
618 * directories and shared memory objects. We
619 * don't support shared memory objects in the file
620 * system, and have dubious support for truncating
621 * symlinks. Just ignore the request in other cases.
625 if ((error = UFS_TRUNCATE(vp, vap->va_size, IO_NORMAL,
629 if (vap->va_atime.tv_sec != VNOVAL ||
630 vap->va_mtime.tv_sec != VNOVAL ||
631 vap->va_birthtime.tv_sec != VNOVAL) {
632 if (vp->v_mount->mnt_flag & MNT_RDONLY)
634 if ((ip->i_flags & SF_SNAPSHOT) != 0)
638 * If times is NULL, ... The caller must be the owner of
639 * the file, have permission to write the file, or be the
641 * If times is non-NULL, ... The caller must be the owner of
642 * the file or be the super-user.
644 * Possibly for historical reasons, try to use VADMIN in
645 * preference to VWRITE for a NULL timestamp. This means we
646 * will return EACCES in preference to EPERM if neither
649 if (vap->va_vaflags & VA_UTIMES_NULL) {
651 * NFSv4.1, draft 21, 6.2.1.3.1, Discussion of Mask Attributes
653 * "A user having ACL_WRITE_DATA or ACL_WRITE_ATTRIBUTES
654 * will be allowed to set the times [..] to the current
657 * XXX: Calling it four times seems a little excessive.
659 error = VOP_ACCESSX(vp, VWRITE_ATTRIBUTES, cred, td);
661 error = VOP_ACCESS(vp, VWRITE, cred, td);
663 error = VOP_ACCESSX(vp, VWRITE_ATTRIBUTES, cred, td);
666 if (vap->va_atime.tv_sec != VNOVAL)
667 ip->i_flag |= IN_ACCESS;
668 if (vap->va_mtime.tv_sec != VNOVAL)
669 ip->i_flag |= IN_CHANGE | IN_UPDATE;
670 if (vap->va_birthtime.tv_sec != VNOVAL &&
671 ip->i_ump->um_fstype == UFS2)
672 ip->i_flag |= IN_MODIFIED;
674 if (vap->va_atime.tv_sec != VNOVAL) {
675 DIP_SET(ip, i_atime, vap->va_atime.tv_sec);
676 DIP_SET(ip, i_atimensec, vap->va_atime.tv_nsec);
678 if (vap->va_mtime.tv_sec != VNOVAL) {
679 DIP_SET(ip, i_mtime, vap->va_mtime.tv_sec);
680 DIP_SET(ip, i_mtimensec, vap->va_mtime.tv_nsec);
682 if (vap->va_birthtime.tv_sec != VNOVAL &&
683 ip->i_ump->um_fstype == UFS2) {
684 ip->i_din2->di_birthtime = vap->va_birthtime.tv_sec;
685 ip->i_din2->di_birthnsec = vap->va_birthtime.tv_nsec;
687 error = UFS_UPDATE(vp, 0);
692 if (vap->va_mode != (mode_t)VNOVAL) {
693 if (vp->v_mount->mnt_flag & MNT_RDONLY)
695 if ((ip->i_flags & SF_SNAPSHOT) != 0 && (vap->va_mode &
696 (S_IXUSR | S_IWUSR | S_IXGRP | S_IWGRP | S_IXOTH | S_IWOTH)))
698 error = ufs_chmod(vp, (int)vap->va_mode, cred, td);
705 ufs_update_nfs4_acl_after_mode_change(struct vnode *vp, int mode,
706 int file_owner_id, struct ucred *cred, struct thread *td)
711 aclp = acl_alloc(M_WAITOK);
712 error = ufs_getacl_nfs4_internal(vp, aclp, td);
714 * We don't have to handle EOPNOTSUPP here, as the filesystem claims
720 acl_nfs4_sync_acl_from_mode(aclp, mode, file_owner_id);
721 error = ufs_setacl_nfs4_internal(vp, aclp, td);
730 * Mark this file's access time for update for vfs_mark_atime(). This
731 * is called from execve() and mmap().
735 struct vop_markatime_args /* {
739 struct vnode *vp = ap->a_vp;
740 struct inode *ip = VTOI(vp);
743 ip->i_flag |= IN_ACCESS;
746 * XXXKIB No UFS_UPDATE(ap->a_vp, 0) there.
752 * Change the mode on a file.
753 * Inode must be locked before calling.
756 ufs_chmod(vp, mode, cred, td)
762 struct inode *ip = VTOI(vp);
766 * To modify the permissions on a file, must possess VADMIN
769 if ((error = VOP_ACCESSX(vp, VWRITE_ACL, cred, td)))
772 * Privileged processes may set the sticky bit on non-directories,
773 * as well as set the setgid bit on a file with a group that the
774 * process is not a member of. Both of these are allowed in
777 if (vp->v_type != VDIR && (mode & S_ISTXT)) {
778 if (priv_check_cred(cred, PRIV_VFS_STICKYFILE, 0))
781 if (!groupmember(ip->i_gid, cred) && (mode & ISGID)) {
782 error = priv_check_cred(cred, PRIV_VFS_SETGID, 0);
788 * Deny setting setuid if we are not the file owner.
790 if ((mode & ISUID) && ip->i_uid != cred->cr_uid) {
791 error = priv_check_cred(cred, PRIV_VFS_ADMIN, 0);
796 ip->i_mode &= ~ALLPERMS;
797 ip->i_mode |= (mode & ALLPERMS);
798 DIP_SET(ip, i_mode, ip->i_mode);
799 ip->i_flag |= IN_CHANGE;
801 if ((vp->v_mount->mnt_flag & MNT_NFS4ACLS) != 0)
802 error = ufs_update_nfs4_acl_after_mode_change(vp, mode, ip->i_uid, cred, td);
804 if (error == 0 && (ip->i_flag & IN_CHANGE) != 0)
805 error = UFS_UPDATE(vp, 0);
811 * Perform chown operation on inode ip;
812 * inode must be locked prior to call.
815 ufs_chown(vp, uid, gid, cred, td)
822 struct inode *ip = VTOI(vp);
831 if (uid == (uid_t)VNOVAL)
833 if (gid == (gid_t)VNOVAL)
836 * To modify the ownership of a file, must possess VADMIN for that
839 if ((error = VOP_ACCESSX(vp, VWRITE_OWNER, cred, td)))
842 * To change the owner of a file, or change the group of a file to a
843 * group of which we are not a member, the caller must have
846 if (((uid != ip->i_uid && uid != cred->cr_uid) ||
847 (gid != ip->i_gid && !groupmember(gid, cred))) &&
848 (error = priv_check_cred(cred, PRIV_VFS_CHOWN, 0)))
853 if ((error = getinoquota(ip)) != 0)
856 dqrele(vp, ip->i_dquot[USRQUOTA]);
857 ip->i_dquot[USRQUOTA] = NODQUOT;
860 dqrele(vp, ip->i_dquot[GRPQUOTA]);
861 ip->i_dquot[GRPQUOTA] = NODQUOT;
863 change = DIP(ip, i_blocks);
864 (void) chkdq(ip, -change, cred, CHOWN);
865 (void) chkiq(ip, -1, cred, CHOWN);
866 for (i = 0; i < MAXQUOTAS; i++) {
867 dqrele(vp, ip->i_dquot[i]);
868 ip->i_dquot[i] = NODQUOT;
872 DIP_SET(ip, i_gid, gid);
874 DIP_SET(ip, i_uid, uid);
876 if ((error = getinoquota(ip)) == 0) {
878 dqrele(vp, ip->i_dquot[USRQUOTA]);
879 ip->i_dquot[USRQUOTA] = NODQUOT;
882 dqrele(vp, ip->i_dquot[GRPQUOTA]);
883 ip->i_dquot[GRPQUOTA] = NODQUOT;
885 if ((error = chkdq(ip, change, cred, CHOWN)) == 0) {
886 if ((error = chkiq(ip, 1, cred, CHOWN)) == 0)
889 (void) chkdq(ip, -change, cred, CHOWN|FORCE);
891 for (i = 0; i < MAXQUOTAS; i++) {
892 dqrele(vp, ip->i_dquot[i]);
893 ip->i_dquot[i] = NODQUOT;
897 DIP_SET(ip, i_gid, ogid);
899 DIP_SET(ip, i_uid, ouid);
900 if (getinoquota(ip) == 0) {
902 dqrele(vp, ip->i_dquot[USRQUOTA]);
903 ip->i_dquot[USRQUOTA] = NODQUOT;
906 dqrele(vp, ip->i_dquot[GRPQUOTA]);
907 ip->i_dquot[GRPQUOTA] = NODQUOT;
909 (void) chkdq(ip, change, cred, FORCE|CHOWN);
910 (void) chkiq(ip, 1, cred, FORCE|CHOWN);
911 (void) getinoquota(ip);
916 panic("ufs_chown: lost quota");
918 ip->i_flag |= IN_CHANGE;
919 if ((ip->i_mode & (ISUID | ISGID)) && (ouid != uid || ogid != gid)) {
920 if (priv_check_cred(cred, PRIV_VFS_RETAINSUGID, 0)) {
921 ip->i_mode &= ~(ISUID | ISGID);
922 DIP_SET(ip, i_mode, ip->i_mode);
925 error = UFS_UPDATE(vp, 0);
931 struct vop_remove_args /* {
934 struct componentname *a_cnp;
938 struct vnode *vp = ap->a_vp;
939 struct vnode *dvp = ap->a_dvp;
945 if ((ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
946 (VTOI(dvp)->i_flags & APPEND)) {
951 ufs_gjournal_orphan(vp);
953 error = ufs_dirremove(dvp, ip, ap->a_cnp->cn_flags, 0);
954 if (ip->i_nlink <= 0)
955 vp->v_vflag |= VV_NOSYNC;
956 if ((ip->i_flags & SF_SNAPSHOT) != 0) {
958 * Avoid deadlock where another thread is trying to
959 * update the inodeblock for dvp and is waiting on
960 * snaplk. Temporary unlock the vnode lock for the
961 * unlinked file and sync the directory. This should
962 * allow vput() of the directory to not block later on
963 * while holding the snapshot vnode locked, assuming
964 * that the directory hasn't been unlinked too.
967 (void) VOP_FSYNC(dvp, MNT_WAIT, td);
968 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
979 struct vop_link_args /* {
980 struct vnode *a_tdvp;
982 struct componentname *a_cnp;
985 struct vnode *vp = ap->a_vp;
986 struct vnode *tdvp = ap->a_tdvp;
987 struct componentname *cnp = ap->a_cnp;
989 struct direct newdir;
993 if ((cnp->cn_flags & HASBUF) == 0)
994 panic("ufs_link: no name");
996 if (tdvp->v_mount != vp->v_mount) {
1000 if (VTOI(tdvp)->i_effnlink < 2)
1001 panic("ufs_link: Bad link count %d on parent",
1002 VTOI(tdvp)->i_effnlink);
1004 if ((nlink_t)ip->i_nlink >= LINK_MAX) {
1009 * The file may have been removed after namei droped the original
1012 if (ip->i_effnlink == 0) {
1016 if (ip->i_flags & (IMMUTABLE | APPEND)) {
1022 DIP_SET(ip, i_nlink, ip->i_nlink);
1023 ip->i_flag |= IN_CHANGE;
1024 if (DOINGSOFTDEP(vp))
1025 softdep_setup_link(VTOI(tdvp), ip);
1026 error = UFS_UPDATE(vp, !(DOINGSOFTDEP(vp) | DOINGASYNC(vp)));
1028 ufs_makedirentry(ip, cnp, &newdir);
1029 error = ufs_direnter(tdvp, vp, &newdir, cnp, NULL, 0);
1035 DIP_SET(ip, i_nlink, ip->i_nlink);
1036 ip->i_flag |= IN_CHANGE;
1037 if (DOINGSOFTDEP(vp))
1038 softdep_revert_link(VTOI(tdvp), ip);
1045 * whiteout vnode call
1049 struct vop_whiteout_args /* {
1050 struct vnode *a_dvp;
1051 struct componentname *a_cnp;
1055 struct vnode *dvp = ap->a_dvp;
1056 struct componentname *cnp = ap->a_cnp;
1057 struct direct newdir;
1060 switch (ap->a_flags) {
1062 /* 4.4 format directories support whiteout operations */
1063 if (dvp->v_mount->mnt_maxsymlinklen > 0)
1065 return (EOPNOTSUPP);
1068 /* create a new directory whiteout */
1070 if ((cnp->cn_flags & SAVENAME) == 0)
1071 panic("ufs_whiteout: missing name");
1072 if (dvp->v_mount->mnt_maxsymlinklen <= 0)
1073 panic("ufs_whiteout: old format filesystem");
1076 newdir.d_ino = WINO;
1077 newdir.d_namlen = cnp->cn_namelen;
1078 bcopy(cnp->cn_nameptr, newdir.d_name, (unsigned)cnp->cn_namelen + 1);
1079 newdir.d_type = DT_WHT;
1080 error = ufs_direnter(dvp, NULL, &newdir, cnp, NULL, 0);
1084 /* remove an existing directory whiteout */
1086 if (dvp->v_mount->mnt_maxsymlinklen <= 0)
1087 panic("ufs_whiteout: old format filesystem");
1090 cnp->cn_flags &= ~DOWHITEOUT;
1091 error = ufs_dirremove(dvp, NULL, cnp->cn_flags, 0);
1094 panic("ufs_whiteout: unknown op");
1099 static volatile int rename_restarts;
1100 SYSCTL_INT(_vfs_ufs, OID_AUTO, rename_restarts, CTLFLAG_RD,
1101 __DEVOLATILE(int *, &rename_restarts), 0,
1102 "Times rename had to restart due to lock contention");
1105 * Rename system call.
1106 * rename("foo", "bar");
1109 * link("foo", "bar");
1111 * but ``atomically''. Can't do full commit without saving state in the
1112 * inode on disk which isn't feasible at this time. Best we can do is
1113 * always guarantee the target exists.
1115 * Basic algorithm is:
1117 * 1) Bump link count on source while we're linking it to the
1118 * target. This also ensure the inode won't be deleted out
1119 * from underneath us while we work (it may be truncated by
1120 * a concurrent `trunc' or `open' for creation).
1121 * 2) Link source to destination. If destination already exists,
1123 * 3) Unlink source reference to inode if still around. If a
1124 * directory was moved and the parent of the destination
1125 * is different from the source, patch the ".." entry in the
1130 struct vop_rename_args /* {
1131 struct vnode *a_fdvp;
1132 struct vnode *a_fvp;
1133 struct componentname *a_fcnp;
1134 struct vnode *a_tdvp;
1135 struct vnode *a_tvp;
1136 struct componentname *a_tcnp;
1139 struct vnode *tvp = ap->a_tvp;
1140 struct vnode *tdvp = ap->a_tdvp;
1141 struct vnode *fvp = ap->a_fvp;
1142 struct vnode *fdvp = ap->a_fdvp;
1144 struct componentname *tcnp = ap->a_tcnp;
1145 struct componentname *fcnp = ap->a_fcnp;
1146 struct thread *td = fcnp->cn_thread;
1147 struct inode *fip, *tip, *tdp, *fdp;
1148 struct direct newdir;
1150 int doingdirectory, newparent;
1156 if ((tcnp->cn_flags & HASBUF) == 0 ||
1157 (fcnp->cn_flags & HASBUF) == 0)
1158 panic("ufs_rename: no name");
1162 VOP_UNLOCK(tdvp, 0);
1163 if (tvp && tvp != tdvp)
1166 * Check for cross-device rename.
1168 if ((fvp->v_mount != tdvp->v_mount) ||
1169 (tvp && (fvp->v_mount != tvp->v_mount))) {
1174 error = vfs_busy(mp, 0);
1181 * We need to acquire 2 to 4 locks depending on whether tvp is NULL
1182 * and fdvp and tdvp are the same directory. Subsequently we need
1183 * to double-check all paths and in the directory rename case we
1184 * need to verify that we are not creating a directory loop. To
1185 * handle this we acquire all but fdvp using non-blocking
1186 * acquisitions. If we fail to acquire any lock in the path we will
1187 * drop all held locks, acquire the new lock in a blocking fashion,
1188 * and then release it and restart the rename. This acquire/release
1189 * step ensures that we do not spin on a lock waiting for release.
1191 error = vn_lock(fdvp, LK_EXCLUSIVE);
1194 if (vn_lock(tdvp, LK_EXCLUSIVE | LK_NOWAIT) != 0) {
1195 VOP_UNLOCK(fdvp, 0);
1196 error = vn_lock(tdvp, LK_EXCLUSIVE);
1199 VOP_UNLOCK(tdvp, 0);
1200 atomic_add_int(&rename_restarts, 1);
1204 * Re-resolve fvp to be certain it still exists and fetch the
1207 error = ufs_lookup_ino(fdvp, NULL, fcnp, &ino);
1209 VOP_UNLOCK(fdvp, 0);
1210 VOP_UNLOCK(tdvp, 0);
1213 error = VFS_VGET(mp, ino, LK_EXCLUSIVE | LK_NOWAIT, &nvp);
1215 VOP_UNLOCK(fdvp, 0);
1216 VOP_UNLOCK(tdvp, 0);
1219 error = VFS_VGET(mp, ino, LK_EXCLUSIVE, &nvp);
1225 atomic_add_int(&rename_restarts, 1);
1231 * Re-resolve tvp and acquire the vnode lock if present.
1233 error = ufs_lookup_ino(tdvp, NULL, tcnp, &ino);
1234 if (error != 0 && error != EJUSTRETURN) {
1235 VOP_UNLOCK(fdvp, 0);
1236 VOP_UNLOCK(tdvp, 0);
1241 * If tvp disappeared we just carry on.
1243 if (error == EJUSTRETURN && tvp != NULL) {
1248 * Get the tvp ino if the lookup succeeded. We may have to restart
1249 * if the non-blocking acquire fails.
1253 error = VFS_VGET(mp, ino, LK_EXCLUSIVE | LK_NOWAIT, &nvp);
1258 VOP_UNLOCK(fdvp, 0);
1259 VOP_UNLOCK(tdvp, 0);
1263 error = VFS_VGET(mp, ino, LK_EXCLUSIVE, &nvp);
1267 atomic_add_int(&rename_restarts, 1);
1277 if (tvp && ((VTOI(tvp)->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
1278 (VTOI(tdvp)->i_flags & APPEND))) {
1283 * Renaming a file to itself has no effect. The upper layers should
1284 * not call us in that case. However, things could change after
1285 * we drop the locks above.
1293 ino = fip->i_number;
1294 if (fip->i_nlink >= LINK_MAX) {
1298 if ((fip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))
1299 || (fdp->i_flags & APPEND)) {
1303 if ((fip->i_mode & IFMT) == IFDIR) {
1305 * Avoid ".", "..", and aliases of "." for obvious reasons.
1307 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
1309 (fcnp->cn_flags | tcnp->cn_flags) & ISDOTDOT) {
1313 if (fdp->i_number != tdp->i_number)
1314 newparent = tdp->i_number;
1317 if ((fvp->v_type == VDIR && fvp->v_mountedhere != NULL) ||
1318 (tvp != NULL && tvp->v_type == VDIR &&
1319 tvp->v_mountedhere != NULL)) {
1325 * If ".." must be changed (ie the directory gets a new
1326 * parent) then the source directory must not be in the
1327 * directory hierarchy above the target, as this would
1328 * orphan everything below the source directory. Also
1329 * the user must have write permission in the source so
1330 * as to be able to change "..".
1332 if (doingdirectory && newparent) {
1333 error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_thread);
1336 error = ufs_checkpath(ino, fdp->i_number, tdp, tcnp->cn_cred,
1339 * We encountered a lock that we have to wait for. Unlock
1340 * everything else and VGET before restarting.
1343 VOP_UNLOCK(fdvp, 0);
1345 VOP_UNLOCK(tdvp, 0);
1348 error = VFS_VGET(mp, ino, LK_SHARED, &nvp);
1351 atomic_add_int(&rename_restarts, 1);
1356 if ((tcnp->cn_flags & SAVESTART) == 0)
1357 panic("ufs_rename: lost to startdir");
1359 if (fip->i_effnlink == 0 || fdp->i_effnlink == 0 ||
1360 tdp->i_effnlink == 0)
1361 panic("Bad effnlink fip %p, fdp %p, tdp %p", fip, fdp, tdp);
1364 * 1) Bump link count while we're moving stuff
1365 * around. If we crash somewhere before
1366 * completing our work, the link count
1367 * may be wrong, but correctable.
1371 DIP_SET(fip, i_nlink, fip->i_nlink);
1372 fip->i_flag |= IN_CHANGE;
1373 if (DOINGSOFTDEP(fvp))
1374 softdep_setup_link(tdp, fip);
1375 error = UFS_UPDATE(fvp, !(DOINGSOFTDEP(fvp) | DOINGASYNC(fvp)));
1380 * 2) If target doesn't exist, link the target
1381 * to the source and unlink the source.
1382 * Otherwise, rewrite the target directory
1383 * entry to reference the source inode and
1384 * expunge the original entry's existence.
1387 if (tdp->i_dev != fip->i_dev)
1388 panic("ufs_rename: EXDEV");
1389 if (doingdirectory && newparent) {
1391 * Account for ".." in new directory.
1392 * When source and destination have the same
1393 * parent we don't adjust the link count. The
1394 * actual link modification is completed when
1395 * .. is rewritten below.
1397 if ((nlink_t)tdp->i_nlink >= LINK_MAX) {
1402 ufs_makedirentry(fip, tcnp, &newdir);
1403 error = ufs_direnter(tdvp, NULL, &newdir, tcnp, NULL, 1);
1406 /* Setup tdvp for directory compaction if needed. */
1407 if (tdp->i_count && tdp->i_endoff &&
1408 tdp->i_endoff < tdp->i_size)
1409 endoff = tdp->i_endoff;
1411 if (tip->i_dev != tdp->i_dev || tip->i_dev != fip->i_dev)
1412 panic("ufs_rename: EXDEV");
1414 * Short circuit rename(foo, foo).
1416 if (tip->i_number == fip->i_number)
1417 panic("ufs_rename: same file");
1419 * If the parent directory is "sticky", then the caller
1420 * must possess VADMIN for the parent directory, or the
1421 * destination of the rename. This implements append-only
1424 if ((tdp->i_mode & S_ISTXT) &&
1425 VOP_ACCESS(tdvp, VADMIN, tcnp->cn_cred, td) &&
1426 VOP_ACCESS(tvp, VADMIN, tcnp->cn_cred, td)) {
1431 * Target must be empty if a directory and have no links
1432 * to it. Also, ensure source and target are compatible
1433 * (both directories, or both not directories).
1435 if ((tip->i_mode & IFMT) == IFDIR) {
1436 if ((tip->i_effnlink > 2) ||
1437 !ufs_dirempty(tip, tdp->i_number, tcnp->cn_cred)) {
1441 if (!doingdirectory) {
1446 } else if (doingdirectory) {
1450 if (doingdirectory) {
1453 if (DOINGSOFTDEP(tdvp))
1454 softdep_change_linkcnt(tdp);
1457 if (DOINGSOFTDEP(tvp))
1458 softdep_change_linkcnt(tip);
1460 error = ufs_dirrewrite(tdp, tip, fip->i_number,
1461 IFTODT(fip->i_mode),
1462 (doingdirectory && newparent) ? newparent : doingdirectory);
1464 if (doingdirectory) {
1467 if (DOINGSOFTDEP(tdvp))
1468 softdep_change_linkcnt(tdp);
1471 if (DOINGSOFTDEP(tvp))
1472 softdep_change_linkcnt(tip);
1475 if (doingdirectory && !DOINGSOFTDEP(tvp)) {
1477 * The only stuff left in the directory is "."
1478 * and "..". The "." reference is inconsequential
1479 * since we are quashing it. We have removed the "."
1480 * reference and the reference in the parent directory,
1481 * but there may be other hard links. The soft
1482 * dependency code will arrange to do these operations
1483 * after the parent directory entry has been deleted on
1484 * disk, so when running with that code we avoid doing
1489 DIP_SET(tdp, i_nlink, tdp->i_nlink);
1490 tdp->i_flag |= IN_CHANGE;
1493 DIP_SET(tip, i_nlink, tip->i_nlink);
1494 tip->i_flag |= IN_CHANGE;
1499 * 3) Unlink the source. We have to resolve the path again to
1500 * fixup the directory offset and count for ufs_dirremove.
1503 error = ufs_lookup_ino(fdvp, NULL, fcnp, &ino);
1505 panic("ufs_rename: from entry went away!");
1506 if (ino != fip->i_number)
1507 panic("ufs_rename: ino mismatch %ju != %ju\n",
1508 (uintmax_t)ino, (uintmax_t)fip->i_number);
1511 * If the source is a directory with a
1512 * new parent, the link count of the old
1513 * parent directory must be decremented
1514 * and ".." set to point to the new parent.
1516 if (doingdirectory && newparent) {
1518 * If tip exists we simply use its link, otherwise we must
1524 DIP_SET(tdp, i_nlink, tdp->i_nlink);
1525 tdp->i_flag |= IN_CHANGE;
1526 if (DOINGSOFTDEP(tdvp))
1527 softdep_setup_dotdot_link(tdp, fip);
1528 error = UFS_UPDATE(tdvp, !(DOINGSOFTDEP(tdvp) |
1530 /* Don't go to bad here as the new link exists. */
1533 } else if (DOINGSUJ(tdvp))
1534 /* Journal must account for each new link. */
1535 softdep_setup_dotdot_link(tdp, fip);
1536 fip->i_offset = mastertemplate.dot_reclen;
1537 ufs_dirrewrite(fip, fdp, newparent, DT_DIR, 0);
1540 error = ufs_dirremove(fdvp, fip, fcnp->cn_flags, 0);
1542 * The kern_renameat() looks up the fvp using the DELETE flag, which
1543 * causes the removal of the name cache entry for fvp.
1544 * As the relookup of the fvp is done in two steps:
1545 * ufs_lookup_ino() and then VFS_VGET(), another thread might do a
1546 * normal lookup of the from name just before the VFS_VGET() call,
1547 * causing the cache entry to be re-instantiated.
1549 * The same issue also applies to tvp if it exists as
1550 * otherwise we may have a stale name cache entry for the new
1551 * name that references the old i-node if it has other links
1552 * or open file descriptors.
1557 cache_purge_negative(tdvp);
1565 * If compaction or fsync was requested do it now that other locks
1566 * are no longer needed.
1568 if (error == 0 && endoff != 0) {
1570 if (tdp->i_dirhash != NULL)
1571 ufsdirhash_dirtrunc(tdp, endoff);
1573 UFS_TRUNCATE(tdvp, endoff, IO_NORMAL | IO_SYNC, tcnp->cn_cred);
1575 if (error == 0 && tdp->i_flag & IN_NEEDSYNC)
1576 error = VOP_FSYNC(tdvp, MNT_WAIT, td);
1585 DIP_SET(fip, i_nlink, fip->i_nlink);
1586 fip->i_flag |= IN_CHANGE;
1587 if (DOINGSOFTDEP(fvp))
1588 softdep_revert_link(tdp, fip);
1605 ufs_do_posix1e_acl_inheritance_dir(struct vnode *dvp, struct vnode *tvp,
1606 mode_t dmode, struct ucred *cred, struct thread *td)
1609 struct inode *ip = VTOI(tvp);
1610 struct acl *dacl, *acl;
1612 acl = acl_alloc(M_WAITOK);
1613 dacl = acl_alloc(M_WAITOK);
1616 * Retrieve default ACL from parent, if any.
1618 error = VOP_GETACL(dvp, ACL_TYPE_DEFAULT, acl, cred, td);
1622 * Retrieved a default ACL, so merge mode and ACL if
1623 * necessary. If the ACL is empty, fall through to
1624 * the "not defined or available" case.
1626 if (acl->acl_cnt != 0) {
1627 dmode = acl_posix1e_newfilemode(dmode, acl);
1629 DIP_SET(ip, i_mode, dmode);
1631 ufs_sync_acl_from_inode(ip, acl);
1638 * Just use the mode as-is.
1641 DIP_SET(ip, i_mode, dmode);
1650 * XXX: If we abort now, will Soft Updates notify the extattr
1651 * code that the EAs for the file need to be released?
1653 error = VOP_SETACL(tvp, ACL_TYPE_ACCESS, acl, cred, td);
1655 error = VOP_SETACL(tvp, ACL_TYPE_DEFAULT, dacl, cred, td);
1662 * XXX: This should not happen, as EOPNOTSUPP above
1663 * was supposed to free acl.
1665 printf("ufs_mkdir: VOP_GETACL() but no VOP_SETACL()\n");
1667 panic("ufs_mkdir: VOP_GETACL() but no VOP_SETACL()");
1683 ufs_do_posix1e_acl_inheritance_file(struct vnode *dvp, struct vnode *tvp,
1684 mode_t mode, struct ucred *cred, struct thread *td)
1687 struct inode *ip = VTOI(tvp);
1690 acl = acl_alloc(M_WAITOK);
1693 * Retrieve default ACL for parent, if any.
1695 error = VOP_GETACL(dvp, ACL_TYPE_DEFAULT, acl, cred, td);
1699 * Retrieved a default ACL, so merge mode and ACL if
1702 if (acl->acl_cnt != 0) {
1704 * Two possible ways for default ACL to not
1705 * be present. First, the EA can be
1706 * undefined, or second, the default ACL can
1707 * be blank. If it's blank, fall through to
1708 * the it's not defined case.
1710 mode = acl_posix1e_newfilemode(mode, acl);
1712 DIP_SET(ip, i_mode, mode);
1713 ufs_sync_acl_from_inode(ip, acl);
1720 * Just use the mode as-is.
1723 DIP_SET(ip, i_mode, mode);
1732 * XXX: If we abort now, will Soft Updates notify the extattr
1733 * code that the EAs for the file need to be released?
1735 error = VOP_SETACL(tvp, ACL_TYPE_ACCESS, acl, cred, td);
1742 * XXX: This should not happen, as EOPNOTSUPP above was
1743 * supposed to free acl.
1745 printf("ufs_makeinode: VOP_GETACL() but no "
1747 /* panic("ufs_makeinode: VOP_GETACL() but no "
1762 ufs_do_nfs4_acl_inheritance(struct vnode *dvp, struct vnode *tvp,
1763 mode_t child_mode, struct ucred *cred, struct thread *td)
1766 struct acl *parent_aclp, *child_aclp;
1768 parent_aclp = acl_alloc(M_WAITOK);
1769 child_aclp = acl_alloc(M_WAITOK | M_ZERO);
1771 error = ufs_getacl_nfs4_internal(dvp, parent_aclp, td);
1774 acl_nfs4_compute_inherited_acl(parent_aclp, child_aclp,
1775 child_mode, VTOI(tvp)->i_uid, tvp->v_type == VDIR);
1776 error = ufs_setacl_nfs4_internal(tvp, child_aclp, td);
1780 acl_free(parent_aclp);
1781 acl_free(child_aclp);
1792 struct vop_mkdir_args /* {
1793 struct vnode *a_dvp;
1794 struct vnode **a_vpp;
1795 struct componentname *a_cnp;
1796 struct vattr *a_vap;
1799 struct vnode *dvp = ap->a_dvp;
1800 struct vattr *vap = ap->a_vap;
1801 struct componentname *cnp = ap->a_cnp;
1802 struct inode *ip, *dp;
1805 struct dirtemplate dirtemplate, *dtp;
1806 struct direct newdir;
1811 if ((cnp->cn_flags & HASBUF) == 0)
1812 panic("ufs_mkdir: no name");
1815 if ((nlink_t)dp->i_nlink >= LINK_MAX) {
1819 dmode = vap->va_mode & 0777;
1822 * Must simulate part of ufs_makeinode here to acquire the inode,
1823 * but not have it entered in the parent directory. The entry is
1824 * made later after writing "." and ".." entries.
1826 error = UFS_VALLOC(dvp, dmode, cnp->cn_cred, &tvp);
1830 ip->i_gid = dp->i_gid;
1831 DIP_SET(ip, i_gid, dp->i_gid);
1835 struct ucred ucred, *ucp;
1840 * If we are hacking owners here, (only do this where told to)
1841 * and we are not giving it TO root, (would subvert quotas)
1842 * then go ahead and give it to the other user.
1843 * The new directory also inherits the SUID bit.
1844 * If user's UID and dir UID are the same,
1845 * 'give it away' so that the SUID is still forced on.
1847 if ((dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
1848 (dp->i_mode & ISUID) && dp->i_uid) {
1850 ip->i_uid = dp->i_uid;
1851 DIP_SET(ip, i_uid, dp->i_uid);
1853 if (dp->i_uid != cnp->cn_cred->cr_uid) {
1855 * Make sure the correct user gets charged
1857 * Make a dummy credential for the victim.
1858 * XXX This seems to never be accessed out of
1859 * our context so a stack variable is ok.
1861 refcount_init(&ucred.cr_ref, 1);
1862 ucred.cr_uid = ip->i_uid;
1863 ucred.cr_ngroups = 1;
1864 ucred.cr_groups = &ucred_group;
1865 ucred.cr_groups[0] = dp->i_gid;
1870 ip->i_uid = cnp->cn_cred->cr_uid;
1871 DIP_SET(ip, i_uid, ip->i_uid);
1874 if ((error = getinoquota(ip)) ||
1875 (error = chkiq(ip, 1, ucp, 0))) {
1876 if (DOINGSOFTDEP(tvp))
1877 softdep_revert_link(dp, ip);
1878 UFS_VFREE(tvp, ip->i_number, dmode);
1884 #else /* !SUIDDIR */
1885 ip->i_uid = cnp->cn_cred->cr_uid;
1886 DIP_SET(ip, i_uid, ip->i_uid);
1888 if ((error = getinoquota(ip)) ||
1889 (error = chkiq(ip, 1, cnp->cn_cred, 0))) {
1890 if (DOINGSOFTDEP(tvp))
1891 softdep_revert_link(dp, ip);
1892 UFS_VFREE(tvp, ip->i_number, dmode);
1897 #endif /* !SUIDDIR */
1898 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
1900 DIP_SET(ip, i_mode, dmode);
1901 tvp->v_type = VDIR; /* Rest init'd in getnewvnode(). */
1904 DIP_SET(ip, i_nlink, 2);
1906 if (cnp->cn_flags & ISWHITEOUT) {
1907 ip->i_flags |= UF_OPAQUE;
1908 DIP_SET(ip, i_flags, ip->i_flags);
1912 * Bump link count in parent directory to reflect work done below.
1913 * Should be done before reference is created so cleanup is
1914 * possible if we crash.
1918 DIP_SET(dp, i_nlink, dp->i_nlink);
1919 dp->i_flag |= IN_CHANGE;
1920 if (DOINGSOFTDEP(dvp))
1921 softdep_setup_mkdir(dp, ip);
1922 error = UFS_UPDATE(dvp, !(DOINGSOFTDEP(dvp) | DOINGASYNC(dvp)));
1926 if (dvp->v_mount->mnt_flag & MNT_MULTILABEL) {
1927 error = mac_vnode_create_extattr(cnp->cn_cred, dvp->v_mount,
1934 if (dvp->v_mount->mnt_flag & MNT_ACLS) {
1935 error = ufs_do_posix1e_acl_inheritance_dir(dvp, tvp, dmode,
1936 cnp->cn_cred, cnp->cn_thread);
1939 } else if (dvp->v_mount->mnt_flag & MNT_NFS4ACLS) {
1940 error = ufs_do_nfs4_acl_inheritance(dvp, tvp, dmode,
1941 cnp->cn_cred, cnp->cn_thread);
1945 #endif /* !UFS_ACL */
1948 * Initialize directory with "." and ".." from static template.
1950 if (dvp->v_mount->mnt_maxsymlinklen > 0)
1951 dtp = &mastertemplate;
1953 dtp = (struct dirtemplate *)&omastertemplate;
1955 dirtemplate.dot_ino = ip->i_number;
1956 dirtemplate.dotdot_ino = dp->i_number;
1957 if ((error = UFS_BALLOC(tvp, (off_t)0, DIRBLKSIZ, cnp->cn_cred,
1958 BA_CLRBUF, &bp)) != 0)
1960 ip->i_size = DIRBLKSIZ;
1961 DIP_SET(ip, i_size, DIRBLKSIZ);
1962 ip->i_flag |= IN_CHANGE | IN_UPDATE;
1963 vnode_pager_setsize(tvp, (u_long)ip->i_size);
1964 bcopy((caddr_t)&dirtemplate, (caddr_t)bp->b_data, sizeof dirtemplate);
1965 if (DOINGSOFTDEP(tvp)) {
1967 * Ensure that the entire newly allocated block is a
1968 * valid directory so that future growth within the
1969 * block does not have to ensure that the block is
1970 * written before the inode.
1973 while (blkoff < bp->b_bcount) {
1975 (bp->b_data + blkoff))->d_reclen = DIRBLKSIZ;
1976 blkoff += DIRBLKSIZ;
1979 if ((error = UFS_UPDATE(tvp, !(DOINGSOFTDEP(tvp) |
1980 DOINGASYNC(tvp)))) != 0) {
1985 * Directory set up, now install its entry in the parent directory.
1987 * If we are not doing soft dependencies, then we must write out the
1988 * buffer containing the new directory body before entering the new
1989 * name in the parent. If we are doing soft dependencies, then the
1990 * buffer containing the new directory body will be passed to and
1991 * released in the soft dependency code after the code has attached
1992 * an appropriate ordering dependency to the buffer which ensures that
1993 * the buffer is written before the new name is written in the parent.
1995 if (DOINGASYNC(dvp))
1997 else if (!DOINGSOFTDEP(dvp) && ((error = bwrite(bp))))
1999 ufs_makedirentry(ip, cnp, &newdir);
2000 error = ufs_direnter(dvp, tvp, &newdir, cnp, bp, 0);
2008 DIP_SET(dp, i_nlink, dp->i_nlink);
2009 dp->i_flag |= IN_CHANGE;
2011 * No need to do an explicit VOP_TRUNCATE here, vrele will
2012 * do this for us because we set the link count to 0.
2016 DIP_SET(ip, i_nlink, 0);
2017 ip->i_flag |= IN_CHANGE;
2018 if (DOINGSOFTDEP(tvp))
2019 softdep_revert_mkdir(dp, ip);
2028 * Rmdir system call.
2032 struct vop_rmdir_args /* {
2033 struct vnode *a_dvp;
2035 struct componentname *a_cnp;
2038 struct vnode *vp = ap->a_vp;
2039 struct vnode *dvp = ap->a_dvp;
2040 struct componentname *cnp = ap->a_cnp;
2041 struct inode *ip, *dp;
2048 * Do not remove a directory that is in the process of being renamed.
2049 * Verify the directory is empty (and valid). Rmdir ".." will not be
2050 * valid since ".." will contain a reference to the current directory
2051 * and thus be non-empty. Do not allow the removal of mounted on
2052 * directories (this can happen when an NFS exported filesystem
2053 * tries to remove a locally mounted on directory).
2056 if (ip->i_effnlink < 2) {
2060 if (dp->i_effnlink < 3)
2061 panic("ufs_dirrem: Bad link count %d on parent",
2063 if (!ufs_dirempty(ip, dp->i_number, cnp->cn_cred)) {
2067 if ((dp->i_flags & APPEND)
2068 || (ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))) {
2072 if (vp->v_mountedhere != 0) {
2077 ufs_gjournal_orphan(vp);
2080 * Delete reference to directory before purging
2081 * inode. If we crash in between, the directory
2082 * will be reattached to lost+found,
2086 if (DOINGSOFTDEP(vp))
2087 softdep_setup_rmdir(dp, ip);
2088 error = ufs_dirremove(dvp, ip, cnp->cn_flags, 1);
2092 if (DOINGSOFTDEP(vp))
2093 softdep_revert_rmdir(dp, ip);
2098 * The only stuff left in the directory is "." and "..". The "."
2099 * reference is inconsequential since we are quashing it. The soft
2100 * dependency code will arrange to do these operations after
2101 * the parent directory entry has been deleted on disk, so
2102 * when running with that code we avoid doing them now.
2104 if (!DOINGSOFTDEP(vp)) {
2106 DIP_SET(dp, i_nlink, dp->i_nlink);
2107 dp->i_flag |= IN_CHANGE;
2108 error = UFS_UPDATE(dvp, 0);
2110 DIP_SET(ip, i_nlink, ip->i_nlink);
2111 ip->i_flag |= IN_CHANGE;
2115 /* Kill any active hash; i_effnlink == 0, so it will not come back. */
2116 if (ip->i_dirhash != NULL)
2117 ufsdirhash_free(ip);
2124 * symlink -- make a symbolic link
2128 struct vop_symlink_args /* {
2129 struct vnode *a_dvp;
2130 struct vnode **a_vpp;
2131 struct componentname *a_cnp;
2132 struct vattr *a_vap;
2136 struct vnode *vp, **vpp = ap->a_vpp;
2140 error = ufs_makeinode(IFLNK | ap->a_vap->va_mode, ap->a_dvp,
2145 len = strlen(ap->a_target);
2146 if (len < vp->v_mount->mnt_maxsymlinklen) {
2148 bcopy(ap->a_target, SHORTLINK(ip), len);
2150 DIP_SET(ip, i_size, len);
2151 ip->i_flag |= IN_CHANGE | IN_UPDATE;
2152 error = UFS_UPDATE(vp, 0);
2154 error = vn_rdwr(UIO_WRITE, vp, ap->a_target, len, (off_t)0,
2155 UIO_SYSSPACE, IO_NODELOCKED | IO_NOMACCHECK,
2156 ap->a_cnp->cn_cred, NOCRED, NULL, NULL);
2163 * Vnode op for reading directories.
2165 * The routine below assumes that the on-disk format of a directory
2166 * is the same as that defined by <sys/dirent.h>. If the on-disk
2167 * format changes, then it will be necessary to do a conversion
2168 * from the on-disk format that read returns to the format defined
2169 * by <sys/dirent.h>.
2173 struct vop_readdir_args /* {
2176 struct ucred *a_cred;
2182 struct uio *uio = ap->a_uio;
2188 if (ap->a_ncookies != NULL)
2190 * Ensure that the block is aligned. The caller can use
2191 * the cookies to determine where in the block to start.
2193 uio->uio_offset &= ~(DIRBLKSIZ - 1);
2194 ip = VTOI(ap->a_vp);
2195 if (ip->i_effnlink == 0)
2197 off = uio->uio_offset;
2198 count = uio->uio_resid;
2199 /* Make sure we don't return partial entries. */
2200 if (count <= ((uio->uio_offset + count) & (DIRBLKSIZ -1)))
2202 count -= (uio->uio_offset + count) & (DIRBLKSIZ -1);
2203 lost = uio->uio_resid - count;
2204 uio->uio_resid = count;
2205 uio->uio_iov->iov_len = count;
2206 # if (BYTE_ORDER == LITTLE_ENDIAN)
2207 if (ap->a_vp->v_mount->mnt_maxsymlinklen > 0) {
2208 error = VOP_READ(ap->a_vp, uio, 0, ap->a_cred);
2210 struct dirent *dp, *edp;
2218 auio.uio_iov = &aiov;
2219 auio.uio_iovcnt = 1;
2220 auio.uio_segflg = UIO_SYSSPACE;
2221 aiov.iov_len = count;
2222 dirbuf = malloc(count, M_TEMP, M_WAITOK);
2223 aiov.iov_base = dirbuf;
2224 error = VOP_READ(ap->a_vp, &auio, 0, ap->a_cred);
2226 readcnt = count - auio.uio_resid;
2227 edp = (struct dirent *)&dirbuf[readcnt];
2228 for (dp = (struct dirent *)dirbuf; dp < edp; ) {
2230 dp->d_namlen = dp->d_type;
2232 if (dp->d_reclen > 0) {
2233 dp = (struct dirent *)
2234 ((char *)dp + dp->d_reclen);
2241 error = uiomove(dirbuf, readcnt, uio);
2243 free(dirbuf, M_TEMP);
2246 error = VOP_READ(ap->a_vp, uio, 0, ap->a_cred);
2248 if (!error && ap->a_ncookies != NULL) {
2249 struct dirent* dpStart;
2250 struct dirent* dpEnd;
2256 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
2257 panic("ufs_readdir: unexpected uio from NFS server");
2258 dpStart = (struct dirent *)
2259 ((char *)uio->uio_iov->iov_base - (uio->uio_offset - off));
2260 dpEnd = (struct dirent *) uio->uio_iov->iov_base;
2261 for (dp = dpStart, ncookies = 0;
2263 dp = (struct dirent *)((caddr_t) dp + dp->d_reclen))
2265 cookies = malloc(ncookies * sizeof(u_long), M_TEMP,
2267 for (dp = dpStart, cookiep = cookies;
2269 dp = (struct dirent *)((caddr_t) dp + dp->d_reclen)) {
2270 off += dp->d_reclen;
2271 *cookiep++ = (u_long) off;
2273 *ap->a_ncookies = ncookies;
2274 *ap->a_cookies = cookies;
2276 uio->uio_resid += lost;
2278 *ap->a_eofflag = VTOI(ap->a_vp)->i_size <= uio->uio_offset;
2283 * Return target name of a symbolic link
2287 struct vop_readlink_args /* {
2290 struct ucred *a_cred;
2293 struct vnode *vp = ap->a_vp;
2294 struct inode *ip = VTOI(vp);
2298 if ((isize < vp->v_mount->mnt_maxsymlinklen) ||
2299 DIP(ip, i_blocks) == 0) { /* XXX - for old fastlink support */
2300 return (uiomove(SHORTLINK(ip), isize, ap->a_uio));
2302 return (VOP_READ(vp, ap->a_uio, 0, ap->a_cred));
2306 * Calculate the logical to physical mapping if not done already,
2307 * then call the device strategy routine.
2309 * In order to be able to swap to a file, the ufs_bmaparray() operation may not
2310 * deadlock on memory. See ufs_bmap() for details.
2314 struct vop_strategy_args /* {
2319 struct buf *bp = ap->a_bp;
2320 struct vnode *vp = ap->a_vp;
2327 if (bp->b_blkno == bp->b_lblkno) {
2328 error = ufs_bmaparray(vp, bp->b_lblkno, &blkno, bp, NULL, NULL);
2329 bp->b_blkno = blkno;
2331 bp->b_error = error;
2332 bp->b_ioflags |= BIO_ERROR;
2336 if ((long)bp->b_blkno == -1)
2339 if ((long)bp->b_blkno == -1) {
2343 bp->b_iooffset = dbtob(bp->b_blkno);
2344 bo = ip->i_umbufobj;
2345 BO_STRATEGY(bo, bp);
2350 * Print out the contents of an inode.
2354 struct vop_print_args /* {
2358 struct vnode *vp = ap->a_vp;
2359 struct inode *ip = VTOI(vp);
2361 printf("\tino %lu, on dev %s", (u_long)ip->i_number,
2362 devtoname(ip->i_dev));
2363 if (vp->v_type == VFIFO)
2370 * Close wrapper for fifos.
2372 * Update the times on the inode then do device close.
2376 struct vop_close_args /* {
2379 struct ucred *a_cred;
2380 struct thread *a_td;
2383 struct vnode *vp = ap->a_vp;
2387 usecount = vp->v_usecount;
2389 ufs_itimes_locked(vp);
2391 return (fifo_specops.vop_close(ap));
2395 * Kqfilter wrapper for fifos.
2397 * Fall through to ufs kqfilter routines if needed
2400 ufsfifo_kqfilter(ap)
2401 struct vop_kqfilter_args *ap;
2405 error = fifo_specops.vop_kqfilter(ap);
2407 error = vfs_kqfilter(ap);
2412 * Return POSIX pathconf information applicable to fifos.
2415 ufsfifo_pathconf(ap)
2416 struct vop_pathconf_args /* {
2423 switch (ap->a_name) {
2424 case _PC_ACL_EXTENDED:
2426 case _PC_ACL_PATH_MAX:
2427 case _PC_MAC_PRESENT:
2428 return (ufs_pathconf(ap));
2430 return (fifo_specops.vop_pathconf(ap));
2436 * Return POSIX pathconf information applicable to ufs filesystems.
2440 struct vop_pathconf_args /* {
2449 switch (ap->a_name) {
2451 *ap->a_retval = LINK_MAX;
2454 *ap->a_retval = NAME_MAX;
2457 *ap->a_retval = PATH_MAX;
2460 *ap->a_retval = PIPE_BUF;
2462 case _PC_CHOWN_RESTRICTED:
2468 case _PC_ACL_EXTENDED:
2470 if (ap->a_vp->v_mount->mnt_flag & MNT_ACLS)
2481 if (ap->a_vp->v_mount->mnt_flag & MNT_NFS4ACLS)
2490 case _PC_ACL_PATH_MAX:
2492 if (ap->a_vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS))
2493 *ap->a_retval = ACL_MAX_ENTRIES;
2500 case _PC_MAC_PRESENT:
2502 if (ap->a_vp->v_mount->mnt_flag & MNT_MULTILABEL)
2510 case _PC_MIN_HOLE_SIZE:
2511 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2514 /* _PC_ASYNC_IO should have been handled by upper layers. */
2515 KASSERT(0, ("_PC_ASYNC_IO should not get here"));
2524 case _PC_ALLOC_SIZE_MIN:
2525 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_bsize;
2527 case _PC_FILESIZEBITS:
2530 case _PC_REC_INCR_XFER_SIZE:
2531 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2533 case _PC_REC_MAX_XFER_SIZE:
2534 *ap->a_retval = -1; /* means ``unlimited'' */
2536 case _PC_REC_MIN_XFER_SIZE:
2537 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2539 case _PC_REC_XFER_ALIGN:
2540 *ap->a_retval = PAGE_SIZE;
2542 case _PC_SYMLINK_MAX:
2543 *ap->a_retval = MAXPATHLEN;
2554 * Initialize the vnode associated with a new inode, handle aliased
2558 ufs_vinit(mntp, fifoops, vpp)
2560 struct vop_vector *fifoops;
2568 vp->v_type = IFTOVT(ip->i_mode);
2569 if (vp->v_type == VFIFO)
2571 ASSERT_VOP_LOCKED(vp, "ufs_vinit");
2572 if (ip->i_number == ROOTINO)
2573 vp->v_vflag |= VV_ROOT;
2579 * Allocate a new inode.
2580 * Vnode dvp must be locked.
2583 ufs_makeinode(mode, dvp, vpp, cnp)
2587 struct componentname *cnp;
2589 struct inode *ip, *pdir;
2590 struct direct newdir;
2596 if ((cnp->cn_flags & HASBUF) == 0)
2597 panic("ufs_makeinode: no name");
2600 if ((mode & IFMT) == 0)
2603 if (VTOI(dvp)->i_effnlink < 2)
2604 panic("ufs_makeinode: Bad link count %d on parent",
2605 VTOI(dvp)->i_effnlink);
2606 error = UFS_VALLOC(dvp, mode, cnp->cn_cred, &tvp);
2610 ip->i_gid = pdir->i_gid;
2611 DIP_SET(ip, i_gid, pdir->i_gid);
2615 struct ucred ucred, *ucp;
2620 * If we are not the owner of the directory,
2621 * and we are hacking owners here, (only do this where told to)
2622 * and we are not giving it TO root, (would subvert quotas)
2623 * then go ahead and give it to the other user.
2624 * Note that this drops off the execute bits for security.
2626 if ((dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
2627 (pdir->i_mode & ISUID) &&
2628 (pdir->i_uid != cnp->cn_cred->cr_uid) && pdir->i_uid) {
2629 ip->i_uid = pdir->i_uid;
2630 DIP_SET(ip, i_uid, ip->i_uid);
2634 * Make sure the correct user gets charged
2636 * Quickly knock up a dummy credential for the victim.
2637 * XXX This seems to never be accessed out of our
2638 * context so a stack variable is ok.
2640 refcount_init(&ucred.cr_ref, 1);
2641 ucred.cr_uid = ip->i_uid;
2642 ucred.cr_ngroups = 1;
2643 ucred.cr_groups = &ucred_group;
2644 ucred.cr_groups[0] = pdir->i_gid;
2648 ip->i_uid = cnp->cn_cred->cr_uid;
2649 DIP_SET(ip, i_uid, ip->i_uid);
2653 if ((error = getinoquota(ip)) ||
2654 (error = chkiq(ip, 1, ucp, 0))) {
2655 if (DOINGSOFTDEP(tvp))
2656 softdep_revert_link(pdir, ip);
2657 UFS_VFREE(tvp, ip->i_number, mode);
2663 #else /* !SUIDDIR */
2664 ip->i_uid = cnp->cn_cred->cr_uid;
2665 DIP_SET(ip, i_uid, ip->i_uid);
2667 if ((error = getinoquota(ip)) ||
2668 (error = chkiq(ip, 1, cnp->cn_cred, 0))) {
2669 if (DOINGSOFTDEP(tvp))
2670 softdep_revert_link(pdir, ip);
2671 UFS_VFREE(tvp, ip->i_number, mode);
2676 #endif /* !SUIDDIR */
2677 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
2679 DIP_SET(ip, i_mode, mode);
2680 tvp->v_type = IFTOVT(mode); /* Rest init'd in getnewvnode(). */
2683 DIP_SET(ip, i_nlink, 1);
2684 if (DOINGSOFTDEP(tvp))
2685 softdep_setup_create(VTOI(dvp), ip);
2686 if ((ip->i_mode & ISGID) && !groupmember(ip->i_gid, cnp->cn_cred) &&
2687 priv_check_cred(cnp->cn_cred, PRIV_VFS_SETGID, 0)) {
2688 ip->i_mode &= ~ISGID;
2689 DIP_SET(ip, i_mode, ip->i_mode);
2692 if (cnp->cn_flags & ISWHITEOUT) {
2693 ip->i_flags |= UF_OPAQUE;
2694 DIP_SET(ip, i_flags, ip->i_flags);
2698 * Make sure inode goes to disk before directory entry.
2700 error = UFS_UPDATE(tvp, !(DOINGSOFTDEP(tvp) | DOINGASYNC(tvp)));
2704 if (dvp->v_mount->mnt_flag & MNT_MULTILABEL) {
2705 error = mac_vnode_create_extattr(cnp->cn_cred, dvp->v_mount,
2712 if (dvp->v_mount->mnt_flag & MNT_ACLS) {
2713 error = ufs_do_posix1e_acl_inheritance_file(dvp, tvp, mode,
2714 cnp->cn_cred, cnp->cn_thread);
2717 } else if (dvp->v_mount->mnt_flag & MNT_NFS4ACLS) {
2718 error = ufs_do_nfs4_acl_inheritance(dvp, tvp, mode,
2719 cnp->cn_cred, cnp->cn_thread);
2723 #endif /* !UFS_ACL */
2724 ufs_makedirentry(ip, cnp, &newdir);
2725 error = ufs_direnter(dvp, tvp, &newdir, cnp, NULL, 0);
2733 * Write error occurred trying to update the inode
2734 * or the directory so must deallocate the inode.
2738 DIP_SET(ip, i_nlink, 0);
2739 ip->i_flag |= IN_CHANGE;
2740 if (DOINGSOFTDEP(tvp))
2741 softdep_revert_create(VTOI(dvp), ip);
2747 ufs_ioctl(struct vop_ioctl_args *ap)
2750 switch (ap->a_command) {
2753 return (vn_bmap_seekhole(ap->a_vp, ap->a_command,
2754 (off_t *)ap->a_data, ap->a_cred));
2760 /* Global vfs data structures for ufs. */
2761 struct vop_vector ufs_vnodeops = {
2762 .vop_default = &default_vnodeops,
2763 .vop_fsync = VOP_PANIC,
2764 .vop_read = VOP_PANIC,
2765 .vop_reallocblks = VOP_PANIC,
2766 .vop_write = VOP_PANIC,
2767 .vop_accessx = ufs_accessx,
2768 .vop_bmap = ufs_bmap,
2769 .vop_cachedlookup = ufs_lookup,
2770 .vop_close = ufs_close,
2771 .vop_create = ufs_create,
2772 .vop_getattr = ufs_getattr,
2773 .vop_inactive = ufs_inactive,
2774 .vop_ioctl = ufs_ioctl,
2775 .vop_link = ufs_link,
2776 .vop_lookup = vfs_cache_lookup,
2777 .vop_markatime = ufs_markatime,
2778 .vop_mkdir = ufs_mkdir,
2779 .vop_mknod = ufs_mknod,
2780 .vop_open = ufs_open,
2781 .vop_pathconf = ufs_pathconf,
2782 .vop_poll = vop_stdpoll,
2783 .vop_print = ufs_print,
2784 .vop_readdir = ufs_readdir,
2785 .vop_readlink = ufs_readlink,
2786 .vop_reclaim = ufs_reclaim,
2787 .vop_remove = ufs_remove,
2788 .vop_rename = ufs_rename,
2789 .vop_rmdir = ufs_rmdir,
2790 .vop_setattr = ufs_setattr,
2792 .vop_setlabel = vop_stdsetlabel_ea,
2794 .vop_strategy = ufs_strategy,
2795 .vop_symlink = ufs_symlink,
2796 .vop_whiteout = ufs_whiteout,
2798 .vop_getextattr = ufs_getextattr,
2799 .vop_deleteextattr = ufs_deleteextattr,
2800 .vop_setextattr = ufs_setextattr,
2803 .vop_getacl = ufs_getacl,
2804 .vop_setacl = ufs_setacl,
2805 .vop_aclcheck = ufs_aclcheck,
2809 struct vop_vector ufs_fifoops = {
2810 .vop_default = &fifo_specops,
2811 .vop_fsync = VOP_PANIC,
2812 .vop_accessx = ufs_accessx,
2813 .vop_close = ufsfifo_close,
2814 .vop_getattr = ufs_getattr,
2815 .vop_inactive = ufs_inactive,
2816 .vop_kqfilter = ufsfifo_kqfilter,
2817 .vop_markatime = ufs_markatime,
2818 .vop_pathconf = ufsfifo_pathconf,
2819 .vop_print = ufs_print,
2820 .vop_read = VOP_PANIC,
2821 .vop_reclaim = ufs_reclaim,
2822 .vop_setattr = ufs_setattr,
2824 .vop_setlabel = vop_stdsetlabel_ea,
2826 .vop_write = VOP_PANIC,
2828 .vop_getextattr = ufs_getextattr,
2829 .vop_deleteextattr = ufs_deleteextattr,
2830 .vop_setextattr = ufs_setextattr,
2833 .vop_getacl = ufs_getacl,
2834 .vop_setacl = ufs_setacl,
2835 .vop_aclcheck = ufs_aclcheck,