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_mmapped_t ufs_mmapped;
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 | CTLFLAG_MPSAFE, 0,
132 * A virgin directory (no blushing please).
134 static struct dirtemplate mastertemplate = {
135 0, 12, DT_DIR, 1, ".",
136 0, DIRBLKSIZ - 12, DT_DIR, 2, ".."
138 static struct odirtemplate omastertemplate = {
140 0, DIRBLKSIZ - 12, 2, ".."
144 ufs_itimes_locked(struct vnode *vp)
149 ASSERT_VI_LOCKED(vp, __func__);
154 if ((ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) == 0)
157 if ((vp->v_type == VBLK || vp->v_type == VCHR) && !DOINGSOFTDEP(vp))
158 UFS_INODE_SET_FLAG(ip, IN_LAZYMOD);
159 else if (((vp->v_mount->mnt_kern_flag &
160 (MNTK_SUSPENDED | MNTK_SUSPEND)) == 0) ||
161 (ip->i_flag & (IN_CHANGE | IN_UPDATE)))
162 UFS_INODE_SET_FLAG(ip, IN_MODIFIED);
163 else if (ip->i_flag & IN_ACCESS)
164 UFS_INODE_SET_FLAG(ip, IN_LAZYACCESS);
166 if (ip->i_flag & IN_ACCESS) {
167 DIP_SET(ip, i_atime, ts.tv_sec);
168 DIP_SET(ip, i_atimensec, ts.tv_nsec);
170 if (ip->i_flag & IN_UPDATE) {
171 DIP_SET(ip, i_mtime, ts.tv_sec);
172 DIP_SET(ip, i_mtimensec, ts.tv_nsec);
174 if (ip->i_flag & IN_CHANGE) {
175 DIP_SET(ip, i_ctime, ts.tv_sec);
176 DIP_SET(ip, i_ctimensec, ts.tv_nsec);
177 DIP_SET(ip, i_modrev, DIP(ip, i_modrev) + 1);
181 ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE);
185 ufs_itimes(struct vnode *vp)
189 ufs_itimes_locked(vp);
194 * Create a regular file
198 struct vop_create_args /* {
200 struct vnode **a_vpp;
201 struct componentname *a_cnp;
208 ufs_makeinode(MAKEIMODE(ap->a_vap->va_type, ap->a_vap->va_mode),
209 ap->a_dvp, ap->a_vpp, ap->a_cnp, "ufs_create");
212 if ((ap->a_cnp->cn_flags & MAKEENTRY) != 0)
213 cache_enter(ap->a_dvp, *ap->a_vpp, ap->a_cnp);
223 struct vop_mknod_args /* {
225 struct vnode **a_vpp;
226 struct componentname *a_cnp;
230 struct vattr *vap = ap->a_vap;
231 struct vnode **vpp = ap->a_vpp;
236 error = ufs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode),
237 ap->a_dvp, vpp, ap->a_cnp, "ufs_mknod");
241 UFS_INODE_SET_FLAG(ip, IN_ACCESS | IN_CHANGE | IN_UPDATE);
242 if (vap->va_rdev != VNOVAL) {
244 * Want to be able to use this to make badblock
245 * inodes, so don't truncate the dev number.
247 DIP_SET(ip, i_rdev, vap->va_rdev);
250 * Remove inode, then reload it through VFS_VGET so it is
251 * checked to see if it is an alias of an existing entry in
252 * the inode cache. XXX I don't believe this is necessary now.
254 (*vpp)->v_type = VNON;
255 ino = ip->i_number; /* Save this before vgone() invalidates ip. */
258 error = VFS_VGET(ap->a_dvp->v_mount, ino, LK_EXCLUSIVE, vpp);
271 ufs_open(struct vop_open_args *ap)
273 struct vnode *vp = ap->a_vp;
276 if (vp->v_type == VCHR || vp->v_type == VBLK)
281 * Files marked append-only must be opened for appending.
283 if ((ip->i_flags & APPEND) &&
284 (ap->a_mode & (FWRITE | O_APPEND)) == FWRITE)
286 vnode_create_vobject(vp, DIP(ip, i_size), ap->a_td);
293 * Update the times on the inode.
298 struct vop_close_args /* {
301 struct ucred *a_cred;
305 struct vnode *vp = ap->a_vp;
309 usecount = vp->v_usecount;
311 ufs_itimes_locked(vp);
318 struct vop_accessx_args /* {
321 struct ucred *a_cred;
325 struct vnode *vp = ap->a_vp;
326 struct inode *ip = VTOI(vp);
327 accmode_t accmode = ap->a_accmode;
335 * Disallow write attempts on read-only filesystems;
336 * unless the file is a socket, fifo, or a block or
337 * character device resident on the filesystem.
339 if (accmode & VMODIFY_PERMS) {
340 switch (vp->v_type) {
344 if (vp->v_mount->mnt_flag & MNT_RDONLY)
348 * Inode is accounted in the quotas only if struct
349 * dquot is attached to it. VOP_ACCESS() is called
350 * from vn_open_cred() and provides a convenient
351 * point to call getinoquota(). The lock mode is
352 * exclusive when the file is opening for write.
354 if (VOP_ISLOCKED(vp) == LK_EXCLUSIVE) {
355 error = getinoquota(ip);
367 * If immutable bit set, nobody gets to write it. "& ~VADMIN_PERMS"
368 * permits the owner of the file to remove the IMMUTABLE flag.
370 if ((accmode & (VMODIFY_PERMS & ~VADMIN_PERMS)) &&
371 (ip->i_flags & (IMMUTABLE | SF_SNAPSHOT)))
375 if ((vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS)) != 0) {
376 if (vp->v_mount->mnt_flag & MNT_NFS4ACLS)
377 type = ACL_TYPE_NFS4;
379 type = ACL_TYPE_ACCESS;
381 acl = acl_alloc(M_WAITOK);
382 if (type == ACL_TYPE_NFS4)
383 error = ufs_getacl_nfs4_internal(vp, acl, ap->a_td);
385 error = VOP_GETACL(vp, type, acl, ap->a_cred, ap->a_td);
388 if (type == ACL_TYPE_NFS4) {
389 error = vaccess_acl_nfs4(vp->v_type, ip->i_uid,
390 ip->i_gid, acl, accmode, ap->a_cred, NULL);
392 error = vfs_unixify_accmode(&accmode);
394 error = vaccess_acl_posix1e(vp->v_type, ip->i_uid,
395 ip->i_gid, acl, accmode, ap->a_cred, NULL);
399 if (error != EOPNOTSUPP)
401 "ufs_accessx(): Error retrieving ACL on object (%d).\n",
404 * XXX: Fall back until debugged. Should
405 * eventually possibly log an error, and return
408 error = vfs_unixify_accmode(&accmode);
410 error = vaccess(vp->v_type, ip->i_mode, ip->i_uid,
411 ip->i_gid, accmode, ap->a_cred, NULL);
417 #endif /* !UFS_ACL */
418 error = vfs_unixify_accmode(&accmode);
420 error = vaccess(vp->v_type, ip->i_mode, ip->i_uid, ip->i_gid,
421 accmode, ap->a_cred, NULL);
428 struct vop_getattr_args /* {
431 struct ucred *a_cred;
434 struct vnode *vp = ap->a_vp;
435 struct inode *ip = VTOI(vp);
436 struct vattr *vap = ap->a_vap;
439 ufs_itimes_locked(vp);
441 vap->va_atime.tv_sec = ip->i_din1->di_atime;
442 vap->va_atime.tv_nsec = ip->i_din1->di_atimensec;
444 vap->va_atime.tv_sec = ip->i_din2->di_atime;
445 vap->va_atime.tv_nsec = ip->i_din2->di_atimensec;
449 * Copy from inode table
451 vap->va_fsid = dev2udev(ITOUMP(ip)->um_dev);
452 vap->va_fileid = ip->i_number;
453 vap->va_mode = ip->i_mode & ~IFMT;
454 vap->va_nlink = ip->i_effnlink;
455 vap->va_uid = ip->i_uid;
456 vap->va_gid = ip->i_gid;
458 vap->va_rdev = ip->i_din1->di_rdev;
459 vap->va_size = ip->i_din1->di_size;
460 vap->va_mtime.tv_sec = ip->i_din1->di_mtime;
461 vap->va_mtime.tv_nsec = ip->i_din1->di_mtimensec;
462 vap->va_ctime.tv_sec = ip->i_din1->di_ctime;
463 vap->va_ctime.tv_nsec = ip->i_din1->di_ctimensec;
464 vap->va_bytes = dbtob((u_quad_t)ip->i_din1->di_blocks);
465 vap->va_filerev = ip->i_din1->di_modrev;
467 vap->va_rdev = ip->i_din2->di_rdev;
468 vap->va_size = ip->i_din2->di_size;
469 vap->va_mtime.tv_sec = ip->i_din2->di_mtime;
470 vap->va_mtime.tv_nsec = ip->i_din2->di_mtimensec;
471 vap->va_ctime.tv_sec = ip->i_din2->di_ctime;
472 vap->va_ctime.tv_nsec = ip->i_din2->di_ctimensec;
473 vap->va_birthtime.tv_sec = ip->i_din2->di_birthtime;
474 vap->va_birthtime.tv_nsec = ip->i_din2->di_birthnsec;
475 vap->va_bytes = dbtob((u_quad_t)ip->i_din2->di_blocks);
476 vap->va_filerev = ip->i_din2->di_modrev;
478 vap->va_flags = ip->i_flags;
479 vap->va_gen = ip->i_gen;
480 vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
481 vap->va_type = IFTOVT(ip->i_mode);
486 * Set attribute vnode op. called from several syscalls
490 struct vop_setattr_args /* {
493 struct ucred *a_cred;
496 struct vattr *vap = ap->a_vap;
497 struct vnode *vp = ap->a_vp;
498 struct inode *ip = VTOI(vp);
499 struct ucred *cred = ap->a_cred;
500 struct thread *td = curthread;
504 * Check for unsettable attributes.
506 if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
507 (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
508 (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
509 ((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
512 if (vap->va_flags != VNOVAL) {
513 if ((vap->va_flags & ~(SF_APPEND | SF_ARCHIVED | SF_IMMUTABLE |
514 SF_NOUNLINK | SF_SNAPSHOT | UF_APPEND | UF_ARCHIVE |
515 UF_HIDDEN | UF_IMMUTABLE | UF_NODUMP | UF_NOUNLINK |
516 UF_OFFLINE | UF_OPAQUE | UF_READONLY | UF_REPARSE |
517 UF_SPARSE | UF_SYSTEM)) != 0)
519 if (vp->v_mount->mnt_flag & MNT_RDONLY)
522 * Callers may only modify the file flags on objects they
523 * have VADMIN rights for.
525 if ((error = VOP_ACCESS(vp, VADMIN, cred, td)))
528 * Unprivileged processes are not permitted to unset system
529 * flags, or modify flags if any system flags are set.
530 * Privileged non-jail processes may not modify system flags
531 * if securelevel > 0 and any existing system flags are set.
532 * Privileged jail processes behave like privileged non-jail
533 * processes if the PR_ALLOW_CHFLAGS permission bit is set;
534 * otherwise, they behave like unprivileged processes.
536 if (!priv_check_cred(cred, PRIV_VFS_SYSFLAGS)) {
538 (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND)) {
539 error = securelevel_gt(cred, 0);
543 /* The snapshot flag cannot be toggled. */
544 if ((vap->va_flags ^ ip->i_flags) & SF_SNAPSHOT)
548 (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND) ||
549 ((vap->va_flags ^ ip->i_flags) & SF_SETTABLE))
552 ip->i_flags = vap->va_flags;
553 DIP_SET(ip, i_flags, vap->va_flags);
554 UFS_INODE_SET_FLAG(ip, IN_CHANGE);
555 error = UFS_UPDATE(vp, 0);
556 if (ip->i_flags & (IMMUTABLE | APPEND))
560 * If immutable or append, no one can change any of its attributes
561 * except the ones already handled (in some cases, file flags
562 * including the immutability flags themselves for the superuser).
564 if (ip->i_flags & (IMMUTABLE | APPEND))
567 * Go through the fields and update iff not VNOVAL.
569 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
570 if (vp->v_mount->mnt_flag & MNT_RDONLY)
572 if ((error = ufs_chown(vp, vap->va_uid, vap->va_gid, cred,
576 if (vap->va_size != VNOVAL) {
578 * XXX most of the following special cases should be in
579 * callers instead of in N filesystems. The VDIR check
582 switch (vp->v_type) {
588 * Truncation should have an effect in these cases.
589 * Disallow it if the filesystem is read-only or
590 * the file is being snapshotted.
592 if (vp->v_mount->mnt_flag & MNT_RDONLY)
594 if ((ip->i_flags & SF_SNAPSHOT) != 0)
599 * According to POSIX, the result is unspecified
600 * for file types other than regular files,
601 * directories and shared memory objects. We
602 * don't support shared memory objects in the file
603 * system, and have dubious support for truncating
604 * symlinks. Just ignore the request in other cases.
608 if ((error = UFS_TRUNCATE(vp, vap->va_size, IO_NORMAL |
609 ((vap->va_vaflags & VA_SYNC) != 0 ? IO_SYNC : 0),
613 if (vap->va_atime.tv_sec != VNOVAL ||
614 vap->va_mtime.tv_sec != VNOVAL ||
615 vap->va_birthtime.tv_sec != VNOVAL) {
616 if (vp->v_mount->mnt_flag & MNT_RDONLY)
618 if ((ip->i_flags & SF_SNAPSHOT) != 0)
620 error = vn_utimes_perm(vp, vap, cred, td);
623 UFS_INODE_SET_FLAG(ip, IN_CHANGE | IN_MODIFIED);
624 if (vap->va_atime.tv_sec != VNOVAL) {
625 ip->i_flag &= ~IN_ACCESS;
626 DIP_SET(ip, i_atime, vap->va_atime.tv_sec);
627 DIP_SET(ip, i_atimensec, vap->va_atime.tv_nsec);
629 if (vap->va_mtime.tv_sec != VNOVAL) {
630 ip->i_flag &= ~IN_UPDATE;
631 DIP_SET(ip, i_mtime, vap->va_mtime.tv_sec);
632 DIP_SET(ip, i_mtimensec, vap->va_mtime.tv_nsec);
634 if (vap->va_birthtime.tv_sec != VNOVAL && I_IS_UFS2(ip)) {
635 ip->i_din2->di_birthtime = vap->va_birthtime.tv_sec;
636 ip->i_din2->di_birthnsec = vap->va_birthtime.tv_nsec;
638 error = UFS_UPDATE(vp, 0);
643 if (vap->va_mode != (mode_t)VNOVAL) {
644 if (vp->v_mount->mnt_flag & MNT_RDONLY)
646 if ((ip->i_flags & SF_SNAPSHOT) != 0 && (vap->va_mode &
647 (S_IXUSR | S_IWUSR | S_IXGRP | S_IWGRP | S_IXOTH | S_IWOTH)))
649 error = ufs_chmod(vp, (int)vap->va_mode, cred, td);
656 ufs_update_nfs4_acl_after_mode_change(struct vnode *vp, int mode,
657 int file_owner_id, struct ucred *cred, struct thread *td)
662 aclp = acl_alloc(M_WAITOK);
663 error = ufs_getacl_nfs4_internal(vp, aclp, td);
665 * We don't have to handle EOPNOTSUPP here, as the filesystem claims
671 acl_nfs4_sync_acl_from_mode(aclp, mode, file_owner_id);
672 error = ufs_setacl_nfs4_internal(vp, aclp, td);
682 struct vop_mmapped_args /* {
694 if ((mp->mnt_flag & (MNT_NOATIME | MNT_RDONLY)) == 0)
695 UFS_INODE_SET_FLAG_SHARED(ip, IN_ACCESS);
697 * XXXKIB No UFS_UPDATE(ap->a_vp, 0) there.
703 * Change the mode on a file.
704 * Inode must be locked before calling.
707 ufs_chmod(vp, mode, cred, td)
713 struct inode *ip = VTOI(vp);
717 * To modify the permissions on a file, must possess VADMIN
720 if ((error = VOP_ACCESSX(vp, VWRITE_ACL, cred, td)))
723 * Privileged processes may set the sticky bit on non-directories,
724 * as well as set the setgid bit on a file with a group that the
725 * process is not a member of. Both of these are allowed in
728 if (vp->v_type != VDIR && (mode & S_ISTXT)) {
729 if (priv_check_cred(cred, PRIV_VFS_STICKYFILE))
732 if (!groupmember(ip->i_gid, cred) && (mode & ISGID)) {
733 error = priv_check_cred(cred, PRIV_VFS_SETGID);
739 * Deny setting setuid if we are not the file owner.
741 if ((mode & ISUID) && ip->i_uid != cred->cr_uid) {
742 error = priv_check_cred(cred, PRIV_VFS_ADMIN);
747 ip->i_mode &= ~ALLPERMS;
748 ip->i_mode |= (mode & ALLPERMS);
749 DIP_SET(ip, i_mode, ip->i_mode);
750 UFS_INODE_SET_FLAG(ip, IN_CHANGE);
752 if ((vp->v_mount->mnt_flag & MNT_NFS4ACLS) != 0)
753 error = ufs_update_nfs4_acl_after_mode_change(vp, mode, ip->i_uid, cred, td);
755 if (error == 0 && (ip->i_flag & IN_CHANGE) != 0)
756 error = UFS_UPDATE(vp, 0);
762 * Perform chown operation on inode ip;
763 * inode must be locked prior to call.
766 ufs_chown(vp, uid, gid, cred, td)
773 struct inode *ip = VTOI(vp);
782 if (uid == (uid_t)VNOVAL)
784 if (gid == (gid_t)VNOVAL)
787 * To modify the ownership of a file, must possess VADMIN for that
790 if ((error = VOP_ACCESSX(vp, VWRITE_OWNER, cred, td)))
793 * To change the owner of a file, or change the group of a file to a
794 * group of which we are not a member, the caller must have
797 if (((uid != ip->i_uid && uid != cred->cr_uid) ||
798 (gid != ip->i_gid && !groupmember(gid, cred))) &&
799 (error = priv_check_cred(cred, PRIV_VFS_CHOWN)))
804 if ((error = getinoquota(ip)) != 0)
807 dqrele(vp, ip->i_dquot[USRQUOTA]);
808 ip->i_dquot[USRQUOTA] = NODQUOT;
811 dqrele(vp, ip->i_dquot[GRPQUOTA]);
812 ip->i_dquot[GRPQUOTA] = NODQUOT;
814 change = DIP(ip, i_blocks);
815 (void) chkdq(ip, -change, cred, CHOWN|FORCE);
816 (void) chkiq(ip, -1, cred, CHOWN|FORCE);
817 for (i = 0; i < MAXQUOTAS; i++) {
818 dqrele(vp, ip->i_dquot[i]);
819 ip->i_dquot[i] = NODQUOT;
823 DIP_SET(ip, i_gid, gid);
825 DIP_SET(ip, i_uid, uid);
827 if ((error = getinoquota(ip)) == 0) {
829 dqrele(vp, ip->i_dquot[USRQUOTA]);
830 ip->i_dquot[USRQUOTA] = NODQUOT;
833 dqrele(vp, ip->i_dquot[GRPQUOTA]);
834 ip->i_dquot[GRPQUOTA] = NODQUOT;
836 if ((error = chkdq(ip, change, cred, CHOWN)) == 0) {
837 if ((error = chkiq(ip, 1, cred, CHOWN)) == 0)
840 (void) chkdq(ip, -change, cred, CHOWN|FORCE);
842 for (i = 0; i < MAXQUOTAS; i++) {
843 dqrele(vp, ip->i_dquot[i]);
844 ip->i_dquot[i] = NODQUOT;
848 DIP_SET(ip, i_gid, ogid);
850 DIP_SET(ip, i_uid, ouid);
851 if (getinoquota(ip) == 0) {
853 dqrele(vp, ip->i_dquot[USRQUOTA]);
854 ip->i_dquot[USRQUOTA] = NODQUOT;
857 dqrele(vp, ip->i_dquot[GRPQUOTA]);
858 ip->i_dquot[GRPQUOTA] = NODQUOT;
860 (void) chkdq(ip, change, cred, FORCE|CHOWN);
861 (void) chkiq(ip, 1, cred, FORCE|CHOWN);
862 (void) getinoquota(ip);
867 panic("ufs_chown: lost quota");
869 UFS_INODE_SET_FLAG(ip, IN_CHANGE);
870 if ((ip->i_mode & (ISUID | ISGID)) && (ouid != uid || ogid != gid)) {
871 if (priv_check_cred(cred, PRIV_VFS_RETAINSUGID)) {
872 ip->i_mode &= ~(ISUID | ISGID);
873 DIP_SET(ip, i_mode, ip->i_mode);
876 error = UFS_UPDATE(vp, 0);
882 struct vop_remove_args /* {
885 struct componentname *a_cnp;
889 struct vnode *vp = ap->a_vp;
890 struct vnode *dvp = ap->a_dvp;
896 if ((ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
897 (VTOI(dvp)->i_flags & APPEND)) {
902 ufs_gjournal_orphan(vp);
904 error = ufs_dirremove(dvp, ip, ap->a_cnp->cn_flags, 0);
905 if (ip->i_nlink <= 0)
906 vp->v_vflag |= VV_NOSYNC;
907 if ((ip->i_flags & SF_SNAPSHOT) != 0) {
909 * Avoid deadlock where another thread is trying to
910 * update the inodeblock for dvp and is waiting on
911 * snaplk. Temporary unlock the vnode lock for the
912 * unlinked file and sync the directory. This should
913 * allow vput() of the directory to not block later on
914 * while holding the snapshot vnode locked, assuming
915 * that the directory hasn't been unlinked too.
918 (void) VOP_FSYNC(dvp, MNT_WAIT, td);
919 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
926 print_bad_link_count(const char *funcname, struct vnode *dvp)
931 uprintf("%s: Bad link count %d on parent inode %jd in file system %s\n",
932 funcname, dip->i_effnlink, (intmax_t)dip->i_number,
933 dvp->v_mount->mnt_stat.f_mntonname);
941 struct vop_link_args /* {
942 struct vnode *a_tdvp;
944 struct componentname *a_cnp;
947 struct vnode *vp = ap->a_vp;
948 struct vnode *tdvp = ap->a_tdvp;
949 struct componentname *cnp = ap->a_cnp;
951 struct direct newdir;
955 if ((cnp->cn_flags & HASBUF) == 0)
956 panic("ufs_link: no name");
958 if (VTOI(tdvp)->i_effnlink < 2) {
959 print_bad_link_count("ufs_link", tdvp);
964 if (ip->i_nlink >= UFS_LINK_MAX) {
969 * The file may have been removed after namei droped the original
972 if (ip->i_effnlink == 0) {
976 if (ip->i_flags & (IMMUTABLE | APPEND)) {
982 DIP_SET(ip, i_nlink, ip->i_nlink);
983 UFS_INODE_SET_FLAG(ip, IN_CHANGE);
984 if (DOINGSOFTDEP(vp))
985 softdep_setup_link(VTOI(tdvp), ip);
986 error = UFS_UPDATE(vp, !DOINGSOFTDEP(vp) && !DOINGASYNC(vp));
988 ufs_makedirentry(ip, cnp, &newdir);
989 error = ufs_direnter(tdvp, vp, &newdir, cnp, NULL, 0);
995 DIP_SET(ip, i_nlink, ip->i_nlink);
996 UFS_INODE_SET_FLAG(ip, IN_CHANGE);
997 if (DOINGSOFTDEP(vp))
998 softdep_revert_link(VTOI(tdvp), ip);
1005 * whiteout vnode call
1009 struct vop_whiteout_args /* {
1010 struct vnode *a_dvp;
1011 struct componentname *a_cnp;
1015 struct vnode *dvp = ap->a_dvp;
1016 struct componentname *cnp = ap->a_cnp;
1017 struct direct newdir;
1020 switch (ap->a_flags) {
1022 /* 4.4 format directories support whiteout operations */
1023 if (dvp->v_mount->mnt_maxsymlinklen > 0)
1025 return (EOPNOTSUPP);
1028 /* create a new directory whiteout */
1030 if ((cnp->cn_flags & SAVENAME) == 0)
1031 panic("ufs_whiteout: missing name");
1032 if (dvp->v_mount->mnt_maxsymlinklen <= 0)
1033 panic("ufs_whiteout: old format filesystem");
1036 newdir.d_ino = UFS_WINO;
1037 newdir.d_namlen = cnp->cn_namelen;
1038 bcopy(cnp->cn_nameptr, newdir.d_name, (unsigned)cnp->cn_namelen + 1);
1039 newdir.d_type = DT_WHT;
1040 error = ufs_direnter(dvp, NULL, &newdir, cnp, NULL, 0);
1044 /* remove an existing directory whiteout */
1046 if (dvp->v_mount->mnt_maxsymlinklen <= 0)
1047 panic("ufs_whiteout: old format filesystem");
1050 cnp->cn_flags &= ~DOWHITEOUT;
1051 error = ufs_dirremove(dvp, NULL, cnp->cn_flags, 0);
1054 panic("ufs_whiteout: unknown op");
1059 static volatile int rename_restarts;
1060 SYSCTL_INT(_vfs_ufs, OID_AUTO, rename_restarts, CTLFLAG_RD,
1061 __DEVOLATILE(int *, &rename_restarts), 0,
1062 "Times rename had to restart due to lock contention");
1065 * Rename system call.
1066 * rename("foo", "bar");
1069 * link("foo", "bar");
1071 * but ``atomically''. Can't do full commit without saving state in the
1072 * inode on disk which isn't feasible at this time. Best we can do is
1073 * always guarantee the target exists.
1075 * Basic algorithm is:
1077 * 1) Bump link count on source while we're linking it to the
1078 * target. This also ensure the inode won't be deleted out
1079 * from underneath us while we work (it may be truncated by
1080 * a concurrent `trunc' or `open' for creation).
1081 * 2) Link source to destination. If destination already exists,
1083 * 3) Unlink source reference to inode if still around. If a
1084 * directory was moved and the parent of the destination
1085 * is different from the source, patch the ".." entry in the
1090 struct vop_rename_args /* {
1091 struct vnode *a_fdvp;
1092 struct vnode *a_fvp;
1093 struct componentname *a_fcnp;
1094 struct vnode *a_tdvp;
1095 struct vnode *a_tvp;
1096 struct componentname *a_tcnp;
1099 struct vnode *tvp = ap->a_tvp;
1100 struct vnode *tdvp = ap->a_tdvp;
1101 struct vnode *fvp = ap->a_fvp;
1102 struct vnode *fdvp = ap->a_fdvp;
1104 struct componentname *tcnp = ap->a_tcnp;
1105 struct componentname *fcnp = ap->a_fcnp;
1106 struct thread *td = fcnp->cn_thread;
1107 struct inode *fip, *tip, *tdp, *fdp;
1108 struct direct newdir;
1110 int doingdirectory, newparent;
1116 if ((tcnp->cn_flags & HASBUF) == 0 ||
1117 (fcnp->cn_flags & HASBUF) == 0)
1118 panic("ufs_rename: no name");
1123 if (tvp && tvp != tdvp)
1126 * Check for cross-device rename.
1128 if ((fvp->v_mount != tdvp->v_mount) ||
1129 (tvp && (fvp->v_mount != tvp->v_mount))) {
1136 * We need to acquire 2 to 4 locks depending on whether tvp is NULL
1137 * and fdvp and tdvp are the same directory. Subsequently we need
1138 * to double-check all paths and in the directory rename case we
1139 * need to verify that we are not creating a directory loop. To
1140 * handle this we acquire all but fdvp using non-blocking
1141 * acquisitions. If we fail to acquire any lock in the path we will
1142 * drop all held locks, acquire the new lock in a blocking fashion,
1143 * and then release it and restart the rename. This acquire/release
1144 * step ensures that we do not spin on a lock waiting for release.
1146 error = vn_lock(fdvp, LK_EXCLUSIVE);
1149 if (vn_lock(tdvp, LK_EXCLUSIVE | LK_NOWAIT) != 0) {
1151 error = vn_lock(tdvp, LK_EXCLUSIVE);
1155 atomic_add_int(&rename_restarts, 1);
1159 * Re-resolve fvp to be certain it still exists and fetch the
1162 error = ufs_lookup_ino(fdvp, NULL, fcnp, &ino);
1168 error = VFS_VGET(mp, ino, LK_EXCLUSIVE | LK_NOWAIT, &nvp);
1174 error = VFS_VGET(mp, ino, LK_EXCLUSIVE, &nvp);
1180 atomic_add_int(&rename_restarts, 1);
1186 * Re-resolve tvp and acquire the vnode lock if present.
1188 error = ufs_lookup_ino(tdvp, NULL, tcnp, &ino);
1189 if (error != 0 && error != EJUSTRETURN) {
1196 * If tvp disappeared we just carry on.
1198 if (error == EJUSTRETURN && tvp != NULL) {
1203 * Get the tvp ino if the lookup succeeded. We may have to restart
1204 * if the non-blocking acquire fails.
1208 error = VFS_VGET(mp, ino, LK_EXCLUSIVE | LK_NOWAIT, &nvp);
1218 error = VFS_VGET(mp, ino, LK_EXCLUSIVE, &nvp);
1222 atomic_add_int(&rename_restarts, 1);
1232 if (tvp && ((VTOI(tvp)->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
1233 (VTOI(tdvp)->i_flags & APPEND))) {
1238 * Renaming a file to itself has no effect. The upper layers should
1239 * not call us in that case. However, things could change after
1240 * we drop the locks above.
1248 ino = fip->i_number;
1249 if (fip->i_nlink >= UFS_LINK_MAX) {
1253 if ((fip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))
1254 || (fdp->i_flags & APPEND)) {
1258 if ((fip->i_mode & IFMT) == IFDIR) {
1260 * Avoid ".", "..", and aliases of "." for obvious reasons.
1262 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
1264 (fcnp->cn_flags | tcnp->cn_flags) & ISDOTDOT) {
1268 if (fdp->i_number != tdp->i_number)
1269 newparent = tdp->i_number;
1272 if ((fvp->v_type == VDIR && fvp->v_mountedhere != NULL) ||
1273 (tvp != NULL && tvp->v_type == VDIR &&
1274 tvp->v_mountedhere != NULL)) {
1280 * If ".." must be changed (ie the directory gets a new
1281 * parent) then the source directory must not be in the
1282 * directory hierarchy above the target, as this would
1283 * orphan everything below the source directory. Also
1284 * the user must have write permission in the source so
1285 * as to be able to change "..".
1287 if (doingdirectory && newparent) {
1288 error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_thread);
1291 error = ufs_checkpath(ino, fdp->i_number, tdp, tcnp->cn_cred,
1294 * We encountered a lock that we have to wait for. Unlock
1295 * everything else and VGET before restarting.
1303 error = VFS_VGET(mp, ino, LK_SHARED, &nvp);
1306 atomic_add_int(&rename_restarts, 1);
1311 if ((tcnp->cn_flags & SAVESTART) == 0)
1312 panic("ufs_rename: lost to startdir");
1314 if (fip->i_effnlink == 0 || fdp->i_effnlink == 0 ||
1315 tdp->i_effnlink == 0)
1316 panic("Bad effnlink fip %p, fdp %p, tdp %p", fip, fdp, tdp);
1319 * 1) Bump link count while we're moving stuff
1320 * around. If we crash somewhere before
1321 * completing our work, the link count
1322 * may be wrong, but correctable.
1326 DIP_SET(fip, i_nlink, fip->i_nlink);
1327 UFS_INODE_SET_FLAG(fip, IN_CHANGE);
1328 if (DOINGSOFTDEP(fvp))
1329 softdep_setup_link(tdp, fip);
1330 error = UFS_UPDATE(fvp, !DOINGSOFTDEP(fvp) && !DOINGASYNC(fvp));
1335 * 2) If target doesn't exist, link the target
1336 * to the source and unlink the source.
1337 * Otherwise, rewrite the target directory
1338 * entry to reference the source inode and
1339 * expunge the original entry's existence.
1342 if (ITODEV(tdp) != ITODEV(fip))
1343 panic("ufs_rename: EXDEV");
1344 if (doingdirectory && newparent) {
1346 * Account for ".." in new directory.
1347 * When source and destination have the same
1348 * parent we don't adjust the link count. The
1349 * actual link modification is completed when
1350 * .. is rewritten below.
1352 if (tdp->i_nlink >= UFS_LINK_MAX) {
1357 ufs_makedirentry(fip, tcnp, &newdir);
1358 error = ufs_direnter(tdvp, NULL, &newdir, tcnp, NULL, 1);
1361 /* Setup tdvp for directory compaction if needed. */
1362 if (tdp->i_count && tdp->i_endoff &&
1363 tdp->i_endoff < tdp->i_size)
1364 endoff = tdp->i_endoff;
1366 if (ITODEV(tip) != ITODEV(tdp) || ITODEV(tip) != ITODEV(fip))
1367 panic("ufs_rename: EXDEV");
1369 * Short circuit rename(foo, foo).
1371 if (tip->i_number == fip->i_number)
1372 panic("ufs_rename: same file");
1374 * If the parent directory is "sticky", then the caller
1375 * must possess VADMIN for the parent directory, or the
1376 * destination of the rename. This implements append-only
1379 if ((tdp->i_mode & S_ISTXT) &&
1380 VOP_ACCESS(tdvp, VADMIN, tcnp->cn_cred, td) &&
1381 VOP_ACCESS(tvp, VADMIN, tcnp->cn_cred, td)) {
1386 * Target must be empty if a directory and have no links
1387 * to it. Also, ensure source and target are compatible
1388 * (both directories, or both not directories).
1390 if ((tip->i_mode & IFMT) == IFDIR) {
1391 if ((tip->i_effnlink > 2) ||
1392 !ufs_dirempty(tip, tdp->i_number, tcnp->cn_cred)) {
1396 if (!doingdirectory) {
1401 } else if (doingdirectory) {
1405 if (doingdirectory) {
1408 if (DOINGSOFTDEP(tdvp))
1409 softdep_change_linkcnt(tdp);
1412 if (DOINGSOFTDEP(tvp))
1413 softdep_change_linkcnt(tip);
1415 error = ufs_dirrewrite(tdp, tip, fip->i_number,
1416 IFTODT(fip->i_mode),
1417 (doingdirectory && newparent) ? newparent : doingdirectory);
1419 if (doingdirectory) {
1422 if (DOINGSOFTDEP(tdvp))
1423 softdep_change_linkcnt(tdp);
1426 if (DOINGSOFTDEP(tvp))
1427 softdep_change_linkcnt(tip);
1430 if (doingdirectory && !DOINGSOFTDEP(tvp)) {
1432 * The only stuff left in the directory is "."
1433 * and "..". The "." reference is inconsequential
1434 * since we are quashing it. We have removed the "."
1435 * reference and the reference in the parent directory,
1436 * but there may be other hard links. The soft
1437 * dependency code will arrange to do these operations
1438 * after the parent directory entry has been deleted on
1439 * disk, so when running with that code we avoid doing
1444 DIP_SET(tdp, i_nlink, tdp->i_nlink);
1445 UFS_INODE_SET_FLAG(tdp, IN_CHANGE);
1448 DIP_SET(tip, i_nlink, tip->i_nlink);
1449 UFS_INODE_SET_FLAG(tip, IN_CHANGE);
1454 * 3) Unlink the source. We have to resolve the path again to
1455 * fixup the directory offset and count for ufs_dirremove.
1458 error = ufs_lookup_ino(fdvp, NULL, fcnp, &ino);
1460 panic("ufs_rename: from entry went away!");
1461 if (ino != fip->i_number)
1462 panic("ufs_rename: ino mismatch %ju != %ju\n",
1463 (uintmax_t)ino, (uintmax_t)fip->i_number);
1466 * If the source is a directory with a
1467 * new parent, the link count of the old
1468 * parent directory must be decremented
1469 * and ".." set to point to the new parent.
1471 if (doingdirectory && newparent) {
1473 * If tip exists we simply use its link, otherwise we must
1479 DIP_SET(tdp, i_nlink, tdp->i_nlink);
1480 UFS_INODE_SET_FLAG(tdp, IN_CHANGE);
1481 if (DOINGSOFTDEP(tdvp))
1482 softdep_setup_dotdot_link(tdp, fip);
1483 error = UFS_UPDATE(tdvp, !DOINGSOFTDEP(tdvp) &&
1485 /* Don't go to bad here as the new link exists. */
1488 } else if (DOINGSUJ(tdvp))
1489 /* Journal must account for each new link. */
1490 softdep_setup_dotdot_link(tdp, fip);
1491 fip->i_offset = mastertemplate.dot_reclen;
1492 ufs_dirrewrite(fip, fdp, newparent, DT_DIR, 0);
1495 error = ufs_dirremove(fdvp, fip, fcnp->cn_flags, 0);
1497 * The kern_renameat() looks up the fvp using the DELETE flag, which
1498 * causes the removal of the name cache entry for fvp.
1499 * As the relookup of the fvp is done in two steps:
1500 * ufs_lookup_ino() and then VFS_VGET(), another thread might do a
1501 * normal lookup of the from name just before the VFS_VGET() call,
1502 * causing the cache entry to be re-instantiated.
1504 * The same issue also applies to tvp if it exists as
1505 * otherwise we may have a stale name cache entry for the new
1506 * name that references the old i-node if it has other links
1507 * or open file descriptors.
1512 cache_purge_negative(tdvp);
1520 * If compaction or fsync was requested do it now that other locks
1521 * are no longer needed.
1523 if (error == 0 && endoff != 0) {
1524 error = UFS_TRUNCATE(tdvp, endoff, IO_NORMAL |
1525 (DOINGASYNC(tdvp) ? 0 : IO_SYNC), tcnp->cn_cred);
1528 "ufs_rename: failed to truncate, error %d\n",
1531 else if (tdp->i_dirhash != NULL)
1532 ufsdirhash_dirtrunc(tdp, endoff);
1535 * Even if the directory compaction failed, rename was
1536 * succesful. Do not propagate a UFS_TRUNCATE() error
1541 if (error == 0 && tdp->i_flag & IN_NEEDSYNC)
1542 error = VOP_FSYNC(tdvp, MNT_WAIT, td);
1549 DIP_SET(fip, i_nlink, fip->i_nlink);
1550 UFS_INODE_SET_FLAG(fip, IN_CHANGE);
1551 if (DOINGSOFTDEP(fvp))
1552 softdep_revert_link(tdp, fip);
1567 ufs_do_posix1e_acl_inheritance_dir(struct vnode *dvp, struct vnode *tvp,
1568 mode_t dmode, struct ucred *cred, struct thread *td)
1571 struct inode *ip = VTOI(tvp);
1572 struct acl *dacl, *acl;
1574 acl = acl_alloc(M_WAITOK);
1575 dacl = acl_alloc(M_WAITOK);
1578 * Retrieve default ACL from parent, if any.
1580 error = VOP_GETACL(dvp, ACL_TYPE_DEFAULT, acl, cred, td);
1584 * Retrieved a default ACL, so merge mode and ACL if
1585 * necessary. If the ACL is empty, fall through to
1586 * the "not defined or available" case.
1588 if (acl->acl_cnt != 0) {
1589 dmode = acl_posix1e_newfilemode(dmode, acl);
1591 DIP_SET(ip, i_mode, dmode);
1593 ufs_sync_acl_from_inode(ip, acl);
1600 * Just use the mode as-is.
1603 DIP_SET(ip, i_mode, dmode);
1612 * XXX: If we abort now, will Soft Updates notify the extattr
1613 * code that the EAs for the file need to be released?
1615 error = VOP_SETACL(tvp, ACL_TYPE_ACCESS, acl, cred, td);
1617 error = VOP_SETACL(tvp, ACL_TYPE_DEFAULT, dacl, cred, td);
1624 * XXX: This should not happen, as EOPNOTSUPP above
1625 * was supposed to free acl.
1627 printf("ufs_mkdir: VOP_GETACL() but no VOP_SETACL()\n");
1629 panic("ufs_mkdir: VOP_GETACL() but no VOP_SETACL()");
1645 ufs_do_posix1e_acl_inheritance_file(struct vnode *dvp, struct vnode *tvp,
1646 mode_t mode, struct ucred *cred, struct thread *td)
1649 struct inode *ip = VTOI(tvp);
1652 acl = acl_alloc(M_WAITOK);
1655 * Retrieve default ACL for parent, if any.
1657 error = VOP_GETACL(dvp, ACL_TYPE_DEFAULT, acl, cred, td);
1661 * Retrieved a default ACL, so merge mode and ACL if
1664 if (acl->acl_cnt != 0) {
1666 * Two possible ways for default ACL to not
1667 * be present. First, the EA can be
1668 * undefined, or second, the default ACL can
1669 * be blank. If it's blank, fall through to
1670 * the it's not defined case.
1672 mode = acl_posix1e_newfilemode(mode, acl);
1674 DIP_SET(ip, i_mode, mode);
1675 ufs_sync_acl_from_inode(ip, acl);
1682 * Just use the mode as-is.
1685 DIP_SET(ip, i_mode, mode);
1694 * XXX: If we abort now, will Soft Updates notify the extattr
1695 * code that the EAs for the file need to be released?
1697 error = VOP_SETACL(tvp, ACL_TYPE_ACCESS, acl, cred, td);
1704 * XXX: This should not happen, as EOPNOTSUPP above was
1705 * supposed to free acl.
1707 printf("ufs_do_posix1e_acl_inheritance_file: VOP_GETACL() "
1708 "but no VOP_SETACL()\n");
1709 /* panic("ufs_do_posix1e_acl_inheritance_file: VOP_GETACL() "
1710 "but no VOP_SETACL()"); */
1724 ufs_do_nfs4_acl_inheritance(struct vnode *dvp, struct vnode *tvp,
1725 mode_t child_mode, struct ucred *cred, struct thread *td)
1728 struct acl *parent_aclp, *child_aclp;
1730 parent_aclp = acl_alloc(M_WAITOK);
1731 child_aclp = acl_alloc(M_WAITOK | M_ZERO);
1733 error = ufs_getacl_nfs4_internal(dvp, parent_aclp, td);
1736 acl_nfs4_compute_inherited_acl(parent_aclp, child_aclp,
1737 child_mode, VTOI(tvp)->i_uid, tvp->v_type == VDIR);
1738 error = ufs_setacl_nfs4_internal(tvp, child_aclp, td);
1742 acl_free(parent_aclp);
1743 acl_free(child_aclp);
1754 struct vop_mkdir_args /* {
1755 struct vnode *a_dvp;
1756 struct vnode **a_vpp;
1757 struct componentname *a_cnp;
1758 struct vattr *a_vap;
1761 struct vnode *dvp = ap->a_dvp;
1762 struct vattr *vap = ap->a_vap;
1763 struct componentname *cnp = ap->a_cnp;
1764 struct inode *ip, *dp;
1767 struct dirtemplate dirtemplate, *dtp;
1768 struct direct newdir;
1773 if ((cnp->cn_flags & HASBUF) == 0)
1774 panic("ufs_mkdir: no name");
1777 if (dp->i_nlink >= UFS_LINK_MAX) {
1781 dmode = vap->va_mode & 0777;
1784 * Must simulate part of ufs_makeinode here to acquire the inode,
1785 * but not have it entered in the parent directory. The entry is
1786 * made later after writing "." and ".." entries.
1788 if (dp->i_effnlink < 2) {
1789 print_bad_link_count("ufs_mkdir", dvp);
1793 error = UFS_VALLOC(dvp, dmode, cnp->cn_cred, &tvp);
1797 ip->i_gid = dp->i_gid;
1798 DIP_SET(ip, i_gid, dp->i_gid);
1802 struct ucred ucred, *ucp;
1807 * If we are hacking owners here, (only do this where told to)
1808 * and we are not giving it TO root, (would subvert quotas)
1809 * then go ahead and give it to the other user.
1810 * The new directory also inherits the SUID bit.
1811 * If user's UID and dir UID are the same,
1812 * 'give it away' so that the SUID is still forced on.
1814 if ((dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
1815 (dp->i_mode & ISUID) && dp->i_uid) {
1817 ip->i_uid = dp->i_uid;
1818 DIP_SET(ip, i_uid, dp->i_uid);
1820 if (dp->i_uid != cnp->cn_cred->cr_uid) {
1822 * Make sure the correct user gets charged
1824 * Make a dummy credential for the victim.
1825 * XXX This seems to never be accessed out of
1826 * our context so a stack variable is ok.
1828 refcount_init(&ucred.cr_ref, 1);
1829 ucred.cr_uid = ip->i_uid;
1830 ucred.cr_ngroups = 1;
1831 ucred.cr_groups = &ucred_group;
1832 ucred.cr_groups[0] = dp->i_gid;
1837 ip->i_uid = cnp->cn_cred->cr_uid;
1838 DIP_SET(ip, i_uid, ip->i_uid);
1841 if ((error = getinoquota(ip)) ||
1842 (error = chkiq(ip, 1, ucp, 0))) {
1843 if (DOINGSOFTDEP(tvp))
1844 softdep_revert_link(dp, ip);
1845 UFS_VFREE(tvp, ip->i_number, dmode);
1852 #else /* !SUIDDIR */
1853 ip->i_uid = cnp->cn_cred->cr_uid;
1854 DIP_SET(ip, i_uid, ip->i_uid);
1856 if ((error = getinoquota(ip)) ||
1857 (error = chkiq(ip, 1, cnp->cn_cred, 0))) {
1858 if (DOINGSOFTDEP(tvp))
1859 softdep_revert_link(dp, ip);
1860 UFS_VFREE(tvp, ip->i_number, dmode);
1866 #endif /* !SUIDDIR */
1867 UFS_INODE_SET_FLAG(ip, IN_ACCESS | IN_CHANGE | IN_UPDATE);
1869 DIP_SET(ip, i_mode, dmode);
1870 tvp->v_type = VDIR; /* Rest init'd in getnewvnode(). */
1873 DIP_SET(ip, i_nlink, 2);
1875 if (cnp->cn_flags & ISWHITEOUT) {
1876 ip->i_flags |= UF_OPAQUE;
1877 DIP_SET(ip, i_flags, ip->i_flags);
1881 * Bump link count in parent directory to reflect work done below.
1882 * Should be done before reference is created so cleanup is
1883 * possible if we crash.
1887 DIP_SET(dp, i_nlink, dp->i_nlink);
1888 UFS_INODE_SET_FLAG(dp, IN_CHANGE);
1889 if (DOINGSOFTDEP(dvp))
1890 softdep_setup_mkdir(dp, ip);
1891 error = UFS_UPDATE(dvp, !DOINGSOFTDEP(dvp) && !DOINGASYNC(dvp));
1895 if (dvp->v_mount->mnt_flag & MNT_MULTILABEL) {
1896 error = mac_vnode_create_extattr(cnp->cn_cred, dvp->v_mount,
1903 if (dvp->v_mount->mnt_flag & MNT_ACLS) {
1904 error = ufs_do_posix1e_acl_inheritance_dir(dvp, tvp, dmode,
1905 cnp->cn_cred, cnp->cn_thread);
1908 } else if (dvp->v_mount->mnt_flag & MNT_NFS4ACLS) {
1909 error = ufs_do_nfs4_acl_inheritance(dvp, tvp, dmode,
1910 cnp->cn_cred, cnp->cn_thread);
1914 #endif /* !UFS_ACL */
1917 * Initialize directory with "." and ".." from static template.
1919 if (dvp->v_mount->mnt_maxsymlinklen > 0)
1920 dtp = &mastertemplate;
1922 dtp = (struct dirtemplate *)&omastertemplate;
1924 dirtemplate.dot_ino = ip->i_number;
1925 dirtemplate.dotdot_ino = dp->i_number;
1926 vnode_pager_setsize(tvp, DIRBLKSIZ);
1927 if ((error = UFS_BALLOC(tvp, (off_t)0, DIRBLKSIZ, cnp->cn_cred,
1928 BA_CLRBUF, &bp)) != 0)
1930 ip->i_size = DIRBLKSIZ;
1931 DIP_SET(ip, i_size, DIRBLKSIZ);
1932 UFS_INODE_SET_FLAG(ip, IN_CHANGE | IN_UPDATE);
1933 bcopy((caddr_t)&dirtemplate, (caddr_t)bp->b_data, sizeof dirtemplate);
1934 if (DOINGSOFTDEP(tvp)) {
1936 * Ensure that the entire newly allocated block is a
1937 * valid directory so that future growth within the
1938 * block does not have to ensure that the block is
1939 * written before the inode.
1942 while (blkoff < bp->b_bcount) {
1944 (bp->b_data + blkoff))->d_reclen = DIRBLKSIZ;
1945 blkoff += DIRBLKSIZ;
1948 if ((error = UFS_UPDATE(tvp, !DOINGSOFTDEP(tvp) &&
1949 !DOINGASYNC(tvp))) != 0) {
1954 * Directory set up, now install its entry in the parent directory.
1956 * If we are not doing soft dependencies, then we must write out the
1957 * buffer containing the new directory body before entering the new
1958 * name in the parent. If we are doing soft dependencies, then the
1959 * buffer containing the new directory body will be passed to and
1960 * released in the soft dependency code after the code has attached
1961 * an appropriate ordering dependency to the buffer which ensures that
1962 * the buffer is written before the new name is written in the parent.
1964 if (DOINGASYNC(dvp))
1966 else if (!DOINGSOFTDEP(dvp) && ((error = bwrite(bp))))
1968 ufs_makedirentry(ip, cnp, &newdir);
1969 error = ufs_direnter(dvp, tvp, &newdir, cnp, bp, 0);
1977 DIP_SET(dp, i_nlink, dp->i_nlink);
1978 UFS_INODE_SET_FLAG(dp, IN_CHANGE);
1980 * No need to do an explicit VOP_TRUNCATE here, vrele will
1981 * do this for us because we set the link count to 0.
1985 DIP_SET(ip, i_nlink, 0);
1986 UFS_INODE_SET_FLAG(ip, IN_CHANGE);
1987 if (DOINGSOFTDEP(tvp))
1988 softdep_revert_mkdir(dp, ip);
1997 * Rmdir system call.
2001 struct vop_rmdir_args /* {
2002 struct vnode *a_dvp;
2004 struct componentname *a_cnp;
2007 struct vnode *vp = ap->a_vp;
2008 struct vnode *dvp = ap->a_dvp;
2009 struct componentname *cnp = ap->a_cnp;
2010 struct inode *ip, *dp;
2017 * Do not remove a directory that is in the process of being renamed.
2018 * Verify the directory is empty (and valid). Rmdir ".." will not be
2019 * valid since ".." will contain a reference to the current directory
2020 * and thus be non-empty. Do not allow the removal of mounted on
2021 * directories (this can happen when an NFS exported filesystem
2022 * tries to remove a locally mounted on directory).
2025 if (dp->i_effnlink <= 2) {
2026 if (dp->i_effnlink == 2)
2027 print_bad_link_count("ufs_rmdir", dvp);
2031 if (!ufs_dirempty(ip, dp->i_number, cnp->cn_cred)) {
2035 if ((dp->i_flags & APPEND)
2036 || (ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))) {
2040 if (vp->v_mountedhere != 0) {
2045 ufs_gjournal_orphan(vp);
2048 * Delete reference to directory before purging
2049 * inode. If we crash in between, the directory
2050 * will be reattached to lost+found,
2054 if (DOINGSOFTDEP(vp))
2055 softdep_setup_rmdir(dp, ip);
2056 error = ufs_dirremove(dvp, ip, cnp->cn_flags, 1);
2060 if (DOINGSOFTDEP(vp))
2061 softdep_revert_rmdir(dp, ip);
2066 * The only stuff left in the directory is "." and "..". The "."
2067 * reference is inconsequential since we are quashing it. The soft
2068 * dependency code will arrange to do these operations after
2069 * the parent directory entry has been deleted on disk, so
2070 * when running with that code we avoid doing them now.
2072 if (!DOINGSOFTDEP(vp)) {
2074 DIP_SET(dp, i_nlink, dp->i_nlink);
2075 UFS_INODE_SET_FLAG(dp, IN_CHANGE);
2076 error = UFS_UPDATE(dvp, 0);
2078 DIP_SET(ip, i_nlink, ip->i_nlink);
2079 UFS_INODE_SET_FLAG(ip, IN_CHANGE);
2083 /* Kill any active hash; i_effnlink == 0, so it will not come back. */
2084 if (ip->i_dirhash != NULL)
2085 ufsdirhash_free(ip);
2092 * symlink -- make a symbolic link
2096 struct vop_symlink_args /* {
2097 struct vnode *a_dvp;
2098 struct vnode **a_vpp;
2099 struct componentname *a_cnp;
2100 struct vattr *a_vap;
2101 const char *a_target;
2104 struct vnode *vp, **vpp = ap->a_vpp;
2108 error = ufs_makeinode(IFLNK | ap->a_vap->va_mode, ap->a_dvp,
2109 vpp, ap->a_cnp, "ufs_symlink");
2113 len = strlen(ap->a_target);
2114 if (len < vp->v_mount->mnt_maxsymlinklen) {
2116 bcopy(ap->a_target, SHORTLINK(ip), len);
2118 DIP_SET(ip, i_size, len);
2119 UFS_INODE_SET_FLAG(ip, IN_CHANGE | IN_UPDATE);
2120 error = UFS_UPDATE(vp, 0);
2122 error = vn_rdwr(UIO_WRITE, vp, __DECONST(void *, ap->a_target),
2123 len, (off_t)0, UIO_SYSSPACE, IO_NODELOCKED | IO_NOMACCHECK,
2124 ap->a_cnp->cn_cred, NOCRED, NULL, NULL);
2131 * Vnode op for reading directories.
2135 struct vop_readdir_args /* {
2138 struct ucred *a_cred;
2144 struct vnode *vp = ap->a_vp;
2145 struct uio *uio = ap->a_uio;
2148 struct direct *dp, *edp;
2150 struct dirent dstdp;
2151 off_t offset, startoffset;
2152 size_t readcnt, skipcnt;
2157 if (uio->uio_offset < 0)
2160 if (ip->i_effnlink == 0)
2162 if (ap->a_ncookies != NULL) {
2163 if (uio->uio_resid < 0)
2166 ncookies = uio->uio_resid;
2167 if (uio->uio_offset >= ip->i_size)
2169 else if (ip->i_size - uio->uio_offset < ncookies)
2170 ncookies = ip->i_size - uio->uio_offset;
2171 ncookies = ncookies / (offsetof(struct direct, d_name) + 4) + 1;
2172 cookies = malloc(ncookies * sizeof(*cookies), M_TEMP, M_WAITOK);
2173 *ap->a_ncookies = ncookies;
2174 *ap->a_cookies = cookies;
2179 offset = startoffset = uio->uio_offset;
2180 startresid = uio->uio_resid;
2182 while (error == 0 && uio->uio_resid > 0 &&
2183 uio->uio_offset < ip->i_size) {
2184 error = ffs_blkatoff(vp, uio->uio_offset, NULL, &bp);
2187 if (bp->b_offset + bp->b_bcount > ip->i_size)
2188 readcnt = ip->i_size - bp->b_offset;
2190 readcnt = bp->b_bcount;
2191 skipcnt = (size_t)(uio->uio_offset - bp->b_offset) &
2192 ~(size_t)(DIRBLKSIZ - 1);
2193 offset = bp->b_offset + skipcnt;
2194 dp = (struct direct *)&bp->b_data[skipcnt];
2195 edp = (struct direct *)&bp->b_data[readcnt];
2196 while (error == 0 && uio->uio_resid > 0 && dp < edp) {
2197 if (dp->d_reclen <= offsetof(struct direct, d_name) ||
2198 (caddr_t)dp + dp->d_reclen > (caddr_t)edp) {
2202 #if BYTE_ORDER == LITTLE_ENDIAN
2203 /* Old filesystem format. */
2204 if (vp->v_mount->mnt_maxsymlinklen <= 0) {
2205 dstdp.d_namlen = dp->d_type;
2206 dstdp.d_type = dp->d_namlen;
2210 dstdp.d_namlen = dp->d_namlen;
2211 dstdp.d_type = dp->d_type;
2213 if (offsetof(struct direct, d_name) + dstdp.d_namlen >
2218 if (offset < startoffset || dp->d_ino == 0)
2220 dstdp.d_fileno = dp->d_ino;
2221 dstdp.d_reclen = GENERIC_DIRSIZ(&dstdp);
2222 bcopy(dp->d_name, dstdp.d_name, dstdp.d_namlen);
2223 /* NOTE: d_off is the offset of the *next* entry. */
2224 dstdp.d_off = offset + dp->d_reclen;
2225 dirent_terminate(&dstdp);
2226 if (dstdp.d_reclen > uio->uio_resid) {
2227 if (uio->uio_resid == startresid)
2230 error = EJUSTRETURN;
2234 error = uiomove((caddr_t)&dstdp, dstdp.d_reclen, uio);
2237 if (cookies != NULL) {
2238 KASSERT(ncookies > 0,
2239 ("ufs_readdir: cookies buffer too small"));
2240 *cookies = offset + dp->d_reclen;
2245 offset += dp->d_reclen;
2246 dp = (struct direct *)((caddr_t)dp + dp->d_reclen);
2249 uio->uio_offset = offset;
2251 /* We need to correct uio_offset. */
2252 uio->uio_offset = offset;
2253 if (error == EJUSTRETURN)
2255 if (ap->a_ncookies != NULL) {
2257 ap->a_ncookies -= ncookies;
2259 free(*ap->a_cookies, M_TEMP);
2260 *ap->a_ncookies = 0;
2261 *ap->a_cookies = NULL;
2264 if (error == 0 && ap->a_eofflag)
2265 *ap->a_eofflag = ip->i_size <= uio->uio_offset;
2270 * Return target name of a symbolic link
2274 struct vop_readlink_args /* {
2277 struct ucred *a_cred;
2280 struct vnode *vp = ap->a_vp;
2281 struct inode *ip = VTOI(vp);
2285 if ((isize < vp->v_mount->mnt_maxsymlinklen) ||
2286 DIP(ip, i_blocks) == 0) { /* XXX - for old fastlink support */
2287 return (uiomove(SHORTLINK(ip), isize, ap->a_uio));
2289 return (VOP_READ(vp, ap->a_uio, 0, ap->a_cred));
2293 * Calculate the logical to physical mapping if not done already,
2294 * then call the device strategy routine.
2296 * In order to be able to swap to a file, the ufs_bmaparray() operation may not
2297 * deadlock on memory. See ufs_bmap() for details.
2301 struct vop_strategy_args /* {
2306 struct buf *bp = ap->a_bp;
2307 struct vnode *vp = ap->a_vp;
2311 if (bp->b_blkno == bp->b_lblkno) {
2312 error = ufs_bmaparray(vp, bp->b_lblkno, &blkno, bp, NULL, NULL);
2313 bp->b_blkno = blkno;
2315 bp->b_error = error;
2316 bp->b_ioflags |= BIO_ERROR;
2320 if ((long)bp->b_blkno == -1)
2323 if ((long)bp->b_blkno == -1) {
2327 bp->b_iooffset = dbtob(bp->b_blkno);
2328 BO_STRATEGY(VFSTOUFS(vp->v_mount)->um_bo, bp);
2333 * Print out the contents of an inode.
2337 struct vop_print_args /* {
2341 struct vnode *vp = ap->a_vp;
2342 struct inode *ip = VTOI(vp);
2344 printf("\tnlink=%d, effnlink=%d, size=%jd", ip->i_nlink,
2345 ip->i_effnlink, (intmax_t)ip->i_size);
2347 printf(", extsize %d", ip->i_din2->di_extsize);
2348 printf("\n\tgeneration=%jx, uid=%d, gid=%d, flags=0x%b\n",
2349 (uintmax_t)ip->i_gen, ip->i_uid, ip->i_gid,
2350 (u_int)ip->i_flags, PRINT_INODE_FLAGS);
2351 printf("\tino %lu, on dev %s", (u_long)ip->i_number,
2352 devtoname(ITODEV(ip)));
2353 if (vp->v_type == VFIFO)
2360 * Close wrapper for fifos.
2362 * Update the times on the inode then do device close.
2366 struct vop_close_args /* {
2369 struct ucred *a_cred;
2370 struct thread *a_td;
2373 struct vnode *vp = ap->a_vp;
2377 usecount = vp->v_usecount;
2379 ufs_itimes_locked(vp);
2381 return (fifo_specops.vop_close(ap));
2385 * Kqfilter wrapper for fifos.
2387 * Fall through to ufs kqfilter routines if needed
2390 ufsfifo_kqfilter(ap)
2391 struct vop_kqfilter_args *ap;
2395 error = fifo_specops.vop_kqfilter(ap);
2397 error = vfs_kqfilter(ap);
2402 * Return POSIX pathconf information applicable to ufs filesystems.
2406 struct vop_pathconf_args /* {
2415 switch (ap->a_name) {
2417 *ap->a_retval = UFS_LINK_MAX;
2420 *ap->a_retval = UFS_MAXNAMLEN;
2423 if (ap->a_vp->v_type == VDIR || ap->a_vp->v_type == VFIFO)
2424 *ap->a_retval = PIPE_BUF;
2428 case _PC_CHOWN_RESTRICTED:
2435 case _PC_ACL_EXTENDED:
2436 if (ap->a_vp->v_mount->mnt_flag & MNT_ACLS)
2442 if (ap->a_vp->v_mount->mnt_flag & MNT_NFS4ACLS)
2448 case _PC_ACL_PATH_MAX:
2450 if (ap->a_vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS))
2451 *ap->a_retval = ACL_MAX_ENTRIES;
2459 case _PC_MAC_PRESENT:
2460 if (ap->a_vp->v_mount->mnt_flag & MNT_MULTILABEL)
2466 case _PC_MIN_HOLE_SIZE:
2467 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2475 case _PC_ALLOC_SIZE_MIN:
2476 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_bsize;
2478 case _PC_FILESIZEBITS:
2481 case _PC_REC_INCR_XFER_SIZE:
2482 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2484 case _PC_REC_MAX_XFER_SIZE:
2485 *ap->a_retval = -1; /* means ``unlimited'' */
2487 case _PC_REC_MIN_XFER_SIZE:
2488 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2490 case _PC_REC_XFER_ALIGN:
2491 *ap->a_retval = PAGE_SIZE;
2493 case _PC_SYMLINK_MAX:
2494 *ap->a_retval = MAXPATHLEN;
2498 error = vop_stdpathconf(ap);
2505 * Initialize the vnode associated with a new inode, handle aliased
2509 ufs_vinit(mntp, fifoops, vpp)
2511 struct vop_vector *fifoops;
2518 ASSERT_VOP_LOCKED(vp, "ufs_vinit");
2520 vp->v_type = IFTOVT(ip->i_mode);
2522 * Only unallocated inodes should be of type VNON.
2524 if (ip->i_mode != 0 && vp->v_type == VNON)
2526 if (vp->v_type == VFIFO)
2528 if (ip->i_number == UFS_ROOTINO)
2529 vp->v_vflag |= VV_ROOT;
2535 * Allocate a new inode.
2536 * Vnode dvp must be locked.
2539 ufs_makeinode(mode, dvp, vpp, cnp, callfunc)
2543 struct componentname *cnp;
2544 const char *callfunc;
2546 struct inode *ip, *pdir;
2547 struct direct newdir;
2553 if ((cnp->cn_flags & HASBUF) == 0)
2554 panic("%s: no name", callfunc);
2557 if ((mode & IFMT) == 0)
2560 if (pdir->i_effnlink < 2) {
2561 print_bad_link_count(callfunc, dvp);
2564 error = UFS_VALLOC(dvp, mode, cnp->cn_cred, &tvp);
2568 ip->i_gid = pdir->i_gid;
2569 DIP_SET(ip, i_gid, pdir->i_gid);
2573 struct ucred ucred, *ucp;
2578 * If we are not the owner of the directory,
2579 * and we are hacking owners here, (only do this where told to)
2580 * and we are not giving it TO root, (would subvert quotas)
2581 * then go ahead and give it to the other user.
2582 * Note that this drops off the execute bits for security.
2584 if ((dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
2585 (pdir->i_mode & ISUID) &&
2586 (pdir->i_uid != cnp->cn_cred->cr_uid) && pdir->i_uid) {
2587 ip->i_uid = pdir->i_uid;
2588 DIP_SET(ip, i_uid, ip->i_uid);
2592 * Make sure the correct user gets charged
2594 * Quickly knock up a dummy credential for the victim.
2595 * XXX This seems to never be accessed out of our
2596 * context so a stack variable is ok.
2598 refcount_init(&ucred.cr_ref, 1);
2599 ucred.cr_uid = ip->i_uid;
2600 ucred.cr_ngroups = 1;
2601 ucred.cr_groups = &ucred_group;
2602 ucred.cr_groups[0] = pdir->i_gid;
2606 ip->i_uid = cnp->cn_cred->cr_uid;
2607 DIP_SET(ip, i_uid, ip->i_uid);
2611 if ((error = getinoquota(ip)) ||
2612 (error = chkiq(ip, 1, ucp, 0))) {
2613 if (DOINGSOFTDEP(tvp))
2614 softdep_revert_link(pdir, ip);
2615 UFS_VFREE(tvp, ip->i_number, mode);
2622 #else /* !SUIDDIR */
2623 ip->i_uid = cnp->cn_cred->cr_uid;
2624 DIP_SET(ip, i_uid, ip->i_uid);
2626 if ((error = getinoquota(ip)) ||
2627 (error = chkiq(ip, 1, cnp->cn_cred, 0))) {
2628 if (DOINGSOFTDEP(tvp))
2629 softdep_revert_link(pdir, ip);
2630 UFS_VFREE(tvp, ip->i_number, mode);
2636 #endif /* !SUIDDIR */
2637 UFS_INODE_SET_FLAG(ip, IN_ACCESS | IN_CHANGE | IN_UPDATE);
2639 DIP_SET(ip, i_mode, mode);
2640 tvp->v_type = IFTOVT(mode); /* Rest init'd in getnewvnode(). */
2643 DIP_SET(ip, i_nlink, 1);
2644 if (DOINGSOFTDEP(tvp))
2645 softdep_setup_create(VTOI(dvp), ip);
2646 if ((ip->i_mode & ISGID) && !groupmember(ip->i_gid, cnp->cn_cred) &&
2647 priv_check_cred(cnp->cn_cred, PRIV_VFS_SETGID)) {
2648 ip->i_mode &= ~ISGID;
2649 DIP_SET(ip, i_mode, ip->i_mode);
2652 if (cnp->cn_flags & ISWHITEOUT) {
2653 ip->i_flags |= UF_OPAQUE;
2654 DIP_SET(ip, i_flags, ip->i_flags);
2658 * Make sure inode goes to disk before directory entry.
2660 error = UFS_UPDATE(tvp, !DOINGSOFTDEP(tvp) && !DOINGASYNC(tvp));
2664 if (dvp->v_mount->mnt_flag & MNT_MULTILABEL) {
2665 error = mac_vnode_create_extattr(cnp->cn_cred, dvp->v_mount,
2672 if (dvp->v_mount->mnt_flag & MNT_ACLS) {
2673 error = ufs_do_posix1e_acl_inheritance_file(dvp, tvp, mode,
2674 cnp->cn_cred, cnp->cn_thread);
2677 } else if (dvp->v_mount->mnt_flag & MNT_NFS4ACLS) {
2678 error = ufs_do_nfs4_acl_inheritance(dvp, tvp, mode,
2679 cnp->cn_cred, cnp->cn_thread);
2683 #endif /* !UFS_ACL */
2684 ufs_makedirentry(ip, cnp, &newdir);
2685 error = ufs_direnter(dvp, tvp, &newdir, cnp, NULL, 0);
2693 * Write error occurred trying to update the inode
2694 * or the directory so must deallocate the inode.
2698 DIP_SET(ip, i_nlink, 0);
2699 UFS_INODE_SET_FLAG(ip, IN_CHANGE);
2700 if (DOINGSOFTDEP(tvp))
2701 softdep_revert_create(VTOI(dvp), ip);
2708 ufs_ioctl(struct vop_ioctl_args *ap)
2714 switch (ap->a_command) {
2716 error = vn_lock(vp, LK_SHARED);
2718 error = ufs_bmap_seekdata(vp, (off_t *)ap->a_data);
2724 return (vn_bmap_seekhole(vp, ap->a_command, (off_t *)ap->a_data,
2731 /* Global vfs data structures for ufs. */
2732 struct vop_vector ufs_vnodeops = {
2733 .vop_default = &default_vnodeops,
2734 .vop_fsync = VOP_PANIC,
2735 .vop_read = VOP_PANIC,
2736 .vop_reallocblks = VOP_PANIC,
2737 .vop_write = VOP_PANIC,
2738 .vop_accessx = ufs_accessx,
2739 .vop_bmap = ufs_bmap,
2740 .vop_cachedlookup = ufs_lookup,
2741 .vop_close = ufs_close,
2742 .vop_create = ufs_create,
2743 .vop_getattr = ufs_getattr,
2744 .vop_inactive = ufs_inactive,
2745 .vop_ioctl = ufs_ioctl,
2746 .vop_link = ufs_link,
2747 .vop_lookup = vfs_cache_lookup,
2748 .vop_mmapped = ufs_mmapped,
2749 .vop_mkdir = ufs_mkdir,
2750 .vop_mknod = ufs_mknod,
2751 .vop_need_inactive = ufs_need_inactive,
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,
2780 VFS_VOP_VECTOR_REGISTER(ufs_vnodeops);
2782 struct vop_vector ufs_fifoops = {
2783 .vop_default = &fifo_specops,
2784 .vop_fsync = VOP_PANIC,
2785 .vop_accessx = ufs_accessx,
2786 .vop_close = ufsfifo_close,
2787 .vop_getattr = ufs_getattr,
2788 .vop_inactive = ufs_inactive,
2789 .vop_kqfilter = ufsfifo_kqfilter,
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,
2810 VFS_VOP_VECTOR_REGISTER(ufs_fifoops);