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);
210 if ((ap->a_cnp->cn_flags & MAKEENTRY) != 0)
211 cache_enter(ap->a_dvp, *ap->a_vpp, ap->a_cnp);
221 struct vop_mknod_args /* {
223 struct vnode **a_vpp;
224 struct componentname *a_cnp;
228 struct vattr *vap = ap->a_vap;
229 struct vnode **vpp = ap->a_vpp;
234 error = ufs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode),
235 ap->a_dvp, vpp, ap->a_cnp);
239 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
240 if (vap->va_rdev != VNOVAL) {
242 * Want to be able to use this to make badblock
243 * inodes, so don't truncate the dev number.
245 DIP_SET(ip, i_rdev, vap->va_rdev);
248 * Remove inode, then reload it through VFS_VGET so it is
249 * checked to see if it is an alias of an existing entry in
250 * the inode cache. XXX I don't believe this is necessary now.
252 (*vpp)->v_type = VNON;
253 ino = ip->i_number; /* Save this before vgone() invalidates ip. */
256 error = VFS_VGET(ap->a_dvp->v_mount, ino, LK_EXCLUSIVE, vpp);
269 ufs_open(struct vop_open_args *ap)
271 struct vnode *vp = ap->a_vp;
274 if (vp->v_type == VCHR || vp->v_type == VBLK)
279 * Files marked append-only must be opened for appending.
281 if ((ip->i_flags & APPEND) &&
282 (ap->a_mode & (FWRITE | O_APPEND)) == FWRITE)
284 vnode_create_vobject(vp, DIP(ip, i_size), ap->a_td);
291 * Update the times on the inode.
296 struct vop_close_args /* {
299 struct ucred *a_cred;
303 struct vnode *vp = ap->a_vp;
307 usecount = vp->v_usecount;
309 ufs_itimes_locked(vp);
316 struct vop_accessx_args /* {
319 struct ucred *a_cred;
323 struct vnode *vp = ap->a_vp;
324 struct inode *ip = VTOI(vp);
325 accmode_t accmode = ap->a_accmode;
336 * Disallow write attempts on read-only filesystems;
337 * unless the file is a socket, fifo, or a block or
338 * character device resident on the filesystem.
340 if (accmode & VMODIFY_PERMS) {
341 switch (vp->v_type) {
345 if (vp->v_mount->mnt_flag & MNT_RDONLY)
349 * Inode is accounted in the quotas only if struct
350 * dquot is attached to it. VOP_ACCESS() is called
351 * from vn_open_cred() and provides a convenient
352 * point to call getinoquota().
354 if (VOP_ISLOCKED(vp) != LK_EXCLUSIVE) {
357 * Upgrade vnode lock, since getinoquota()
358 * requires exclusive lock to modify inode.
362 vn_lock(vp, LK_UPGRADE | LK_RETRY);
364 if (vp->v_iflag & VI_DOOMED) {
372 error = getinoquota(ip);
375 vn_lock(vp, LK_DOWNGRADE | LK_RETRY);
386 * If immutable bit set, nobody gets to write it. "& ~VADMIN_PERMS"
387 * permits the owner of the file to remove the IMMUTABLE flag.
389 if ((accmode & (VMODIFY_PERMS & ~VADMIN_PERMS)) &&
390 (ip->i_flags & (IMMUTABLE | SF_SNAPSHOT)))
394 if ((vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS)) != 0) {
395 if (vp->v_mount->mnt_flag & MNT_NFS4ACLS)
396 type = ACL_TYPE_NFS4;
398 type = ACL_TYPE_ACCESS;
400 acl = acl_alloc(M_WAITOK);
401 if (type == ACL_TYPE_NFS4)
402 error = ufs_getacl_nfs4_internal(vp, acl, ap->a_td);
404 error = VOP_GETACL(vp, type, acl, ap->a_cred, ap->a_td);
407 if (type == ACL_TYPE_NFS4) {
408 error = vaccess_acl_nfs4(vp->v_type, ip->i_uid,
409 ip->i_gid, acl, accmode, ap->a_cred, NULL);
411 error = vfs_unixify_accmode(&accmode);
413 error = vaccess_acl_posix1e(vp->v_type, ip->i_uid,
414 ip->i_gid, acl, accmode, ap->a_cred, NULL);
418 if (error != EOPNOTSUPP)
420 "ufs_accessx(): Error retrieving ACL on object (%d).\n",
423 * XXX: Fall back until debugged. Should
424 * eventually possibly log an error, and return
427 error = vfs_unixify_accmode(&accmode);
429 error = vaccess(vp->v_type, ip->i_mode, ip->i_uid,
430 ip->i_gid, accmode, ap->a_cred, NULL);
436 #endif /* !UFS_ACL */
437 error = vfs_unixify_accmode(&accmode);
439 error = vaccess(vp->v_type, ip->i_mode, ip->i_uid, ip->i_gid,
440 accmode, ap->a_cred, NULL);
447 struct vop_getattr_args /* {
450 struct ucred *a_cred;
453 struct vnode *vp = ap->a_vp;
454 struct inode *ip = VTOI(vp);
455 struct vattr *vap = ap->a_vap;
458 ufs_itimes_locked(vp);
459 if (ip->i_ump->um_fstype == UFS1) {
460 vap->va_atime.tv_sec = ip->i_din1->di_atime;
461 vap->va_atime.tv_nsec = ip->i_din1->di_atimensec;
463 vap->va_atime.tv_sec = ip->i_din2->di_atime;
464 vap->va_atime.tv_nsec = ip->i_din2->di_atimensec;
468 * Copy from inode table
470 vap->va_fsid = dev2udev(ip->i_dev);
471 vap->va_fileid = ip->i_number;
472 vap->va_mode = ip->i_mode & ~IFMT;
473 vap->va_nlink = ip->i_effnlink;
474 vap->va_uid = ip->i_uid;
475 vap->va_gid = ip->i_gid;
476 if (ip->i_ump->um_fstype == UFS1) {
477 vap->va_rdev = ip->i_din1->di_rdev;
478 vap->va_size = ip->i_din1->di_size;
479 vap->va_mtime.tv_sec = ip->i_din1->di_mtime;
480 vap->va_mtime.tv_nsec = ip->i_din1->di_mtimensec;
481 vap->va_ctime.tv_sec = ip->i_din1->di_ctime;
482 vap->va_ctime.tv_nsec = ip->i_din1->di_ctimensec;
483 vap->va_bytes = dbtob((u_quad_t)ip->i_din1->di_blocks);
484 vap->va_filerev = ip->i_din1->di_modrev;
486 vap->va_rdev = ip->i_din2->di_rdev;
487 vap->va_size = ip->i_din2->di_size;
488 vap->va_mtime.tv_sec = ip->i_din2->di_mtime;
489 vap->va_mtime.tv_nsec = ip->i_din2->di_mtimensec;
490 vap->va_ctime.tv_sec = ip->i_din2->di_ctime;
491 vap->va_ctime.tv_nsec = ip->i_din2->di_ctimensec;
492 vap->va_birthtime.tv_sec = ip->i_din2->di_birthtime;
493 vap->va_birthtime.tv_nsec = ip->i_din2->di_birthnsec;
494 vap->va_bytes = dbtob((u_quad_t)ip->i_din2->di_blocks);
495 vap->va_filerev = ip->i_din2->di_modrev;
497 vap->va_flags = ip->i_flags;
498 vap->va_gen = ip->i_gen;
499 vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
500 vap->va_type = IFTOVT(ip->i_mode);
505 * Set attribute vnode op. called from several syscalls
509 struct vop_setattr_args /* {
512 struct ucred *a_cred;
515 struct vattr *vap = ap->a_vap;
516 struct vnode *vp = ap->a_vp;
517 struct inode *ip = VTOI(vp);
518 struct ucred *cred = ap->a_cred;
519 struct thread *td = curthread;
523 * Check for unsettable attributes.
525 if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
526 (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
527 (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
528 ((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
531 if (vap->va_flags != VNOVAL) {
532 if ((vap->va_flags & ~(SF_APPEND | SF_ARCHIVED | SF_IMMUTABLE |
533 SF_NOUNLINK | SF_SNAPSHOT | UF_APPEND | UF_ARCHIVE |
534 UF_HIDDEN | UF_IMMUTABLE | UF_NODUMP | UF_NOUNLINK |
535 UF_OFFLINE | UF_OPAQUE | UF_READONLY | UF_REPARSE |
536 UF_SPARSE | UF_SYSTEM)) != 0)
538 if (vp->v_mount->mnt_flag & MNT_RDONLY)
541 * Callers may only modify the file flags on objects they
542 * have VADMIN rights for.
544 if ((error = VOP_ACCESS(vp, VADMIN, cred, td)))
547 * Unprivileged processes are not permitted to unset system
548 * flags, or modify flags if any system flags are set.
549 * Privileged non-jail processes may not modify system flags
550 * if securelevel > 0 and any existing system flags are set.
551 * Privileged jail processes behave like privileged non-jail
552 * processes if the security.jail.chflags_allowed sysctl is
553 * is non-zero; otherwise, they behave like unprivileged
556 if (!priv_check_cred(cred, PRIV_VFS_SYSFLAGS, 0)) {
558 (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND)) {
559 error = securelevel_gt(cred, 0);
563 /* The snapshot flag cannot be toggled. */
564 if ((vap->va_flags ^ ip->i_flags) & SF_SNAPSHOT)
568 (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND) ||
569 ((vap->va_flags ^ ip->i_flags) & SF_SETTABLE))
572 ip->i_flags = vap->va_flags;
573 DIP_SET(ip, i_flags, vap->va_flags);
574 ip->i_flag |= IN_CHANGE;
575 error = UFS_UPDATE(vp, 0);
576 if (ip->i_flags & (IMMUTABLE | APPEND))
580 * If immutable or append, no one can change any of its attributes
581 * except the ones already handled (in some cases, file flags
582 * including the immutability flags themselves for the superuser).
584 if (ip->i_flags & (IMMUTABLE | APPEND))
587 * Go through the fields and update iff not VNOVAL.
589 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
590 if (vp->v_mount->mnt_flag & MNT_RDONLY)
592 if ((error = ufs_chown(vp, vap->va_uid, vap->va_gid, cred,
596 if (vap->va_size != VNOVAL) {
598 * XXX most of the following special cases should be in
599 * callers instead of in N filesystems. The VDIR check
602 switch (vp->v_type) {
608 * Truncation should have an effect in these cases.
609 * Disallow it if the filesystem is read-only or
610 * the file is being snapshotted.
612 if (vp->v_mount->mnt_flag & MNT_RDONLY)
614 if ((ip->i_flags & SF_SNAPSHOT) != 0)
619 * According to POSIX, the result is unspecified
620 * for file types other than regular files,
621 * directories and shared memory objects. We
622 * don't support shared memory objects in the file
623 * system, and have dubious support for truncating
624 * symlinks. Just ignore the request in other cases.
628 if ((error = UFS_TRUNCATE(vp, vap->va_size, IO_NORMAL,
632 if (vap->va_atime.tv_sec != VNOVAL ||
633 vap->va_mtime.tv_sec != VNOVAL ||
634 vap->va_birthtime.tv_sec != VNOVAL) {
635 if (vp->v_mount->mnt_flag & MNT_RDONLY)
637 if ((ip->i_flags & SF_SNAPSHOT) != 0)
639 error = vn_utimes_perm(vp, vap, cred, td);
642 if (vap->va_atime.tv_sec != VNOVAL)
643 ip->i_flag |= IN_ACCESS;
644 if (vap->va_mtime.tv_sec != VNOVAL)
645 ip->i_flag |= IN_CHANGE | IN_UPDATE;
646 if (vap->va_birthtime.tv_sec != VNOVAL &&
647 ip->i_ump->um_fstype == UFS2)
648 ip->i_flag |= IN_MODIFIED;
650 if (vap->va_atime.tv_sec != VNOVAL) {
651 DIP_SET(ip, i_atime, vap->va_atime.tv_sec);
652 DIP_SET(ip, i_atimensec, vap->va_atime.tv_nsec);
654 if (vap->va_mtime.tv_sec != VNOVAL) {
655 DIP_SET(ip, i_mtime, vap->va_mtime.tv_sec);
656 DIP_SET(ip, i_mtimensec, vap->va_mtime.tv_nsec);
658 if (vap->va_birthtime.tv_sec != VNOVAL &&
659 ip->i_ump->um_fstype == UFS2) {
660 ip->i_din2->di_birthtime = vap->va_birthtime.tv_sec;
661 ip->i_din2->di_birthnsec = vap->va_birthtime.tv_nsec;
663 error = UFS_UPDATE(vp, 0);
668 if (vap->va_mode != (mode_t)VNOVAL) {
669 if (vp->v_mount->mnt_flag & MNT_RDONLY)
671 if ((ip->i_flags & SF_SNAPSHOT) != 0 && (vap->va_mode &
672 (S_IXUSR | S_IWUSR | S_IXGRP | S_IWGRP | S_IXOTH | S_IWOTH)))
674 error = ufs_chmod(vp, (int)vap->va_mode, cred, td);
681 ufs_update_nfs4_acl_after_mode_change(struct vnode *vp, int mode,
682 int file_owner_id, struct ucred *cred, struct thread *td)
687 aclp = acl_alloc(M_WAITOK);
688 error = ufs_getacl_nfs4_internal(vp, aclp, td);
690 * We don't have to handle EOPNOTSUPP here, as the filesystem claims
696 acl_nfs4_sync_acl_from_mode(aclp, mode, file_owner_id);
697 error = ufs_setacl_nfs4_internal(vp, aclp, td);
706 * Mark this file's access time for update for vfs_mark_atime(). This
707 * is called from execve() and mmap().
711 struct vop_markatime_args /* {
715 struct vnode *vp = ap->a_vp;
716 struct inode *ip = VTOI(vp);
719 ip->i_flag |= IN_ACCESS;
722 * XXXKIB No UFS_UPDATE(ap->a_vp, 0) there.
728 * Change the mode on a file.
729 * Inode must be locked before calling.
732 ufs_chmod(vp, mode, cred, td)
738 struct inode *ip = VTOI(vp);
742 * To modify the permissions on a file, must possess VADMIN
745 if ((error = VOP_ACCESSX(vp, VWRITE_ACL, cred, td)))
748 * Privileged processes may set the sticky bit on non-directories,
749 * as well as set the setgid bit on a file with a group that the
750 * process is not a member of. Both of these are allowed in
753 if (vp->v_type != VDIR && (mode & S_ISTXT)) {
754 if (priv_check_cred(cred, PRIV_VFS_STICKYFILE, 0))
757 if (!groupmember(ip->i_gid, cred) && (mode & ISGID)) {
758 error = priv_check_cred(cred, PRIV_VFS_SETGID, 0);
764 * Deny setting setuid if we are not the file owner.
766 if ((mode & ISUID) && ip->i_uid != cred->cr_uid) {
767 error = priv_check_cred(cred, PRIV_VFS_ADMIN, 0);
772 ip->i_mode &= ~ALLPERMS;
773 ip->i_mode |= (mode & ALLPERMS);
774 DIP_SET(ip, i_mode, ip->i_mode);
775 ip->i_flag |= IN_CHANGE;
777 if ((vp->v_mount->mnt_flag & MNT_NFS4ACLS) != 0)
778 error = ufs_update_nfs4_acl_after_mode_change(vp, mode, ip->i_uid, cred, td);
780 if (error == 0 && (ip->i_flag & IN_CHANGE) != 0)
781 error = UFS_UPDATE(vp, 0);
787 * Perform chown operation on inode ip;
788 * inode must be locked prior to call.
791 ufs_chown(vp, uid, gid, cred, td)
798 struct inode *ip = VTOI(vp);
807 if (uid == (uid_t)VNOVAL)
809 if (gid == (gid_t)VNOVAL)
812 * To modify the ownership of a file, must possess VADMIN for that
815 if ((error = VOP_ACCESSX(vp, VWRITE_OWNER, cred, td)))
818 * To change the owner of a file, or change the group of a file to a
819 * group of which we are not a member, the caller must have
822 if (((uid != ip->i_uid && uid != cred->cr_uid) ||
823 (gid != ip->i_gid && !groupmember(gid, cred))) &&
824 (error = priv_check_cred(cred, PRIV_VFS_CHOWN, 0)))
829 if ((error = getinoquota(ip)) != 0)
832 dqrele(vp, ip->i_dquot[USRQUOTA]);
833 ip->i_dquot[USRQUOTA] = NODQUOT;
836 dqrele(vp, ip->i_dquot[GRPQUOTA]);
837 ip->i_dquot[GRPQUOTA] = NODQUOT;
839 change = DIP(ip, i_blocks);
840 (void) chkdq(ip, -change, cred, CHOWN);
841 (void) chkiq(ip, -1, cred, CHOWN);
842 for (i = 0; i < MAXQUOTAS; i++) {
843 dqrele(vp, ip->i_dquot[i]);
844 ip->i_dquot[i] = NODQUOT;
848 DIP_SET(ip, i_gid, gid);
850 DIP_SET(ip, i_uid, uid);
852 if ((error = getinoquota(ip)) == 0) {
854 dqrele(vp, ip->i_dquot[USRQUOTA]);
855 ip->i_dquot[USRQUOTA] = NODQUOT;
858 dqrele(vp, ip->i_dquot[GRPQUOTA]);
859 ip->i_dquot[GRPQUOTA] = NODQUOT;
861 if ((error = chkdq(ip, change, cred, CHOWN)) == 0) {
862 if ((error = chkiq(ip, 1, cred, CHOWN)) == 0)
865 (void) chkdq(ip, -change, cred, CHOWN|FORCE);
867 for (i = 0; i < MAXQUOTAS; i++) {
868 dqrele(vp, ip->i_dquot[i]);
869 ip->i_dquot[i] = NODQUOT;
873 DIP_SET(ip, i_gid, ogid);
875 DIP_SET(ip, i_uid, ouid);
876 if (getinoquota(ip) == 0) {
878 dqrele(vp, ip->i_dquot[USRQUOTA]);
879 ip->i_dquot[USRQUOTA] = NODQUOT;
882 dqrele(vp, ip->i_dquot[GRPQUOTA]);
883 ip->i_dquot[GRPQUOTA] = NODQUOT;
885 (void) chkdq(ip, change, cred, FORCE|CHOWN);
886 (void) chkiq(ip, 1, cred, FORCE|CHOWN);
887 (void) getinoquota(ip);
892 panic("ufs_chown: lost quota");
894 ip->i_flag |= IN_CHANGE;
895 if ((ip->i_mode & (ISUID | ISGID)) && (ouid != uid || ogid != gid)) {
896 if (priv_check_cred(cred, PRIV_VFS_RETAINSUGID, 0)) {
897 ip->i_mode &= ~(ISUID | ISGID);
898 DIP_SET(ip, i_mode, ip->i_mode);
901 error = UFS_UPDATE(vp, 0);
907 struct vop_remove_args /* {
910 struct componentname *a_cnp;
914 struct vnode *vp = ap->a_vp;
915 struct vnode *dvp = ap->a_dvp;
921 if ((ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
922 (VTOI(dvp)->i_flags & APPEND)) {
927 ufs_gjournal_orphan(vp);
929 error = ufs_dirremove(dvp, ip, ap->a_cnp->cn_flags, 0);
930 if (ip->i_nlink <= 0)
931 vp->v_vflag |= VV_NOSYNC;
932 if ((ip->i_flags & SF_SNAPSHOT) != 0) {
934 * Avoid deadlock where another thread is trying to
935 * update the inodeblock for dvp and is waiting on
936 * snaplk. Temporary unlock the vnode lock for the
937 * unlinked file and sync the directory. This should
938 * allow vput() of the directory to not block later on
939 * while holding the snapshot vnode locked, assuming
940 * that the directory hasn't been unlinked too.
943 (void) VOP_FSYNC(dvp, MNT_WAIT, td);
944 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
955 struct vop_link_args /* {
956 struct vnode *a_tdvp;
958 struct componentname *a_cnp;
961 struct vnode *vp = ap->a_vp;
962 struct vnode *tdvp = ap->a_tdvp;
963 struct componentname *cnp = ap->a_cnp;
965 struct direct newdir;
969 if ((cnp->cn_flags & HASBUF) == 0)
970 panic("ufs_link: no name");
972 if (VTOI(tdvp)->i_effnlink < 2)
973 panic("ufs_link: Bad link count %d on parent",
974 VTOI(tdvp)->i_effnlink);
976 if ((nlink_t)ip->i_nlink >= LINK_MAX) {
981 * The file may have been removed after namei droped the original
984 if (ip->i_effnlink == 0) {
988 if (ip->i_flags & (IMMUTABLE | APPEND)) {
994 DIP_SET(ip, i_nlink, ip->i_nlink);
995 ip->i_flag |= IN_CHANGE;
996 if (DOINGSOFTDEP(vp))
997 softdep_setup_link(VTOI(tdvp), ip);
998 error = UFS_UPDATE(vp, !(DOINGSOFTDEP(vp) | DOINGASYNC(vp)));
1000 ufs_makedirentry(ip, cnp, &newdir);
1001 error = ufs_direnter(tdvp, vp, &newdir, cnp, NULL, 0);
1007 DIP_SET(ip, i_nlink, ip->i_nlink);
1008 ip->i_flag |= IN_CHANGE;
1009 if (DOINGSOFTDEP(vp))
1010 softdep_revert_link(VTOI(tdvp), ip);
1017 * whiteout vnode call
1021 struct vop_whiteout_args /* {
1022 struct vnode *a_dvp;
1023 struct componentname *a_cnp;
1027 struct vnode *dvp = ap->a_dvp;
1028 struct componentname *cnp = ap->a_cnp;
1029 struct direct newdir;
1032 switch (ap->a_flags) {
1034 /* 4.4 format directories support whiteout operations */
1035 if (dvp->v_mount->mnt_maxsymlinklen > 0)
1037 return (EOPNOTSUPP);
1040 /* create a new directory whiteout */
1042 if ((cnp->cn_flags & SAVENAME) == 0)
1043 panic("ufs_whiteout: missing name");
1044 if (dvp->v_mount->mnt_maxsymlinklen <= 0)
1045 panic("ufs_whiteout: old format filesystem");
1048 newdir.d_ino = WINO;
1049 newdir.d_namlen = cnp->cn_namelen;
1050 bcopy(cnp->cn_nameptr, newdir.d_name, (unsigned)cnp->cn_namelen + 1);
1051 newdir.d_type = DT_WHT;
1052 error = ufs_direnter(dvp, NULL, &newdir, cnp, NULL, 0);
1056 /* remove an existing directory whiteout */
1058 if (dvp->v_mount->mnt_maxsymlinklen <= 0)
1059 panic("ufs_whiteout: old format filesystem");
1062 cnp->cn_flags &= ~DOWHITEOUT;
1063 error = ufs_dirremove(dvp, NULL, cnp->cn_flags, 0);
1066 panic("ufs_whiteout: unknown op");
1071 static volatile int rename_restarts;
1072 SYSCTL_INT(_vfs_ufs, OID_AUTO, rename_restarts, CTLFLAG_RD,
1073 __DEVOLATILE(int *, &rename_restarts), 0,
1074 "Times rename had to restart due to lock contention");
1077 * Rename system call.
1078 * rename("foo", "bar");
1081 * link("foo", "bar");
1083 * but ``atomically''. Can't do full commit without saving state in the
1084 * inode on disk which isn't feasible at this time. Best we can do is
1085 * always guarantee the target exists.
1087 * Basic algorithm is:
1089 * 1) Bump link count on source while we're linking it to the
1090 * target. This also ensure the inode won't be deleted out
1091 * from underneath us while we work (it may be truncated by
1092 * a concurrent `trunc' or `open' for creation).
1093 * 2) Link source to destination. If destination already exists,
1095 * 3) Unlink source reference to inode if still around. If a
1096 * directory was moved and the parent of the destination
1097 * is different from the source, patch the ".." entry in the
1102 struct vop_rename_args /* {
1103 struct vnode *a_fdvp;
1104 struct vnode *a_fvp;
1105 struct componentname *a_fcnp;
1106 struct vnode *a_tdvp;
1107 struct vnode *a_tvp;
1108 struct componentname *a_tcnp;
1111 struct vnode *tvp = ap->a_tvp;
1112 struct vnode *tdvp = ap->a_tdvp;
1113 struct vnode *fvp = ap->a_fvp;
1114 struct vnode *fdvp = ap->a_fdvp;
1116 struct componentname *tcnp = ap->a_tcnp;
1117 struct componentname *fcnp = ap->a_fcnp;
1118 struct thread *td = fcnp->cn_thread;
1119 struct inode *fip, *tip, *tdp, *fdp;
1120 struct direct newdir;
1122 int doingdirectory, newparent;
1128 if ((tcnp->cn_flags & HASBUF) == 0 ||
1129 (fcnp->cn_flags & HASBUF) == 0)
1130 panic("ufs_rename: no name");
1134 VOP_UNLOCK(tdvp, 0);
1135 if (tvp && tvp != tdvp)
1138 * Check for cross-device rename.
1140 if ((fvp->v_mount != tdvp->v_mount) ||
1141 (tvp && (fvp->v_mount != tvp->v_mount))) {
1148 * We need to acquire 2 to 4 locks depending on whether tvp is NULL
1149 * and fdvp and tdvp are the same directory. Subsequently we need
1150 * to double-check all paths and in the directory rename case we
1151 * need to verify that we are not creating a directory loop. To
1152 * handle this we acquire all but fdvp using non-blocking
1153 * acquisitions. If we fail to acquire any lock in the path we will
1154 * drop all held locks, acquire the new lock in a blocking fashion,
1155 * and then release it and restart the rename. This acquire/release
1156 * step ensures that we do not spin on a lock waiting for release.
1158 error = vn_lock(fdvp, LK_EXCLUSIVE);
1161 if (vn_lock(tdvp, LK_EXCLUSIVE | LK_NOWAIT) != 0) {
1162 VOP_UNLOCK(fdvp, 0);
1163 error = vn_lock(tdvp, LK_EXCLUSIVE);
1166 VOP_UNLOCK(tdvp, 0);
1167 atomic_add_int(&rename_restarts, 1);
1171 * Re-resolve fvp to be certain it still exists and fetch the
1174 error = ufs_lookup_ino(fdvp, NULL, fcnp, &ino);
1176 VOP_UNLOCK(fdvp, 0);
1177 VOP_UNLOCK(tdvp, 0);
1180 error = VFS_VGET(mp, ino, LK_EXCLUSIVE | LK_NOWAIT, &nvp);
1182 VOP_UNLOCK(fdvp, 0);
1183 VOP_UNLOCK(tdvp, 0);
1186 error = VFS_VGET(mp, ino, LK_EXCLUSIVE, &nvp);
1192 atomic_add_int(&rename_restarts, 1);
1198 * Re-resolve tvp and acquire the vnode lock if present.
1200 error = ufs_lookup_ino(tdvp, NULL, tcnp, &ino);
1201 if (error != 0 && error != EJUSTRETURN) {
1202 VOP_UNLOCK(fdvp, 0);
1203 VOP_UNLOCK(tdvp, 0);
1208 * If tvp disappeared we just carry on.
1210 if (error == EJUSTRETURN && tvp != NULL) {
1215 * Get the tvp ino if the lookup succeeded. We may have to restart
1216 * if the non-blocking acquire fails.
1220 error = VFS_VGET(mp, ino, LK_EXCLUSIVE | LK_NOWAIT, &nvp);
1225 VOP_UNLOCK(fdvp, 0);
1226 VOP_UNLOCK(tdvp, 0);
1230 error = VFS_VGET(mp, ino, LK_EXCLUSIVE, &nvp);
1234 atomic_add_int(&rename_restarts, 1);
1244 if (tvp && ((VTOI(tvp)->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
1245 (VTOI(tdvp)->i_flags & APPEND))) {
1250 * Renaming a file to itself has no effect. The upper layers should
1251 * not call us in that case. However, things could change after
1252 * we drop the locks above.
1260 ino = fip->i_number;
1261 if (fip->i_nlink >= LINK_MAX) {
1265 if ((fip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))
1266 || (fdp->i_flags & APPEND)) {
1270 if ((fip->i_mode & IFMT) == IFDIR) {
1272 * Avoid ".", "..", and aliases of "." for obvious reasons.
1274 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
1276 (fcnp->cn_flags | tcnp->cn_flags) & ISDOTDOT) {
1280 if (fdp->i_number != tdp->i_number)
1281 newparent = tdp->i_number;
1284 if ((fvp->v_type == VDIR && fvp->v_mountedhere != NULL) ||
1285 (tvp != NULL && tvp->v_type == VDIR &&
1286 tvp->v_mountedhere != NULL)) {
1292 * If ".." must be changed (ie the directory gets a new
1293 * parent) then the source directory must not be in the
1294 * directory hierarchy above the target, as this would
1295 * orphan everything below the source directory. Also
1296 * the user must have write permission in the source so
1297 * as to be able to change "..".
1299 if (doingdirectory && newparent) {
1300 error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_thread);
1303 error = ufs_checkpath(ino, fdp->i_number, tdp, tcnp->cn_cred,
1306 * We encountered a lock that we have to wait for. Unlock
1307 * everything else and VGET before restarting.
1310 VOP_UNLOCK(fdvp, 0);
1312 VOP_UNLOCK(tdvp, 0);
1315 error = VFS_VGET(mp, ino, LK_SHARED, &nvp);
1318 atomic_add_int(&rename_restarts, 1);
1323 if ((tcnp->cn_flags & SAVESTART) == 0)
1324 panic("ufs_rename: lost to startdir");
1326 if (fip->i_effnlink == 0 || fdp->i_effnlink == 0 ||
1327 tdp->i_effnlink == 0)
1328 panic("Bad effnlink fip %p, fdp %p, tdp %p", fip, fdp, tdp);
1331 * 1) Bump link count while we're moving stuff
1332 * around. If we crash somewhere before
1333 * completing our work, the link count
1334 * may be wrong, but correctable.
1338 DIP_SET(fip, i_nlink, fip->i_nlink);
1339 fip->i_flag |= IN_CHANGE;
1340 if (DOINGSOFTDEP(fvp))
1341 softdep_setup_link(tdp, fip);
1342 error = UFS_UPDATE(fvp, !(DOINGSOFTDEP(fvp) | DOINGASYNC(fvp)));
1347 * 2) If target doesn't exist, link the target
1348 * to the source and unlink the source.
1349 * Otherwise, rewrite the target directory
1350 * entry to reference the source inode and
1351 * expunge the original entry's existence.
1354 if (tdp->i_dev != fip->i_dev)
1355 panic("ufs_rename: EXDEV");
1356 if (doingdirectory && newparent) {
1358 * Account for ".." in new directory.
1359 * When source and destination have the same
1360 * parent we don't adjust the link count. The
1361 * actual link modification is completed when
1362 * .. is rewritten below.
1364 if ((nlink_t)tdp->i_nlink >= LINK_MAX) {
1369 ufs_makedirentry(fip, tcnp, &newdir);
1370 error = ufs_direnter(tdvp, NULL, &newdir, tcnp, NULL, 1);
1373 /* Setup tdvp for directory compaction if needed. */
1374 if (tdp->i_count && tdp->i_endoff &&
1375 tdp->i_endoff < tdp->i_size)
1376 endoff = tdp->i_endoff;
1378 if (tip->i_dev != tdp->i_dev || tip->i_dev != fip->i_dev)
1379 panic("ufs_rename: EXDEV");
1381 * Short circuit rename(foo, foo).
1383 if (tip->i_number == fip->i_number)
1384 panic("ufs_rename: same file");
1386 * If the parent directory is "sticky", then the caller
1387 * must possess VADMIN for the parent directory, or the
1388 * destination of the rename. This implements append-only
1391 if ((tdp->i_mode & S_ISTXT) &&
1392 VOP_ACCESS(tdvp, VADMIN, tcnp->cn_cred, td) &&
1393 VOP_ACCESS(tvp, VADMIN, tcnp->cn_cred, td)) {
1398 * Target must be empty if a directory and have no links
1399 * to it. Also, ensure source and target are compatible
1400 * (both directories, or both not directories).
1402 if ((tip->i_mode & IFMT) == IFDIR) {
1403 if ((tip->i_effnlink > 2) ||
1404 !ufs_dirempty(tip, tdp->i_number, tcnp->cn_cred)) {
1408 if (!doingdirectory) {
1413 } else if (doingdirectory) {
1417 if (doingdirectory) {
1420 if (DOINGSOFTDEP(tdvp))
1421 softdep_change_linkcnt(tdp);
1424 if (DOINGSOFTDEP(tvp))
1425 softdep_change_linkcnt(tip);
1427 error = ufs_dirrewrite(tdp, tip, fip->i_number,
1428 IFTODT(fip->i_mode),
1429 (doingdirectory && newparent) ? newparent : doingdirectory);
1431 if (doingdirectory) {
1434 if (DOINGSOFTDEP(tdvp))
1435 softdep_change_linkcnt(tdp);
1438 if (DOINGSOFTDEP(tvp))
1439 softdep_change_linkcnt(tip);
1442 if (doingdirectory && !DOINGSOFTDEP(tvp)) {
1444 * The only stuff left in the directory is "."
1445 * and "..". The "." reference is inconsequential
1446 * since we are quashing it. We have removed the "."
1447 * reference and the reference in the parent directory,
1448 * but there may be other hard links. The soft
1449 * dependency code will arrange to do these operations
1450 * after the parent directory entry has been deleted on
1451 * disk, so when running with that code we avoid doing
1456 DIP_SET(tdp, i_nlink, tdp->i_nlink);
1457 tdp->i_flag |= IN_CHANGE;
1460 DIP_SET(tip, i_nlink, tip->i_nlink);
1461 tip->i_flag |= IN_CHANGE;
1466 * 3) Unlink the source. We have to resolve the path again to
1467 * fixup the directory offset and count for ufs_dirremove.
1470 error = ufs_lookup_ino(fdvp, NULL, fcnp, &ino);
1472 panic("ufs_rename: from entry went away!");
1473 if (ino != fip->i_number)
1474 panic("ufs_rename: ino mismatch %ju != %ju\n",
1475 (uintmax_t)ino, (uintmax_t)fip->i_number);
1478 * If the source is a directory with a
1479 * new parent, the link count of the old
1480 * parent directory must be decremented
1481 * and ".." set to point to the new parent.
1483 if (doingdirectory && newparent) {
1485 * If tip exists we simply use its link, otherwise we must
1491 DIP_SET(tdp, i_nlink, tdp->i_nlink);
1492 tdp->i_flag |= IN_CHANGE;
1493 if (DOINGSOFTDEP(tdvp))
1494 softdep_setup_dotdot_link(tdp, fip);
1495 error = UFS_UPDATE(tdvp, !(DOINGSOFTDEP(tdvp) |
1497 /* Don't go to bad here as the new link exists. */
1500 } else if (DOINGSUJ(tdvp))
1501 /* Journal must account for each new link. */
1502 softdep_setup_dotdot_link(tdp, fip);
1503 fip->i_offset = mastertemplate.dot_reclen;
1504 ufs_dirrewrite(fip, fdp, newparent, DT_DIR, 0);
1507 error = ufs_dirremove(fdvp, fip, fcnp->cn_flags, 0);
1509 * The kern_renameat() looks up the fvp using the DELETE flag, which
1510 * causes the removal of the name cache entry for fvp.
1511 * As the relookup of the fvp is done in two steps:
1512 * ufs_lookup_ino() and then VFS_VGET(), another thread might do a
1513 * normal lookup of the from name just before the VFS_VGET() call,
1514 * causing the cache entry to be re-instantiated.
1516 * The same issue also applies to tvp if it exists as
1517 * otherwise we may have a stale name cache entry for the new
1518 * name that references the old i-node if it has other links
1519 * or open file descriptors.
1524 cache_purge_negative(tdvp);
1532 * If compaction or fsync was requested do it now that other locks
1533 * are no longer needed.
1535 if (error == 0 && endoff != 0) {
1537 if (tdp->i_dirhash != NULL)
1538 ufsdirhash_dirtrunc(tdp, endoff);
1540 UFS_TRUNCATE(tdvp, endoff, IO_NORMAL | IO_SYNC, tcnp->cn_cred);
1542 if (error == 0 && tdp->i_flag & IN_NEEDSYNC)
1543 error = VOP_FSYNC(tdvp, MNT_WAIT, td);
1550 DIP_SET(fip, i_nlink, fip->i_nlink);
1551 fip->i_flag |= IN_CHANGE;
1552 if (DOINGSOFTDEP(fvp))
1553 softdep_revert_link(tdp, fip);
1568 ufs_do_posix1e_acl_inheritance_dir(struct vnode *dvp, struct vnode *tvp,
1569 mode_t dmode, struct ucred *cred, struct thread *td)
1572 struct inode *ip = VTOI(tvp);
1573 struct acl *dacl, *acl;
1575 acl = acl_alloc(M_WAITOK);
1576 dacl = acl_alloc(M_WAITOK);
1579 * Retrieve default ACL from parent, if any.
1581 error = VOP_GETACL(dvp, ACL_TYPE_DEFAULT, acl, cred, td);
1585 * Retrieved a default ACL, so merge mode and ACL if
1586 * necessary. If the ACL is empty, fall through to
1587 * the "not defined or available" case.
1589 if (acl->acl_cnt != 0) {
1590 dmode = acl_posix1e_newfilemode(dmode, acl);
1592 DIP_SET(ip, i_mode, dmode);
1594 ufs_sync_acl_from_inode(ip, acl);
1601 * Just use the mode as-is.
1604 DIP_SET(ip, i_mode, dmode);
1613 * XXX: If we abort now, will Soft Updates notify the extattr
1614 * code that the EAs for the file need to be released?
1616 error = VOP_SETACL(tvp, ACL_TYPE_ACCESS, acl, cred, td);
1618 error = VOP_SETACL(tvp, ACL_TYPE_DEFAULT, dacl, cred, td);
1625 * XXX: This should not happen, as EOPNOTSUPP above
1626 * was supposed to free acl.
1628 printf("ufs_mkdir: VOP_GETACL() but no VOP_SETACL()\n");
1630 panic("ufs_mkdir: VOP_GETACL() but no VOP_SETACL()");
1646 ufs_do_posix1e_acl_inheritance_file(struct vnode *dvp, struct vnode *tvp,
1647 mode_t mode, struct ucred *cred, struct thread *td)
1650 struct inode *ip = VTOI(tvp);
1653 acl = acl_alloc(M_WAITOK);
1656 * Retrieve default ACL for parent, if any.
1658 error = VOP_GETACL(dvp, ACL_TYPE_DEFAULT, acl, cred, td);
1662 * Retrieved a default ACL, so merge mode and ACL if
1665 if (acl->acl_cnt != 0) {
1667 * Two possible ways for default ACL to not
1668 * be present. First, the EA can be
1669 * undefined, or second, the default ACL can
1670 * be blank. If it's blank, fall through to
1671 * the it's not defined case.
1673 mode = acl_posix1e_newfilemode(mode, acl);
1675 DIP_SET(ip, i_mode, mode);
1676 ufs_sync_acl_from_inode(ip, acl);
1683 * Just use the mode as-is.
1686 DIP_SET(ip, i_mode, mode);
1695 * XXX: If we abort now, will Soft Updates notify the extattr
1696 * code that the EAs for the file need to be released?
1698 error = VOP_SETACL(tvp, ACL_TYPE_ACCESS, acl, cred, td);
1705 * XXX: This should not happen, as EOPNOTSUPP above was
1706 * supposed to free acl.
1708 printf("ufs_makeinode: VOP_GETACL() but no "
1710 /* panic("ufs_makeinode: VOP_GETACL() but no "
1725 ufs_do_nfs4_acl_inheritance(struct vnode *dvp, struct vnode *tvp,
1726 mode_t child_mode, struct ucred *cred, struct thread *td)
1729 struct acl *parent_aclp, *child_aclp;
1731 parent_aclp = acl_alloc(M_WAITOK);
1732 child_aclp = acl_alloc(M_WAITOK | M_ZERO);
1734 error = ufs_getacl_nfs4_internal(dvp, parent_aclp, td);
1737 acl_nfs4_compute_inherited_acl(parent_aclp, child_aclp,
1738 child_mode, VTOI(tvp)->i_uid, tvp->v_type == VDIR);
1739 error = ufs_setacl_nfs4_internal(tvp, child_aclp, td);
1743 acl_free(parent_aclp);
1744 acl_free(child_aclp);
1755 struct vop_mkdir_args /* {
1756 struct vnode *a_dvp;
1757 struct vnode **a_vpp;
1758 struct componentname *a_cnp;
1759 struct vattr *a_vap;
1762 struct vnode *dvp = ap->a_dvp;
1763 struct vattr *vap = ap->a_vap;
1764 struct componentname *cnp = ap->a_cnp;
1765 struct inode *ip, *dp;
1768 struct dirtemplate dirtemplate, *dtp;
1769 struct direct newdir;
1774 if ((cnp->cn_flags & HASBUF) == 0)
1775 panic("ufs_mkdir: no name");
1778 if ((nlink_t)dp->i_nlink >= LINK_MAX) {
1782 dmode = vap->va_mode & 0777;
1785 * Must simulate part of ufs_makeinode here to acquire the inode,
1786 * but not have it entered in the parent directory. The entry is
1787 * made later after writing "." and ".." entries.
1789 error = UFS_VALLOC(dvp, dmode, cnp->cn_cred, &tvp);
1793 ip->i_gid = dp->i_gid;
1794 DIP_SET(ip, i_gid, dp->i_gid);
1798 struct ucred ucred, *ucp;
1803 * If we are hacking owners here, (only do this where told to)
1804 * and we are not giving it TO root, (would subvert quotas)
1805 * then go ahead and give it to the other user.
1806 * The new directory also inherits the SUID bit.
1807 * If user's UID and dir UID are the same,
1808 * 'give it away' so that the SUID is still forced on.
1810 if ((dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
1811 (dp->i_mode & ISUID) && dp->i_uid) {
1813 ip->i_uid = dp->i_uid;
1814 DIP_SET(ip, i_uid, dp->i_uid);
1816 if (dp->i_uid != cnp->cn_cred->cr_uid) {
1818 * Make sure the correct user gets charged
1820 * Make a dummy credential for the victim.
1821 * XXX This seems to never be accessed out of
1822 * our context so a stack variable is ok.
1824 refcount_init(&ucred.cr_ref, 1);
1825 ucred.cr_uid = ip->i_uid;
1826 ucred.cr_ngroups = 1;
1827 ucred.cr_groups = &ucred_group;
1828 ucred.cr_groups[0] = dp->i_gid;
1833 ip->i_uid = cnp->cn_cred->cr_uid;
1834 DIP_SET(ip, i_uid, ip->i_uid);
1837 if ((error = getinoquota(ip)) ||
1838 (error = chkiq(ip, 1, ucp, 0))) {
1839 if (DOINGSOFTDEP(tvp))
1840 softdep_revert_link(dp, ip);
1841 UFS_VFREE(tvp, ip->i_number, dmode);
1847 #else /* !SUIDDIR */
1848 ip->i_uid = cnp->cn_cred->cr_uid;
1849 DIP_SET(ip, i_uid, ip->i_uid);
1851 if ((error = getinoquota(ip)) ||
1852 (error = chkiq(ip, 1, cnp->cn_cred, 0))) {
1853 if (DOINGSOFTDEP(tvp))
1854 softdep_revert_link(dp, ip);
1855 UFS_VFREE(tvp, ip->i_number, dmode);
1860 #endif /* !SUIDDIR */
1861 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
1863 DIP_SET(ip, i_mode, dmode);
1864 tvp->v_type = VDIR; /* Rest init'd in getnewvnode(). */
1867 DIP_SET(ip, i_nlink, 2);
1869 if (cnp->cn_flags & ISWHITEOUT) {
1870 ip->i_flags |= UF_OPAQUE;
1871 DIP_SET(ip, i_flags, ip->i_flags);
1875 * Bump link count in parent directory to reflect work done below.
1876 * Should be done before reference is created so cleanup is
1877 * possible if we crash.
1881 DIP_SET(dp, i_nlink, dp->i_nlink);
1882 dp->i_flag |= IN_CHANGE;
1883 if (DOINGSOFTDEP(dvp))
1884 softdep_setup_mkdir(dp, ip);
1885 error = UFS_UPDATE(dvp, !(DOINGSOFTDEP(dvp) | DOINGASYNC(dvp)));
1889 if (dvp->v_mount->mnt_flag & MNT_MULTILABEL) {
1890 error = mac_vnode_create_extattr(cnp->cn_cred, dvp->v_mount,
1897 if (dvp->v_mount->mnt_flag & MNT_ACLS) {
1898 error = ufs_do_posix1e_acl_inheritance_dir(dvp, tvp, dmode,
1899 cnp->cn_cred, cnp->cn_thread);
1902 } else if (dvp->v_mount->mnt_flag & MNT_NFS4ACLS) {
1903 error = ufs_do_nfs4_acl_inheritance(dvp, tvp, dmode,
1904 cnp->cn_cred, cnp->cn_thread);
1908 #endif /* !UFS_ACL */
1911 * Initialize directory with "." and ".." from static template.
1913 if (dvp->v_mount->mnt_maxsymlinklen > 0)
1914 dtp = &mastertemplate;
1916 dtp = (struct dirtemplate *)&omastertemplate;
1918 dirtemplate.dot_ino = ip->i_number;
1919 dirtemplate.dotdot_ino = dp->i_number;
1920 if ((error = UFS_BALLOC(tvp, (off_t)0, DIRBLKSIZ, cnp->cn_cred,
1921 BA_CLRBUF, &bp)) != 0)
1923 ip->i_size = DIRBLKSIZ;
1924 DIP_SET(ip, i_size, DIRBLKSIZ);
1925 ip->i_flag |= IN_CHANGE | IN_UPDATE;
1926 vnode_pager_setsize(tvp, (u_long)ip->i_size);
1927 bcopy((caddr_t)&dirtemplate, (caddr_t)bp->b_data, sizeof dirtemplate);
1928 if (DOINGSOFTDEP(tvp)) {
1930 * Ensure that the entire newly allocated block is a
1931 * valid directory so that future growth within the
1932 * block does not have to ensure that the block is
1933 * written before the inode.
1936 while (blkoff < bp->b_bcount) {
1938 (bp->b_data + blkoff))->d_reclen = DIRBLKSIZ;
1939 blkoff += DIRBLKSIZ;
1942 if ((error = UFS_UPDATE(tvp, !(DOINGSOFTDEP(tvp) |
1943 DOINGASYNC(tvp)))) != 0) {
1948 * Directory set up, now install its entry in the parent directory.
1950 * If we are not doing soft dependencies, then we must write out the
1951 * buffer containing the new directory body before entering the new
1952 * name in the parent. If we are doing soft dependencies, then the
1953 * buffer containing the new directory body will be passed to and
1954 * released in the soft dependency code after the code has attached
1955 * an appropriate ordering dependency to the buffer which ensures that
1956 * the buffer is written before the new name is written in the parent.
1958 if (DOINGASYNC(dvp))
1960 else if (!DOINGSOFTDEP(dvp) && ((error = bwrite(bp))))
1962 ufs_makedirentry(ip, cnp, &newdir);
1963 error = ufs_direnter(dvp, tvp, &newdir, cnp, bp, 0);
1971 DIP_SET(dp, i_nlink, dp->i_nlink);
1972 dp->i_flag |= IN_CHANGE;
1974 * No need to do an explicit VOP_TRUNCATE here, vrele will
1975 * do this for us because we set the link count to 0.
1979 DIP_SET(ip, i_nlink, 0);
1980 ip->i_flag |= IN_CHANGE;
1981 if (DOINGSOFTDEP(tvp))
1982 softdep_revert_mkdir(dp, ip);
1991 * Rmdir system call.
1995 struct vop_rmdir_args /* {
1996 struct vnode *a_dvp;
1998 struct componentname *a_cnp;
2001 struct vnode *vp = ap->a_vp;
2002 struct vnode *dvp = ap->a_dvp;
2003 struct componentname *cnp = ap->a_cnp;
2004 struct inode *ip, *dp;
2011 * Do not remove a directory that is in the process of being renamed.
2012 * Verify the directory is empty (and valid). Rmdir ".." will not be
2013 * valid since ".." will contain a reference to the current directory
2014 * and thus be non-empty. Do not allow the removal of mounted on
2015 * directories (this can happen when an NFS exported filesystem
2016 * tries to remove a locally mounted on directory).
2019 if (ip->i_effnlink < 2) {
2023 if (dp->i_effnlink < 3)
2024 panic("ufs_dirrem: Bad link count %d on parent",
2026 if (!ufs_dirempty(ip, dp->i_number, cnp->cn_cred)) {
2030 if ((dp->i_flags & APPEND)
2031 || (ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))) {
2035 if (vp->v_mountedhere != 0) {
2040 ufs_gjournal_orphan(vp);
2043 * Delete reference to directory before purging
2044 * inode. If we crash in between, the directory
2045 * will be reattached to lost+found,
2049 if (DOINGSOFTDEP(vp))
2050 softdep_setup_rmdir(dp, ip);
2051 error = ufs_dirremove(dvp, ip, cnp->cn_flags, 1);
2055 if (DOINGSOFTDEP(vp))
2056 softdep_revert_rmdir(dp, ip);
2061 * The only stuff left in the directory is "." and "..". The "."
2062 * reference is inconsequential since we are quashing it. The soft
2063 * dependency code will arrange to do these operations after
2064 * the parent directory entry has been deleted on disk, so
2065 * when running with that code we avoid doing them now.
2067 if (!DOINGSOFTDEP(vp)) {
2069 DIP_SET(dp, i_nlink, dp->i_nlink);
2070 dp->i_flag |= IN_CHANGE;
2071 error = UFS_UPDATE(dvp, 0);
2073 DIP_SET(ip, i_nlink, ip->i_nlink);
2074 ip->i_flag |= IN_CHANGE;
2078 /* Kill any active hash; i_effnlink == 0, so it will not come back. */
2079 if (ip->i_dirhash != NULL)
2080 ufsdirhash_free(ip);
2087 * symlink -- make a symbolic link
2091 struct vop_symlink_args /* {
2092 struct vnode *a_dvp;
2093 struct vnode **a_vpp;
2094 struct componentname *a_cnp;
2095 struct vattr *a_vap;
2099 struct vnode *vp, **vpp = ap->a_vpp;
2103 error = ufs_makeinode(IFLNK | ap->a_vap->va_mode, ap->a_dvp,
2108 len = strlen(ap->a_target);
2109 if (len < vp->v_mount->mnt_maxsymlinklen) {
2111 bcopy(ap->a_target, SHORTLINK(ip), len);
2113 DIP_SET(ip, i_size, len);
2114 ip->i_flag |= IN_CHANGE | IN_UPDATE;
2115 error = UFS_UPDATE(vp, 0);
2117 error = vn_rdwr(UIO_WRITE, vp, ap->a_target, len, (off_t)0,
2118 UIO_SYSSPACE, IO_NODELOCKED | IO_NOMACCHECK,
2119 ap->a_cnp->cn_cred, NOCRED, NULL, NULL);
2126 * Vnode op for reading directories.
2130 struct vop_readdir_args /* {
2133 struct ucred *a_cred;
2139 struct vnode *vp = ap->a_vp;
2140 struct uio *uio = ap->a_uio;
2143 struct direct *dp, *edp;
2145 struct dirent dstdp;
2146 off_t offset, startoffset;
2147 size_t readcnt, skipcnt;
2152 if (uio->uio_offset < 0)
2155 if (ip->i_effnlink == 0)
2157 if (ap->a_ncookies != NULL) {
2158 ncookies = uio->uio_resid;
2159 if (uio->uio_offset >= ip->i_size)
2161 else if (ip->i_size - uio->uio_offset < ncookies)
2162 ncookies = ip->i_size - uio->uio_offset;
2163 ncookies = ncookies / (offsetof(struct direct, d_name) + 4) + 1;
2164 cookies = malloc(ncookies * sizeof(*cookies), M_TEMP, M_WAITOK);
2165 *ap->a_ncookies = ncookies;
2166 *ap->a_cookies = cookies;
2171 offset = startoffset = uio->uio_offset;
2172 startresid = uio->uio_resid;
2174 while (error == 0 && uio->uio_resid > 0 &&
2175 uio->uio_offset < ip->i_size) {
2176 error = ffs_blkatoff(vp, uio->uio_offset, NULL, &bp);
2179 if (bp->b_offset + bp->b_bcount > ip->i_size)
2180 readcnt = ip->i_size - bp->b_offset;
2182 readcnt = bp->b_bcount;
2183 skipcnt = (size_t)(uio->uio_offset - bp->b_offset) &
2184 ~(size_t)(DIRBLKSIZ - 1);
2185 offset = bp->b_offset + skipcnt;
2186 dp = (struct direct *)&bp->b_data[skipcnt];
2187 edp = (struct direct *)&bp->b_data[readcnt];
2188 while (error == 0 && uio->uio_resid > 0 && dp < edp) {
2189 if (dp->d_reclen <= offsetof(struct direct, d_name) ||
2190 (caddr_t)dp + dp->d_reclen > (caddr_t)edp) {
2194 #if BYTE_ORDER == LITTLE_ENDIAN
2195 /* Old filesystem format. */
2196 if (vp->v_mount->mnt_maxsymlinklen <= 0) {
2197 dstdp.d_namlen = dp->d_type;
2198 dstdp.d_type = dp->d_namlen;
2202 dstdp.d_namlen = dp->d_namlen;
2203 dstdp.d_type = dp->d_type;
2205 if (offsetof(struct direct, d_name) + dstdp.d_namlen >
2210 if (offset < startoffset || dp->d_ino == 0)
2212 dstdp.d_fileno = dp->d_ino;
2213 dstdp.d_reclen = GENERIC_DIRSIZ(&dstdp);
2214 bcopy(dp->d_name, dstdp.d_name, dstdp.d_namlen);
2215 dstdp.d_name[dstdp.d_namlen] = '\0';
2216 if (dstdp.d_reclen > uio->uio_resid) {
2217 if (uio->uio_resid == startresid)
2220 error = EJUSTRETURN;
2224 error = uiomove((caddr_t)&dstdp, dstdp.d_reclen, uio);
2227 if (cookies != NULL) {
2228 KASSERT(ncookies > 0,
2229 ("ufs_readdir: cookies buffer too small"));
2230 *cookies = offset + dp->d_reclen;
2235 offset += dp->d_reclen;
2236 dp = (struct direct *)((caddr_t)dp + dp->d_reclen);
2239 uio->uio_offset = offset;
2241 /* We need to correct uio_offset. */
2242 uio->uio_offset = offset;
2243 if (error == EJUSTRETURN)
2245 if (ap->a_ncookies != NULL) {
2247 ap->a_ncookies -= ncookies;
2249 free(*ap->a_cookies, M_TEMP);
2250 *ap->a_ncookies = 0;
2251 *ap->a_cookies = NULL;
2254 if (error == 0 && ap->a_eofflag)
2255 *ap->a_eofflag = ip->i_size <= uio->uio_offset;
2260 * Return target name of a symbolic link
2264 struct vop_readlink_args /* {
2267 struct ucred *a_cred;
2270 struct vnode *vp = ap->a_vp;
2271 struct inode *ip = VTOI(vp);
2275 if ((isize < vp->v_mount->mnt_maxsymlinklen) ||
2276 DIP(ip, i_blocks) == 0) { /* XXX - for old fastlink support */
2277 return (uiomove(SHORTLINK(ip), isize, ap->a_uio));
2279 return (VOP_READ(vp, ap->a_uio, 0, ap->a_cred));
2283 * Calculate the logical to physical mapping if not done already,
2284 * then call the device strategy routine.
2286 * In order to be able to swap to a file, the ufs_bmaparray() operation may not
2287 * deadlock on memory. See ufs_bmap() for details.
2291 struct vop_strategy_args /* {
2296 struct buf *bp = ap->a_bp;
2297 struct vnode *vp = ap->a_vp;
2304 if (bp->b_blkno == bp->b_lblkno) {
2305 error = ufs_bmaparray(vp, bp->b_lblkno, &blkno, bp, NULL, NULL);
2306 bp->b_blkno = blkno;
2308 bp->b_error = error;
2309 bp->b_ioflags |= BIO_ERROR;
2313 if ((long)bp->b_blkno == -1)
2316 if ((long)bp->b_blkno == -1) {
2320 bp->b_iooffset = dbtob(bp->b_blkno);
2321 bo = ip->i_umbufobj;
2322 BO_STRATEGY(bo, bp);
2327 * Print out the contents of an inode.
2331 struct vop_print_args /* {
2335 struct vnode *vp = ap->a_vp;
2336 struct inode *ip = VTOI(vp);
2338 printf("\tino %lu, on dev %s", (u_long)ip->i_number,
2339 devtoname(ip->i_dev));
2340 if (vp->v_type == VFIFO)
2347 * Close wrapper for fifos.
2349 * Update the times on the inode then do device close.
2353 struct vop_close_args /* {
2356 struct ucred *a_cred;
2357 struct thread *a_td;
2360 struct vnode *vp = ap->a_vp;
2364 usecount = vp->v_usecount;
2366 ufs_itimes_locked(vp);
2368 return (fifo_specops.vop_close(ap));
2372 * Kqfilter wrapper for fifos.
2374 * Fall through to ufs kqfilter routines if needed
2377 ufsfifo_kqfilter(ap)
2378 struct vop_kqfilter_args *ap;
2382 error = fifo_specops.vop_kqfilter(ap);
2384 error = vfs_kqfilter(ap);
2389 * Return POSIX pathconf information applicable to fifos.
2392 ufsfifo_pathconf(ap)
2393 struct vop_pathconf_args /* {
2400 switch (ap->a_name) {
2401 case _PC_ACL_EXTENDED:
2403 case _PC_ACL_PATH_MAX:
2404 case _PC_MAC_PRESENT:
2405 return (ufs_pathconf(ap));
2407 return (fifo_specops.vop_pathconf(ap));
2413 * Return POSIX pathconf information applicable to ufs filesystems.
2417 struct vop_pathconf_args /* {
2426 switch (ap->a_name) {
2428 *ap->a_retval = LINK_MAX;
2431 *ap->a_retval = NAME_MAX;
2434 *ap->a_retval = PATH_MAX;
2437 *ap->a_retval = PIPE_BUF;
2439 case _PC_CHOWN_RESTRICTED:
2445 case _PC_ACL_EXTENDED:
2447 if (ap->a_vp->v_mount->mnt_flag & MNT_ACLS)
2458 if (ap->a_vp->v_mount->mnt_flag & MNT_NFS4ACLS)
2467 case _PC_ACL_PATH_MAX:
2469 if (ap->a_vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS))
2470 *ap->a_retval = ACL_MAX_ENTRIES;
2477 case _PC_MAC_PRESENT:
2479 if (ap->a_vp->v_mount->mnt_flag & MNT_MULTILABEL)
2487 case _PC_MIN_HOLE_SIZE:
2488 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2491 /* _PC_ASYNC_IO should have been handled by upper layers. */
2492 KASSERT(0, ("_PC_ASYNC_IO should not get here"));
2501 case _PC_ALLOC_SIZE_MIN:
2502 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_bsize;
2504 case _PC_FILESIZEBITS:
2507 case _PC_REC_INCR_XFER_SIZE:
2508 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2510 case _PC_REC_MAX_XFER_SIZE:
2511 *ap->a_retval = -1; /* means ``unlimited'' */
2513 case _PC_REC_MIN_XFER_SIZE:
2514 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2516 case _PC_REC_XFER_ALIGN:
2517 *ap->a_retval = PAGE_SIZE;
2519 case _PC_SYMLINK_MAX:
2520 *ap->a_retval = MAXPATHLEN;
2531 * Initialize the vnode associated with a new inode, handle aliased
2535 ufs_vinit(mntp, fifoops, vpp)
2537 struct vop_vector *fifoops;
2545 vp->v_type = IFTOVT(ip->i_mode);
2546 if (vp->v_type == VFIFO)
2548 ASSERT_VOP_LOCKED(vp, "ufs_vinit");
2549 if (ip->i_number == ROOTINO)
2550 vp->v_vflag |= VV_ROOT;
2556 * Allocate a new inode.
2557 * Vnode dvp must be locked.
2560 ufs_makeinode(mode, dvp, vpp, cnp)
2564 struct componentname *cnp;
2566 struct inode *ip, *pdir;
2567 struct direct newdir;
2573 if ((cnp->cn_flags & HASBUF) == 0)
2574 panic("ufs_makeinode: no name");
2577 if ((mode & IFMT) == 0)
2580 if (VTOI(dvp)->i_effnlink < 2)
2581 panic("ufs_makeinode: Bad link count %d on parent",
2582 VTOI(dvp)->i_effnlink);
2583 error = UFS_VALLOC(dvp, mode, cnp->cn_cred, &tvp);
2587 ip->i_gid = pdir->i_gid;
2588 DIP_SET(ip, i_gid, pdir->i_gid);
2592 struct ucred ucred, *ucp;
2597 * If we are not the owner of the directory,
2598 * and we are hacking owners here, (only do this where told to)
2599 * and we are not giving it TO root, (would subvert quotas)
2600 * then go ahead and give it to the other user.
2601 * Note that this drops off the execute bits for security.
2603 if ((dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
2604 (pdir->i_mode & ISUID) &&
2605 (pdir->i_uid != cnp->cn_cred->cr_uid) && pdir->i_uid) {
2606 ip->i_uid = pdir->i_uid;
2607 DIP_SET(ip, i_uid, ip->i_uid);
2611 * Make sure the correct user gets charged
2613 * Quickly knock up a dummy credential for the victim.
2614 * XXX This seems to never be accessed out of our
2615 * context so a stack variable is ok.
2617 refcount_init(&ucred.cr_ref, 1);
2618 ucred.cr_uid = ip->i_uid;
2619 ucred.cr_ngroups = 1;
2620 ucred.cr_groups = &ucred_group;
2621 ucred.cr_groups[0] = pdir->i_gid;
2625 ip->i_uid = cnp->cn_cred->cr_uid;
2626 DIP_SET(ip, i_uid, ip->i_uid);
2630 if ((error = getinoquota(ip)) ||
2631 (error = chkiq(ip, 1, ucp, 0))) {
2632 if (DOINGSOFTDEP(tvp))
2633 softdep_revert_link(pdir, ip);
2634 UFS_VFREE(tvp, ip->i_number, mode);
2640 #else /* !SUIDDIR */
2641 ip->i_uid = cnp->cn_cred->cr_uid;
2642 DIP_SET(ip, i_uid, ip->i_uid);
2644 if ((error = getinoquota(ip)) ||
2645 (error = chkiq(ip, 1, cnp->cn_cred, 0))) {
2646 if (DOINGSOFTDEP(tvp))
2647 softdep_revert_link(pdir, ip);
2648 UFS_VFREE(tvp, ip->i_number, mode);
2653 #endif /* !SUIDDIR */
2654 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
2656 DIP_SET(ip, i_mode, mode);
2657 tvp->v_type = IFTOVT(mode); /* Rest init'd in getnewvnode(). */
2660 DIP_SET(ip, i_nlink, 1);
2661 if (DOINGSOFTDEP(tvp))
2662 softdep_setup_create(VTOI(dvp), ip);
2663 if ((ip->i_mode & ISGID) && !groupmember(ip->i_gid, cnp->cn_cred) &&
2664 priv_check_cred(cnp->cn_cred, PRIV_VFS_SETGID, 0)) {
2665 ip->i_mode &= ~ISGID;
2666 DIP_SET(ip, i_mode, ip->i_mode);
2669 if (cnp->cn_flags & ISWHITEOUT) {
2670 ip->i_flags |= UF_OPAQUE;
2671 DIP_SET(ip, i_flags, ip->i_flags);
2675 * Make sure inode goes to disk before directory entry.
2677 error = UFS_UPDATE(tvp, !(DOINGSOFTDEP(tvp) | DOINGASYNC(tvp)));
2681 if (dvp->v_mount->mnt_flag & MNT_MULTILABEL) {
2682 error = mac_vnode_create_extattr(cnp->cn_cred, dvp->v_mount,
2689 if (dvp->v_mount->mnt_flag & MNT_ACLS) {
2690 error = ufs_do_posix1e_acl_inheritance_file(dvp, tvp, mode,
2691 cnp->cn_cred, cnp->cn_thread);
2694 } else if (dvp->v_mount->mnt_flag & MNT_NFS4ACLS) {
2695 error = ufs_do_nfs4_acl_inheritance(dvp, tvp, mode,
2696 cnp->cn_cred, cnp->cn_thread);
2700 #endif /* !UFS_ACL */
2701 ufs_makedirentry(ip, cnp, &newdir);
2702 error = ufs_direnter(dvp, tvp, &newdir, cnp, NULL, 0);
2710 * Write error occurred trying to update the inode
2711 * or the directory so must deallocate the inode.
2715 DIP_SET(ip, i_nlink, 0);
2716 ip->i_flag |= IN_CHANGE;
2717 if (DOINGSOFTDEP(tvp))
2718 softdep_revert_create(VTOI(dvp), ip);
2724 ufs_ioctl(struct vop_ioctl_args *ap)
2727 switch (ap->a_command) {
2730 return (vn_bmap_seekhole(ap->a_vp, ap->a_command,
2731 (off_t *)ap->a_data, ap->a_cred));
2737 /* Global vfs data structures for ufs. */
2738 struct vop_vector ufs_vnodeops = {
2739 .vop_default = &default_vnodeops,
2740 .vop_fsync = VOP_PANIC,
2741 .vop_read = VOP_PANIC,
2742 .vop_reallocblks = VOP_PANIC,
2743 .vop_write = VOP_PANIC,
2744 .vop_accessx = ufs_accessx,
2745 .vop_bmap = ufs_bmap,
2746 .vop_cachedlookup = ufs_lookup,
2747 .vop_close = ufs_close,
2748 .vop_create = ufs_create,
2749 .vop_getattr = ufs_getattr,
2750 .vop_inactive = ufs_inactive,
2751 .vop_ioctl = ufs_ioctl,
2752 .vop_link = ufs_link,
2753 .vop_lookup = vfs_cache_lookup,
2754 .vop_markatime = ufs_markatime,
2755 .vop_mkdir = ufs_mkdir,
2756 .vop_mknod = ufs_mknod,
2757 .vop_open = ufs_open,
2758 .vop_pathconf = ufs_pathconf,
2759 .vop_poll = vop_stdpoll,
2760 .vop_print = ufs_print,
2761 .vop_readdir = ufs_readdir,
2762 .vop_readlink = ufs_readlink,
2763 .vop_reclaim = ufs_reclaim,
2764 .vop_remove = ufs_remove,
2765 .vop_rename = ufs_rename,
2766 .vop_rmdir = ufs_rmdir,
2767 .vop_setattr = ufs_setattr,
2769 .vop_setlabel = vop_stdsetlabel_ea,
2771 .vop_strategy = ufs_strategy,
2772 .vop_symlink = ufs_symlink,
2773 .vop_whiteout = ufs_whiteout,
2775 .vop_getextattr = ufs_getextattr,
2776 .vop_deleteextattr = ufs_deleteextattr,
2777 .vop_setextattr = ufs_setextattr,
2780 .vop_getacl = ufs_getacl,
2781 .vop_setacl = ufs_setacl,
2782 .vop_aclcheck = ufs_aclcheck,
2786 struct vop_vector ufs_fifoops = {
2787 .vop_default = &fifo_specops,
2788 .vop_fsync = VOP_PANIC,
2789 .vop_accessx = ufs_accessx,
2790 .vop_close = ufsfifo_close,
2791 .vop_getattr = ufs_getattr,
2792 .vop_inactive = ufs_inactive,
2793 .vop_kqfilter = ufsfifo_kqfilter,
2794 .vop_markatime = ufs_markatime,
2795 .vop_pathconf = ufsfifo_pathconf,
2796 .vop_print = ufs_print,
2797 .vop_read = VOP_PANIC,
2798 .vop_reclaim = ufs_reclaim,
2799 .vop_setattr = ufs_setattr,
2801 .vop_setlabel = vop_stdsetlabel_ea,
2803 .vop_write = VOP_PANIC,
2805 .vop_getextattr = ufs_getextattr,
2806 .vop_deleteextattr = ufs_deleteextattr,
2807 .vop_setextattr = ufs_setextattr,
2810 .vop_getacl = ufs_getacl,
2811 .vop_setacl = ufs_setacl,
2812 .vop_aclcheck = ufs_aclcheck,