2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1982, 1986, 1989, 1993, 1995
5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)ufs_vnops.c 8.27 (Berkeley) 5/27/95
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
42 #include "opt_quota.h"
43 #include "opt_suiddir.h"
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/malloc.h>
50 #include <sys/namei.h>
51 #include <sys/kernel.h>
52 #include <sys/fcntl.h>
53 #include <sys/filio.h>
57 #include <sys/mount.h>
59 #include <sys/refcount.h>
60 #include <sys/unistd.h>
61 #include <sys/vnode.h>
62 #include <sys/dirent.h>
63 #include <sys/lockf.h>
67 #include <security/mac/mac_framework.h>
69 #include <sys/file.h> /* XXX */
72 #include <vm/vm_extern.h>
74 #include <ufs/ufs/acl.h>
75 #include <ufs/ufs/extattr.h>
76 #include <ufs/ufs/quota.h>
77 #include <ufs/ufs/inode.h>
78 #include <ufs/ufs/dir.h>
79 #include <ufs/ufs/ufsmount.h>
80 #include <ufs/ufs/ufs_extern.h>
82 #include <ufs/ufs/dirhash.h>
85 #include <ufs/ufs/gjournal.h>
86 FEATURE(ufs_gjournal, "Journaling support through GEOM for UFS");
90 FEATURE(ufs_quota, "UFS disk quotas support");
91 FEATURE(ufs_quota64, "64bit UFS disk quotas support");
96 "Give all new files in directory the same ownership as the directory");
100 #include <ufs/ffs/ffs_extern.h>
102 static vop_accessx_t ufs_accessx;
103 static int ufs_chmod(struct vnode *, int, struct ucred *, struct thread *);
104 static int ufs_chown(struct vnode *, uid_t, gid_t, struct ucred *, struct thread *);
105 static vop_close_t ufs_close;
106 static vop_create_t ufs_create;
107 static vop_getattr_t ufs_getattr;
108 static vop_ioctl_t ufs_ioctl;
109 static vop_link_t ufs_link;
110 static int ufs_makeinode(int mode, struct vnode *, struct vnode **, struct componentname *, const char *);
111 static vop_markatime_t ufs_markatime;
112 static vop_mkdir_t ufs_mkdir;
113 static vop_mknod_t ufs_mknod;
114 static vop_open_t ufs_open;
115 static vop_pathconf_t ufs_pathconf;
116 static vop_print_t ufs_print;
117 static vop_readlink_t ufs_readlink;
118 static vop_remove_t ufs_remove;
119 static vop_rename_t ufs_rename;
120 static vop_rmdir_t ufs_rmdir;
121 static vop_setattr_t ufs_setattr;
122 static vop_strategy_t ufs_strategy;
123 static vop_symlink_t ufs_symlink;
124 static vop_whiteout_t ufs_whiteout;
125 static vop_close_t ufsfifo_close;
126 static vop_kqfilter_t ufsfifo_kqfilter;
128 SYSCTL_NODE(_vfs, OID_AUTO, ufs, CTLFLAG_RD, 0, "UFS filesystem");
131 * A virgin directory (no blushing please).
133 static struct dirtemplate mastertemplate = {
134 0, 12, DT_DIR, 1, ".",
135 0, DIRBLKSIZ - 12, DT_DIR, 2, ".."
137 static struct odirtemplate omastertemplate = {
139 0, DIRBLKSIZ - 12, 2, ".."
143 ufs_itimes_locked(struct vnode *vp)
148 ASSERT_VI_LOCKED(vp, __func__);
153 if ((ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) == 0)
156 if ((vp->v_type == VBLK || vp->v_type == VCHR) && !DOINGSOFTDEP(vp))
157 ip->i_flag |= IN_LAZYMOD;
158 else if (((vp->v_mount->mnt_kern_flag &
159 (MNTK_SUSPENDED | MNTK_SUSPEND)) == 0) ||
160 (ip->i_flag & (IN_CHANGE | IN_UPDATE)))
161 ip->i_flag |= IN_MODIFIED;
162 else if (ip->i_flag & IN_ACCESS)
163 ip->i_flag |= IN_LAZYACCESS;
165 if (ip->i_flag & IN_ACCESS) {
166 DIP_SET(ip, i_atime, ts.tv_sec);
167 DIP_SET(ip, i_atimensec, ts.tv_nsec);
169 if (ip->i_flag & IN_UPDATE) {
170 DIP_SET(ip, i_mtime, ts.tv_sec);
171 DIP_SET(ip, i_mtimensec, ts.tv_nsec);
173 if (ip->i_flag & IN_CHANGE) {
174 DIP_SET(ip, i_ctime, ts.tv_sec);
175 DIP_SET(ip, i_ctimensec, ts.tv_nsec);
176 DIP_SET(ip, i_modrev, DIP(ip, i_modrev) + 1);
180 ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE);
184 ufs_itimes(struct vnode *vp)
188 ufs_itimes_locked(vp);
193 * Create a regular file
197 struct vop_create_args /* {
199 struct vnode **a_vpp;
200 struct componentname *a_cnp;
207 ufs_makeinode(MAKEIMODE(ap->a_vap->va_type, ap->a_vap->va_mode),
208 ap->a_dvp, ap->a_vpp, ap->a_cnp, "ufs_create");
211 if ((ap->a_cnp->cn_flags & MAKEENTRY) != 0)
212 cache_enter(ap->a_dvp, *ap->a_vpp, ap->a_cnp);
222 struct vop_mknod_args /* {
224 struct vnode **a_vpp;
225 struct componentname *a_cnp;
229 struct vattr *vap = ap->a_vap;
230 struct vnode **vpp = ap->a_vpp;
235 error = ufs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode),
236 ap->a_dvp, vpp, ap->a_cnp, "ufs_mknod");
240 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
241 if (vap->va_rdev != VNOVAL) {
243 * Want to be able to use this to make badblock
244 * inodes, so don't truncate the dev number.
246 DIP_SET(ip, i_rdev, vap->va_rdev);
249 * Remove inode, then reload it through VFS_VGET so it is
250 * checked to see if it is an alias of an existing entry in
251 * the inode cache. XXX I don't believe this is necessary now.
253 (*vpp)->v_type = VNON;
254 ino = ip->i_number; /* Save this before vgone() invalidates ip. */
257 error = VFS_VGET(ap->a_dvp->v_mount, ino, LK_EXCLUSIVE, vpp);
270 ufs_open(struct vop_open_args *ap)
272 struct vnode *vp = ap->a_vp;
275 if (vp->v_type == VCHR || vp->v_type == VBLK)
280 * Files marked append-only must be opened for appending.
282 if ((ip->i_flags & APPEND) &&
283 (ap->a_mode & (FWRITE | O_APPEND)) == FWRITE)
285 vnode_create_vobject(vp, DIP(ip, i_size), ap->a_td);
292 * Update the times on the inode.
297 struct vop_close_args /* {
300 struct ucred *a_cred;
304 struct vnode *vp = ap->a_vp;
308 usecount = vp->v_usecount;
310 ufs_itimes_locked(vp);
317 struct vop_accessx_args /* {
320 struct ucred *a_cred;
324 struct vnode *vp = ap->a_vp;
325 struct inode *ip = VTOI(vp);
326 accmode_t accmode = ap->a_accmode;
337 * Disallow write attempts on read-only filesystems;
338 * unless the file is a socket, fifo, or a block or
339 * character device resident on the filesystem.
341 if (accmode & VMODIFY_PERMS) {
342 switch (vp->v_type) {
346 if (vp->v_mount->mnt_flag & MNT_RDONLY)
350 * Inode is accounted in the quotas only if struct
351 * dquot is attached to it. VOP_ACCESS() is called
352 * from vn_open_cred() and provides a convenient
353 * point to call getinoquota().
355 if (VOP_ISLOCKED(vp) != LK_EXCLUSIVE) {
358 * Upgrade vnode lock, since getinoquota()
359 * requires exclusive lock to modify inode.
363 vn_lock(vp, LK_UPGRADE | LK_RETRY);
365 if (vp->v_iflag & VI_DOOMED) {
373 error = getinoquota(ip);
376 vn_lock(vp, LK_DOWNGRADE | LK_RETRY);
387 * If immutable bit set, nobody gets to write it. "& ~VADMIN_PERMS"
388 * permits the owner of the file to remove the IMMUTABLE flag.
390 if ((accmode & (VMODIFY_PERMS & ~VADMIN_PERMS)) &&
391 (ip->i_flags & (IMMUTABLE | SF_SNAPSHOT)))
395 if ((vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS)) != 0) {
396 if (vp->v_mount->mnt_flag & MNT_NFS4ACLS)
397 type = ACL_TYPE_NFS4;
399 type = ACL_TYPE_ACCESS;
401 acl = acl_alloc(M_WAITOK);
402 if (type == ACL_TYPE_NFS4)
403 error = ufs_getacl_nfs4_internal(vp, acl, ap->a_td);
405 error = VOP_GETACL(vp, type, acl, ap->a_cred, ap->a_td);
408 if (type == ACL_TYPE_NFS4) {
409 error = vaccess_acl_nfs4(vp->v_type, ip->i_uid,
410 ip->i_gid, acl, accmode, ap->a_cred, NULL);
412 error = vfs_unixify_accmode(&accmode);
414 error = vaccess_acl_posix1e(vp->v_type, ip->i_uid,
415 ip->i_gid, acl, accmode, ap->a_cred, NULL);
419 if (error != EOPNOTSUPP)
421 "ufs_accessx(): Error retrieving ACL on object (%d).\n",
424 * XXX: Fall back until debugged. Should
425 * eventually possibly log an error, and return
428 error = vfs_unixify_accmode(&accmode);
430 error = vaccess(vp->v_type, ip->i_mode, ip->i_uid,
431 ip->i_gid, accmode, ap->a_cred, NULL);
437 #endif /* !UFS_ACL */
438 error = vfs_unixify_accmode(&accmode);
440 error = vaccess(vp->v_type, ip->i_mode, ip->i_uid, ip->i_gid,
441 accmode, ap->a_cred, NULL);
448 struct vop_getattr_args /* {
451 struct ucred *a_cred;
454 struct vnode *vp = ap->a_vp;
455 struct inode *ip = VTOI(vp);
456 struct vattr *vap = ap->a_vap;
459 ufs_itimes_locked(vp);
461 vap->va_atime.tv_sec = ip->i_din1->di_atime;
462 vap->va_atime.tv_nsec = ip->i_din1->di_atimensec;
464 vap->va_atime.tv_sec = ip->i_din2->di_atime;
465 vap->va_atime.tv_nsec = ip->i_din2->di_atimensec;
469 * Copy from inode table
471 vap->va_fsid = dev2udev(ITOUMP(ip)->um_dev);
472 vap->va_fileid = ip->i_number;
473 vap->va_mode = ip->i_mode & ~IFMT;
474 vap->va_nlink = ip->i_effnlink;
475 vap->va_uid = ip->i_uid;
476 vap->va_gid = ip->i_gid;
478 vap->va_rdev = ip->i_din1->di_rdev;
479 vap->va_size = ip->i_din1->di_size;
480 vap->va_mtime.tv_sec = ip->i_din1->di_mtime;
481 vap->va_mtime.tv_nsec = ip->i_din1->di_mtimensec;
482 vap->va_ctime.tv_sec = ip->i_din1->di_ctime;
483 vap->va_ctime.tv_nsec = ip->i_din1->di_ctimensec;
484 vap->va_bytes = dbtob((u_quad_t)ip->i_din1->di_blocks);
485 vap->va_filerev = ip->i_din1->di_modrev;
487 vap->va_rdev = ip->i_din2->di_rdev;
488 vap->va_size = ip->i_din2->di_size;
489 vap->va_mtime.tv_sec = ip->i_din2->di_mtime;
490 vap->va_mtime.tv_nsec = ip->i_din2->di_mtimensec;
491 vap->va_ctime.tv_sec = ip->i_din2->di_ctime;
492 vap->va_ctime.tv_nsec = ip->i_din2->di_ctimensec;
493 vap->va_birthtime.tv_sec = ip->i_din2->di_birthtime;
494 vap->va_birthtime.tv_nsec = ip->i_din2->di_birthnsec;
495 vap->va_bytes = dbtob((u_quad_t)ip->i_din2->di_blocks);
496 vap->va_filerev = ip->i_din2->di_modrev;
498 vap->va_flags = ip->i_flags;
499 vap->va_gen = ip->i_gen;
500 vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
501 vap->va_type = IFTOVT(ip->i_mode);
506 * Set attribute vnode op. called from several syscalls
510 struct vop_setattr_args /* {
513 struct ucred *a_cred;
516 struct vattr *vap = ap->a_vap;
517 struct vnode *vp = ap->a_vp;
518 struct inode *ip = VTOI(vp);
519 struct ucred *cred = ap->a_cred;
520 struct thread *td = curthread;
524 * Check for unsettable attributes.
526 if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
527 (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
528 (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
529 ((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
532 if (vap->va_flags != VNOVAL) {
533 if ((vap->va_flags & ~(SF_APPEND | SF_ARCHIVED | SF_IMMUTABLE |
534 SF_NOUNLINK | SF_SNAPSHOT | UF_APPEND | UF_ARCHIVE |
535 UF_HIDDEN | UF_IMMUTABLE | UF_NODUMP | UF_NOUNLINK |
536 UF_OFFLINE | UF_OPAQUE | UF_READONLY | UF_REPARSE |
537 UF_SPARSE | UF_SYSTEM)) != 0)
539 if (vp->v_mount->mnt_flag & MNT_RDONLY)
542 * Callers may only modify the file flags on objects they
543 * have VADMIN rights for.
545 if ((error = VOP_ACCESS(vp, VADMIN, cred, td)))
548 * Unprivileged processes are not permitted to unset system
549 * flags, or modify flags if any system flags are set.
550 * Privileged non-jail processes may not modify system flags
551 * if securelevel > 0 and any existing system flags are set.
552 * Privileged jail processes behave like privileged non-jail
553 * processes if the PR_ALLOW_CHFLAGS permission bit is set;
554 * otherwise, they behave like unprivileged processes.
556 if (!priv_check_cred(cred, PRIV_VFS_SYSFLAGS, 0)) {
558 (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND)) {
559 error = securelevel_gt(cred, 0);
563 /* The snapshot flag cannot be toggled. */
564 if ((vap->va_flags ^ ip->i_flags) & SF_SNAPSHOT)
568 (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND) ||
569 ((vap->va_flags ^ ip->i_flags) & SF_SETTABLE))
572 ip->i_flags = vap->va_flags;
573 DIP_SET(ip, i_flags, vap->va_flags);
574 ip->i_flag |= IN_CHANGE;
575 error = UFS_UPDATE(vp, 0);
576 if (ip->i_flags & (IMMUTABLE | APPEND))
580 * If immutable or append, no one can change any of its attributes
581 * except the ones already handled (in some cases, file flags
582 * including the immutability flags themselves for the superuser).
584 if (ip->i_flags & (IMMUTABLE | APPEND))
587 * Go through the fields and update iff not VNOVAL.
589 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
590 if (vp->v_mount->mnt_flag & MNT_RDONLY)
592 if ((error = ufs_chown(vp, vap->va_uid, vap->va_gid, cred,
596 if (vap->va_size != VNOVAL) {
598 * XXX most of the following special cases should be in
599 * callers instead of in N filesystems. The VDIR check
602 switch (vp->v_type) {
608 * Truncation should have an effect in these cases.
609 * Disallow it if the filesystem is read-only or
610 * the file is being snapshotted.
612 if (vp->v_mount->mnt_flag & MNT_RDONLY)
614 if ((ip->i_flags & SF_SNAPSHOT) != 0)
619 * According to POSIX, the result is unspecified
620 * for file types other than regular files,
621 * directories and shared memory objects. We
622 * don't support shared memory objects in the file
623 * system, and have dubious support for truncating
624 * symlinks. Just ignore the request in other cases.
628 if ((error = UFS_TRUNCATE(vp, vap->va_size, IO_NORMAL |
629 ((vap->va_vaflags & VA_SYNC) != 0 ? IO_SYNC : 0),
633 if (vap->va_atime.tv_sec != VNOVAL ||
634 vap->va_mtime.tv_sec != VNOVAL ||
635 vap->va_birthtime.tv_sec != VNOVAL) {
636 if (vp->v_mount->mnt_flag & MNT_RDONLY)
638 if ((ip->i_flags & SF_SNAPSHOT) != 0)
640 error = vn_utimes_perm(vp, vap, cred, td);
643 ip->i_flag |= IN_CHANGE | IN_MODIFIED;
644 if (vap->va_atime.tv_sec != VNOVAL) {
645 ip->i_flag &= ~IN_ACCESS;
646 DIP_SET(ip, i_atime, vap->va_atime.tv_sec);
647 DIP_SET(ip, i_atimensec, vap->va_atime.tv_nsec);
649 if (vap->va_mtime.tv_sec != VNOVAL) {
650 ip->i_flag &= ~IN_UPDATE;
651 DIP_SET(ip, i_mtime, vap->va_mtime.tv_sec);
652 DIP_SET(ip, i_mtimensec, vap->va_mtime.tv_nsec);
654 if (vap->va_birthtime.tv_sec != VNOVAL && I_IS_UFS2(ip)) {
655 ip->i_din2->di_birthtime = vap->va_birthtime.tv_sec;
656 ip->i_din2->di_birthnsec = vap->va_birthtime.tv_nsec;
658 error = UFS_UPDATE(vp, 0);
663 if (vap->va_mode != (mode_t)VNOVAL) {
664 if (vp->v_mount->mnt_flag & MNT_RDONLY)
666 if ((ip->i_flags & SF_SNAPSHOT) != 0 && (vap->va_mode &
667 (S_IXUSR | S_IWUSR | S_IXGRP | S_IWGRP | S_IXOTH | S_IWOTH)))
669 error = ufs_chmod(vp, (int)vap->va_mode, cred, td);
676 ufs_update_nfs4_acl_after_mode_change(struct vnode *vp, int mode,
677 int file_owner_id, struct ucred *cred, struct thread *td)
682 aclp = acl_alloc(M_WAITOK);
683 error = ufs_getacl_nfs4_internal(vp, aclp, td);
685 * We don't have to handle EOPNOTSUPP here, as the filesystem claims
691 acl_nfs4_sync_acl_from_mode(aclp, mode, file_owner_id);
692 error = ufs_setacl_nfs4_internal(vp, aclp, td);
701 * Mark this file's access time for update for vfs_mark_atime(). This
702 * is called from execve() and mmap().
706 struct vop_markatime_args /* {
710 struct vnode *vp = ap->a_vp;
711 struct inode *ip = VTOI(vp);
714 ip->i_flag |= IN_ACCESS;
717 * XXXKIB No UFS_UPDATE(ap->a_vp, 0) there.
723 * Change the mode on a file.
724 * Inode must be locked before calling.
727 ufs_chmod(vp, mode, cred, td)
733 struct inode *ip = VTOI(vp);
737 * To modify the permissions on a file, must possess VADMIN
740 if ((error = VOP_ACCESSX(vp, VWRITE_ACL, cred, td)))
743 * Privileged processes may set the sticky bit on non-directories,
744 * as well as set the setgid bit on a file with a group that the
745 * process is not a member of. Both of these are allowed in
748 if (vp->v_type != VDIR && (mode & S_ISTXT)) {
749 if (priv_check_cred(cred, PRIV_VFS_STICKYFILE, 0))
752 if (!groupmember(ip->i_gid, cred) && (mode & ISGID)) {
753 error = priv_check_cred(cred, PRIV_VFS_SETGID, 0);
759 * Deny setting setuid if we are not the file owner.
761 if ((mode & ISUID) && ip->i_uid != cred->cr_uid) {
762 error = priv_check_cred(cred, PRIV_VFS_ADMIN, 0);
767 ip->i_mode &= ~ALLPERMS;
768 ip->i_mode |= (mode & ALLPERMS);
769 DIP_SET(ip, i_mode, ip->i_mode);
770 ip->i_flag |= IN_CHANGE;
772 if ((vp->v_mount->mnt_flag & MNT_NFS4ACLS) != 0)
773 error = ufs_update_nfs4_acl_after_mode_change(vp, mode, ip->i_uid, cred, td);
775 if (error == 0 && (ip->i_flag & IN_CHANGE) != 0)
776 error = UFS_UPDATE(vp, 0);
782 * Perform chown operation on inode ip;
783 * inode must be locked prior to call.
786 ufs_chown(vp, uid, gid, cred, td)
793 struct inode *ip = VTOI(vp);
802 if (uid == (uid_t)VNOVAL)
804 if (gid == (gid_t)VNOVAL)
807 * To modify the ownership of a file, must possess VADMIN for that
810 if ((error = VOP_ACCESSX(vp, VWRITE_OWNER, cred, td)))
813 * To change the owner of a file, or change the group of a file to a
814 * group of which we are not a member, the caller must have
817 if (((uid != ip->i_uid && uid != cred->cr_uid) ||
818 (gid != ip->i_gid && !groupmember(gid, cred))) &&
819 (error = priv_check_cred(cred, PRIV_VFS_CHOWN, 0)))
824 if ((error = getinoquota(ip)) != 0)
827 dqrele(vp, ip->i_dquot[USRQUOTA]);
828 ip->i_dquot[USRQUOTA] = NODQUOT;
831 dqrele(vp, ip->i_dquot[GRPQUOTA]);
832 ip->i_dquot[GRPQUOTA] = NODQUOT;
834 change = DIP(ip, i_blocks);
835 (void) chkdq(ip, -change, cred, CHOWN);
836 (void) chkiq(ip, -1, cred, CHOWN);
837 for (i = 0; i < MAXQUOTAS; i++) {
838 dqrele(vp, ip->i_dquot[i]);
839 ip->i_dquot[i] = NODQUOT;
843 DIP_SET(ip, i_gid, gid);
845 DIP_SET(ip, i_uid, uid);
847 if ((error = getinoquota(ip)) == 0) {
849 dqrele(vp, ip->i_dquot[USRQUOTA]);
850 ip->i_dquot[USRQUOTA] = NODQUOT;
853 dqrele(vp, ip->i_dquot[GRPQUOTA]);
854 ip->i_dquot[GRPQUOTA] = NODQUOT;
856 if ((error = chkdq(ip, change, cred, CHOWN)) == 0) {
857 if ((error = chkiq(ip, 1, cred, CHOWN)) == 0)
860 (void) chkdq(ip, -change, cred, CHOWN|FORCE);
862 for (i = 0; i < MAXQUOTAS; i++) {
863 dqrele(vp, ip->i_dquot[i]);
864 ip->i_dquot[i] = NODQUOT;
868 DIP_SET(ip, i_gid, ogid);
870 DIP_SET(ip, i_uid, ouid);
871 if (getinoquota(ip) == 0) {
873 dqrele(vp, ip->i_dquot[USRQUOTA]);
874 ip->i_dquot[USRQUOTA] = NODQUOT;
877 dqrele(vp, ip->i_dquot[GRPQUOTA]);
878 ip->i_dquot[GRPQUOTA] = NODQUOT;
880 (void) chkdq(ip, change, cred, FORCE|CHOWN);
881 (void) chkiq(ip, 1, cred, FORCE|CHOWN);
882 (void) getinoquota(ip);
887 panic("ufs_chown: lost quota");
889 ip->i_flag |= IN_CHANGE;
890 if ((ip->i_mode & (ISUID | ISGID)) && (ouid != uid || ogid != gid)) {
891 if (priv_check_cred(cred, PRIV_VFS_RETAINSUGID, 0)) {
892 ip->i_mode &= ~(ISUID | ISGID);
893 DIP_SET(ip, i_mode, ip->i_mode);
896 error = UFS_UPDATE(vp, 0);
902 struct vop_remove_args /* {
905 struct componentname *a_cnp;
909 struct vnode *vp = ap->a_vp;
910 struct vnode *dvp = ap->a_dvp;
916 if ((ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
917 (VTOI(dvp)->i_flags & APPEND)) {
922 ufs_gjournal_orphan(vp);
924 error = ufs_dirremove(dvp, ip, ap->a_cnp->cn_flags, 0);
925 if (ip->i_nlink <= 0)
926 vp->v_vflag |= VV_NOSYNC;
927 if ((ip->i_flags & SF_SNAPSHOT) != 0) {
929 * Avoid deadlock where another thread is trying to
930 * update the inodeblock for dvp and is waiting on
931 * snaplk. Temporary unlock the vnode lock for the
932 * unlinked file and sync the directory. This should
933 * allow vput() of the directory to not block later on
934 * while holding the snapshot vnode locked, assuming
935 * that the directory hasn't been unlinked too.
938 (void) VOP_FSYNC(dvp, MNT_WAIT, td);
939 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
946 print_bad_link_count(const char *funcname, struct vnode *dvp)
951 uprintf("%s: Bad link count %d on parent inode %jd in file system %s\n",
952 funcname, dip->i_effnlink, (intmax_t)dip->i_number,
953 dvp->v_mount->mnt_stat.f_mntonname);
961 struct vop_link_args /* {
962 struct vnode *a_tdvp;
964 struct componentname *a_cnp;
967 struct vnode *vp = ap->a_vp;
968 struct vnode *tdvp = ap->a_tdvp;
969 struct componentname *cnp = ap->a_cnp;
971 struct direct newdir;
975 if ((cnp->cn_flags & HASBUF) == 0)
976 panic("ufs_link: no name");
978 if (VTOI(tdvp)->i_effnlink < 2) {
979 print_bad_link_count("ufs_link", tdvp);
984 if (ip->i_nlink >= UFS_LINK_MAX) {
989 * The file may have been removed after namei droped the original
992 if (ip->i_effnlink == 0) {
996 if (ip->i_flags & (IMMUTABLE | APPEND)) {
1002 DIP_SET(ip, i_nlink, ip->i_nlink);
1003 ip->i_flag |= IN_CHANGE;
1004 if (DOINGSOFTDEP(vp))
1005 softdep_setup_link(VTOI(tdvp), ip);
1006 error = UFS_UPDATE(vp, !DOINGSOFTDEP(vp) && !DOINGASYNC(vp));
1008 ufs_makedirentry(ip, cnp, &newdir);
1009 error = ufs_direnter(tdvp, vp, &newdir, cnp, NULL, 0);
1015 DIP_SET(ip, i_nlink, ip->i_nlink);
1016 ip->i_flag |= IN_CHANGE;
1017 if (DOINGSOFTDEP(vp))
1018 softdep_revert_link(VTOI(tdvp), ip);
1025 * whiteout vnode call
1029 struct vop_whiteout_args /* {
1030 struct vnode *a_dvp;
1031 struct componentname *a_cnp;
1035 struct vnode *dvp = ap->a_dvp;
1036 struct componentname *cnp = ap->a_cnp;
1037 struct direct newdir;
1040 switch (ap->a_flags) {
1042 /* 4.4 format directories support whiteout operations */
1043 if (dvp->v_mount->mnt_maxsymlinklen > 0)
1045 return (EOPNOTSUPP);
1048 /* create a new directory whiteout */
1050 if ((cnp->cn_flags & SAVENAME) == 0)
1051 panic("ufs_whiteout: missing name");
1052 if (dvp->v_mount->mnt_maxsymlinklen <= 0)
1053 panic("ufs_whiteout: old format filesystem");
1056 newdir.d_ino = UFS_WINO;
1057 newdir.d_namlen = cnp->cn_namelen;
1058 bcopy(cnp->cn_nameptr, newdir.d_name, (unsigned)cnp->cn_namelen + 1);
1059 newdir.d_type = DT_WHT;
1060 error = ufs_direnter(dvp, NULL, &newdir, cnp, NULL, 0);
1064 /* remove an existing directory whiteout */
1066 if (dvp->v_mount->mnt_maxsymlinklen <= 0)
1067 panic("ufs_whiteout: old format filesystem");
1070 cnp->cn_flags &= ~DOWHITEOUT;
1071 error = ufs_dirremove(dvp, NULL, cnp->cn_flags, 0);
1074 panic("ufs_whiteout: unknown op");
1079 static volatile int rename_restarts;
1080 SYSCTL_INT(_vfs_ufs, OID_AUTO, rename_restarts, CTLFLAG_RD,
1081 __DEVOLATILE(int *, &rename_restarts), 0,
1082 "Times rename had to restart due to lock contention");
1085 * Rename system call.
1086 * rename("foo", "bar");
1089 * link("foo", "bar");
1091 * but ``atomically''. Can't do full commit without saving state in the
1092 * inode on disk which isn't feasible at this time. Best we can do is
1093 * always guarantee the target exists.
1095 * Basic algorithm is:
1097 * 1) Bump link count on source while we're linking it to the
1098 * target. This also ensure the inode won't be deleted out
1099 * from underneath us while we work (it may be truncated by
1100 * a concurrent `trunc' or `open' for creation).
1101 * 2) Link source to destination. If destination already exists,
1103 * 3) Unlink source reference to inode if still around. If a
1104 * directory was moved and the parent of the destination
1105 * is different from the source, patch the ".." entry in the
1110 struct vop_rename_args /* {
1111 struct vnode *a_fdvp;
1112 struct vnode *a_fvp;
1113 struct componentname *a_fcnp;
1114 struct vnode *a_tdvp;
1115 struct vnode *a_tvp;
1116 struct componentname *a_tcnp;
1119 struct vnode *tvp = ap->a_tvp;
1120 struct vnode *tdvp = ap->a_tdvp;
1121 struct vnode *fvp = ap->a_fvp;
1122 struct vnode *fdvp = ap->a_fdvp;
1124 struct componentname *tcnp = ap->a_tcnp;
1125 struct componentname *fcnp = ap->a_fcnp;
1126 struct thread *td = fcnp->cn_thread;
1127 struct inode *fip, *tip, *tdp, *fdp;
1128 struct direct newdir;
1130 int doingdirectory, newparent;
1136 if ((tcnp->cn_flags & HASBUF) == 0 ||
1137 (fcnp->cn_flags & HASBUF) == 0)
1138 panic("ufs_rename: no name");
1142 VOP_UNLOCK(tdvp, 0);
1143 if (tvp && tvp != tdvp)
1146 * Check for cross-device rename.
1148 if ((fvp->v_mount != tdvp->v_mount) ||
1149 (tvp && (fvp->v_mount != tvp->v_mount))) {
1156 * We need to acquire 2 to 4 locks depending on whether tvp is NULL
1157 * and fdvp and tdvp are the same directory. Subsequently we need
1158 * to double-check all paths and in the directory rename case we
1159 * need to verify that we are not creating a directory loop. To
1160 * handle this we acquire all but fdvp using non-blocking
1161 * acquisitions. If we fail to acquire any lock in the path we will
1162 * drop all held locks, acquire the new lock in a blocking fashion,
1163 * and then release it and restart the rename. This acquire/release
1164 * step ensures that we do not spin on a lock waiting for release.
1166 error = vn_lock(fdvp, LK_EXCLUSIVE);
1169 if (vn_lock(tdvp, LK_EXCLUSIVE | LK_NOWAIT) != 0) {
1170 VOP_UNLOCK(fdvp, 0);
1171 error = vn_lock(tdvp, LK_EXCLUSIVE);
1174 VOP_UNLOCK(tdvp, 0);
1175 atomic_add_int(&rename_restarts, 1);
1179 * Re-resolve fvp to be certain it still exists and fetch the
1182 error = ufs_lookup_ino(fdvp, NULL, fcnp, &ino);
1184 VOP_UNLOCK(fdvp, 0);
1185 VOP_UNLOCK(tdvp, 0);
1188 error = VFS_VGET(mp, ino, LK_EXCLUSIVE | LK_NOWAIT, &nvp);
1190 VOP_UNLOCK(fdvp, 0);
1191 VOP_UNLOCK(tdvp, 0);
1194 error = VFS_VGET(mp, ino, LK_EXCLUSIVE, &nvp);
1200 atomic_add_int(&rename_restarts, 1);
1206 * Re-resolve tvp and acquire the vnode lock if present.
1208 error = ufs_lookup_ino(tdvp, NULL, tcnp, &ino);
1209 if (error != 0 && error != EJUSTRETURN) {
1210 VOP_UNLOCK(fdvp, 0);
1211 VOP_UNLOCK(tdvp, 0);
1216 * If tvp disappeared we just carry on.
1218 if (error == EJUSTRETURN && tvp != NULL) {
1223 * Get the tvp ino if the lookup succeeded. We may have to restart
1224 * if the non-blocking acquire fails.
1228 error = VFS_VGET(mp, ino, LK_EXCLUSIVE | LK_NOWAIT, &nvp);
1233 VOP_UNLOCK(fdvp, 0);
1234 VOP_UNLOCK(tdvp, 0);
1238 error = VFS_VGET(mp, ino, LK_EXCLUSIVE, &nvp);
1242 atomic_add_int(&rename_restarts, 1);
1252 if (tvp && ((VTOI(tvp)->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
1253 (VTOI(tdvp)->i_flags & APPEND))) {
1258 * Renaming a file to itself has no effect. The upper layers should
1259 * not call us in that case. However, things could change after
1260 * we drop the locks above.
1268 ino = fip->i_number;
1269 if (fip->i_nlink >= UFS_LINK_MAX) {
1273 if ((fip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))
1274 || (fdp->i_flags & APPEND)) {
1278 if ((fip->i_mode & IFMT) == IFDIR) {
1280 * Avoid ".", "..", and aliases of "." for obvious reasons.
1282 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
1284 (fcnp->cn_flags | tcnp->cn_flags) & ISDOTDOT) {
1288 if (fdp->i_number != tdp->i_number)
1289 newparent = tdp->i_number;
1292 if ((fvp->v_type == VDIR && fvp->v_mountedhere != NULL) ||
1293 (tvp != NULL && tvp->v_type == VDIR &&
1294 tvp->v_mountedhere != NULL)) {
1300 * If ".." must be changed (ie the directory gets a new
1301 * parent) then the source directory must not be in the
1302 * directory hierarchy above the target, as this would
1303 * orphan everything below the source directory. Also
1304 * the user must have write permission in the source so
1305 * as to be able to change "..".
1307 if (doingdirectory && newparent) {
1308 error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_thread);
1311 error = ufs_checkpath(ino, fdp->i_number, tdp, tcnp->cn_cred,
1314 * We encountered a lock that we have to wait for. Unlock
1315 * everything else and VGET before restarting.
1318 VOP_UNLOCK(fdvp, 0);
1320 VOP_UNLOCK(tdvp, 0);
1323 error = VFS_VGET(mp, ino, LK_SHARED, &nvp);
1326 atomic_add_int(&rename_restarts, 1);
1331 if ((tcnp->cn_flags & SAVESTART) == 0)
1332 panic("ufs_rename: lost to startdir");
1334 if (fip->i_effnlink == 0 || fdp->i_effnlink == 0 ||
1335 tdp->i_effnlink == 0)
1336 panic("Bad effnlink fip %p, fdp %p, tdp %p", fip, fdp, tdp);
1339 * 1) Bump link count while we're moving stuff
1340 * around. If we crash somewhere before
1341 * completing our work, the link count
1342 * may be wrong, but correctable.
1346 DIP_SET(fip, i_nlink, fip->i_nlink);
1347 fip->i_flag |= IN_CHANGE;
1348 if (DOINGSOFTDEP(fvp))
1349 softdep_setup_link(tdp, fip);
1350 error = UFS_UPDATE(fvp, !DOINGSOFTDEP(fvp) && !DOINGASYNC(fvp));
1355 * 2) If target doesn't exist, link the target
1356 * to the source and unlink the source.
1357 * Otherwise, rewrite the target directory
1358 * entry to reference the source inode and
1359 * expunge the original entry's existence.
1362 if (ITODEV(tdp) != ITODEV(fip))
1363 panic("ufs_rename: EXDEV");
1364 if (doingdirectory && newparent) {
1366 * Account for ".." in new directory.
1367 * When source and destination have the same
1368 * parent we don't adjust the link count. The
1369 * actual link modification is completed when
1370 * .. is rewritten below.
1372 if (tdp->i_nlink >= UFS_LINK_MAX) {
1377 ufs_makedirentry(fip, tcnp, &newdir);
1378 error = ufs_direnter(tdvp, NULL, &newdir, tcnp, NULL, 1);
1381 /* Setup tdvp for directory compaction if needed. */
1382 if (tdp->i_count && tdp->i_endoff &&
1383 tdp->i_endoff < tdp->i_size)
1384 endoff = tdp->i_endoff;
1386 if (ITODEV(tip) != ITODEV(tdp) || ITODEV(tip) != ITODEV(fip))
1387 panic("ufs_rename: EXDEV");
1389 * Short circuit rename(foo, foo).
1391 if (tip->i_number == fip->i_number)
1392 panic("ufs_rename: same file");
1394 * If the parent directory is "sticky", then the caller
1395 * must possess VADMIN for the parent directory, or the
1396 * destination of the rename. This implements append-only
1399 if ((tdp->i_mode & S_ISTXT) &&
1400 VOP_ACCESS(tdvp, VADMIN, tcnp->cn_cred, td) &&
1401 VOP_ACCESS(tvp, VADMIN, tcnp->cn_cred, td)) {
1406 * Target must be empty if a directory and have no links
1407 * to it. Also, ensure source and target are compatible
1408 * (both directories, or both not directories).
1410 if ((tip->i_mode & IFMT) == IFDIR) {
1411 if ((tip->i_effnlink > 2) ||
1412 !ufs_dirempty(tip, tdp->i_number, tcnp->cn_cred)) {
1416 if (!doingdirectory) {
1421 } else if (doingdirectory) {
1425 if (doingdirectory) {
1428 if (DOINGSOFTDEP(tdvp))
1429 softdep_change_linkcnt(tdp);
1432 if (DOINGSOFTDEP(tvp))
1433 softdep_change_linkcnt(tip);
1435 error = ufs_dirrewrite(tdp, tip, fip->i_number,
1436 IFTODT(fip->i_mode),
1437 (doingdirectory && newparent) ? newparent : doingdirectory);
1439 if (doingdirectory) {
1442 if (DOINGSOFTDEP(tdvp))
1443 softdep_change_linkcnt(tdp);
1446 if (DOINGSOFTDEP(tvp))
1447 softdep_change_linkcnt(tip);
1450 if (doingdirectory && !DOINGSOFTDEP(tvp)) {
1452 * The only stuff left in the directory is "."
1453 * and "..". The "." reference is inconsequential
1454 * since we are quashing it. We have removed the "."
1455 * reference and the reference in the parent directory,
1456 * but there may be other hard links. The soft
1457 * dependency code will arrange to do these operations
1458 * after the parent directory entry has been deleted on
1459 * disk, so when running with that code we avoid doing
1464 DIP_SET(tdp, i_nlink, tdp->i_nlink);
1465 tdp->i_flag |= IN_CHANGE;
1468 DIP_SET(tip, i_nlink, tip->i_nlink);
1469 tip->i_flag |= IN_CHANGE;
1474 * 3) Unlink the source. We have to resolve the path again to
1475 * fixup the directory offset and count for ufs_dirremove.
1478 error = ufs_lookup_ino(fdvp, NULL, fcnp, &ino);
1480 panic("ufs_rename: from entry went away!");
1481 if (ino != fip->i_number)
1482 panic("ufs_rename: ino mismatch %ju != %ju\n",
1483 (uintmax_t)ino, (uintmax_t)fip->i_number);
1486 * If the source is a directory with a
1487 * new parent, the link count of the old
1488 * parent directory must be decremented
1489 * and ".." set to point to the new parent.
1491 if (doingdirectory && newparent) {
1493 * If tip exists we simply use its link, otherwise we must
1499 DIP_SET(tdp, i_nlink, tdp->i_nlink);
1500 tdp->i_flag |= IN_CHANGE;
1501 if (DOINGSOFTDEP(tdvp))
1502 softdep_setup_dotdot_link(tdp, fip);
1503 error = UFS_UPDATE(tdvp, !DOINGSOFTDEP(tdvp) &&
1505 /* Don't go to bad here as the new link exists. */
1508 } else if (DOINGSUJ(tdvp))
1509 /* Journal must account for each new link. */
1510 softdep_setup_dotdot_link(tdp, fip);
1511 fip->i_offset = mastertemplate.dot_reclen;
1512 ufs_dirrewrite(fip, fdp, newparent, DT_DIR, 0);
1515 error = ufs_dirremove(fdvp, fip, fcnp->cn_flags, 0);
1517 * The kern_renameat() looks up the fvp using the DELETE flag, which
1518 * causes the removal of the name cache entry for fvp.
1519 * As the relookup of the fvp is done in two steps:
1520 * ufs_lookup_ino() and then VFS_VGET(), another thread might do a
1521 * normal lookup of the from name just before the VFS_VGET() call,
1522 * causing the cache entry to be re-instantiated.
1524 * The same issue also applies to tvp if it exists as
1525 * otherwise we may have a stale name cache entry for the new
1526 * name that references the old i-node if it has other links
1527 * or open file descriptors.
1532 cache_purge_negative(tdvp);
1540 * If compaction or fsync was requested do it now that other locks
1541 * are no longer needed.
1543 if (error == 0 && endoff != 0) {
1544 error = UFS_TRUNCATE(tdvp, endoff, IO_NORMAL |
1545 (DOINGASYNC(tdvp) ? 0 : IO_SYNC), tcnp->cn_cred);
1548 "ufs_rename: failed to truncate, error %d\n",
1551 else if (tdp->i_dirhash != NULL)
1552 ufsdirhash_dirtrunc(tdp, endoff);
1555 * Even if the directory compaction failed, rename was
1556 * succesful. Do not propagate a UFS_TRUNCATE() error
1561 if (error == 0 && tdp->i_flag & IN_NEEDSYNC)
1562 error = VOP_FSYNC(tdvp, MNT_WAIT, td);
1569 DIP_SET(fip, i_nlink, fip->i_nlink);
1570 fip->i_flag |= IN_CHANGE;
1571 if (DOINGSOFTDEP(fvp))
1572 softdep_revert_link(tdp, fip);
1587 ufs_do_posix1e_acl_inheritance_dir(struct vnode *dvp, struct vnode *tvp,
1588 mode_t dmode, struct ucred *cred, struct thread *td)
1591 struct inode *ip = VTOI(tvp);
1592 struct acl *dacl, *acl;
1594 acl = acl_alloc(M_WAITOK);
1595 dacl = acl_alloc(M_WAITOK);
1598 * Retrieve default ACL from parent, if any.
1600 error = VOP_GETACL(dvp, ACL_TYPE_DEFAULT, acl, cred, td);
1604 * Retrieved a default ACL, so merge mode and ACL if
1605 * necessary. If the ACL is empty, fall through to
1606 * the "not defined or available" case.
1608 if (acl->acl_cnt != 0) {
1609 dmode = acl_posix1e_newfilemode(dmode, acl);
1611 DIP_SET(ip, i_mode, dmode);
1613 ufs_sync_acl_from_inode(ip, acl);
1620 * Just use the mode as-is.
1623 DIP_SET(ip, i_mode, dmode);
1632 * XXX: If we abort now, will Soft Updates notify the extattr
1633 * code that the EAs for the file need to be released?
1635 error = VOP_SETACL(tvp, ACL_TYPE_ACCESS, acl, cred, td);
1637 error = VOP_SETACL(tvp, ACL_TYPE_DEFAULT, dacl, cred, td);
1644 * XXX: This should not happen, as EOPNOTSUPP above
1645 * was supposed to free acl.
1647 printf("ufs_mkdir: VOP_GETACL() but no VOP_SETACL()\n");
1649 panic("ufs_mkdir: VOP_GETACL() but no VOP_SETACL()");
1665 ufs_do_posix1e_acl_inheritance_file(struct vnode *dvp, struct vnode *tvp,
1666 mode_t mode, struct ucred *cred, struct thread *td)
1669 struct inode *ip = VTOI(tvp);
1672 acl = acl_alloc(M_WAITOK);
1675 * Retrieve default ACL for parent, if any.
1677 error = VOP_GETACL(dvp, ACL_TYPE_DEFAULT, acl, cred, td);
1681 * Retrieved a default ACL, so merge mode and ACL if
1684 if (acl->acl_cnt != 0) {
1686 * Two possible ways for default ACL to not
1687 * be present. First, the EA can be
1688 * undefined, or second, the default ACL can
1689 * be blank. If it's blank, fall through to
1690 * the it's not defined case.
1692 mode = acl_posix1e_newfilemode(mode, acl);
1694 DIP_SET(ip, i_mode, mode);
1695 ufs_sync_acl_from_inode(ip, acl);
1702 * Just use the mode as-is.
1705 DIP_SET(ip, i_mode, mode);
1714 * XXX: If we abort now, will Soft Updates notify the extattr
1715 * code that the EAs for the file need to be released?
1717 error = VOP_SETACL(tvp, ACL_TYPE_ACCESS, acl, cred, td);
1724 * XXX: This should not happen, as EOPNOTSUPP above was
1725 * supposed to free acl.
1727 printf("ufs_do_posix1e_acl_inheritance_file: VOP_GETACL() "
1728 "but no VOP_SETACL()\n");
1729 /* panic("ufs_do_posix1e_acl_inheritance_file: VOP_GETACL() "
1730 "but no VOP_SETACL()"); */
1744 ufs_do_nfs4_acl_inheritance(struct vnode *dvp, struct vnode *tvp,
1745 mode_t child_mode, struct ucred *cred, struct thread *td)
1748 struct acl *parent_aclp, *child_aclp;
1750 parent_aclp = acl_alloc(M_WAITOK);
1751 child_aclp = acl_alloc(M_WAITOK | M_ZERO);
1753 error = ufs_getacl_nfs4_internal(dvp, parent_aclp, td);
1756 acl_nfs4_compute_inherited_acl(parent_aclp, child_aclp,
1757 child_mode, VTOI(tvp)->i_uid, tvp->v_type == VDIR);
1758 error = ufs_setacl_nfs4_internal(tvp, child_aclp, td);
1762 acl_free(parent_aclp);
1763 acl_free(child_aclp);
1774 struct vop_mkdir_args /* {
1775 struct vnode *a_dvp;
1776 struct vnode **a_vpp;
1777 struct componentname *a_cnp;
1778 struct vattr *a_vap;
1781 struct vnode *dvp = ap->a_dvp;
1782 struct vattr *vap = ap->a_vap;
1783 struct componentname *cnp = ap->a_cnp;
1784 struct inode *ip, *dp;
1787 struct dirtemplate dirtemplate, *dtp;
1788 struct direct newdir;
1793 if ((cnp->cn_flags & HASBUF) == 0)
1794 panic("ufs_mkdir: no name");
1797 if (dp->i_nlink >= UFS_LINK_MAX) {
1801 dmode = vap->va_mode & 0777;
1804 * Must simulate part of ufs_makeinode here to acquire the inode,
1805 * but not have it entered in the parent directory. The entry is
1806 * made later after writing "." and ".." entries.
1808 if (dp->i_effnlink < 2) {
1809 print_bad_link_count("ufs_mkdir", dvp);
1813 error = UFS_VALLOC(dvp, dmode, cnp->cn_cred, &tvp);
1817 ip->i_gid = dp->i_gid;
1818 DIP_SET(ip, i_gid, dp->i_gid);
1822 struct ucred ucred, *ucp;
1827 * If we are hacking owners here, (only do this where told to)
1828 * and we are not giving it TO root, (would subvert quotas)
1829 * then go ahead and give it to the other user.
1830 * The new directory also inherits the SUID bit.
1831 * If user's UID and dir UID are the same,
1832 * 'give it away' so that the SUID is still forced on.
1834 if ((dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
1835 (dp->i_mode & ISUID) && dp->i_uid) {
1837 ip->i_uid = dp->i_uid;
1838 DIP_SET(ip, i_uid, dp->i_uid);
1840 if (dp->i_uid != cnp->cn_cred->cr_uid) {
1842 * Make sure the correct user gets charged
1844 * Make a dummy credential for the victim.
1845 * XXX This seems to never be accessed out of
1846 * our context so a stack variable is ok.
1848 refcount_init(&ucred.cr_ref, 1);
1849 ucred.cr_uid = ip->i_uid;
1850 ucred.cr_ngroups = 1;
1851 ucred.cr_groups = &ucred_group;
1852 ucred.cr_groups[0] = dp->i_gid;
1857 ip->i_uid = cnp->cn_cred->cr_uid;
1858 DIP_SET(ip, i_uid, ip->i_uid);
1861 if ((error = getinoquota(ip)) ||
1862 (error = chkiq(ip, 1, ucp, 0))) {
1863 if (DOINGSOFTDEP(tvp))
1864 softdep_revert_link(dp, ip);
1865 UFS_VFREE(tvp, ip->i_number, dmode);
1871 #else /* !SUIDDIR */
1872 ip->i_uid = cnp->cn_cred->cr_uid;
1873 DIP_SET(ip, i_uid, ip->i_uid);
1875 if ((error = getinoquota(ip)) ||
1876 (error = chkiq(ip, 1, cnp->cn_cred, 0))) {
1877 if (DOINGSOFTDEP(tvp))
1878 softdep_revert_link(dp, ip);
1879 UFS_VFREE(tvp, ip->i_number, dmode);
1884 #endif /* !SUIDDIR */
1885 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
1887 DIP_SET(ip, i_mode, dmode);
1888 tvp->v_type = VDIR; /* Rest init'd in getnewvnode(). */
1891 DIP_SET(ip, i_nlink, 2);
1893 if (cnp->cn_flags & ISWHITEOUT) {
1894 ip->i_flags |= UF_OPAQUE;
1895 DIP_SET(ip, i_flags, ip->i_flags);
1899 * Bump link count in parent directory to reflect work done below.
1900 * Should be done before reference is created so cleanup is
1901 * possible if we crash.
1905 DIP_SET(dp, i_nlink, dp->i_nlink);
1906 dp->i_flag |= IN_CHANGE;
1907 if (DOINGSOFTDEP(dvp))
1908 softdep_setup_mkdir(dp, ip);
1909 error = UFS_UPDATE(dvp, !DOINGSOFTDEP(dvp) && !DOINGASYNC(dvp));
1913 if (dvp->v_mount->mnt_flag & MNT_MULTILABEL) {
1914 error = mac_vnode_create_extattr(cnp->cn_cred, dvp->v_mount,
1921 if (dvp->v_mount->mnt_flag & MNT_ACLS) {
1922 error = ufs_do_posix1e_acl_inheritance_dir(dvp, tvp, dmode,
1923 cnp->cn_cred, cnp->cn_thread);
1926 } else if (dvp->v_mount->mnt_flag & MNT_NFS4ACLS) {
1927 error = ufs_do_nfs4_acl_inheritance(dvp, tvp, dmode,
1928 cnp->cn_cred, cnp->cn_thread);
1932 #endif /* !UFS_ACL */
1935 * Initialize directory with "." and ".." from static template.
1937 if (dvp->v_mount->mnt_maxsymlinklen > 0)
1938 dtp = &mastertemplate;
1940 dtp = (struct dirtemplate *)&omastertemplate;
1942 dirtemplate.dot_ino = ip->i_number;
1943 dirtemplate.dotdot_ino = dp->i_number;
1944 vnode_pager_setsize(tvp, DIRBLKSIZ);
1945 if ((error = UFS_BALLOC(tvp, (off_t)0, DIRBLKSIZ, cnp->cn_cred,
1946 BA_CLRBUF, &bp)) != 0)
1948 ip->i_size = DIRBLKSIZ;
1949 DIP_SET(ip, i_size, DIRBLKSIZ);
1950 ip->i_flag |= IN_CHANGE | IN_UPDATE;
1951 bcopy((caddr_t)&dirtemplate, (caddr_t)bp->b_data, sizeof dirtemplate);
1952 if (DOINGSOFTDEP(tvp)) {
1954 * Ensure that the entire newly allocated block is a
1955 * valid directory so that future growth within the
1956 * block does not have to ensure that the block is
1957 * written before the inode.
1960 while (blkoff < bp->b_bcount) {
1962 (bp->b_data + blkoff))->d_reclen = DIRBLKSIZ;
1963 blkoff += DIRBLKSIZ;
1966 if ((error = UFS_UPDATE(tvp, !DOINGSOFTDEP(tvp) &&
1967 !DOINGASYNC(tvp))) != 0) {
1972 * Directory set up, now install its entry in the parent directory.
1974 * If we are not doing soft dependencies, then we must write out the
1975 * buffer containing the new directory body before entering the new
1976 * name in the parent. If we are doing soft dependencies, then the
1977 * buffer containing the new directory body will be passed to and
1978 * released in the soft dependency code after the code has attached
1979 * an appropriate ordering dependency to the buffer which ensures that
1980 * the buffer is written before the new name is written in the parent.
1982 if (DOINGASYNC(dvp))
1984 else if (!DOINGSOFTDEP(dvp) && ((error = bwrite(bp))))
1986 ufs_makedirentry(ip, cnp, &newdir);
1987 error = ufs_direnter(dvp, tvp, &newdir, cnp, bp, 0);
1995 DIP_SET(dp, i_nlink, dp->i_nlink);
1996 dp->i_flag |= IN_CHANGE;
1998 * No need to do an explicit VOP_TRUNCATE here, vrele will
1999 * do this for us because we set the link count to 0.
2003 DIP_SET(ip, i_nlink, 0);
2004 ip->i_flag |= IN_CHANGE;
2005 if (DOINGSOFTDEP(tvp))
2006 softdep_revert_mkdir(dp, ip);
2015 * Rmdir system call.
2019 struct vop_rmdir_args /* {
2020 struct vnode *a_dvp;
2022 struct componentname *a_cnp;
2025 struct vnode *vp = ap->a_vp;
2026 struct vnode *dvp = ap->a_dvp;
2027 struct componentname *cnp = ap->a_cnp;
2028 struct inode *ip, *dp;
2035 * Do not remove a directory that is in the process of being renamed.
2036 * Verify the directory is empty (and valid). Rmdir ".." will not be
2037 * valid since ".." will contain a reference to the current directory
2038 * and thus be non-empty. Do not allow the removal of mounted on
2039 * directories (this can happen when an NFS exported filesystem
2040 * tries to remove a locally mounted on directory).
2043 if (dp->i_effnlink <= 2) {
2044 if (dp->i_effnlink == 2)
2045 print_bad_link_count("ufs_rmdir", dvp);
2049 if (!ufs_dirempty(ip, dp->i_number, cnp->cn_cred)) {
2053 if ((dp->i_flags & APPEND)
2054 || (ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))) {
2058 if (vp->v_mountedhere != 0) {
2063 ufs_gjournal_orphan(vp);
2066 * Delete reference to directory before purging
2067 * inode. If we crash in between, the directory
2068 * will be reattached to lost+found,
2072 if (DOINGSOFTDEP(vp))
2073 softdep_setup_rmdir(dp, ip);
2074 error = ufs_dirremove(dvp, ip, cnp->cn_flags, 1);
2078 if (DOINGSOFTDEP(vp))
2079 softdep_revert_rmdir(dp, ip);
2084 * The only stuff left in the directory is "." and "..". The "."
2085 * reference is inconsequential since we are quashing it. The soft
2086 * dependency code will arrange to do these operations after
2087 * the parent directory entry has been deleted on disk, so
2088 * when running with that code we avoid doing them now.
2090 if (!DOINGSOFTDEP(vp)) {
2092 DIP_SET(dp, i_nlink, dp->i_nlink);
2093 dp->i_flag |= IN_CHANGE;
2094 error = UFS_UPDATE(dvp, 0);
2096 DIP_SET(ip, i_nlink, ip->i_nlink);
2097 ip->i_flag |= IN_CHANGE;
2101 /* Kill any active hash; i_effnlink == 0, so it will not come back. */
2102 if (ip->i_dirhash != NULL)
2103 ufsdirhash_free(ip);
2110 * symlink -- make a symbolic link
2114 struct vop_symlink_args /* {
2115 struct vnode *a_dvp;
2116 struct vnode **a_vpp;
2117 struct componentname *a_cnp;
2118 struct vattr *a_vap;
2122 struct vnode *vp, **vpp = ap->a_vpp;
2126 error = ufs_makeinode(IFLNK | ap->a_vap->va_mode, ap->a_dvp,
2127 vpp, ap->a_cnp, "ufs_symlink");
2131 len = strlen(ap->a_target);
2132 if (len < vp->v_mount->mnt_maxsymlinklen) {
2134 bcopy(ap->a_target, SHORTLINK(ip), len);
2136 DIP_SET(ip, i_size, len);
2137 ip->i_flag |= IN_CHANGE | IN_UPDATE;
2138 error = UFS_UPDATE(vp, 0);
2140 error = vn_rdwr(UIO_WRITE, vp, ap->a_target, len, (off_t)0,
2141 UIO_SYSSPACE, IO_NODELOCKED | IO_NOMACCHECK,
2142 ap->a_cnp->cn_cred, NOCRED, NULL, NULL);
2149 * Vnode op for reading directories.
2153 struct vop_readdir_args /* {
2156 struct ucred *a_cred;
2162 struct vnode *vp = ap->a_vp;
2163 struct uio *uio = ap->a_uio;
2166 struct direct *dp, *edp;
2168 struct dirent dstdp;
2169 off_t offset, startoffset;
2170 size_t readcnt, skipcnt;
2175 if (uio->uio_offset < 0)
2178 if (ip->i_effnlink == 0)
2180 if (ap->a_ncookies != NULL) {
2181 if (uio->uio_resid < 0)
2184 ncookies = uio->uio_resid;
2185 if (uio->uio_offset >= ip->i_size)
2187 else if (ip->i_size - uio->uio_offset < ncookies)
2188 ncookies = ip->i_size - uio->uio_offset;
2189 ncookies = ncookies / (offsetof(struct direct, d_name) + 4) + 1;
2190 cookies = malloc(ncookies * sizeof(*cookies), M_TEMP, M_WAITOK);
2191 *ap->a_ncookies = ncookies;
2192 *ap->a_cookies = cookies;
2197 offset = startoffset = uio->uio_offset;
2198 startresid = uio->uio_resid;
2200 while (error == 0 && uio->uio_resid > 0 &&
2201 uio->uio_offset < ip->i_size) {
2202 error = ffs_blkatoff(vp, uio->uio_offset, NULL, &bp);
2205 if (bp->b_offset + bp->b_bcount > ip->i_size)
2206 readcnt = ip->i_size - bp->b_offset;
2208 readcnt = bp->b_bcount;
2209 skipcnt = (size_t)(uio->uio_offset - bp->b_offset) &
2210 ~(size_t)(DIRBLKSIZ - 1);
2211 offset = bp->b_offset + skipcnt;
2212 dp = (struct direct *)&bp->b_data[skipcnt];
2213 edp = (struct direct *)&bp->b_data[readcnt];
2214 while (error == 0 && uio->uio_resid > 0 && dp < edp) {
2215 if (dp->d_reclen <= offsetof(struct direct, d_name) ||
2216 (caddr_t)dp + dp->d_reclen > (caddr_t)edp) {
2220 #if BYTE_ORDER == LITTLE_ENDIAN
2221 /* Old filesystem format. */
2222 if (vp->v_mount->mnt_maxsymlinklen <= 0) {
2223 dstdp.d_namlen = dp->d_type;
2224 dstdp.d_type = dp->d_namlen;
2228 dstdp.d_namlen = dp->d_namlen;
2229 dstdp.d_type = dp->d_type;
2231 if (offsetof(struct direct, d_name) + dstdp.d_namlen >
2236 if (offset < startoffset || dp->d_ino == 0)
2238 dstdp.d_fileno = dp->d_ino;
2239 dstdp.d_reclen = GENERIC_DIRSIZ(&dstdp);
2240 bcopy(dp->d_name, dstdp.d_name, dstdp.d_namlen);
2241 dstdp.d_name[dstdp.d_namlen] = '\0';
2242 if (dstdp.d_reclen > uio->uio_resid) {
2243 if (uio->uio_resid == startresid)
2246 error = EJUSTRETURN;
2250 error = uiomove((caddr_t)&dstdp, dstdp.d_reclen, uio);
2253 if (cookies != NULL) {
2254 KASSERT(ncookies > 0,
2255 ("ufs_readdir: cookies buffer too small"));
2256 *cookies = offset + dp->d_reclen;
2261 offset += dp->d_reclen;
2262 dp = (struct direct *)((caddr_t)dp + dp->d_reclen);
2265 uio->uio_offset = offset;
2267 /* We need to correct uio_offset. */
2268 uio->uio_offset = offset;
2269 if (error == EJUSTRETURN)
2271 if (ap->a_ncookies != NULL) {
2273 ap->a_ncookies -= ncookies;
2275 free(*ap->a_cookies, M_TEMP);
2276 *ap->a_ncookies = 0;
2277 *ap->a_cookies = NULL;
2280 if (error == 0 && ap->a_eofflag)
2281 *ap->a_eofflag = ip->i_size <= uio->uio_offset;
2286 * Return target name of a symbolic link
2290 struct vop_readlink_args /* {
2293 struct ucred *a_cred;
2296 struct vnode *vp = ap->a_vp;
2297 struct inode *ip = VTOI(vp);
2301 if ((isize < vp->v_mount->mnt_maxsymlinklen) ||
2302 DIP(ip, i_blocks) == 0) { /* XXX - for old fastlink support */
2303 return (uiomove(SHORTLINK(ip), isize, ap->a_uio));
2305 return (VOP_READ(vp, ap->a_uio, 0, ap->a_cred));
2309 * Calculate the logical to physical mapping if not done already,
2310 * then call the device strategy routine.
2312 * In order to be able to swap to a file, the ufs_bmaparray() operation may not
2313 * deadlock on memory. See ufs_bmap() for details.
2317 struct vop_strategy_args /* {
2322 struct buf *bp = ap->a_bp;
2323 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_STRATEGY(VFSTOUFS(vp->v_mount)->um_bo, bp);
2349 * Print out the contents of an inode.
2353 struct vop_print_args /* {
2357 struct vnode *vp = ap->a_vp;
2358 struct inode *ip = VTOI(vp);
2360 printf("\tino %lu, on dev %s", (u_long)ip->i_number,
2361 devtoname(ITODEV(ip)));
2362 if (vp->v_type == VFIFO)
2369 * Close wrapper for fifos.
2371 * Update the times on the inode then do device close.
2375 struct vop_close_args /* {
2378 struct ucred *a_cred;
2379 struct thread *a_td;
2382 struct vnode *vp = ap->a_vp;
2386 usecount = vp->v_usecount;
2388 ufs_itimes_locked(vp);
2390 return (fifo_specops.vop_close(ap));
2394 * Kqfilter wrapper for fifos.
2396 * Fall through to ufs kqfilter routines if needed
2399 ufsfifo_kqfilter(ap)
2400 struct vop_kqfilter_args *ap;
2404 error = fifo_specops.vop_kqfilter(ap);
2406 error = vfs_kqfilter(ap);
2411 * Return POSIX pathconf information applicable to ufs filesystems.
2415 struct vop_pathconf_args /* {
2424 switch (ap->a_name) {
2426 *ap->a_retval = UFS_LINK_MAX;
2429 *ap->a_retval = UFS_MAXNAMLEN;
2432 if (ap->a_vp->v_type == VDIR || ap->a_vp->v_type == VFIFO)
2433 *ap->a_retval = PIPE_BUF;
2437 case _PC_CHOWN_RESTRICTED:
2443 case _PC_ACL_EXTENDED:
2445 if (ap->a_vp->v_mount->mnt_flag & MNT_ACLS)
2456 if (ap->a_vp->v_mount->mnt_flag & MNT_NFS4ACLS)
2465 case _PC_ACL_PATH_MAX:
2467 if (ap->a_vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS))
2468 *ap->a_retval = ACL_MAX_ENTRIES;
2475 case _PC_MAC_PRESENT:
2477 if (ap->a_vp->v_mount->mnt_flag & MNT_MULTILABEL)
2485 case _PC_MIN_HOLE_SIZE:
2486 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2494 case _PC_ALLOC_SIZE_MIN:
2495 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_bsize;
2497 case _PC_FILESIZEBITS:
2500 case _PC_REC_INCR_XFER_SIZE:
2501 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2503 case _PC_REC_MAX_XFER_SIZE:
2504 *ap->a_retval = -1; /* means ``unlimited'' */
2506 case _PC_REC_MIN_XFER_SIZE:
2507 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2509 case _PC_REC_XFER_ALIGN:
2510 *ap->a_retval = PAGE_SIZE;
2512 case _PC_SYMLINK_MAX:
2513 *ap->a_retval = MAXPATHLEN;
2517 error = vop_stdpathconf(ap);
2524 * Initialize the vnode associated with a new inode, handle aliased
2528 ufs_vinit(mntp, fifoops, vpp)
2530 struct vop_vector *fifoops;
2538 vp->v_type = IFTOVT(ip->i_mode);
2539 if (vp->v_type == VFIFO)
2541 ASSERT_VOP_LOCKED(vp, "ufs_vinit");
2542 if (ip->i_number == UFS_ROOTINO)
2543 vp->v_vflag |= VV_ROOT;
2549 * Allocate a new inode.
2550 * Vnode dvp must be locked.
2553 ufs_makeinode(mode, dvp, vpp, cnp, callfunc)
2557 struct componentname *cnp;
2558 const char *callfunc;
2560 struct inode *ip, *pdir;
2561 struct direct newdir;
2567 if ((cnp->cn_flags & HASBUF) == 0)
2568 panic("%s: no name", callfunc);
2571 if ((mode & IFMT) == 0)
2574 if (pdir->i_effnlink < 2) {
2575 print_bad_link_count(callfunc, dvp);
2578 error = UFS_VALLOC(dvp, mode, cnp->cn_cred, &tvp);
2582 ip->i_gid = pdir->i_gid;
2583 DIP_SET(ip, i_gid, pdir->i_gid);
2587 struct ucred ucred, *ucp;
2592 * If we are not the owner of the directory,
2593 * and we are hacking owners here, (only do this where told to)
2594 * and we are not giving it TO root, (would subvert quotas)
2595 * then go ahead and give it to the other user.
2596 * Note that this drops off the execute bits for security.
2598 if ((dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
2599 (pdir->i_mode & ISUID) &&
2600 (pdir->i_uid != cnp->cn_cred->cr_uid) && pdir->i_uid) {
2601 ip->i_uid = pdir->i_uid;
2602 DIP_SET(ip, i_uid, ip->i_uid);
2606 * Make sure the correct user gets charged
2608 * Quickly knock up a dummy credential for the victim.
2609 * XXX This seems to never be accessed out of our
2610 * context so a stack variable is ok.
2612 refcount_init(&ucred.cr_ref, 1);
2613 ucred.cr_uid = ip->i_uid;
2614 ucred.cr_ngroups = 1;
2615 ucred.cr_groups = &ucred_group;
2616 ucred.cr_groups[0] = pdir->i_gid;
2620 ip->i_uid = cnp->cn_cred->cr_uid;
2621 DIP_SET(ip, i_uid, ip->i_uid);
2625 if ((error = getinoquota(ip)) ||
2626 (error = chkiq(ip, 1, ucp, 0))) {
2627 if (DOINGSOFTDEP(tvp))
2628 softdep_revert_link(pdir, ip);
2629 UFS_VFREE(tvp, ip->i_number, mode);
2635 #else /* !SUIDDIR */
2636 ip->i_uid = cnp->cn_cred->cr_uid;
2637 DIP_SET(ip, i_uid, ip->i_uid);
2639 if ((error = getinoquota(ip)) ||
2640 (error = chkiq(ip, 1, cnp->cn_cred, 0))) {
2641 if (DOINGSOFTDEP(tvp))
2642 softdep_revert_link(pdir, ip);
2643 UFS_VFREE(tvp, ip->i_number, mode);
2648 #endif /* !SUIDDIR */
2649 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
2651 DIP_SET(ip, i_mode, mode);
2652 tvp->v_type = IFTOVT(mode); /* Rest init'd in getnewvnode(). */
2655 DIP_SET(ip, i_nlink, 1);
2656 if (DOINGSOFTDEP(tvp))
2657 softdep_setup_create(VTOI(dvp), ip);
2658 if ((ip->i_mode & ISGID) && !groupmember(ip->i_gid, cnp->cn_cred) &&
2659 priv_check_cred(cnp->cn_cred, PRIV_VFS_SETGID, 0)) {
2660 ip->i_mode &= ~ISGID;
2661 DIP_SET(ip, i_mode, ip->i_mode);
2664 if (cnp->cn_flags & ISWHITEOUT) {
2665 ip->i_flags |= UF_OPAQUE;
2666 DIP_SET(ip, i_flags, ip->i_flags);
2670 * Make sure inode goes to disk before directory entry.
2672 error = UFS_UPDATE(tvp, !DOINGSOFTDEP(tvp) && !DOINGASYNC(tvp));
2676 if (dvp->v_mount->mnt_flag & MNT_MULTILABEL) {
2677 error = mac_vnode_create_extattr(cnp->cn_cred, dvp->v_mount,
2684 if (dvp->v_mount->mnt_flag & MNT_ACLS) {
2685 error = ufs_do_posix1e_acl_inheritance_file(dvp, tvp, mode,
2686 cnp->cn_cred, cnp->cn_thread);
2689 } else if (dvp->v_mount->mnt_flag & MNT_NFS4ACLS) {
2690 error = ufs_do_nfs4_acl_inheritance(dvp, tvp, mode,
2691 cnp->cn_cred, cnp->cn_thread);
2695 #endif /* !UFS_ACL */
2696 ufs_makedirentry(ip, cnp, &newdir);
2697 error = ufs_direnter(dvp, tvp, &newdir, cnp, NULL, 0);
2705 * Write error occurred trying to update the inode
2706 * or the directory so must deallocate the inode.
2710 DIP_SET(ip, i_nlink, 0);
2711 ip->i_flag |= IN_CHANGE;
2712 if (DOINGSOFTDEP(tvp))
2713 softdep_revert_create(VTOI(dvp), ip);
2719 ufs_ioctl(struct vop_ioctl_args *ap)
2722 switch (ap->a_command) {
2725 return (vn_bmap_seekhole(ap->a_vp, ap->a_command,
2726 (off_t *)ap->a_data, ap->a_cred));
2732 /* Global vfs data structures for ufs. */
2733 struct vop_vector ufs_vnodeops = {
2734 .vop_default = &default_vnodeops,
2735 .vop_fsync = VOP_PANIC,
2736 .vop_read = VOP_PANIC,
2737 .vop_reallocblks = VOP_PANIC,
2738 .vop_write = VOP_PANIC,
2739 .vop_accessx = ufs_accessx,
2740 .vop_bmap = ufs_bmap,
2741 .vop_cachedlookup = ufs_lookup,
2742 .vop_close = ufs_close,
2743 .vop_create = ufs_create,
2744 .vop_getattr = ufs_getattr,
2745 .vop_inactive = ufs_inactive,
2746 .vop_ioctl = ufs_ioctl,
2747 .vop_link = ufs_link,
2748 .vop_lookup = vfs_cache_lookup,
2749 .vop_markatime = ufs_markatime,
2750 .vop_mkdir = ufs_mkdir,
2751 .vop_mknod = ufs_mknod,
2752 .vop_open = ufs_open,
2753 .vop_pathconf = ufs_pathconf,
2754 .vop_poll = vop_stdpoll,
2755 .vop_print = ufs_print,
2756 .vop_readdir = ufs_readdir,
2757 .vop_readlink = ufs_readlink,
2758 .vop_reclaim = ufs_reclaim,
2759 .vop_remove = ufs_remove,
2760 .vop_rename = ufs_rename,
2761 .vop_rmdir = ufs_rmdir,
2762 .vop_setattr = ufs_setattr,
2764 .vop_setlabel = vop_stdsetlabel_ea,
2766 .vop_strategy = ufs_strategy,
2767 .vop_symlink = ufs_symlink,
2768 .vop_whiteout = ufs_whiteout,
2770 .vop_getextattr = ufs_getextattr,
2771 .vop_deleteextattr = ufs_deleteextattr,
2772 .vop_setextattr = ufs_setextattr,
2775 .vop_getacl = ufs_getacl,
2776 .vop_setacl = ufs_setacl,
2777 .vop_aclcheck = ufs_aclcheck,
2781 struct vop_vector ufs_fifoops = {
2782 .vop_default = &fifo_specops,
2783 .vop_fsync = VOP_PANIC,
2784 .vop_accessx = ufs_accessx,
2785 .vop_close = ufsfifo_close,
2786 .vop_getattr = ufs_getattr,
2787 .vop_inactive = ufs_inactive,
2788 .vop_kqfilter = ufsfifo_kqfilter,
2789 .vop_markatime = ufs_markatime,
2790 .vop_pathconf = ufs_pathconf,
2791 .vop_print = ufs_print,
2792 .vop_read = VOP_PANIC,
2793 .vop_reclaim = ufs_reclaim,
2794 .vop_setattr = ufs_setattr,
2796 .vop_setlabel = vop_stdsetlabel_ea,
2798 .vop_write = VOP_PANIC,
2800 .vop_getextattr = ufs_getextattr,
2801 .vop_deleteextattr = ufs_deleteextattr,
2802 .vop_setextattr = ufs_setextattr,
2805 .vop_getacl = ufs_getacl,
2806 .vop_setacl = ufs_setacl,
2807 .vop_aclcheck = ufs_aclcheck,