2 * Copyright (c) 1982, 1986, 1989, 1993, 1995
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)ufs_vnops.c 8.27 (Berkeley) 5/27/95
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
40 #include "opt_quota.h"
41 #include "opt_suiddir.h"
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/malloc.h>
48 #include <sys/namei.h>
49 #include <sys/kernel.h>
50 #include <sys/fcntl.h>
51 #include <sys/filio.h>
55 #include <sys/mount.h>
57 #include <sys/refcount.h>
58 #include <sys/unistd.h>
59 #include <sys/vnode.h>
60 #include <sys/dirent.h>
61 #include <sys/lockf.h>
65 #include <security/mac/mac_framework.h>
67 #include <sys/file.h> /* XXX */
70 #include <vm/vm_extern.h>
72 #include <ufs/ufs/acl.h>
73 #include <ufs/ufs/extattr.h>
74 #include <ufs/ufs/quota.h>
75 #include <ufs/ufs/inode.h>
76 #include <ufs/ufs/dir.h>
77 #include <ufs/ufs/ufsmount.h>
78 #include <ufs/ufs/ufs_extern.h>
80 #include <ufs/ufs/dirhash.h>
83 #include <ufs/ufs/gjournal.h>
84 FEATURE(ufs_gjournal, "Journaling support through GEOM for UFS");
88 FEATURE(ufs_quota, "UFS disk quotas support");
89 FEATURE(ufs_quota64, "64bit UFS disk quotas support");
94 "Give all new files in directory the same ownership as the directory");
98 #include <ufs/ffs/ffs_extern.h>
100 static vop_accessx_t ufs_accessx;
101 static int ufs_chmod(struct vnode *, int, struct ucred *, struct thread *);
102 static int ufs_chown(struct vnode *, uid_t, gid_t, struct ucred *, struct thread *);
103 static vop_close_t ufs_close;
104 static vop_create_t ufs_create;
105 static vop_getattr_t ufs_getattr;
106 static vop_ioctl_t ufs_ioctl;
107 static vop_link_t ufs_link;
108 static int ufs_makeinode(int mode, struct vnode *, struct vnode **, struct componentname *);
109 static vop_markatime_t ufs_markatime;
110 static vop_mkdir_t ufs_mkdir;
111 static vop_mknod_t ufs_mknod;
112 static vop_open_t ufs_open;
113 static vop_pathconf_t ufs_pathconf;
114 static vop_print_t ufs_print;
115 static vop_readlink_t ufs_readlink;
116 static vop_remove_t ufs_remove;
117 static vop_rename_t ufs_rename;
118 static vop_rmdir_t ufs_rmdir;
119 static vop_setattr_t ufs_setattr;
120 static vop_strategy_t ufs_strategy;
121 static vop_symlink_t ufs_symlink;
122 static vop_whiteout_t ufs_whiteout;
123 static vop_close_t ufsfifo_close;
124 static vop_kqfilter_t ufsfifo_kqfilter;
125 static vop_pathconf_t ufsfifo_pathconf;
127 SYSCTL_NODE(_vfs, OID_AUTO, ufs, CTLFLAG_RD, 0, "UFS filesystem");
130 * A virgin directory (no blushing please).
132 static struct dirtemplate mastertemplate = {
133 0, 12, DT_DIR, 1, ".",
134 0, DIRBLKSIZ - 12, DT_DIR, 2, ".."
136 static struct odirtemplate omastertemplate = {
138 0, DIRBLKSIZ - 12, 2, ".."
142 ufs_itimes_locked(struct vnode *vp)
147 ASSERT_VI_LOCKED(vp, __func__);
152 if ((ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) == 0)
155 if ((vp->v_type == VBLK || vp->v_type == VCHR) && !DOINGSOFTDEP(vp))
156 ip->i_flag |= IN_LAZYMOD;
157 else if (((vp->v_mount->mnt_kern_flag &
158 (MNTK_SUSPENDED | MNTK_SUSPEND)) == 0) ||
159 (ip->i_flag & (IN_CHANGE | IN_UPDATE)))
160 ip->i_flag |= IN_MODIFIED;
161 else if (ip->i_flag & IN_ACCESS)
162 ip->i_flag |= IN_LAZYACCESS;
164 if (ip->i_flag & IN_ACCESS) {
165 DIP_SET(ip, i_atime, ts.tv_sec);
166 DIP_SET(ip, i_atimensec, ts.tv_nsec);
168 if (ip->i_flag & IN_UPDATE) {
169 DIP_SET(ip, i_mtime, ts.tv_sec);
170 DIP_SET(ip, i_mtimensec, ts.tv_nsec);
172 if (ip->i_flag & IN_CHANGE) {
173 DIP_SET(ip, i_ctime, ts.tv_sec);
174 DIP_SET(ip, i_ctimensec, ts.tv_nsec);
175 DIP_SET(ip, i_modrev, DIP(ip, i_modrev) + 1);
179 ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE);
183 ufs_itimes(struct vnode *vp)
187 ufs_itimes_locked(vp);
192 * Create a regular file
196 struct vop_create_args /* {
198 struct vnode **a_vpp;
199 struct componentname *a_cnp;
206 ufs_makeinode(MAKEIMODE(ap->a_vap->va_type, ap->a_vap->va_mode),
207 ap->a_dvp, ap->a_vpp, ap->a_cnp);
219 struct vop_mknod_args /* {
221 struct vnode **a_vpp;
222 struct componentname *a_cnp;
226 struct vattr *vap = ap->a_vap;
227 struct vnode **vpp = ap->a_vpp;
232 error = ufs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode),
233 ap->a_dvp, vpp, ap->a_cnp);
237 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
238 if (vap->va_rdev != VNOVAL) {
240 * Want to be able to use this to make badblock
241 * inodes, so don't truncate the dev number.
243 DIP_SET(ip, i_rdev, vap->va_rdev);
246 * Remove inode, then reload it through VFS_VGET so it is
247 * checked to see if it is an alias of an existing entry in
248 * the inode cache. XXX I don't believe this is necessary now.
250 (*vpp)->v_type = VNON;
251 ino = ip->i_number; /* Save this before vgone() invalidates ip. */
254 error = VFS_VGET(ap->a_dvp->v_mount, ino, LK_EXCLUSIVE, vpp);
267 ufs_open(struct vop_open_args *ap)
269 struct vnode *vp = ap->a_vp;
272 if (vp->v_type == VCHR || vp->v_type == VBLK)
277 * Files marked append-only must be opened for appending.
279 if ((ip->i_flags & APPEND) &&
280 (ap->a_mode & (FWRITE | O_APPEND)) == FWRITE)
282 vnode_create_vobject(vp, DIP(ip, i_size), ap->a_td);
289 * Update the times on the inode.
294 struct vop_close_args /* {
297 struct ucred *a_cred;
301 struct vnode *vp = ap->a_vp;
305 usecount = vp->v_usecount;
307 ufs_itimes_locked(vp);
314 struct vop_accessx_args /* {
317 struct ucred *a_cred;
321 struct vnode *vp = ap->a_vp;
322 struct inode *ip = VTOI(vp);
323 accmode_t accmode = ap->a_accmode;
334 * Disallow write attempts on read-only filesystems;
335 * unless the file is a socket, fifo, or a block or
336 * character device resident on the filesystem.
338 if (accmode & VMODIFY_PERMS) {
339 switch (vp->v_type) {
343 if (vp->v_mount->mnt_flag & MNT_RDONLY)
347 * Inode is accounted in the quotas only if struct
348 * dquot is attached to it. VOP_ACCESS() is called
349 * from vn_open_cred() and provides a convenient
350 * point to call getinoquota().
352 if (VOP_ISLOCKED(vp) != LK_EXCLUSIVE) {
355 * Upgrade vnode lock, since getinoquota()
356 * requires exclusive lock to modify inode.
360 vn_lock(vp, LK_UPGRADE | LK_RETRY);
362 if (vp->v_iflag & VI_DOOMED) {
370 error = getinoquota(ip);
373 vn_lock(vp, LK_DOWNGRADE | LK_RETRY);
384 * If immutable bit set, nobody gets to write it. "& ~VADMIN_PERMS"
385 * is here, because without it, * it would be impossible for the owner
386 * to remove the IMMUTABLE flag.
388 if ((accmode & (VMODIFY_PERMS & ~VADMIN_PERMS)) &&
389 (ip->i_flags & (IMMUTABLE | SF_SNAPSHOT)))
393 if ((vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS)) != 0) {
394 if (vp->v_mount->mnt_flag & MNT_NFS4ACLS)
395 type = ACL_TYPE_NFS4;
397 type = ACL_TYPE_ACCESS;
399 acl = acl_alloc(M_WAITOK);
400 if (type == ACL_TYPE_NFS4)
401 error = ufs_getacl_nfs4_internal(vp, acl, ap->a_td);
403 error = VOP_GETACL(vp, type, acl, ap->a_cred, ap->a_td);
406 if (type == ACL_TYPE_NFS4) {
407 error = vaccess_acl_nfs4(vp->v_type, ip->i_uid,
408 ip->i_gid, acl, accmode, ap->a_cred, NULL);
410 error = vfs_unixify_accmode(&accmode);
412 error = vaccess_acl_posix1e(vp->v_type, ip->i_uid,
413 ip->i_gid, acl, accmode, ap->a_cred, NULL);
417 if (error != EOPNOTSUPP)
419 "ufs_accessx(): Error retrieving ACL on object (%d).\n",
422 * XXX: Fall back until debugged. Should
423 * eventually possibly log an error, and return
426 error = vfs_unixify_accmode(&accmode);
428 error = vaccess(vp->v_type, ip->i_mode, ip->i_uid,
429 ip->i_gid, accmode, ap->a_cred, NULL);
435 #endif /* !UFS_ACL */
436 error = vfs_unixify_accmode(&accmode);
438 error = vaccess(vp->v_type, ip->i_mode, ip->i_uid, ip->i_gid,
439 accmode, ap->a_cred, NULL);
446 struct vop_getattr_args /* {
449 struct ucred *a_cred;
452 struct vnode *vp = ap->a_vp;
453 struct inode *ip = VTOI(vp);
454 struct vattr *vap = ap->a_vap;
457 ufs_itimes_locked(vp);
458 if (ip->i_ump->um_fstype == UFS1) {
459 vap->va_atime.tv_sec = ip->i_din1->di_atime;
460 vap->va_atime.tv_nsec = ip->i_din1->di_atimensec;
462 vap->va_atime.tv_sec = ip->i_din2->di_atime;
463 vap->va_atime.tv_nsec = ip->i_din2->di_atimensec;
467 * Copy from inode table
469 vap->va_fsid = dev2udev(ip->i_dev);
470 vap->va_fileid = ip->i_number;
471 vap->va_mode = ip->i_mode & ~IFMT;
472 vap->va_nlink = ip->i_effnlink;
473 vap->va_uid = ip->i_uid;
474 vap->va_gid = ip->i_gid;
475 if (ip->i_ump->um_fstype == UFS1) {
476 vap->va_rdev = ip->i_din1->di_rdev;
477 vap->va_size = ip->i_din1->di_size;
478 vap->va_mtime.tv_sec = ip->i_din1->di_mtime;
479 vap->va_mtime.tv_nsec = ip->i_din1->di_mtimensec;
480 vap->va_ctime.tv_sec = ip->i_din1->di_ctime;
481 vap->va_ctime.tv_nsec = ip->i_din1->di_ctimensec;
482 vap->va_bytes = dbtob((u_quad_t)ip->i_din1->di_blocks);
483 vap->va_filerev = ip->i_din1->di_modrev;
485 vap->va_rdev = ip->i_din2->di_rdev;
486 vap->va_size = ip->i_din2->di_size;
487 vap->va_mtime.tv_sec = ip->i_din2->di_mtime;
488 vap->va_mtime.tv_nsec = ip->i_din2->di_mtimensec;
489 vap->va_ctime.tv_sec = ip->i_din2->di_ctime;
490 vap->va_ctime.tv_nsec = ip->i_din2->di_ctimensec;
491 vap->va_birthtime.tv_sec = ip->i_din2->di_birthtime;
492 vap->va_birthtime.tv_nsec = ip->i_din2->di_birthnsec;
493 vap->va_bytes = dbtob((u_quad_t)ip->i_din2->di_blocks);
494 vap->va_filerev = ip->i_din2->di_modrev;
496 vap->va_flags = ip->i_flags;
497 vap->va_gen = ip->i_gen;
498 vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
499 vap->va_type = IFTOVT(ip->i_mode);
504 * Set attribute vnode op. called from several syscalls
508 struct vop_setattr_args /* {
511 struct ucred *a_cred;
514 struct vattr *vap = ap->a_vap;
515 struct vnode *vp = ap->a_vp;
516 struct inode *ip = VTOI(vp);
517 struct ucred *cred = ap->a_cred;
518 struct thread *td = curthread;
522 * Check for unsettable attributes.
524 if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
525 (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
526 (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
527 ((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
530 if (vap->va_flags != VNOVAL) {
531 if ((vap->va_flags & ~(SF_APPEND | SF_ARCHIVED | SF_IMMUTABLE |
532 SF_NOUNLINK | SF_SNAPSHOT | UF_APPEND | UF_ARCHIVE |
533 UF_HIDDEN | UF_IMMUTABLE | UF_NODUMP | UF_NOUNLINK |
534 UF_OFFLINE | UF_OPAQUE | UF_READONLY | UF_REPARSE |
535 UF_SPARSE | UF_SYSTEM)) != 0)
537 if (vp->v_mount->mnt_flag & MNT_RDONLY)
540 * Callers may only modify the file flags on objects they
541 * have VADMIN rights for.
543 if ((error = VOP_ACCESS(vp, VADMIN, cred, td)))
546 * Unprivileged processes are not permitted to unset system
547 * flags, or modify flags if any system flags are set.
548 * Privileged non-jail processes may not modify system flags
549 * if securelevel > 0 and any existing system flags are set.
550 * Privileged jail processes behave like privileged non-jail
551 * processes if the security.jail.chflags_allowed sysctl is
552 * is non-zero; otherwise, they behave like unprivileged
555 if (!priv_check_cred(cred, PRIV_VFS_SYSFLAGS, 0)) {
557 (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND)) {
558 error = securelevel_gt(cred, 0);
562 /* The snapshot flag cannot be toggled. */
563 if ((vap->va_flags ^ ip->i_flags) & SF_SNAPSHOT)
567 (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND) ||
568 ((vap->va_flags ^ ip->i_flags) & SF_SETTABLE))
571 ip->i_flags = vap->va_flags;
572 DIP_SET(ip, i_flags, vap->va_flags);
573 ip->i_flag |= IN_CHANGE;
574 error = UFS_UPDATE(vp, 0);
575 if (ip->i_flags & (IMMUTABLE | APPEND))
579 * If immutable or append, no one can change any of its attributes
580 * except the ones already handled (in some cases, file flags
581 * including the immutability flags themselves for the superuser).
583 if (ip->i_flags & (IMMUTABLE | APPEND))
586 * Go through the fields and update iff not VNOVAL.
588 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
589 if (vp->v_mount->mnt_flag & MNT_RDONLY)
591 if ((error = ufs_chown(vp, vap->va_uid, vap->va_gid, cred,
595 if (vap->va_size != VNOVAL) {
597 * XXX most of the following special cases should be in
598 * callers instead of in N filesystems. The VDIR check
601 switch (vp->v_type) {
607 * Truncation should have an effect in these cases.
608 * Disallow it if the filesystem is read-only or
609 * the file is being snapshotted.
611 if (vp->v_mount->mnt_flag & MNT_RDONLY)
613 if ((ip->i_flags & SF_SNAPSHOT) != 0)
618 * According to POSIX, the result is unspecified
619 * for file types other than regular files,
620 * directories and shared memory objects. We
621 * don't support shared memory objects in the file
622 * system, and have dubious support for truncating
623 * symlinks. Just ignore the request in other cases.
627 if ((error = UFS_TRUNCATE(vp, vap->va_size, IO_NORMAL,
631 if (vap->va_atime.tv_sec != VNOVAL ||
632 vap->va_mtime.tv_sec != VNOVAL ||
633 vap->va_birthtime.tv_sec != VNOVAL) {
634 if (vp->v_mount->mnt_flag & MNT_RDONLY)
636 if ((ip->i_flags & SF_SNAPSHOT) != 0)
638 error = vn_utimes_perm(vp, vap, cred, td);
641 if (vap->va_atime.tv_sec != VNOVAL)
642 ip->i_flag |= IN_ACCESS;
643 if (vap->va_mtime.tv_sec != VNOVAL)
644 ip->i_flag |= IN_CHANGE | IN_UPDATE;
645 if (vap->va_birthtime.tv_sec != VNOVAL &&
646 ip->i_ump->um_fstype == UFS2)
647 ip->i_flag |= IN_MODIFIED;
649 if (vap->va_atime.tv_sec != VNOVAL) {
650 DIP_SET(ip, i_atime, vap->va_atime.tv_sec);
651 DIP_SET(ip, i_atimensec, vap->va_atime.tv_nsec);
653 if (vap->va_mtime.tv_sec != VNOVAL) {
654 DIP_SET(ip, i_mtime, vap->va_mtime.tv_sec);
655 DIP_SET(ip, i_mtimensec, vap->va_mtime.tv_nsec);
657 if (vap->va_birthtime.tv_sec != VNOVAL &&
658 ip->i_ump->um_fstype == UFS2) {
659 ip->i_din2->di_birthtime = vap->va_birthtime.tv_sec;
660 ip->i_din2->di_birthnsec = vap->va_birthtime.tv_nsec;
662 error = UFS_UPDATE(vp, 0);
667 if (vap->va_mode != (mode_t)VNOVAL) {
668 if (vp->v_mount->mnt_flag & MNT_RDONLY)
670 if ((ip->i_flags & SF_SNAPSHOT) != 0 && (vap->va_mode &
671 (S_IXUSR | S_IWUSR | S_IXGRP | S_IWGRP | S_IXOTH | S_IWOTH)))
673 error = ufs_chmod(vp, (int)vap->va_mode, cred, td);
680 ufs_update_nfs4_acl_after_mode_change(struct vnode *vp, int mode,
681 int file_owner_id, struct ucred *cred, struct thread *td)
686 aclp = acl_alloc(M_WAITOK);
687 error = ufs_getacl_nfs4_internal(vp, aclp, td);
689 * We don't have to handle EOPNOTSUPP here, as the filesystem claims
695 acl_nfs4_sync_acl_from_mode(aclp, mode, file_owner_id);
696 error = ufs_setacl_nfs4_internal(vp, aclp, td);
705 * Mark this file's access time for update for vfs_mark_atime(). This
706 * is called from execve() and mmap().
710 struct vop_markatime_args /* {
714 struct vnode *vp = ap->a_vp;
715 struct inode *ip = VTOI(vp);
718 ip->i_flag |= IN_ACCESS;
721 * XXXKIB No UFS_UPDATE(ap->a_vp, 0) there.
727 * Change the mode on a file.
728 * Inode must be locked before calling.
731 ufs_chmod(vp, mode, cred, td)
737 struct inode *ip = VTOI(vp);
741 * To modify the permissions on a file, must possess VADMIN
744 if ((error = VOP_ACCESSX(vp, VWRITE_ACL, cred, td)))
747 * Privileged processes may set the sticky bit on non-directories,
748 * as well as set the setgid bit on a file with a group that the
749 * process is not a member of. Both of these are allowed in
752 if (vp->v_type != VDIR && (mode & S_ISTXT)) {
753 if (priv_check_cred(cred, PRIV_VFS_STICKYFILE, 0))
756 if (!groupmember(ip->i_gid, cred) && (mode & ISGID)) {
757 error = priv_check_cred(cred, PRIV_VFS_SETGID, 0);
763 * Deny setting setuid if we are not the file owner.
765 if ((mode & ISUID) && ip->i_uid != cred->cr_uid) {
766 error = priv_check_cred(cred, PRIV_VFS_ADMIN, 0);
771 ip->i_mode &= ~ALLPERMS;
772 ip->i_mode |= (mode & ALLPERMS);
773 DIP_SET(ip, i_mode, ip->i_mode);
774 ip->i_flag |= IN_CHANGE;
776 if ((vp->v_mount->mnt_flag & MNT_NFS4ACLS) != 0)
777 error = ufs_update_nfs4_acl_after_mode_change(vp, mode, ip->i_uid, cred, td);
779 if (error == 0 && (ip->i_flag & IN_CHANGE) != 0)
780 error = UFS_UPDATE(vp, 0);
786 * Perform chown operation on inode ip;
787 * inode must be locked prior to call.
790 ufs_chown(vp, uid, gid, cred, td)
797 struct inode *ip = VTOI(vp);
806 if (uid == (uid_t)VNOVAL)
808 if (gid == (gid_t)VNOVAL)
811 * To modify the ownership of a file, must possess VADMIN for that
814 if ((error = VOP_ACCESSX(vp, VWRITE_OWNER, cred, td)))
817 * To change the owner of a file, or change the group of a file to a
818 * group of which we are not a member, the caller must have
821 if (((uid != ip->i_uid && uid != cred->cr_uid) ||
822 (gid != ip->i_gid && !groupmember(gid, cred))) &&
823 (error = priv_check_cred(cred, PRIV_VFS_CHOWN, 0)))
828 if ((error = getinoquota(ip)) != 0)
831 dqrele(vp, ip->i_dquot[USRQUOTA]);
832 ip->i_dquot[USRQUOTA] = NODQUOT;
835 dqrele(vp, ip->i_dquot[GRPQUOTA]);
836 ip->i_dquot[GRPQUOTA] = NODQUOT;
838 change = DIP(ip, i_blocks);
839 (void) chkdq(ip, -change, cred, CHOWN);
840 (void) chkiq(ip, -1, cred, CHOWN);
841 for (i = 0; i < MAXQUOTAS; i++) {
842 dqrele(vp, ip->i_dquot[i]);
843 ip->i_dquot[i] = NODQUOT;
847 DIP_SET(ip, i_gid, gid);
849 DIP_SET(ip, i_uid, uid);
851 if ((error = 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 if ((error = chkdq(ip, change, cred, CHOWN)) == 0) {
861 if ((error = chkiq(ip, 1, cred, CHOWN)) == 0)
864 (void) chkdq(ip, -change, cred, CHOWN|FORCE);
866 for (i = 0; i < MAXQUOTAS; i++) {
867 dqrele(vp, ip->i_dquot[i]);
868 ip->i_dquot[i] = NODQUOT;
872 DIP_SET(ip, i_gid, ogid);
874 DIP_SET(ip, i_uid, ouid);
875 if (getinoquota(ip) == 0) {
877 dqrele(vp, ip->i_dquot[USRQUOTA]);
878 ip->i_dquot[USRQUOTA] = NODQUOT;
881 dqrele(vp, ip->i_dquot[GRPQUOTA]);
882 ip->i_dquot[GRPQUOTA] = NODQUOT;
884 (void) chkdq(ip, change, cred, FORCE|CHOWN);
885 (void) chkiq(ip, 1, cred, FORCE|CHOWN);
886 (void) getinoquota(ip);
891 panic("ufs_chown: lost quota");
893 ip->i_flag |= IN_CHANGE;
894 if ((ip->i_mode & (ISUID | ISGID)) && (ouid != uid || ogid != gid)) {
895 if (priv_check_cred(cred, PRIV_VFS_RETAINSUGID, 0)) {
896 ip->i_mode &= ~(ISUID | ISGID);
897 DIP_SET(ip, i_mode, ip->i_mode);
900 error = UFS_UPDATE(vp, 0);
906 struct vop_remove_args /* {
909 struct componentname *a_cnp;
913 struct vnode *vp = ap->a_vp;
914 struct vnode *dvp = ap->a_dvp;
920 if ((ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
921 (VTOI(dvp)->i_flags & APPEND)) {
926 ufs_gjournal_orphan(vp);
928 error = ufs_dirremove(dvp, ip, ap->a_cnp->cn_flags, 0);
929 if (ip->i_nlink <= 0)
930 vp->v_vflag |= VV_NOSYNC;
931 if ((ip->i_flags & SF_SNAPSHOT) != 0) {
933 * Avoid deadlock where another thread is trying to
934 * update the inodeblock for dvp and is waiting on
935 * snaplk. Temporary unlock the vnode lock for the
936 * unlinked file and sync the directory. This should
937 * allow vput() of the directory to not block later on
938 * while holding the snapshot vnode locked, assuming
939 * that the directory hasn't been unlinked too.
942 (void) VOP_FSYNC(dvp, MNT_WAIT, td);
943 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
954 struct vop_link_args /* {
955 struct vnode *a_tdvp;
957 struct componentname *a_cnp;
960 struct vnode *vp = ap->a_vp;
961 struct vnode *tdvp = ap->a_tdvp;
962 struct componentname *cnp = ap->a_cnp;
964 struct direct newdir;
968 if ((cnp->cn_flags & HASBUF) == 0)
969 panic("ufs_link: no name");
971 if (VTOI(tdvp)->i_effnlink < 2)
972 panic("ufs_link: Bad link count %d on parent",
973 VTOI(tdvp)->i_effnlink);
975 if ((nlink_t)ip->i_nlink >= LINK_MAX) {
980 * The file may have been removed after namei droped the original
983 if (ip->i_effnlink == 0) {
987 if (ip->i_flags & (IMMUTABLE | APPEND)) {
993 DIP_SET(ip, i_nlink, ip->i_nlink);
994 ip->i_flag |= IN_CHANGE;
995 if (DOINGSOFTDEP(vp))
996 softdep_setup_link(VTOI(tdvp), ip);
997 error = UFS_UPDATE(vp, !(DOINGSOFTDEP(vp) | DOINGASYNC(vp)));
999 ufs_makedirentry(ip, cnp, &newdir);
1000 error = ufs_direnter(tdvp, vp, &newdir, cnp, NULL, 0);
1006 DIP_SET(ip, i_nlink, ip->i_nlink);
1007 ip->i_flag |= IN_CHANGE;
1008 if (DOINGSOFTDEP(vp))
1009 softdep_revert_link(VTOI(tdvp), ip);
1016 * whiteout vnode call
1020 struct vop_whiteout_args /* {
1021 struct vnode *a_dvp;
1022 struct componentname *a_cnp;
1026 struct vnode *dvp = ap->a_dvp;
1027 struct componentname *cnp = ap->a_cnp;
1028 struct direct newdir;
1031 switch (ap->a_flags) {
1033 /* 4.4 format directories support whiteout operations */
1034 if (dvp->v_mount->mnt_maxsymlinklen > 0)
1036 return (EOPNOTSUPP);
1039 /* create a new directory whiteout */
1041 if ((cnp->cn_flags & SAVENAME) == 0)
1042 panic("ufs_whiteout: missing name");
1043 if (dvp->v_mount->mnt_maxsymlinklen <= 0)
1044 panic("ufs_whiteout: old format filesystem");
1047 newdir.d_ino = WINO;
1048 newdir.d_namlen = cnp->cn_namelen;
1049 bcopy(cnp->cn_nameptr, newdir.d_name, (unsigned)cnp->cn_namelen + 1);
1050 newdir.d_type = DT_WHT;
1051 error = ufs_direnter(dvp, NULL, &newdir, cnp, NULL, 0);
1055 /* remove an existing directory whiteout */
1057 if (dvp->v_mount->mnt_maxsymlinklen <= 0)
1058 panic("ufs_whiteout: old format filesystem");
1061 cnp->cn_flags &= ~DOWHITEOUT;
1062 error = ufs_dirremove(dvp, NULL, cnp->cn_flags, 0);
1065 panic("ufs_whiteout: unknown op");
1070 static volatile int rename_restarts;
1071 SYSCTL_INT(_vfs_ufs, OID_AUTO, rename_restarts, CTLFLAG_RD,
1072 __DEVOLATILE(int *, &rename_restarts), 0,
1073 "Times rename had to restart due to lock contention");
1076 * Rename system call.
1077 * rename("foo", "bar");
1080 * link("foo", "bar");
1082 * but ``atomically''. Can't do full commit without saving state in the
1083 * inode on disk which isn't feasible at this time. Best we can do is
1084 * always guarantee the target exists.
1086 * Basic algorithm is:
1088 * 1) Bump link count on source while we're linking it to the
1089 * target. This also ensure the inode won't be deleted out
1090 * from underneath us while we work (it may be truncated by
1091 * a concurrent `trunc' or `open' for creation).
1092 * 2) Link source to destination. If destination already exists,
1094 * 3) Unlink source reference to inode if still around. If a
1095 * directory was moved and the parent of the destination
1096 * is different from the source, patch the ".." entry in the
1101 struct vop_rename_args /* {
1102 struct vnode *a_fdvp;
1103 struct vnode *a_fvp;
1104 struct componentname *a_fcnp;
1105 struct vnode *a_tdvp;
1106 struct vnode *a_tvp;
1107 struct componentname *a_tcnp;
1110 struct vnode *tvp = ap->a_tvp;
1111 struct vnode *tdvp = ap->a_tdvp;
1112 struct vnode *fvp = ap->a_fvp;
1113 struct vnode *fdvp = ap->a_fdvp;
1115 struct componentname *tcnp = ap->a_tcnp;
1116 struct componentname *fcnp = ap->a_fcnp;
1117 struct thread *td = fcnp->cn_thread;
1118 struct inode *fip, *tip, *tdp, *fdp;
1119 struct direct newdir;
1121 int doingdirectory, newparent;
1127 if ((tcnp->cn_flags & HASBUF) == 0 ||
1128 (fcnp->cn_flags & HASBUF) == 0)
1129 panic("ufs_rename: no name");
1133 VOP_UNLOCK(tdvp, 0);
1134 if (tvp && tvp != tdvp)
1137 * Check for cross-device rename.
1139 if ((fvp->v_mount != tdvp->v_mount) ||
1140 (tvp && (fvp->v_mount != tvp->v_mount))) {
1147 * We need to acquire 2 to 4 locks depending on whether tvp is NULL
1148 * and fdvp and tdvp are the same directory. Subsequently we need
1149 * to double-check all paths and in the directory rename case we
1150 * need to verify that we are not creating a directory loop. To
1151 * handle this we acquire all but fdvp using non-blocking
1152 * acquisitions. If we fail to acquire any lock in the path we will
1153 * drop all held locks, acquire the new lock in a blocking fashion,
1154 * and then release it and restart the rename. This acquire/release
1155 * step ensures that we do not spin on a lock waiting for release.
1157 error = vn_lock(fdvp, LK_EXCLUSIVE);
1160 if (vn_lock(tdvp, LK_EXCLUSIVE | LK_NOWAIT) != 0) {
1161 VOP_UNLOCK(fdvp, 0);
1162 error = vn_lock(tdvp, LK_EXCLUSIVE);
1165 VOP_UNLOCK(tdvp, 0);
1166 atomic_add_int(&rename_restarts, 1);
1170 * Re-resolve fvp to be certain it still exists and fetch the
1173 error = ufs_lookup_ino(fdvp, NULL, fcnp, &ino);
1175 VOP_UNLOCK(fdvp, 0);
1176 VOP_UNLOCK(tdvp, 0);
1179 error = VFS_VGET(mp, ino, LK_EXCLUSIVE | LK_NOWAIT, &nvp);
1181 VOP_UNLOCK(fdvp, 0);
1182 VOP_UNLOCK(tdvp, 0);
1185 error = VFS_VGET(mp, ino, LK_EXCLUSIVE, &nvp);
1191 atomic_add_int(&rename_restarts, 1);
1197 * Re-resolve tvp and acquire the vnode lock if present.
1199 error = ufs_lookup_ino(tdvp, NULL, tcnp, &ino);
1200 if (error != 0 && error != EJUSTRETURN) {
1201 VOP_UNLOCK(fdvp, 0);
1202 VOP_UNLOCK(tdvp, 0);
1207 * If tvp disappeared we just carry on.
1209 if (error == EJUSTRETURN && tvp != NULL) {
1214 * Get the tvp ino if the lookup succeeded. We may have to restart
1215 * if the non-blocking acquire fails.
1219 error = VFS_VGET(mp, ino, LK_EXCLUSIVE | LK_NOWAIT, &nvp);
1224 VOP_UNLOCK(fdvp, 0);
1225 VOP_UNLOCK(tdvp, 0);
1229 error = VFS_VGET(mp, ino, LK_EXCLUSIVE, &nvp);
1233 atomic_add_int(&rename_restarts, 1);
1243 if (tvp && ((VTOI(tvp)->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
1244 (VTOI(tdvp)->i_flags & APPEND))) {
1249 * Renaming a file to itself has no effect. The upper layers should
1250 * not call us in that case. However, things could change after
1251 * we drop the locks above.
1259 ino = fip->i_number;
1260 if (fip->i_nlink >= LINK_MAX) {
1264 if ((fip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))
1265 || (fdp->i_flags & APPEND)) {
1269 if ((fip->i_mode & IFMT) == IFDIR) {
1271 * Avoid ".", "..", and aliases of "." for obvious reasons.
1273 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
1275 (fcnp->cn_flags | tcnp->cn_flags) & ISDOTDOT) {
1279 if (fdp->i_number != tdp->i_number)
1280 newparent = tdp->i_number;
1283 if ((fvp->v_type == VDIR && fvp->v_mountedhere != NULL) ||
1284 (tvp != NULL && tvp->v_type == VDIR &&
1285 tvp->v_mountedhere != NULL)) {
1291 * If ".." must be changed (ie the directory gets a new
1292 * parent) then the source directory must not be in the
1293 * directory hierarchy above the target, as this would
1294 * orphan everything below the source directory. Also
1295 * the user must have write permission in the source so
1296 * as to be able to change "..".
1298 if (doingdirectory && newparent) {
1299 error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_thread);
1302 error = ufs_checkpath(ino, fdp->i_number, tdp, tcnp->cn_cred,
1305 * We encountered a lock that we have to wait for. Unlock
1306 * everything else and VGET before restarting.
1309 VOP_UNLOCK(fdvp, 0);
1311 VOP_UNLOCK(tdvp, 0);
1314 error = VFS_VGET(mp, ino, LK_SHARED, &nvp);
1317 atomic_add_int(&rename_restarts, 1);
1322 if ((tcnp->cn_flags & SAVESTART) == 0)
1323 panic("ufs_rename: lost to startdir");
1325 if (fip->i_effnlink == 0 || fdp->i_effnlink == 0 ||
1326 tdp->i_effnlink == 0)
1327 panic("Bad effnlink fip %p, fdp %p, tdp %p", fip, fdp, tdp);
1330 * 1) Bump link count while we're moving stuff
1331 * around. If we crash somewhere before
1332 * completing our work, the link count
1333 * may be wrong, but correctable.
1337 DIP_SET(fip, i_nlink, fip->i_nlink);
1338 fip->i_flag |= IN_CHANGE;
1339 if (DOINGSOFTDEP(fvp))
1340 softdep_setup_link(tdp, fip);
1341 error = UFS_UPDATE(fvp, !(DOINGSOFTDEP(fvp) | DOINGASYNC(fvp)));
1346 * 2) If target doesn't exist, link the target
1347 * to the source and unlink the source.
1348 * Otherwise, rewrite the target directory
1349 * entry to reference the source inode and
1350 * expunge the original entry's existence.
1353 if (tdp->i_dev != fip->i_dev)
1354 panic("ufs_rename: EXDEV");
1355 if (doingdirectory && newparent) {
1357 * Account for ".." in new directory.
1358 * When source and destination have the same
1359 * parent we don't adjust the link count. The
1360 * actual link modification is completed when
1361 * .. is rewritten below.
1363 if ((nlink_t)tdp->i_nlink >= LINK_MAX) {
1368 ufs_makedirentry(fip, tcnp, &newdir);
1369 error = ufs_direnter(tdvp, NULL, &newdir, tcnp, NULL, 1);
1372 /* Setup tdvp for directory compaction if needed. */
1373 if (tdp->i_count && tdp->i_endoff &&
1374 tdp->i_endoff < tdp->i_size)
1375 endoff = tdp->i_endoff;
1377 if (tip->i_dev != tdp->i_dev || tip->i_dev != fip->i_dev)
1378 panic("ufs_rename: EXDEV");
1380 * Short circuit rename(foo, foo).
1382 if (tip->i_number == fip->i_number)
1383 panic("ufs_rename: same file");
1385 * If the parent directory is "sticky", then the caller
1386 * must possess VADMIN for the parent directory, or the
1387 * destination of the rename. This implements append-only
1390 if ((tdp->i_mode & S_ISTXT) &&
1391 VOP_ACCESS(tdvp, VADMIN, tcnp->cn_cred, td) &&
1392 VOP_ACCESS(tvp, VADMIN, tcnp->cn_cred, td)) {
1397 * Target must be empty if a directory and have no links
1398 * to it. Also, ensure source and target are compatible
1399 * (both directories, or both not directories).
1401 if ((tip->i_mode & IFMT) == IFDIR) {
1402 if ((tip->i_effnlink > 2) ||
1403 !ufs_dirempty(tip, tdp->i_number, tcnp->cn_cred)) {
1407 if (!doingdirectory) {
1412 } else if (doingdirectory) {
1416 if (doingdirectory) {
1419 if (DOINGSOFTDEP(tdvp))
1420 softdep_change_linkcnt(tdp);
1423 if (DOINGSOFTDEP(tvp))
1424 softdep_change_linkcnt(tip);
1426 error = ufs_dirrewrite(tdp, tip, fip->i_number,
1427 IFTODT(fip->i_mode),
1428 (doingdirectory && newparent) ? newparent : doingdirectory);
1430 if (doingdirectory) {
1433 if (DOINGSOFTDEP(tdvp))
1434 softdep_change_linkcnt(tdp);
1437 if (DOINGSOFTDEP(tvp))
1438 softdep_change_linkcnt(tip);
1441 if (doingdirectory && !DOINGSOFTDEP(tvp)) {
1443 * The only stuff left in the directory is "."
1444 * and "..". The "." reference is inconsequential
1445 * since we are quashing it. We have removed the "."
1446 * reference and the reference in the parent directory,
1447 * but there may be other hard links. The soft
1448 * dependency code will arrange to do these operations
1449 * after the parent directory entry has been deleted on
1450 * disk, so when running with that code we avoid doing
1455 DIP_SET(tdp, i_nlink, tdp->i_nlink);
1456 tdp->i_flag |= IN_CHANGE;
1459 DIP_SET(tip, i_nlink, tip->i_nlink);
1460 tip->i_flag |= IN_CHANGE;
1465 * 3) Unlink the source. We have to resolve the path again to
1466 * fixup the directory offset and count for ufs_dirremove.
1469 error = ufs_lookup_ino(fdvp, NULL, fcnp, &ino);
1471 panic("ufs_rename: from entry went away!");
1472 if (ino != fip->i_number)
1473 panic("ufs_rename: ino mismatch %ju != %ju\n",
1474 (uintmax_t)ino, (uintmax_t)fip->i_number);
1477 * If the source is a directory with a
1478 * new parent, the link count of the old
1479 * parent directory must be decremented
1480 * and ".." set to point to the new parent.
1482 if (doingdirectory && newparent) {
1484 * If tip exists we simply use its link, otherwise we must
1490 DIP_SET(tdp, i_nlink, tdp->i_nlink);
1491 tdp->i_flag |= IN_CHANGE;
1492 if (DOINGSOFTDEP(tdvp))
1493 softdep_setup_dotdot_link(tdp, fip);
1494 error = UFS_UPDATE(tdvp, !(DOINGSOFTDEP(tdvp) |
1496 /* Don't go to bad here as the new link exists. */
1499 } else if (DOINGSUJ(tdvp))
1500 /* Journal must account for each new link. */
1501 softdep_setup_dotdot_link(tdp, fip);
1502 fip->i_offset = mastertemplate.dot_reclen;
1503 ufs_dirrewrite(fip, fdp, newparent, DT_DIR, 0);
1506 error = ufs_dirremove(fdvp, fip, fcnp->cn_flags, 0);
1508 * The kern_renameat() looks up the fvp using the DELETE flag, which
1509 * causes the removal of the name cache entry for fvp.
1510 * As the relookup of the fvp is done in two steps:
1511 * ufs_lookup_ino() and then VFS_VGET(), another thread might do a
1512 * normal lookup of the from name just before the VFS_VGET() call,
1513 * causing the cache entry to be re-instantiated.
1515 * The same issue also applies to tvp if it exists as
1516 * otherwise we may have a stale name cache entry for the new
1517 * name that references the old i-node if it has other links
1518 * or open file descriptors.
1523 cache_purge_negative(tdvp);
1531 * If compaction or fsync was requested do it now that other locks
1532 * are no longer needed.
1534 if (error == 0 && endoff != 0) {
1536 if (tdp->i_dirhash != NULL)
1537 ufsdirhash_dirtrunc(tdp, endoff);
1539 UFS_TRUNCATE(tdvp, endoff, IO_NORMAL | IO_SYNC, tcnp->cn_cred);
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 fip->i_flag |= 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_makeinode: VOP_GETACL() but no "
1709 /* panic("ufs_makeinode: VOP_GETACL() but no "
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 ((nlink_t)dp->i_nlink >= 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 error = UFS_VALLOC(dvp, dmode, cnp->cn_cred, &tvp);
1792 ip->i_gid = dp->i_gid;
1793 DIP_SET(ip, i_gid, dp->i_gid);
1797 struct ucred ucred, *ucp;
1802 * If we are hacking owners here, (only do this where told to)
1803 * and we are not giving it TO root, (would subvert quotas)
1804 * then go ahead and give it to the other user.
1805 * The new directory also inherits the SUID bit.
1806 * If user's UID and dir UID are the same,
1807 * 'give it away' so that the SUID is still forced on.
1809 if ((dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
1810 (dp->i_mode & ISUID) && dp->i_uid) {
1812 ip->i_uid = dp->i_uid;
1813 DIP_SET(ip, i_uid, dp->i_uid);
1815 if (dp->i_uid != cnp->cn_cred->cr_uid) {
1817 * Make sure the correct user gets charged
1819 * Make a dummy credential for the victim.
1820 * XXX This seems to never be accessed out of
1821 * our context so a stack variable is ok.
1823 refcount_init(&ucred.cr_ref, 1);
1824 ucred.cr_uid = ip->i_uid;
1825 ucred.cr_ngroups = 1;
1826 ucred.cr_groups = &ucred_group;
1827 ucred.cr_groups[0] = dp->i_gid;
1832 ip->i_uid = cnp->cn_cred->cr_uid;
1833 DIP_SET(ip, i_uid, ip->i_uid);
1836 if ((error = getinoquota(ip)) ||
1837 (error = chkiq(ip, 1, ucp, 0))) {
1838 if (DOINGSOFTDEP(tvp))
1839 softdep_revert_link(dp, ip);
1840 UFS_VFREE(tvp, ip->i_number, dmode);
1846 #else /* !SUIDDIR */
1847 ip->i_uid = cnp->cn_cred->cr_uid;
1848 DIP_SET(ip, i_uid, ip->i_uid);
1850 if ((error = getinoquota(ip)) ||
1851 (error = chkiq(ip, 1, cnp->cn_cred, 0))) {
1852 if (DOINGSOFTDEP(tvp))
1853 softdep_revert_link(dp, ip);
1854 UFS_VFREE(tvp, ip->i_number, dmode);
1859 #endif /* !SUIDDIR */
1860 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
1862 DIP_SET(ip, i_mode, dmode);
1863 tvp->v_type = VDIR; /* Rest init'd in getnewvnode(). */
1866 DIP_SET(ip, i_nlink, 2);
1868 if (cnp->cn_flags & ISWHITEOUT) {
1869 ip->i_flags |= UF_OPAQUE;
1870 DIP_SET(ip, i_flags, ip->i_flags);
1874 * Bump link count in parent directory to reflect work done below.
1875 * Should be done before reference is created so cleanup is
1876 * possible if we crash.
1880 DIP_SET(dp, i_nlink, dp->i_nlink);
1881 dp->i_flag |= IN_CHANGE;
1882 if (DOINGSOFTDEP(dvp))
1883 softdep_setup_mkdir(dp, ip);
1884 error = UFS_UPDATE(dvp, !(DOINGSOFTDEP(dvp) | DOINGASYNC(dvp)));
1888 if (dvp->v_mount->mnt_flag & MNT_MULTILABEL) {
1889 error = mac_vnode_create_extattr(cnp->cn_cred, dvp->v_mount,
1896 if (dvp->v_mount->mnt_flag & MNT_ACLS) {
1897 error = ufs_do_posix1e_acl_inheritance_dir(dvp, tvp, dmode,
1898 cnp->cn_cred, cnp->cn_thread);
1901 } else if (dvp->v_mount->mnt_flag & MNT_NFS4ACLS) {
1902 error = ufs_do_nfs4_acl_inheritance(dvp, tvp, dmode,
1903 cnp->cn_cred, cnp->cn_thread);
1907 #endif /* !UFS_ACL */
1910 * Initialize directory with "." and ".." from static template.
1912 if (dvp->v_mount->mnt_maxsymlinklen > 0)
1913 dtp = &mastertemplate;
1915 dtp = (struct dirtemplate *)&omastertemplate;
1917 dirtemplate.dot_ino = ip->i_number;
1918 dirtemplate.dotdot_ino = dp->i_number;
1919 if ((error = UFS_BALLOC(tvp, (off_t)0, DIRBLKSIZ, cnp->cn_cred,
1920 BA_CLRBUF, &bp)) != 0)
1922 ip->i_size = DIRBLKSIZ;
1923 DIP_SET(ip, i_size, DIRBLKSIZ);
1924 ip->i_flag |= IN_CHANGE | IN_UPDATE;
1925 vnode_pager_setsize(tvp, (u_long)ip->i_size);
1926 bcopy((caddr_t)&dirtemplate, (caddr_t)bp->b_data, sizeof dirtemplate);
1927 if (DOINGSOFTDEP(tvp)) {
1929 * Ensure that the entire newly allocated block is a
1930 * valid directory so that future growth within the
1931 * block does not have to ensure that the block is
1932 * written before the inode.
1935 while (blkoff < bp->b_bcount) {
1937 (bp->b_data + blkoff))->d_reclen = DIRBLKSIZ;
1938 blkoff += DIRBLKSIZ;
1941 if ((error = UFS_UPDATE(tvp, !(DOINGSOFTDEP(tvp) |
1942 DOINGASYNC(tvp)))) != 0) {
1947 * Directory set up, now install its entry in the parent directory.
1949 * If we are not doing soft dependencies, then we must write out the
1950 * buffer containing the new directory body before entering the new
1951 * name in the parent. If we are doing soft dependencies, then the
1952 * buffer containing the new directory body will be passed to and
1953 * released in the soft dependency code after the code has attached
1954 * an appropriate ordering dependency to the buffer which ensures that
1955 * the buffer is written before the new name is written in the parent.
1957 if (DOINGASYNC(dvp))
1959 else if (!DOINGSOFTDEP(dvp) && ((error = bwrite(bp))))
1961 ufs_makedirentry(ip, cnp, &newdir);
1962 error = ufs_direnter(dvp, tvp, &newdir, cnp, bp, 0);
1970 DIP_SET(dp, i_nlink, dp->i_nlink);
1971 dp->i_flag |= IN_CHANGE;
1973 * No need to do an explicit VOP_TRUNCATE here, vrele will
1974 * do this for us because we set the link count to 0.
1978 DIP_SET(ip, i_nlink, 0);
1979 ip->i_flag |= IN_CHANGE;
1980 if (DOINGSOFTDEP(tvp))
1981 softdep_revert_mkdir(dp, ip);
1990 * Rmdir system call.
1994 struct vop_rmdir_args /* {
1995 struct vnode *a_dvp;
1997 struct componentname *a_cnp;
2000 struct vnode *vp = ap->a_vp;
2001 struct vnode *dvp = ap->a_dvp;
2002 struct componentname *cnp = ap->a_cnp;
2003 struct inode *ip, *dp;
2010 * Do not remove a directory that is in the process of being renamed.
2011 * Verify the directory is empty (and valid). Rmdir ".." will not be
2012 * valid since ".." will contain a reference to the current directory
2013 * and thus be non-empty. Do not allow the removal of mounted on
2014 * directories (this can happen when an NFS exported filesystem
2015 * tries to remove a locally mounted on directory).
2018 if (ip->i_effnlink < 2) {
2022 if (dp->i_effnlink < 3)
2023 panic("ufs_dirrem: Bad link count %d on parent",
2025 if (!ufs_dirempty(ip, dp->i_number, cnp->cn_cred)) {
2029 if ((dp->i_flags & APPEND)
2030 || (ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))) {
2034 if (vp->v_mountedhere != 0) {
2039 ufs_gjournal_orphan(vp);
2042 * Delete reference to directory before purging
2043 * inode. If we crash in between, the directory
2044 * will be reattached to lost+found,
2048 if (DOINGSOFTDEP(vp))
2049 softdep_setup_rmdir(dp, ip);
2050 error = ufs_dirremove(dvp, ip, cnp->cn_flags, 1);
2054 if (DOINGSOFTDEP(vp))
2055 softdep_revert_rmdir(dp, ip);
2060 * The only stuff left in the directory is "." and "..". The "."
2061 * reference is inconsequential since we are quashing it. The soft
2062 * dependency code will arrange to do these operations after
2063 * the parent directory entry has been deleted on disk, so
2064 * when running with that code we avoid doing them now.
2066 if (!DOINGSOFTDEP(vp)) {
2068 DIP_SET(dp, i_nlink, dp->i_nlink);
2069 dp->i_flag |= IN_CHANGE;
2070 error = UFS_UPDATE(dvp, 0);
2072 DIP_SET(ip, i_nlink, ip->i_nlink);
2073 ip->i_flag |= IN_CHANGE;
2077 /* Kill any active hash; i_effnlink == 0, so it will not come back. */
2078 if (ip->i_dirhash != NULL)
2079 ufsdirhash_free(ip);
2086 * symlink -- make a symbolic link
2090 struct vop_symlink_args /* {
2091 struct vnode *a_dvp;
2092 struct vnode **a_vpp;
2093 struct componentname *a_cnp;
2094 struct vattr *a_vap;
2098 struct vnode *vp, **vpp = ap->a_vpp;
2102 error = ufs_makeinode(IFLNK | ap->a_vap->va_mode, ap->a_dvp,
2107 len = strlen(ap->a_target);
2108 if (len < vp->v_mount->mnt_maxsymlinklen) {
2110 bcopy(ap->a_target, SHORTLINK(ip), len);
2112 DIP_SET(ip, i_size, len);
2113 ip->i_flag |= IN_CHANGE | IN_UPDATE;
2114 error = UFS_UPDATE(vp, 0);
2116 error = vn_rdwr(UIO_WRITE, vp, ap->a_target, len, (off_t)0,
2117 UIO_SYSSPACE, IO_NODELOCKED | IO_NOMACCHECK,
2118 ap->a_cnp->cn_cred, NOCRED, NULL, NULL);
2125 * Vnode op for reading directories.
2129 struct vop_readdir_args /* {
2132 struct ucred *a_cred;
2138 struct vnode *vp = ap->a_vp;
2139 struct uio *uio = ap->a_uio;
2142 struct direct *dp, *edp;
2144 struct dirent dstdp;
2145 off_t offset, startoffset;
2146 size_t readcnt, skipcnt;
2151 if (uio->uio_offset < 0)
2154 if (ip->i_effnlink == 0)
2156 if (ap->a_ncookies != NULL) {
2157 ncookies = uio->uio_resid;
2158 if (uio->uio_offset >= ip->i_size)
2160 else if (ip->i_size - uio->uio_offset < ncookies)
2161 ncookies = ip->i_size - uio->uio_offset;
2162 ncookies = ncookies / (offsetof(struct direct, d_name) + 4) + 1;
2163 cookies = malloc(ncookies * sizeof(*cookies), M_TEMP, M_WAITOK);
2164 *ap->a_ncookies = ncookies;
2165 *ap->a_cookies = cookies;
2170 offset = startoffset = uio->uio_offset;
2171 startresid = uio->uio_resid;
2173 while (error == 0 && uio->uio_resid > 0 &&
2174 uio->uio_offset < ip->i_size) {
2175 error = ffs_blkatoff(vp, uio->uio_offset, NULL, &bp);
2178 if (bp->b_offset + bp->b_bcount > ip->i_size)
2179 readcnt = ip->i_size - bp->b_offset;
2181 readcnt = bp->b_bcount;
2182 skipcnt = (size_t)(uio->uio_offset - bp->b_offset) &
2183 ~(size_t)(DIRBLKSIZ - 1);
2184 offset = bp->b_offset + skipcnt;
2185 dp = (struct direct *)&bp->b_data[skipcnt];
2186 edp = (struct direct *)&bp->b_data[readcnt];
2187 while (error == 0 && uio->uio_resid > 0 && dp < edp) {
2188 if (dp->d_reclen <= offsetof(struct direct, d_name) ||
2189 (caddr_t)dp + dp->d_reclen > (caddr_t)edp) {
2193 #if BYTE_ORDER == LITTLE_ENDIAN
2194 /* Old filesystem format. */
2195 if (vp->v_mount->mnt_maxsymlinklen <= 0) {
2196 dstdp.d_namlen = dp->d_type;
2197 dstdp.d_type = dp->d_namlen;
2201 dstdp.d_namlen = dp->d_namlen;
2202 dstdp.d_type = dp->d_type;
2204 if (offsetof(struct direct, d_name) + dstdp.d_namlen >
2209 if (offset < startoffset || dp->d_ino == 0)
2211 dstdp.d_fileno = dp->d_ino;
2212 dstdp.d_reclen = GENERIC_DIRSIZ(&dstdp);
2213 bcopy(dp->d_name, dstdp.d_name, dstdp.d_namlen);
2214 dstdp.d_name[dstdp.d_namlen] = '\0';
2215 if (dstdp.d_reclen > uio->uio_resid) {
2216 if (uio->uio_resid == startresid)
2219 error = EJUSTRETURN;
2223 error = uiomove((caddr_t)&dstdp, dstdp.d_reclen, uio);
2226 if (cookies != NULL) {
2227 KASSERT(ncookies > 0,
2228 ("ufs_readdir: cookies buffer too small"));
2229 *cookies = offset + dp->d_reclen;
2234 offset += dp->d_reclen;
2235 dp = (struct direct *)((caddr_t)dp + dp->d_reclen);
2238 uio->uio_offset = offset;
2240 /* We need to correct uio_offset. */
2241 uio->uio_offset = offset;
2242 if (error == EJUSTRETURN)
2244 if (ap->a_ncookies != NULL) {
2246 ap->a_ncookies -= ncookies;
2248 free(*ap->a_cookies, M_TEMP);
2249 *ap->a_ncookies = 0;
2250 *ap->a_cookies = NULL;
2253 if (error == 0 && ap->a_eofflag)
2254 *ap->a_eofflag = ip->i_size <= uio->uio_offset;
2259 * Return target name of a symbolic link
2263 struct vop_readlink_args /* {
2266 struct ucred *a_cred;
2269 struct vnode *vp = ap->a_vp;
2270 struct inode *ip = VTOI(vp);
2274 if ((isize < vp->v_mount->mnt_maxsymlinklen) ||
2275 DIP(ip, i_blocks) == 0) { /* XXX - for old fastlink support */
2276 return (uiomove(SHORTLINK(ip), isize, ap->a_uio));
2278 return (VOP_READ(vp, ap->a_uio, 0, ap->a_cred));
2282 * Calculate the logical to physical mapping if not done already,
2283 * then call the device strategy routine.
2285 * In order to be able to swap to a file, the ufs_bmaparray() operation may not
2286 * deadlock on memory. See ufs_bmap() for details.
2290 struct vop_strategy_args /* {
2295 struct buf *bp = ap->a_bp;
2296 struct vnode *vp = ap->a_vp;
2303 if (bp->b_blkno == bp->b_lblkno) {
2304 error = ufs_bmaparray(vp, bp->b_lblkno, &blkno, bp, NULL, NULL);
2305 bp->b_blkno = blkno;
2307 bp->b_error = error;
2308 bp->b_ioflags |= BIO_ERROR;
2312 if ((long)bp->b_blkno == -1)
2315 if ((long)bp->b_blkno == -1) {
2319 bp->b_iooffset = dbtob(bp->b_blkno);
2320 bo = ip->i_umbufobj;
2321 BO_STRATEGY(bo, bp);
2326 * Print out the contents of an inode.
2330 struct vop_print_args /* {
2334 struct vnode *vp = ap->a_vp;
2335 struct inode *ip = VTOI(vp);
2337 printf("\tino %lu, on dev %s", (u_long)ip->i_number,
2338 devtoname(ip->i_dev));
2339 if (vp->v_type == VFIFO)
2346 * Close wrapper for fifos.
2348 * Update the times on the inode then do device close.
2352 struct vop_close_args /* {
2355 struct ucred *a_cred;
2356 struct thread *a_td;
2359 struct vnode *vp = ap->a_vp;
2363 usecount = vp->v_usecount;
2365 ufs_itimes_locked(vp);
2367 return (fifo_specops.vop_close(ap));
2371 * Kqfilter wrapper for fifos.
2373 * Fall through to ufs kqfilter routines if needed
2376 ufsfifo_kqfilter(ap)
2377 struct vop_kqfilter_args *ap;
2381 error = fifo_specops.vop_kqfilter(ap);
2383 error = vfs_kqfilter(ap);
2388 * Return POSIX pathconf information applicable to fifos.
2391 ufsfifo_pathconf(ap)
2392 struct vop_pathconf_args /* {
2399 switch (ap->a_name) {
2400 case _PC_ACL_EXTENDED:
2402 case _PC_ACL_PATH_MAX:
2403 case _PC_MAC_PRESENT:
2404 return (ufs_pathconf(ap));
2406 return (fifo_specops.vop_pathconf(ap));
2412 * Return POSIX pathconf information applicable to ufs filesystems.
2416 struct vop_pathconf_args /* {
2425 switch (ap->a_name) {
2427 *ap->a_retval = LINK_MAX;
2430 *ap->a_retval = NAME_MAX;
2433 *ap->a_retval = PATH_MAX;
2436 *ap->a_retval = PIPE_BUF;
2438 case _PC_CHOWN_RESTRICTED:
2444 case _PC_ACL_EXTENDED:
2446 if (ap->a_vp->v_mount->mnt_flag & MNT_ACLS)
2457 if (ap->a_vp->v_mount->mnt_flag & MNT_NFS4ACLS)
2466 case _PC_ACL_PATH_MAX:
2468 if (ap->a_vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS))
2469 *ap->a_retval = ACL_MAX_ENTRIES;
2476 case _PC_MAC_PRESENT:
2478 if (ap->a_vp->v_mount->mnt_flag & MNT_MULTILABEL)
2486 case _PC_MIN_HOLE_SIZE:
2487 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2490 /* _PC_ASYNC_IO should have been handled by upper layers. */
2491 KASSERT(0, ("_PC_ASYNC_IO should not get here"));
2500 case _PC_ALLOC_SIZE_MIN:
2501 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_bsize;
2503 case _PC_FILESIZEBITS:
2506 case _PC_REC_INCR_XFER_SIZE:
2507 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2509 case _PC_REC_MAX_XFER_SIZE:
2510 *ap->a_retval = -1; /* means ``unlimited'' */
2512 case _PC_REC_MIN_XFER_SIZE:
2513 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2515 case _PC_REC_XFER_ALIGN:
2516 *ap->a_retval = PAGE_SIZE;
2518 case _PC_SYMLINK_MAX:
2519 *ap->a_retval = MAXPATHLEN;
2530 * Initialize the vnode associated with a new inode, handle aliased
2534 ufs_vinit(mntp, fifoops, vpp)
2536 struct vop_vector *fifoops;
2544 vp->v_type = IFTOVT(ip->i_mode);
2545 if (vp->v_type == VFIFO)
2547 ASSERT_VOP_LOCKED(vp, "ufs_vinit");
2548 if (ip->i_number == ROOTINO)
2549 vp->v_vflag |= VV_ROOT;
2555 * Allocate a new inode.
2556 * Vnode dvp must be locked.
2559 ufs_makeinode(mode, dvp, vpp, cnp)
2563 struct componentname *cnp;
2565 struct inode *ip, *pdir;
2566 struct direct newdir;
2572 if ((cnp->cn_flags & HASBUF) == 0)
2573 panic("ufs_makeinode: no name");
2576 if ((mode & IFMT) == 0)
2579 if (VTOI(dvp)->i_effnlink < 2)
2580 panic("ufs_makeinode: Bad link count %d on parent",
2581 VTOI(dvp)->i_effnlink);
2582 error = UFS_VALLOC(dvp, mode, cnp->cn_cred, &tvp);
2586 ip->i_gid = pdir->i_gid;
2587 DIP_SET(ip, i_gid, pdir->i_gid);
2591 struct ucred ucred, *ucp;
2596 * If we are not the owner of the directory,
2597 * and we are hacking owners here, (only do this where told to)
2598 * and we are not giving it TO root, (would subvert quotas)
2599 * then go ahead and give it to the other user.
2600 * Note that this drops off the execute bits for security.
2602 if ((dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
2603 (pdir->i_mode & ISUID) &&
2604 (pdir->i_uid != cnp->cn_cred->cr_uid) && pdir->i_uid) {
2605 ip->i_uid = pdir->i_uid;
2606 DIP_SET(ip, i_uid, ip->i_uid);
2610 * Make sure the correct user gets charged
2612 * Quickly knock up a dummy credential for the victim.
2613 * XXX This seems to never be accessed out of our
2614 * context so a stack variable is ok.
2616 refcount_init(&ucred.cr_ref, 1);
2617 ucred.cr_uid = ip->i_uid;
2618 ucred.cr_ngroups = 1;
2619 ucred.cr_groups = &ucred_group;
2620 ucred.cr_groups[0] = pdir->i_gid;
2624 ip->i_uid = cnp->cn_cred->cr_uid;
2625 DIP_SET(ip, i_uid, ip->i_uid);
2629 if ((error = getinoquota(ip)) ||
2630 (error = chkiq(ip, 1, ucp, 0))) {
2631 if (DOINGSOFTDEP(tvp))
2632 softdep_revert_link(pdir, ip);
2633 UFS_VFREE(tvp, ip->i_number, mode);
2639 #else /* !SUIDDIR */
2640 ip->i_uid = cnp->cn_cred->cr_uid;
2641 DIP_SET(ip, i_uid, ip->i_uid);
2643 if ((error = getinoquota(ip)) ||
2644 (error = chkiq(ip, 1, cnp->cn_cred, 0))) {
2645 if (DOINGSOFTDEP(tvp))
2646 softdep_revert_link(pdir, ip);
2647 UFS_VFREE(tvp, ip->i_number, mode);
2652 #endif /* !SUIDDIR */
2653 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
2655 DIP_SET(ip, i_mode, mode);
2656 tvp->v_type = IFTOVT(mode); /* Rest init'd in getnewvnode(). */
2659 DIP_SET(ip, i_nlink, 1);
2660 if (DOINGSOFTDEP(tvp))
2661 softdep_setup_create(VTOI(dvp), ip);
2662 if ((ip->i_mode & ISGID) && !groupmember(ip->i_gid, cnp->cn_cred) &&
2663 priv_check_cred(cnp->cn_cred, PRIV_VFS_SETGID, 0)) {
2664 ip->i_mode &= ~ISGID;
2665 DIP_SET(ip, i_mode, ip->i_mode);
2668 if (cnp->cn_flags & ISWHITEOUT) {
2669 ip->i_flags |= UF_OPAQUE;
2670 DIP_SET(ip, i_flags, ip->i_flags);
2674 * Make sure inode goes to disk before directory entry.
2676 error = UFS_UPDATE(tvp, !(DOINGSOFTDEP(tvp) | DOINGASYNC(tvp)));
2680 if (dvp->v_mount->mnt_flag & MNT_MULTILABEL) {
2681 error = mac_vnode_create_extattr(cnp->cn_cred, dvp->v_mount,
2688 if (dvp->v_mount->mnt_flag & MNT_ACLS) {
2689 error = ufs_do_posix1e_acl_inheritance_file(dvp, tvp, mode,
2690 cnp->cn_cred, cnp->cn_thread);
2693 } else if (dvp->v_mount->mnt_flag & MNT_NFS4ACLS) {
2694 error = ufs_do_nfs4_acl_inheritance(dvp, tvp, mode,
2695 cnp->cn_cred, cnp->cn_thread);
2699 #endif /* !UFS_ACL */
2700 ufs_makedirentry(ip, cnp, &newdir);
2701 error = ufs_direnter(dvp, tvp, &newdir, cnp, NULL, 0);
2709 * Write error occurred trying to update the inode
2710 * or the directory so must deallocate the inode.
2714 DIP_SET(ip, i_nlink, 0);
2715 ip->i_flag |= IN_CHANGE;
2716 if (DOINGSOFTDEP(tvp))
2717 softdep_revert_create(VTOI(dvp), ip);
2723 ufs_ioctl(struct vop_ioctl_args *ap)
2726 switch (ap->a_command) {
2729 return (vn_bmap_seekhole(ap->a_vp, ap->a_command,
2730 (off_t *)ap->a_data, ap->a_cred));
2736 /* Global vfs data structures for ufs. */
2737 struct vop_vector ufs_vnodeops = {
2738 .vop_default = &default_vnodeops,
2739 .vop_fsync = VOP_PANIC,
2740 .vop_read = VOP_PANIC,
2741 .vop_reallocblks = VOP_PANIC,
2742 .vop_write = VOP_PANIC,
2743 .vop_accessx = ufs_accessx,
2744 .vop_bmap = ufs_bmap,
2745 .vop_cachedlookup = ufs_lookup,
2746 .vop_close = ufs_close,
2747 .vop_create = ufs_create,
2748 .vop_getattr = ufs_getattr,
2749 .vop_inactive = ufs_inactive,
2750 .vop_ioctl = ufs_ioctl,
2751 .vop_link = ufs_link,
2752 .vop_lookup = vfs_cache_lookup,
2753 .vop_markatime = ufs_markatime,
2754 .vop_mkdir = ufs_mkdir,
2755 .vop_mknod = ufs_mknod,
2756 .vop_open = ufs_open,
2757 .vop_pathconf = ufs_pathconf,
2758 .vop_poll = vop_stdpoll,
2759 .vop_print = ufs_print,
2760 .vop_readdir = ufs_readdir,
2761 .vop_readlink = ufs_readlink,
2762 .vop_reclaim = ufs_reclaim,
2763 .vop_remove = ufs_remove,
2764 .vop_rename = ufs_rename,
2765 .vop_rmdir = ufs_rmdir,
2766 .vop_setattr = ufs_setattr,
2768 .vop_setlabel = vop_stdsetlabel_ea,
2770 .vop_strategy = ufs_strategy,
2771 .vop_symlink = ufs_symlink,
2772 .vop_whiteout = ufs_whiteout,
2774 .vop_getextattr = ufs_getextattr,
2775 .vop_deleteextattr = ufs_deleteextattr,
2776 .vop_setextattr = ufs_setextattr,
2779 .vop_getacl = ufs_getacl,
2780 .vop_setacl = ufs_setacl,
2781 .vop_aclcheck = ufs_aclcheck,
2785 struct vop_vector ufs_fifoops = {
2786 .vop_default = &fifo_specops,
2787 .vop_fsync = VOP_PANIC,
2788 .vop_accessx = ufs_accessx,
2789 .vop_close = ufsfifo_close,
2790 .vop_getattr = ufs_getattr,
2791 .vop_inactive = ufs_inactive,
2792 .vop_kqfilter = ufsfifo_kqfilter,
2793 .vop_markatime = ufs_markatime,
2794 .vop_pathconf = ufsfifo_pathconf,
2795 .vop_print = ufs_print,
2796 .vop_read = VOP_PANIC,
2797 .vop_reclaim = ufs_reclaim,
2798 .vop_setattr = ufs_setattr,
2800 .vop_setlabel = vop_stdsetlabel_ea,
2802 .vop_write = VOP_PANIC,
2804 .vop_getextattr = ufs_getextattr,
2805 .vop_deleteextattr = ufs_deleteextattr,
2806 .vop_setextattr = ufs_setextattr,
2809 .vop_getacl = ufs_getacl,
2810 .vop_setacl = ufs_setacl,
2811 .vop_aclcheck = ufs_aclcheck,