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 * permits the owner of the file to remove the IMMUTABLE flag.
387 if ((accmode & (VMODIFY_PERMS & ~VADMIN_PERMS)) &&
388 (ip->i_flags & (IMMUTABLE | SF_SNAPSHOT)))
392 if ((vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS)) != 0) {
393 if (vp->v_mount->mnt_flag & MNT_NFS4ACLS)
394 type = ACL_TYPE_NFS4;
396 type = ACL_TYPE_ACCESS;
398 acl = acl_alloc(M_WAITOK);
399 if (type == ACL_TYPE_NFS4)
400 error = ufs_getacl_nfs4_internal(vp, acl, ap->a_td);
402 error = VOP_GETACL(vp, type, acl, ap->a_cred, ap->a_td);
405 if (type == ACL_TYPE_NFS4) {
406 error = vaccess_acl_nfs4(vp->v_type, ip->i_uid,
407 ip->i_gid, acl, accmode, ap->a_cred, NULL);
409 error = vfs_unixify_accmode(&accmode);
411 error = vaccess_acl_posix1e(vp->v_type, ip->i_uid,
412 ip->i_gid, acl, accmode, ap->a_cred, NULL);
416 if (error != EOPNOTSUPP)
418 "ufs_accessx(): Error retrieving ACL on object (%d).\n",
421 * XXX: Fall back until debugged. Should
422 * eventually possibly log an error, and return
425 error = vfs_unixify_accmode(&accmode);
427 error = vaccess(vp->v_type, ip->i_mode, ip->i_uid,
428 ip->i_gid, accmode, ap->a_cred, NULL);
434 #endif /* !UFS_ACL */
435 error = vfs_unixify_accmode(&accmode);
437 error = vaccess(vp->v_type, ip->i_mode, ip->i_uid, ip->i_gid,
438 accmode, ap->a_cred, NULL);
445 struct vop_getattr_args /* {
448 struct ucred *a_cred;
451 struct vnode *vp = ap->a_vp;
452 struct inode *ip = VTOI(vp);
453 struct vattr *vap = ap->a_vap;
456 ufs_itimes_locked(vp);
457 if (ip->i_ump->um_fstype == UFS1) {
458 vap->va_atime.tv_sec = ip->i_din1->di_atime;
459 vap->va_atime.tv_nsec = ip->i_din1->di_atimensec;
461 vap->va_atime.tv_sec = ip->i_din2->di_atime;
462 vap->va_atime.tv_nsec = ip->i_din2->di_atimensec;
466 * Copy from inode table
468 vap->va_fsid = dev2udev(ip->i_dev);
469 vap->va_fileid = ip->i_number;
470 vap->va_mode = ip->i_mode & ~IFMT;
471 vap->va_nlink = ip->i_effnlink;
472 vap->va_uid = ip->i_uid;
473 vap->va_gid = ip->i_gid;
474 if (ip->i_ump->um_fstype == UFS1) {
475 vap->va_rdev = ip->i_din1->di_rdev;
476 vap->va_size = ip->i_din1->di_size;
477 vap->va_mtime.tv_sec = ip->i_din1->di_mtime;
478 vap->va_mtime.tv_nsec = ip->i_din1->di_mtimensec;
479 vap->va_ctime.tv_sec = ip->i_din1->di_ctime;
480 vap->va_ctime.tv_nsec = ip->i_din1->di_ctimensec;
481 vap->va_bytes = dbtob((u_quad_t)ip->i_din1->di_blocks);
482 vap->va_filerev = ip->i_din1->di_modrev;
484 vap->va_rdev = ip->i_din2->di_rdev;
485 vap->va_size = ip->i_din2->di_size;
486 vap->va_mtime.tv_sec = ip->i_din2->di_mtime;
487 vap->va_mtime.tv_nsec = ip->i_din2->di_mtimensec;
488 vap->va_ctime.tv_sec = ip->i_din2->di_ctime;
489 vap->va_ctime.tv_nsec = ip->i_din2->di_ctimensec;
490 vap->va_birthtime.tv_sec = ip->i_din2->di_birthtime;
491 vap->va_birthtime.tv_nsec = ip->i_din2->di_birthnsec;
492 vap->va_bytes = dbtob((u_quad_t)ip->i_din2->di_blocks);
493 vap->va_filerev = ip->i_din2->di_modrev;
495 vap->va_flags = ip->i_flags;
496 vap->va_gen = ip->i_gen;
497 vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
498 vap->va_type = IFTOVT(ip->i_mode);
503 * Set attribute vnode op. called from several syscalls
507 struct vop_setattr_args /* {
510 struct ucred *a_cred;
513 struct vattr *vap = ap->a_vap;
514 struct vnode *vp = ap->a_vp;
515 struct inode *ip = VTOI(vp);
516 struct ucred *cred = ap->a_cred;
517 struct thread *td = curthread;
521 * Check for unsettable attributes.
523 if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
524 (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
525 (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
526 ((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
529 if (vap->va_flags != VNOVAL) {
530 if ((vap->va_flags & ~(SF_APPEND | SF_ARCHIVED | SF_IMMUTABLE |
531 SF_NOUNLINK | SF_SNAPSHOT | UF_APPEND | UF_ARCHIVE |
532 UF_HIDDEN | UF_IMMUTABLE | UF_NODUMP | UF_NOUNLINK |
533 UF_OFFLINE | UF_OPAQUE | UF_READONLY | UF_REPARSE |
534 UF_SPARSE | UF_SYSTEM)) != 0)
536 if (vp->v_mount->mnt_flag & MNT_RDONLY)
539 * Callers may only modify the file flags on objects they
540 * have VADMIN rights for.
542 if ((error = VOP_ACCESS(vp, VADMIN, cred, td)))
545 * Unprivileged processes are not permitted to unset system
546 * flags, or modify flags if any system flags are set.
547 * Privileged non-jail processes may not modify system flags
548 * if securelevel > 0 and any existing system flags are set.
549 * Privileged jail processes behave like privileged non-jail
550 * processes if the security.jail.chflags_allowed sysctl is
551 * is non-zero; otherwise, they behave like unprivileged
554 if (!priv_check_cred(cred, PRIV_VFS_SYSFLAGS, 0)) {
556 (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND)) {
557 error = securelevel_gt(cred, 0);
561 /* The snapshot flag cannot be toggled. */
562 if ((vap->va_flags ^ ip->i_flags) & SF_SNAPSHOT)
566 (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND) ||
567 ((vap->va_flags ^ ip->i_flags) & SF_SETTABLE))
570 ip->i_flags = vap->va_flags;
571 DIP_SET(ip, i_flags, vap->va_flags);
572 ip->i_flag |= IN_CHANGE;
573 error = UFS_UPDATE(vp, 0);
574 if (ip->i_flags & (IMMUTABLE | APPEND))
578 * If immutable or append, no one can change any of its attributes
579 * except the ones already handled (in some cases, file flags
580 * including the immutability flags themselves for the superuser).
582 if (ip->i_flags & (IMMUTABLE | APPEND))
585 * Go through the fields and update iff not VNOVAL.
587 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
588 if (vp->v_mount->mnt_flag & MNT_RDONLY)
590 if ((error = ufs_chown(vp, vap->va_uid, vap->va_gid, cred,
594 if (vap->va_size != VNOVAL) {
596 * XXX most of the following special cases should be in
597 * callers instead of in N filesystems. The VDIR check
600 switch (vp->v_type) {
606 * Truncation should have an effect in these cases.
607 * Disallow it if the filesystem is read-only or
608 * the file is being snapshotted.
610 if (vp->v_mount->mnt_flag & MNT_RDONLY)
612 if ((ip->i_flags & SF_SNAPSHOT) != 0)
617 * According to POSIX, the result is unspecified
618 * for file types other than regular files,
619 * directories and shared memory objects. We
620 * don't support shared memory objects in the file
621 * system, and have dubious support for truncating
622 * symlinks. Just ignore the request in other cases.
626 if ((error = UFS_TRUNCATE(vp, vap->va_size, IO_NORMAL,
630 if (vap->va_atime.tv_sec != VNOVAL ||
631 vap->va_mtime.tv_sec != VNOVAL ||
632 vap->va_birthtime.tv_sec != VNOVAL) {
633 if (vp->v_mount->mnt_flag & MNT_RDONLY)
635 if ((ip->i_flags & SF_SNAPSHOT) != 0)
637 error = vn_utimes_perm(vp, vap, cred, td);
640 if (vap->va_atime.tv_sec != VNOVAL)
641 ip->i_flag |= IN_ACCESS;
642 if (vap->va_mtime.tv_sec != VNOVAL)
643 ip->i_flag |= IN_CHANGE | IN_UPDATE;
644 if (vap->va_birthtime.tv_sec != VNOVAL &&
645 ip->i_ump->um_fstype == UFS2)
646 ip->i_flag |= IN_MODIFIED;
648 if (vap->va_atime.tv_sec != VNOVAL) {
649 DIP_SET(ip, i_atime, vap->va_atime.tv_sec);
650 DIP_SET(ip, i_atimensec, vap->va_atime.tv_nsec);
652 if (vap->va_mtime.tv_sec != VNOVAL) {
653 DIP_SET(ip, i_mtime, vap->va_mtime.tv_sec);
654 DIP_SET(ip, i_mtimensec, vap->va_mtime.tv_nsec);
656 if (vap->va_birthtime.tv_sec != VNOVAL &&
657 ip->i_ump->um_fstype == UFS2) {
658 ip->i_din2->di_birthtime = vap->va_birthtime.tv_sec;
659 ip->i_din2->di_birthnsec = vap->va_birthtime.tv_nsec;
661 error = UFS_UPDATE(vp, 0);
666 if (vap->va_mode != (mode_t)VNOVAL) {
667 if (vp->v_mount->mnt_flag & MNT_RDONLY)
669 if ((ip->i_flags & SF_SNAPSHOT) != 0 && (vap->va_mode &
670 (S_IXUSR | S_IWUSR | S_IXGRP | S_IWGRP | S_IXOTH | S_IWOTH)))
672 error = ufs_chmod(vp, (int)vap->va_mode, cred, td);
679 ufs_update_nfs4_acl_after_mode_change(struct vnode *vp, int mode,
680 int file_owner_id, struct ucred *cred, struct thread *td)
685 aclp = acl_alloc(M_WAITOK);
686 error = ufs_getacl_nfs4_internal(vp, aclp, td);
688 * We don't have to handle EOPNOTSUPP here, as the filesystem claims
694 acl_nfs4_sync_acl_from_mode(aclp, mode, file_owner_id);
695 error = ufs_setacl_nfs4_internal(vp, aclp, td);
704 * Mark this file's access time for update for vfs_mark_atime(). This
705 * is called from execve() and mmap().
709 struct vop_markatime_args /* {
713 struct vnode *vp = ap->a_vp;
714 struct inode *ip = VTOI(vp);
717 ip->i_flag |= IN_ACCESS;
720 * XXXKIB No UFS_UPDATE(ap->a_vp, 0) there.
726 * Change the mode on a file.
727 * Inode must be locked before calling.
730 ufs_chmod(vp, mode, cred, td)
736 struct inode *ip = VTOI(vp);
740 * To modify the permissions on a file, must possess VADMIN
743 if ((error = VOP_ACCESSX(vp, VWRITE_ACL, cred, td)))
746 * Privileged processes may set the sticky bit on non-directories,
747 * as well as set the setgid bit on a file with a group that the
748 * process is not a member of. Both of these are allowed in
751 if (vp->v_type != VDIR && (mode & S_ISTXT)) {
752 if (priv_check_cred(cred, PRIV_VFS_STICKYFILE, 0))
755 if (!groupmember(ip->i_gid, cred) && (mode & ISGID)) {
756 error = priv_check_cred(cred, PRIV_VFS_SETGID, 0);
762 * Deny setting setuid if we are not the file owner.
764 if ((mode & ISUID) && ip->i_uid != cred->cr_uid) {
765 error = priv_check_cred(cred, PRIV_VFS_ADMIN, 0);
770 ip->i_mode &= ~ALLPERMS;
771 ip->i_mode |= (mode & ALLPERMS);
772 DIP_SET(ip, i_mode, ip->i_mode);
773 ip->i_flag |= IN_CHANGE;
775 if ((vp->v_mount->mnt_flag & MNT_NFS4ACLS) != 0)
776 error = ufs_update_nfs4_acl_after_mode_change(vp, mode, ip->i_uid, cred, td);
778 if (error == 0 && (ip->i_flag & IN_CHANGE) != 0)
779 error = UFS_UPDATE(vp, 0);
785 * Perform chown operation on inode ip;
786 * inode must be locked prior to call.
789 ufs_chown(vp, uid, gid, cred, td)
796 struct inode *ip = VTOI(vp);
805 if (uid == (uid_t)VNOVAL)
807 if (gid == (gid_t)VNOVAL)
810 * To modify the ownership of a file, must possess VADMIN for that
813 if ((error = VOP_ACCESSX(vp, VWRITE_OWNER, cred, td)))
816 * To change the owner of a file, or change the group of a file to a
817 * group of which we are not a member, the caller must have
820 if (((uid != ip->i_uid && uid != cred->cr_uid) ||
821 (gid != ip->i_gid && !groupmember(gid, cred))) &&
822 (error = priv_check_cred(cred, PRIV_VFS_CHOWN, 0)))
827 if ((error = getinoquota(ip)) != 0)
830 dqrele(vp, ip->i_dquot[USRQUOTA]);
831 ip->i_dquot[USRQUOTA] = NODQUOT;
834 dqrele(vp, ip->i_dquot[GRPQUOTA]);
835 ip->i_dquot[GRPQUOTA] = NODQUOT;
837 change = DIP(ip, i_blocks);
838 (void) chkdq(ip, -change, cred, CHOWN);
839 (void) chkiq(ip, -1, cred, CHOWN);
840 for (i = 0; i < MAXQUOTAS; i++) {
841 dqrele(vp, ip->i_dquot[i]);
842 ip->i_dquot[i] = NODQUOT;
846 DIP_SET(ip, i_gid, gid);
848 DIP_SET(ip, i_uid, uid);
850 if ((error = getinoquota(ip)) == 0) {
852 dqrele(vp, ip->i_dquot[USRQUOTA]);
853 ip->i_dquot[USRQUOTA] = NODQUOT;
856 dqrele(vp, ip->i_dquot[GRPQUOTA]);
857 ip->i_dquot[GRPQUOTA] = NODQUOT;
859 if ((error = chkdq(ip, change, cred, CHOWN)) == 0) {
860 if ((error = chkiq(ip, 1, cred, CHOWN)) == 0)
863 (void) chkdq(ip, -change, cred, CHOWN|FORCE);
865 for (i = 0; i < MAXQUOTAS; i++) {
866 dqrele(vp, ip->i_dquot[i]);
867 ip->i_dquot[i] = NODQUOT;
871 DIP_SET(ip, i_gid, ogid);
873 DIP_SET(ip, i_uid, ouid);
874 if (getinoquota(ip) == 0) {
876 dqrele(vp, ip->i_dquot[USRQUOTA]);
877 ip->i_dquot[USRQUOTA] = NODQUOT;
880 dqrele(vp, ip->i_dquot[GRPQUOTA]);
881 ip->i_dquot[GRPQUOTA] = NODQUOT;
883 (void) chkdq(ip, change, cred, FORCE|CHOWN);
884 (void) chkiq(ip, 1, cred, FORCE|CHOWN);
885 (void) getinoquota(ip);
890 panic("ufs_chown: lost quota");
892 ip->i_flag |= IN_CHANGE;
893 if ((ip->i_mode & (ISUID | ISGID)) && (ouid != uid || ogid != gid)) {
894 if (priv_check_cred(cred, PRIV_VFS_RETAINSUGID, 0)) {
895 ip->i_mode &= ~(ISUID | ISGID);
896 DIP_SET(ip, i_mode, ip->i_mode);
899 error = UFS_UPDATE(vp, 0);
905 struct vop_remove_args /* {
908 struct componentname *a_cnp;
912 struct vnode *vp = ap->a_vp;
913 struct vnode *dvp = ap->a_dvp;
919 if ((ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
920 (VTOI(dvp)->i_flags & APPEND)) {
925 ufs_gjournal_orphan(vp);
927 error = ufs_dirremove(dvp, ip, ap->a_cnp->cn_flags, 0);
928 if (ip->i_nlink <= 0)
929 vp->v_vflag |= VV_NOSYNC;
930 if ((ip->i_flags & SF_SNAPSHOT) != 0) {
932 * Avoid deadlock where another thread is trying to
933 * update the inodeblock for dvp and is waiting on
934 * snaplk. Temporary unlock the vnode lock for the
935 * unlinked file and sync the directory. This should
936 * allow vput() of the directory to not block later on
937 * while holding the snapshot vnode locked, assuming
938 * that the directory hasn't been unlinked too.
941 (void) VOP_FSYNC(dvp, MNT_WAIT, td);
942 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
953 struct vop_link_args /* {
954 struct vnode *a_tdvp;
956 struct componentname *a_cnp;
959 struct vnode *vp = ap->a_vp;
960 struct vnode *tdvp = ap->a_tdvp;
961 struct componentname *cnp = ap->a_cnp;
963 struct direct newdir;
967 if ((cnp->cn_flags & HASBUF) == 0)
968 panic("ufs_link: no name");
970 if (VTOI(tdvp)->i_effnlink < 2)
971 panic("ufs_link: Bad link count %d on parent",
972 VTOI(tdvp)->i_effnlink);
974 if ((nlink_t)ip->i_nlink >= LINK_MAX) {
979 * The file may have been removed after namei droped the original
982 if (ip->i_effnlink == 0) {
986 if (ip->i_flags & (IMMUTABLE | APPEND)) {
992 DIP_SET(ip, i_nlink, ip->i_nlink);
993 ip->i_flag |= IN_CHANGE;
994 if (DOINGSOFTDEP(vp))
995 softdep_setup_link(VTOI(tdvp), ip);
996 error = UFS_UPDATE(vp, !(DOINGSOFTDEP(vp) | DOINGASYNC(vp)));
998 ufs_makedirentry(ip, cnp, &newdir);
999 error = ufs_direnter(tdvp, vp, &newdir, cnp, NULL, 0);
1005 DIP_SET(ip, i_nlink, ip->i_nlink);
1006 ip->i_flag |= IN_CHANGE;
1007 if (DOINGSOFTDEP(vp))
1008 softdep_revert_link(VTOI(tdvp), ip);
1015 * whiteout vnode call
1019 struct vop_whiteout_args /* {
1020 struct vnode *a_dvp;
1021 struct componentname *a_cnp;
1025 struct vnode *dvp = ap->a_dvp;
1026 struct componentname *cnp = ap->a_cnp;
1027 struct direct newdir;
1030 switch (ap->a_flags) {
1032 /* 4.4 format directories support whiteout operations */
1033 if (dvp->v_mount->mnt_maxsymlinklen > 0)
1035 return (EOPNOTSUPP);
1038 /* create a new directory whiteout */
1040 if ((cnp->cn_flags & SAVENAME) == 0)
1041 panic("ufs_whiteout: missing name");
1042 if (dvp->v_mount->mnt_maxsymlinklen <= 0)
1043 panic("ufs_whiteout: old format filesystem");
1046 newdir.d_ino = WINO;
1047 newdir.d_namlen = cnp->cn_namelen;
1048 bcopy(cnp->cn_nameptr, newdir.d_name, (unsigned)cnp->cn_namelen + 1);
1049 newdir.d_type = DT_WHT;
1050 error = ufs_direnter(dvp, NULL, &newdir, cnp, NULL, 0);
1054 /* remove an existing directory whiteout */
1056 if (dvp->v_mount->mnt_maxsymlinklen <= 0)
1057 panic("ufs_whiteout: old format filesystem");
1060 cnp->cn_flags &= ~DOWHITEOUT;
1061 error = ufs_dirremove(dvp, NULL, cnp->cn_flags, 0);
1064 panic("ufs_whiteout: unknown op");
1069 static volatile int rename_restarts;
1070 SYSCTL_INT(_vfs_ufs, OID_AUTO, rename_restarts, CTLFLAG_RD,
1071 __DEVOLATILE(int *, &rename_restarts), 0,
1072 "Times rename had to restart due to lock contention");
1075 * Rename system call.
1076 * rename("foo", "bar");
1079 * link("foo", "bar");
1081 * but ``atomically''. Can't do full commit without saving state in the
1082 * inode on disk which isn't feasible at this time. Best we can do is
1083 * always guarantee the target exists.
1085 * Basic algorithm is:
1087 * 1) Bump link count on source while we're linking it to the
1088 * target. This also ensure the inode won't be deleted out
1089 * from underneath us while we work (it may be truncated by
1090 * a concurrent `trunc' or `open' for creation).
1091 * 2) Link source to destination. If destination already exists,
1093 * 3) Unlink source reference to inode if still around. If a
1094 * directory was moved and the parent of the destination
1095 * is different from the source, patch the ".." entry in the
1100 struct vop_rename_args /* {
1101 struct vnode *a_fdvp;
1102 struct vnode *a_fvp;
1103 struct componentname *a_fcnp;
1104 struct vnode *a_tdvp;
1105 struct vnode *a_tvp;
1106 struct componentname *a_tcnp;
1109 struct vnode *tvp = ap->a_tvp;
1110 struct vnode *tdvp = ap->a_tdvp;
1111 struct vnode *fvp = ap->a_fvp;
1112 struct vnode *fdvp = ap->a_fdvp;
1114 struct componentname *tcnp = ap->a_tcnp;
1115 struct componentname *fcnp = ap->a_fcnp;
1116 struct thread *td = fcnp->cn_thread;
1117 struct inode *fip, *tip, *tdp, *fdp;
1118 struct direct newdir;
1120 int doingdirectory, newparent;
1126 if ((tcnp->cn_flags & HASBUF) == 0 ||
1127 (fcnp->cn_flags & HASBUF) == 0)
1128 panic("ufs_rename: no name");
1132 VOP_UNLOCK(tdvp, 0);
1133 if (tvp && tvp != tdvp)
1136 * Check for cross-device rename.
1138 if ((fvp->v_mount != tdvp->v_mount) ||
1139 (tvp && (fvp->v_mount != tvp->v_mount))) {
1146 * We need to acquire 2 to 4 locks depending on whether tvp is NULL
1147 * and fdvp and tdvp are the same directory. Subsequently we need
1148 * to double-check all paths and in the directory rename case we
1149 * need to verify that we are not creating a directory loop. To
1150 * handle this we acquire all but fdvp using non-blocking
1151 * acquisitions. If we fail to acquire any lock in the path we will
1152 * drop all held locks, acquire the new lock in a blocking fashion,
1153 * and then release it and restart the rename. This acquire/release
1154 * step ensures that we do not spin on a lock waiting for release.
1156 error = vn_lock(fdvp, LK_EXCLUSIVE);
1159 if (vn_lock(tdvp, LK_EXCLUSIVE | LK_NOWAIT) != 0) {
1160 VOP_UNLOCK(fdvp, 0);
1161 error = vn_lock(tdvp, LK_EXCLUSIVE);
1164 VOP_UNLOCK(tdvp, 0);
1165 atomic_add_int(&rename_restarts, 1);
1169 * Re-resolve fvp to be certain it still exists and fetch the
1172 error = ufs_lookup_ino(fdvp, NULL, fcnp, &ino);
1174 VOP_UNLOCK(fdvp, 0);
1175 VOP_UNLOCK(tdvp, 0);
1178 error = VFS_VGET(mp, ino, LK_EXCLUSIVE | LK_NOWAIT, &nvp);
1180 VOP_UNLOCK(fdvp, 0);
1181 VOP_UNLOCK(tdvp, 0);
1184 error = VFS_VGET(mp, ino, LK_EXCLUSIVE, &nvp);
1190 atomic_add_int(&rename_restarts, 1);
1196 * Re-resolve tvp and acquire the vnode lock if present.
1198 error = ufs_lookup_ino(tdvp, NULL, tcnp, &ino);
1199 if (error != 0 && error != EJUSTRETURN) {
1200 VOP_UNLOCK(fdvp, 0);
1201 VOP_UNLOCK(tdvp, 0);
1206 * If tvp disappeared we just carry on.
1208 if (error == EJUSTRETURN && tvp != NULL) {
1213 * Get the tvp ino if the lookup succeeded. We may have to restart
1214 * if the non-blocking acquire fails.
1218 error = VFS_VGET(mp, ino, LK_EXCLUSIVE | LK_NOWAIT, &nvp);
1223 VOP_UNLOCK(fdvp, 0);
1224 VOP_UNLOCK(tdvp, 0);
1228 error = VFS_VGET(mp, ino, LK_EXCLUSIVE, &nvp);
1232 atomic_add_int(&rename_restarts, 1);
1242 if (tvp && ((VTOI(tvp)->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
1243 (VTOI(tdvp)->i_flags & APPEND))) {
1248 * Renaming a file to itself has no effect. The upper layers should
1249 * not call us in that case. However, things could change after
1250 * we drop the locks above.
1258 ino = fip->i_number;
1259 if (fip->i_nlink >= LINK_MAX) {
1263 if ((fip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))
1264 || (fdp->i_flags & APPEND)) {
1268 if ((fip->i_mode & IFMT) == IFDIR) {
1270 * Avoid ".", "..", and aliases of "." for obvious reasons.
1272 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
1274 (fcnp->cn_flags | tcnp->cn_flags) & ISDOTDOT) {
1278 if (fdp->i_number != tdp->i_number)
1279 newparent = tdp->i_number;
1282 if ((fvp->v_type == VDIR && fvp->v_mountedhere != NULL) ||
1283 (tvp != NULL && tvp->v_type == VDIR &&
1284 tvp->v_mountedhere != NULL)) {
1290 * If ".." must be changed (ie the directory gets a new
1291 * parent) then the source directory must not be in the
1292 * directory hierarchy above the target, as this would
1293 * orphan everything below the source directory. Also
1294 * the user must have write permission in the source so
1295 * as to be able to change "..".
1297 if (doingdirectory && newparent) {
1298 error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_thread);
1301 error = ufs_checkpath(ino, fdp->i_number, tdp, tcnp->cn_cred,
1304 * We encountered a lock that we have to wait for. Unlock
1305 * everything else and VGET before restarting.
1308 VOP_UNLOCK(fdvp, 0);
1310 VOP_UNLOCK(tdvp, 0);
1313 error = VFS_VGET(mp, ino, LK_SHARED, &nvp);
1316 atomic_add_int(&rename_restarts, 1);
1321 if ((tcnp->cn_flags & SAVESTART) == 0)
1322 panic("ufs_rename: lost to startdir");
1324 if (fip->i_effnlink == 0 || fdp->i_effnlink == 0 ||
1325 tdp->i_effnlink == 0)
1326 panic("Bad effnlink fip %p, fdp %p, tdp %p", fip, fdp, tdp);
1329 * 1) Bump link count while we're moving stuff
1330 * around. If we crash somewhere before
1331 * completing our work, the link count
1332 * may be wrong, but correctable.
1336 DIP_SET(fip, i_nlink, fip->i_nlink);
1337 fip->i_flag |= IN_CHANGE;
1338 if (DOINGSOFTDEP(fvp))
1339 softdep_setup_link(tdp, fip);
1340 error = UFS_UPDATE(fvp, !(DOINGSOFTDEP(fvp) | DOINGASYNC(fvp)));
1345 * 2) If target doesn't exist, link the target
1346 * to the source and unlink the source.
1347 * Otherwise, rewrite the target directory
1348 * entry to reference the source inode and
1349 * expunge the original entry's existence.
1352 if (tdp->i_dev != fip->i_dev)
1353 panic("ufs_rename: EXDEV");
1354 if (doingdirectory && newparent) {
1356 * Account for ".." in new directory.
1357 * When source and destination have the same
1358 * parent we don't adjust the link count. The
1359 * actual link modification is completed when
1360 * .. is rewritten below.
1362 if ((nlink_t)tdp->i_nlink >= LINK_MAX) {
1367 ufs_makedirentry(fip, tcnp, &newdir);
1368 error = ufs_direnter(tdvp, NULL, &newdir, tcnp, NULL, 1);
1371 /* Setup tdvp for directory compaction if needed. */
1372 if (tdp->i_count && tdp->i_endoff &&
1373 tdp->i_endoff < tdp->i_size)
1374 endoff = tdp->i_endoff;
1376 if (tip->i_dev != tdp->i_dev || tip->i_dev != fip->i_dev)
1377 panic("ufs_rename: EXDEV");
1379 * Short circuit rename(foo, foo).
1381 if (tip->i_number == fip->i_number)
1382 panic("ufs_rename: same file");
1384 * If the parent directory is "sticky", then the caller
1385 * must possess VADMIN for the parent directory, or the
1386 * destination of the rename. This implements append-only
1389 if ((tdp->i_mode & S_ISTXT) &&
1390 VOP_ACCESS(tdvp, VADMIN, tcnp->cn_cred, td) &&
1391 VOP_ACCESS(tvp, VADMIN, tcnp->cn_cred, td)) {
1396 * Target must be empty if a directory and have no links
1397 * to it. Also, ensure source and target are compatible
1398 * (both directories, or both not directories).
1400 if ((tip->i_mode & IFMT) == IFDIR) {
1401 if ((tip->i_effnlink > 2) ||
1402 !ufs_dirempty(tip, tdp->i_number, tcnp->cn_cred)) {
1406 if (!doingdirectory) {
1411 } else if (doingdirectory) {
1415 if (doingdirectory) {
1418 if (DOINGSOFTDEP(tdvp))
1419 softdep_change_linkcnt(tdp);
1422 if (DOINGSOFTDEP(tvp))
1423 softdep_change_linkcnt(tip);
1425 error = ufs_dirrewrite(tdp, tip, fip->i_number,
1426 IFTODT(fip->i_mode),
1427 (doingdirectory && newparent) ? newparent : doingdirectory);
1429 if (doingdirectory) {
1432 if (DOINGSOFTDEP(tdvp))
1433 softdep_change_linkcnt(tdp);
1436 if (DOINGSOFTDEP(tvp))
1437 softdep_change_linkcnt(tip);
1440 if (doingdirectory && !DOINGSOFTDEP(tvp)) {
1442 * The only stuff left in the directory is "."
1443 * and "..". The "." reference is inconsequential
1444 * since we are quashing it. We have removed the "."
1445 * reference and the reference in the parent directory,
1446 * but there may be other hard links. The soft
1447 * dependency code will arrange to do these operations
1448 * after the parent directory entry has been deleted on
1449 * disk, so when running with that code we avoid doing
1454 DIP_SET(tdp, i_nlink, tdp->i_nlink);
1455 tdp->i_flag |= IN_CHANGE;
1458 DIP_SET(tip, i_nlink, tip->i_nlink);
1459 tip->i_flag |= IN_CHANGE;
1464 * 3) Unlink the source. We have to resolve the path again to
1465 * fixup the directory offset and count for ufs_dirremove.
1468 error = ufs_lookup_ino(fdvp, NULL, fcnp, &ino);
1470 panic("ufs_rename: from entry went away!");
1471 if (ino != fip->i_number)
1472 panic("ufs_rename: ino mismatch %ju != %ju\n",
1473 (uintmax_t)ino, (uintmax_t)fip->i_number);
1476 * If the source is a directory with a
1477 * new parent, the link count of the old
1478 * parent directory must be decremented
1479 * and ".." set to point to the new parent.
1481 if (doingdirectory && newparent) {
1483 * If tip exists we simply use its link, otherwise we must
1489 DIP_SET(tdp, i_nlink, tdp->i_nlink);
1490 tdp->i_flag |= IN_CHANGE;
1491 if (DOINGSOFTDEP(tdvp))
1492 softdep_setup_dotdot_link(tdp, fip);
1493 error = UFS_UPDATE(tdvp, !(DOINGSOFTDEP(tdvp) |
1495 /* Don't go to bad here as the new link exists. */
1498 } else if (DOINGSUJ(tdvp))
1499 /* Journal must account for each new link. */
1500 softdep_setup_dotdot_link(tdp, fip);
1501 fip->i_offset = mastertemplate.dot_reclen;
1502 ufs_dirrewrite(fip, fdp, newparent, DT_DIR, 0);
1505 error = ufs_dirremove(fdvp, fip, fcnp->cn_flags, 0);
1507 * The kern_renameat() looks up the fvp using the DELETE flag, which
1508 * causes the removal of the name cache entry for fvp.
1509 * As the relookup of the fvp is done in two steps:
1510 * ufs_lookup_ino() and then VFS_VGET(), another thread might do a
1511 * normal lookup of the from name just before the VFS_VGET() call,
1512 * causing the cache entry to be re-instantiated.
1514 * The same issue also applies to tvp if it exists as
1515 * otherwise we may have a stale name cache entry for the new
1516 * name that references the old i-node if it has other links
1517 * or open file descriptors.
1522 cache_purge_negative(tdvp);
1530 * If compaction or fsync was requested do it now that other locks
1531 * are no longer needed.
1533 if (error == 0 && endoff != 0) {
1535 if (tdp->i_dirhash != NULL)
1536 ufsdirhash_dirtrunc(tdp, endoff);
1538 UFS_TRUNCATE(tdvp, endoff, IO_NORMAL | IO_SYNC, tcnp->cn_cred);
1540 if (error == 0 && tdp->i_flag & IN_NEEDSYNC)
1541 error = VOP_FSYNC(tdvp, MNT_WAIT, td);
1548 DIP_SET(fip, i_nlink, fip->i_nlink);
1549 fip->i_flag |= IN_CHANGE;
1550 if (DOINGSOFTDEP(fvp))
1551 softdep_revert_link(tdp, fip);
1566 ufs_do_posix1e_acl_inheritance_dir(struct vnode *dvp, struct vnode *tvp,
1567 mode_t dmode, struct ucred *cred, struct thread *td)
1570 struct inode *ip = VTOI(tvp);
1571 struct acl *dacl, *acl;
1573 acl = acl_alloc(M_WAITOK);
1574 dacl = acl_alloc(M_WAITOK);
1577 * Retrieve default ACL from parent, if any.
1579 error = VOP_GETACL(dvp, ACL_TYPE_DEFAULT, acl, cred, td);
1583 * Retrieved a default ACL, so merge mode and ACL if
1584 * necessary. If the ACL is empty, fall through to
1585 * the "not defined or available" case.
1587 if (acl->acl_cnt != 0) {
1588 dmode = acl_posix1e_newfilemode(dmode, acl);
1590 DIP_SET(ip, i_mode, dmode);
1592 ufs_sync_acl_from_inode(ip, acl);
1599 * Just use the mode as-is.
1602 DIP_SET(ip, i_mode, dmode);
1611 * XXX: If we abort now, will Soft Updates notify the extattr
1612 * code that the EAs for the file need to be released?
1614 error = VOP_SETACL(tvp, ACL_TYPE_ACCESS, acl, cred, td);
1616 error = VOP_SETACL(tvp, ACL_TYPE_DEFAULT, dacl, cred, td);
1623 * XXX: This should not happen, as EOPNOTSUPP above
1624 * was supposed to free acl.
1626 printf("ufs_mkdir: VOP_GETACL() but no VOP_SETACL()\n");
1628 panic("ufs_mkdir: VOP_GETACL() but no VOP_SETACL()");
1644 ufs_do_posix1e_acl_inheritance_file(struct vnode *dvp, struct vnode *tvp,
1645 mode_t mode, struct ucred *cred, struct thread *td)
1648 struct inode *ip = VTOI(tvp);
1651 acl = acl_alloc(M_WAITOK);
1654 * Retrieve default ACL for parent, if any.
1656 error = VOP_GETACL(dvp, ACL_TYPE_DEFAULT, acl, cred, td);
1660 * Retrieved a default ACL, so merge mode and ACL if
1663 if (acl->acl_cnt != 0) {
1665 * Two possible ways for default ACL to not
1666 * be present. First, the EA can be
1667 * undefined, or second, the default ACL can
1668 * be blank. If it's blank, fall through to
1669 * the it's not defined case.
1671 mode = acl_posix1e_newfilemode(mode, acl);
1673 DIP_SET(ip, i_mode, mode);
1674 ufs_sync_acl_from_inode(ip, acl);
1681 * Just use the mode as-is.
1684 DIP_SET(ip, i_mode, mode);
1693 * XXX: If we abort now, will Soft Updates notify the extattr
1694 * code that the EAs for the file need to be released?
1696 error = VOP_SETACL(tvp, ACL_TYPE_ACCESS, acl, cred, td);
1703 * XXX: This should not happen, as EOPNOTSUPP above was
1704 * supposed to free acl.
1706 printf("ufs_makeinode: VOP_GETACL() but no "
1708 /* panic("ufs_makeinode: VOP_GETACL() but no "
1723 ufs_do_nfs4_acl_inheritance(struct vnode *dvp, struct vnode *tvp,
1724 mode_t child_mode, struct ucred *cred, struct thread *td)
1727 struct acl *parent_aclp, *child_aclp;
1729 parent_aclp = acl_alloc(M_WAITOK);
1730 child_aclp = acl_alloc(M_WAITOK | M_ZERO);
1732 error = ufs_getacl_nfs4_internal(dvp, parent_aclp, td);
1735 acl_nfs4_compute_inherited_acl(parent_aclp, child_aclp,
1736 child_mode, VTOI(tvp)->i_uid, tvp->v_type == VDIR);
1737 error = ufs_setacl_nfs4_internal(tvp, child_aclp, td);
1741 acl_free(parent_aclp);
1742 acl_free(child_aclp);
1753 struct vop_mkdir_args /* {
1754 struct vnode *a_dvp;
1755 struct vnode **a_vpp;
1756 struct componentname *a_cnp;
1757 struct vattr *a_vap;
1760 struct vnode *dvp = ap->a_dvp;
1761 struct vattr *vap = ap->a_vap;
1762 struct componentname *cnp = ap->a_cnp;
1763 struct inode *ip, *dp;
1766 struct dirtemplate dirtemplate, *dtp;
1767 struct direct newdir;
1772 if ((cnp->cn_flags & HASBUF) == 0)
1773 panic("ufs_mkdir: no name");
1776 if ((nlink_t)dp->i_nlink >= LINK_MAX) {
1780 dmode = vap->va_mode & 0777;
1783 * Must simulate part of ufs_makeinode here to acquire the inode,
1784 * but not have it entered in the parent directory. The entry is
1785 * made later after writing "." and ".." entries.
1787 error = UFS_VALLOC(dvp, dmode, cnp->cn_cred, &tvp);
1791 ip->i_gid = dp->i_gid;
1792 DIP_SET(ip, i_gid, dp->i_gid);
1796 struct ucred ucred, *ucp;
1801 * If we are hacking owners here, (only do this where told to)
1802 * and we are not giving it TO root, (would subvert quotas)
1803 * then go ahead and give it to the other user.
1804 * The new directory also inherits the SUID bit.
1805 * If user's UID and dir UID are the same,
1806 * 'give it away' so that the SUID is still forced on.
1808 if ((dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
1809 (dp->i_mode & ISUID) && dp->i_uid) {
1811 ip->i_uid = dp->i_uid;
1812 DIP_SET(ip, i_uid, dp->i_uid);
1814 if (dp->i_uid != cnp->cn_cred->cr_uid) {
1816 * Make sure the correct user gets charged
1818 * Make a dummy credential for the victim.
1819 * XXX This seems to never be accessed out of
1820 * our context so a stack variable is ok.
1822 refcount_init(&ucred.cr_ref, 1);
1823 ucred.cr_uid = ip->i_uid;
1824 ucred.cr_ngroups = 1;
1825 ucred.cr_groups = &ucred_group;
1826 ucred.cr_groups[0] = dp->i_gid;
1831 ip->i_uid = cnp->cn_cred->cr_uid;
1832 DIP_SET(ip, i_uid, ip->i_uid);
1835 if ((error = getinoquota(ip)) ||
1836 (error = chkiq(ip, 1, ucp, 0))) {
1837 if (DOINGSOFTDEP(tvp))
1838 softdep_revert_link(dp, ip);
1839 UFS_VFREE(tvp, ip->i_number, dmode);
1845 #else /* !SUIDDIR */
1846 ip->i_uid = cnp->cn_cred->cr_uid;
1847 DIP_SET(ip, i_uid, ip->i_uid);
1849 if ((error = getinoquota(ip)) ||
1850 (error = chkiq(ip, 1, cnp->cn_cred, 0))) {
1851 if (DOINGSOFTDEP(tvp))
1852 softdep_revert_link(dp, ip);
1853 UFS_VFREE(tvp, ip->i_number, dmode);
1858 #endif /* !SUIDDIR */
1859 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
1861 DIP_SET(ip, i_mode, dmode);
1862 tvp->v_type = VDIR; /* Rest init'd in getnewvnode(). */
1865 DIP_SET(ip, i_nlink, 2);
1867 if (cnp->cn_flags & ISWHITEOUT) {
1868 ip->i_flags |= UF_OPAQUE;
1869 DIP_SET(ip, i_flags, ip->i_flags);
1873 * Bump link count in parent directory to reflect work done below.
1874 * Should be done before reference is created so cleanup is
1875 * possible if we crash.
1879 DIP_SET(dp, i_nlink, dp->i_nlink);
1880 dp->i_flag |= IN_CHANGE;
1881 if (DOINGSOFTDEP(dvp))
1882 softdep_setup_mkdir(dp, ip);
1883 error = UFS_UPDATE(dvp, !(DOINGSOFTDEP(dvp) | DOINGASYNC(dvp)));
1887 if (dvp->v_mount->mnt_flag & MNT_MULTILABEL) {
1888 error = mac_vnode_create_extattr(cnp->cn_cred, dvp->v_mount,
1895 if (dvp->v_mount->mnt_flag & MNT_ACLS) {
1896 error = ufs_do_posix1e_acl_inheritance_dir(dvp, tvp, dmode,
1897 cnp->cn_cred, cnp->cn_thread);
1900 } else if (dvp->v_mount->mnt_flag & MNT_NFS4ACLS) {
1901 error = ufs_do_nfs4_acl_inheritance(dvp, tvp, dmode,
1902 cnp->cn_cred, cnp->cn_thread);
1906 #endif /* !UFS_ACL */
1909 * Initialize directory with "." and ".." from static template.
1911 if (dvp->v_mount->mnt_maxsymlinklen > 0)
1912 dtp = &mastertemplate;
1914 dtp = (struct dirtemplate *)&omastertemplate;
1916 dirtemplate.dot_ino = ip->i_number;
1917 dirtemplate.dotdot_ino = dp->i_number;
1918 if ((error = UFS_BALLOC(tvp, (off_t)0, DIRBLKSIZ, cnp->cn_cred,
1919 BA_CLRBUF, &bp)) != 0)
1921 ip->i_size = DIRBLKSIZ;
1922 DIP_SET(ip, i_size, DIRBLKSIZ);
1923 ip->i_flag |= IN_CHANGE | IN_UPDATE;
1924 vnode_pager_setsize(tvp, (u_long)ip->i_size);
1925 bcopy((caddr_t)&dirtemplate, (caddr_t)bp->b_data, sizeof dirtemplate);
1926 if (DOINGSOFTDEP(tvp)) {
1928 * Ensure that the entire newly allocated block is a
1929 * valid directory so that future growth within the
1930 * block does not have to ensure that the block is
1931 * written before the inode.
1934 while (blkoff < bp->b_bcount) {
1936 (bp->b_data + blkoff))->d_reclen = DIRBLKSIZ;
1937 blkoff += DIRBLKSIZ;
1940 if ((error = UFS_UPDATE(tvp, !(DOINGSOFTDEP(tvp) |
1941 DOINGASYNC(tvp)))) != 0) {
1946 * Directory set up, now install its entry in the parent directory.
1948 * If we are not doing soft dependencies, then we must write out the
1949 * buffer containing the new directory body before entering the new
1950 * name in the parent. If we are doing soft dependencies, then the
1951 * buffer containing the new directory body will be passed to and
1952 * released in the soft dependency code after the code has attached
1953 * an appropriate ordering dependency to the buffer which ensures that
1954 * the buffer is written before the new name is written in the parent.
1956 if (DOINGASYNC(dvp))
1958 else if (!DOINGSOFTDEP(dvp) && ((error = bwrite(bp))))
1960 ufs_makedirentry(ip, cnp, &newdir);
1961 error = ufs_direnter(dvp, tvp, &newdir, cnp, bp, 0);
1969 DIP_SET(dp, i_nlink, dp->i_nlink);
1970 dp->i_flag |= IN_CHANGE;
1972 * No need to do an explicit VOP_TRUNCATE here, vrele will
1973 * do this for us because we set the link count to 0.
1977 DIP_SET(ip, i_nlink, 0);
1978 ip->i_flag |= IN_CHANGE;
1979 if (DOINGSOFTDEP(tvp))
1980 softdep_revert_mkdir(dp, ip);
1989 * Rmdir system call.
1993 struct vop_rmdir_args /* {
1994 struct vnode *a_dvp;
1996 struct componentname *a_cnp;
1999 struct vnode *vp = ap->a_vp;
2000 struct vnode *dvp = ap->a_dvp;
2001 struct componentname *cnp = ap->a_cnp;
2002 struct inode *ip, *dp;
2009 * Do not remove a directory that is in the process of being renamed.
2010 * Verify the directory is empty (and valid). Rmdir ".." will not be
2011 * valid since ".." will contain a reference to the current directory
2012 * and thus be non-empty. Do not allow the removal of mounted on
2013 * directories (this can happen when an NFS exported filesystem
2014 * tries to remove a locally mounted on directory).
2017 if (ip->i_effnlink < 2) {
2021 if (dp->i_effnlink < 3)
2022 panic("ufs_dirrem: Bad link count %d on parent",
2024 if (!ufs_dirempty(ip, dp->i_number, cnp->cn_cred)) {
2028 if ((dp->i_flags & APPEND)
2029 || (ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))) {
2033 if (vp->v_mountedhere != 0) {
2038 ufs_gjournal_orphan(vp);
2041 * Delete reference to directory before purging
2042 * inode. If we crash in between, the directory
2043 * will be reattached to lost+found,
2047 if (DOINGSOFTDEP(vp))
2048 softdep_setup_rmdir(dp, ip);
2049 error = ufs_dirremove(dvp, ip, cnp->cn_flags, 1);
2053 if (DOINGSOFTDEP(vp))
2054 softdep_revert_rmdir(dp, ip);
2059 * The only stuff left in the directory is "." and "..". The "."
2060 * reference is inconsequential since we are quashing it. The soft
2061 * dependency code will arrange to do these operations after
2062 * the parent directory entry has been deleted on disk, so
2063 * when running with that code we avoid doing them now.
2065 if (!DOINGSOFTDEP(vp)) {
2067 DIP_SET(dp, i_nlink, dp->i_nlink);
2068 dp->i_flag |= IN_CHANGE;
2069 error = UFS_UPDATE(dvp, 0);
2071 DIP_SET(ip, i_nlink, ip->i_nlink);
2072 ip->i_flag |= IN_CHANGE;
2076 /* Kill any active hash; i_effnlink == 0, so it will not come back. */
2077 if (ip->i_dirhash != NULL)
2078 ufsdirhash_free(ip);
2085 * symlink -- make a symbolic link
2089 struct vop_symlink_args /* {
2090 struct vnode *a_dvp;
2091 struct vnode **a_vpp;
2092 struct componentname *a_cnp;
2093 struct vattr *a_vap;
2097 struct vnode *vp, **vpp = ap->a_vpp;
2101 error = ufs_makeinode(IFLNK | ap->a_vap->va_mode, ap->a_dvp,
2106 len = strlen(ap->a_target);
2107 if (len < vp->v_mount->mnt_maxsymlinklen) {
2109 bcopy(ap->a_target, SHORTLINK(ip), len);
2111 DIP_SET(ip, i_size, len);
2112 ip->i_flag |= IN_CHANGE | IN_UPDATE;
2113 error = UFS_UPDATE(vp, 0);
2115 error = vn_rdwr(UIO_WRITE, vp, ap->a_target, len, (off_t)0,
2116 UIO_SYSSPACE, IO_NODELOCKED | IO_NOMACCHECK,
2117 ap->a_cnp->cn_cred, NOCRED, NULL, NULL);
2124 * Vnode op for reading directories.
2128 struct vop_readdir_args /* {
2131 struct ucred *a_cred;
2137 struct vnode *vp = ap->a_vp;
2138 struct uio *uio = ap->a_uio;
2141 struct direct *dp, *edp;
2143 struct dirent dstdp;
2144 off_t offset, startoffset;
2145 size_t readcnt, skipcnt;
2150 if (uio->uio_offset < 0)
2153 if (ip->i_effnlink == 0)
2155 if (ap->a_ncookies != NULL) {
2156 ncookies = uio->uio_resid;
2157 if (uio->uio_offset >= ip->i_size)
2159 else if (ip->i_size - uio->uio_offset < ncookies)
2160 ncookies = ip->i_size - uio->uio_offset;
2161 ncookies = ncookies / (offsetof(struct direct, d_name) + 4) + 1;
2162 cookies = malloc(ncookies * sizeof(*cookies), M_TEMP, M_WAITOK);
2163 *ap->a_ncookies = ncookies;
2164 *ap->a_cookies = cookies;
2169 offset = startoffset = uio->uio_offset;
2170 startresid = uio->uio_resid;
2172 while (error == 0 && uio->uio_resid > 0 &&
2173 uio->uio_offset < ip->i_size) {
2174 error = ffs_blkatoff(vp, uio->uio_offset, NULL, &bp);
2177 if (bp->b_offset + bp->b_bcount > ip->i_size)
2178 readcnt = ip->i_size - bp->b_offset;
2180 readcnt = bp->b_bcount;
2181 skipcnt = (size_t)(uio->uio_offset - bp->b_offset) &
2182 ~(size_t)(DIRBLKSIZ - 1);
2183 offset = bp->b_offset + skipcnt;
2184 dp = (struct direct *)&bp->b_data[skipcnt];
2185 edp = (struct direct *)&bp->b_data[readcnt];
2186 while (error == 0 && uio->uio_resid > 0 && dp < edp) {
2187 if (dp->d_reclen <= offsetof(struct direct, d_name) ||
2188 (caddr_t)dp + dp->d_reclen > (caddr_t)edp) {
2192 #if BYTE_ORDER == LITTLE_ENDIAN
2193 /* Old filesystem format. */
2194 if (vp->v_mount->mnt_maxsymlinklen <= 0) {
2195 dstdp.d_namlen = dp->d_type;
2196 dstdp.d_type = dp->d_namlen;
2200 dstdp.d_namlen = dp->d_namlen;
2201 dstdp.d_type = dp->d_type;
2203 if (offsetof(struct direct, d_name) + dstdp.d_namlen >
2208 if (offset < startoffset || dp->d_ino == 0)
2210 dstdp.d_fileno = dp->d_ino;
2211 dstdp.d_reclen = GENERIC_DIRSIZ(&dstdp);
2212 bcopy(dp->d_name, dstdp.d_name, dstdp.d_namlen);
2213 dstdp.d_name[dstdp.d_namlen] = '\0';
2214 if (dstdp.d_reclen > uio->uio_resid) {
2215 if (uio->uio_resid == startresid)
2218 error = EJUSTRETURN;
2222 error = uiomove((caddr_t)&dstdp, dstdp.d_reclen, uio);
2225 if (cookies != NULL) {
2226 KASSERT(ncookies > 0,
2227 ("ufs_readdir: cookies buffer too small"));
2228 *cookies = offset + dp->d_reclen;
2233 offset += dp->d_reclen;
2234 dp = (struct direct *)((caddr_t)dp + dp->d_reclen);
2237 uio->uio_offset = offset;
2239 /* We need to correct uio_offset. */
2240 uio->uio_offset = offset;
2241 if (error == EJUSTRETURN)
2243 if (ap->a_ncookies != NULL) {
2245 ap->a_ncookies -= ncookies;
2247 free(*ap->a_cookies, M_TEMP);
2248 *ap->a_ncookies = 0;
2249 *ap->a_cookies = NULL;
2252 if (error == 0 && ap->a_eofflag)
2253 *ap->a_eofflag = ip->i_size <= uio->uio_offset;
2258 * Return target name of a symbolic link
2262 struct vop_readlink_args /* {
2265 struct ucred *a_cred;
2268 struct vnode *vp = ap->a_vp;
2269 struct inode *ip = VTOI(vp);
2273 if ((isize < vp->v_mount->mnt_maxsymlinklen) ||
2274 DIP(ip, i_blocks) == 0) { /* XXX - for old fastlink support */
2275 return (uiomove(SHORTLINK(ip), isize, ap->a_uio));
2277 return (VOP_READ(vp, ap->a_uio, 0, ap->a_cred));
2281 * Calculate the logical to physical mapping if not done already,
2282 * then call the device strategy routine.
2284 * In order to be able to swap to a file, the ufs_bmaparray() operation may not
2285 * deadlock on memory. See ufs_bmap() for details.
2289 struct vop_strategy_args /* {
2294 struct buf *bp = ap->a_bp;
2295 struct vnode *vp = ap->a_vp;
2302 if (bp->b_blkno == bp->b_lblkno) {
2303 error = ufs_bmaparray(vp, bp->b_lblkno, &blkno, bp, NULL, NULL);
2304 bp->b_blkno = blkno;
2306 bp->b_error = error;
2307 bp->b_ioflags |= BIO_ERROR;
2311 if ((long)bp->b_blkno == -1)
2314 if ((long)bp->b_blkno == -1) {
2318 bp->b_iooffset = dbtob(bp->b_blkno);
2319 bo = ip->i_umbufobj;
2320 BO_STRATEGY(bo, bp);
2325 * Print out the contents of an inode.
2329 struct vop_print_args /* {
2333 struct vnode *vp = ap->a_vp;
2334 struct inode *ip = VTOI(vp);
2336 printf("\tino %lu, on dev %s", (u_long)ip->i_number,
2337 devtoname(ip->i_dev));
2338 if (vp->v_type == VFIFO)
2345 * Close wrapper for fifos.
2347 * Update the times on the inode then do device close.
2351 struct vop_close_args /* {
2354 struct ucred *a_cred;
2355 struct thread *a_td;
2358 struct vnode *vp = ap->a_vp;
2362 usecount = vp->v_usecount;
2364 ufs_itimes_locked(vp);
2366 return (fifo_specops.vop_close(ap));
2370 * Kqfilter wrapper for fifos.
2372 * Fall through to ufs kqfilter routines if needed
2375 ufsfifo_kqfilter(ap)
2376 struct vop_kqfilter_args *ap;
2380 error = fifo_specops.vop_kqfilter(ap);
2382 error = vfs_kqfilter(ap);
2387 * Return POSIX pathconf information applicable to fifos.
2390 ufsfifo_pathconf(ap)
2391 struct vop_pathconf_args /* {
2398 switch (ap->a_name) {
2399 case _PC_ACL_EXTENDED:
2401 case _PC_ACL_PATH_MAX:
2402 case _PC_MAC_PRESENT:
2403 return (ufs_pathconf(ap));
2405 return (fifo_specops.vop_pathconf(ap));
2411 * Return POSIX pathconf information applicable to ufs filesystems.
2415 struct vop_pathconf_args /* {
2424 switch (ap->a_name) {
2426 *ap->a_retval = LINK_MAX;
2429 *ap->a_retval = NAME_MAX;
2432 *ap->a_retval = PATH_MAX;
2435 *ap->a_retval = PIPE_BUF;
2437 case _PC_CHOWN_RESTRICTED:
2443 case _PC_ACL_EXTENDED:
2445 if (ap->a_vp->v_mount->mnt_flag & MNT_ACLS)
2456 if (ap->a_vp->v_mount->mnt_flag & MNT_NFS4ACLS)
2465 case _PC_ACL_PATH_MAX:
2467 if (ap->a_vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS))
2468 *ap->a_retval = ACL_MAX_ENTRIES;
2475 case _PC_MAC_PRESENT:
2477 if (ap->a_vp->v_mount->mnt_flag & MNT_MULTILABEL)
2485 case _PC_MIN_HOLE_SIZE:
2486 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2489 /* _PC_ASYNC_IO should have been handled by upper layers. */
2490 KASSERT(0, ("_PC_ASYNC_IO should not get here"));
2499 case _PC_ALLOC_SIZE_MIN:
2500 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_bsize;
2502 case _PC_FILESIZEBITS:
2505 case _PC_REC_INCR_XFER_SIZE:
2506 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2508 case _PC_REC_MAX_XFER_SIZE:
2509 *ap->a_retval = -1; /* means ``unlimited'' */
2511 case _PC_REC_MIN_XFER_SIZE:
2512 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2514 case _PC_REC_XFER_ALIGN:
2515 *ap->a_retval = PAGE_SIZE;
2517 case _PC_SYMLINK_MAX:
2518 *ap->a_retval = MAXPATHLEN;
2529 * Initialize the vnode associated with a new inode, handle aliased
2533 ufs_vinit(mntp, fifoops, vpp)
2535 struct vop_vector *fifoops;
2543 vp->v_type = IFTOVT(ip->i_mode);
2544 if (vp->v_type == VFIFO)
2546 ASSERT_VOP_LOCKED(vp, "ufs_vinit");
2547 if (ip->i_number == ROOTINO)
2548 vp->v_vflag |= VV_ROOT;
2554 * Allocate a new inode.
2555 * Vnode dvp must be locked.
2558 ufs_makeinode(mode, dvp, vpp, cnp)
2562 struct componentname *cnp;
2564 struct inode *ip, *pdir;
2565 struct direct newdir;
2571 if ((cnp->cn_flags & HASBUF) == 0)
2572 panic("ufs_makeinode: no name");
2575 if ((mode & IFMT) == 0)
2578 if (VTOI(dvp)->i_effnlink < 2)
2579 panic("ufs_makeinode: Bad link count %d on parent",
2580 VTOI(dvp)->i_effnlink);
2581 error = UFS_VALLOC(dvp, mode, cnp->cn_cred, &tvp);
2585 ip->i_gid = pdir->i_gid;
2586 DIP_SET(ip, i_gid, pdir->i_gid);
2590 struct ucred ucred, *ucp;
2595 * If we are not the owner of the directory,
2596 * and we are hacking owners here, (only do this where told to)
2597 * and we are not giving it TO root, (would subvert quotas)
2598 * then go ahead and give it to the other user.
2599 * Note that this drops off the execute bits for security.
2601 if ((dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
2602 (pdir->i_mode & ISUID) &&
2603 (pdir->i_uid != cnp->cn_cred->cr_uid) && pdir->i_uid) {
2604 ip->i_uid = pdir->i_uid;
2605 DIP_SET(ip, i_uid, ip->i_uid);
2609 * Make sure the correct user gets charged
2611 * Quickly knock up a dummy credential for the victim.
2612 * XXX This seems to never be accessed out of our
2613 * context so a stack variable is ok.
2615 refcount_init(&ucred.cr_ref, 1);
2616 ucred.cr_uid = ip->i_uid;
2617 ucred.cr_ngroups = 1;
2618 ucred.cr_groups = &ucred_group;
2619 ucred.cr_groups[0] = pdir->i_gid;
2623 ip->i_uid = cnp->cn_cred->cr_uid;
2624 DIP_SET(ip, i_uid, ip->i_uid);
2628 if ((error = getinoquota(ip)) ||
2629 (error = chkiq(ip, 1, ucp, 0))) {
2630 if (DOINGSOFTDEP(tvp))
2631 softdep_revert_link(pdir, ip);
2632 UFS_VFREE(tvp, ip->i_number, mode);
2638 #else /* !SUIDDIR */
2639 ip->i_uid = cnp->cn_cred->cr_uid;
2640 DIP_SET(ip, i_uid, ip->i_uid);
2642 if ((error = getinoquota(ip)) ||
2643 (error = chkiq(ip, 1, cnp->cn_cred, 0))) {
2644 if (DOINGSOFTDEP(tvp))
2645 softdep_revert_link(pdir, ip);
2646 UFS_VFREE(tvp, ip->i_number, mode);
2651 #endif /* !SUIDDIR */
2652 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
2654 DIP_SET(ip, i_mode, mode);
2655 tvp->v_type = IFTOVT(mode); /* Rest init'd in getnewvnode(). */
2658 DIP_SET(ip, i_nlink, 1);
2659 if (DOINGSOFTDEP(tvp))
2660 softdep_setup_create(VTOI(dvp), ip);
2661 if ((ip->i_mode & ISGID) && !groupmember(ip->i_gid, cnp->cn_cred) &&
2662 priv_check_cred(cnp->cn_cred, PRIV_VFS_SETGID, 0)) {
2663 ip->i_mode &= ~ISGID;
2664 DIP_SET(ip, i_mode, ip->i_mode);
2667 if (cnp->cn_flags & ISWHITEOUT) {
2668 ip->i_flags |= UF_OPAQUE;
2669 DIP_SET(ip, i_flags, ip->i_flags);
2673 * Make sure inode goes to disk before directory entry.
2675 error = UFS_UPDATE(tvp, !(DOINGSOFTDEP(tvp) | DOINGASYNC(tvp)));
2679 if (dvp->v_mount->mnt_flag & MNT_MULTILABEL) {
2680 error = mac_vnode_create_extattr(cnp->cn_cred, dvp->v_mount,
2687 if (dvp->v_mount->mnt_flag & MNT_ACLS) {
2688 error = ufs_do_posix1e_acl_inheritance_file(dvp, tvp, mode,
2689 cnp->cn_cred, cnp->cn_thread);
2692 } else if (dvp->v_mount->mnt_flag & MNT_NFS4ACLS) {
2693 error = ufs_do_nfs4_acl_inheritance(dvp, tvp, mode,
2694 cnp->cn_cred, cnp->cn_thread);
2698 #endif /* !UFS_ACL */
2699 ufs_makedirentry(ip, cnp, &newdir);
2700 error = ufs_direnter(dvp, tvp, &newdir, cnp, NULL, 0);
2708 * Write error occurred trying to update the inode
2709 * or the directory so must deallocate the inode.
2713 DIP_SET(ip, i_nlink, 0);
2714 ip->i_flag |= IN_CHANGE;
2715 if (DOINGSOFTDEP(tvp))
2716 softdep_revert_create(VTOI(dvp), ip);
2722 ufs_ioctl(struct vop_ioctl_args *ap)
2725 switch (ap->a_command) {
2728 return (vn_bmap_seekhole(ap->a_vp, ap->a_command,
2729 (off_t *)ap->a_data, ap->a_cred));
2735 /* Global vfs data structures for ufs. */
2736 struct vop_vector ufs_vnodeops = {
2737 .vop_default = &default_vnodeops,
2738 .vop_fsync = VOP_PANIC,
2739 .vop_read = VOP_PANIC,
2740 .vop_reallocblks = VOP_PANIC,
2741 .vop_write = VOP_PANIC,
2742 .vop_accessx = ufs_accessx,
2743 .vop_bmap = ufs_bmap,
2744 .vop_cachedlookup = ufs_lookup,
2745 .vop_close = ufs_close,
2746 .vop_create = ufs_create,
2747 .vop_getattr = ufs_getattr,
2748 .vop_inactive = ufs_inactive,
2749 .vop_ioctl = ufs_ioctl,
2750 .vop_link = ufs_link,
2751 .vop_lookup = vfs_cache_lookup,
2752 .vop_markatime = ufs_markatime,
2753 .vop_mkdir = ufs_mkdir,
2754 .vop_mknod = ufs_mknod,
2755 .vop_open = ufs_open,
2756 .vop_pathconf = ufs_pathconf,
2757 .vop_poll = vop_stdpoll,
2758 .vop_print = ufs_print,
2759 .vop_readdir = ufs_readdir,
2760 .vop_readlink = ufs_readlink,
2761 .vop_reclaim = ufs_reclaim,
2762 .vop_remove = ufs_remove,
2763 .vop_rename = ufs_rename,
2764 .vop_rmdir = ufs_rmdir,
2765 .vop_setattr = ufs_setattr,
2767 .vop_setlabel = vop_stdsetlabel_ea,
2769 .vop_strategy = ufs_strategy,
2770 .vop_symlink = ufs_symlink,
2771 .vop_whiteout = ufs_whiteout,
2773 .vop_getextattr = ufs_getextattr,
2774 .vop_deleteextattr = ufs_deleteextattr,
2775 .vop_setextattr = ufs_setextattr,
2778 .vop_getacl = ufs_getacl,
2779 .vop_setacl = ufs_setacl,
2780 .vop_aclcheck = ufs_aclcheck,
2784 struct vop_vector ufs_fifoops = {
2785 .vop_default = &fifo_specops,
2786 .vop_fsync = VOP_PANIC,
2787 .vop_accessx = ufs_accessx,
2788 .vop_close = ufsfifo_close,
2789 .vop_getattr = ufs_getattr,
2790 .vop_inactive = ufs_inactive,
2791 .vop_kqfilter = ufsfifo_kqfilter,
2792 .vop_markatime = ufs_markatime,
2793 .vop_pathconf = ufsfifo_pathconf,
2794 .vop_print = ufs_print,
2795 .vop_read = VOP_PANIC,
2796 .vop_reclaim = ufs_reclaim,
2797 .vop_setattr = ufs_setattr,
2799 .vop_setlabel = vop_stdsetlabel_ea,
2801 .vop_write = VOP_PANIC,
2803 .vop_getextattr = ufs_getextattr,
2804 .vop_deleteextattr = ufs_deleteextattr,
2805 .vop_setextattr = ufs_setextattr,
2808 .vop_getacl = ufs_getacl,
2809 .vop_setacl = ufs_setacl,
2810 .vop_aclcheck = ufs_aclcheck,