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>
53 #include <sys/sysctl.h>
56 #include <sys/mount.h>
58 #include <sys/refcount.h>
59 #include <sys/unistd.h>
60 #include <sys/vnode.h>
61 #include <sys/dirent.h>
62 #include <sys/lockf.h>
66 #include <machine/mutex.h>
68 #include <security/mac/mac_framework.h>
70 #include <sys/file.h> /* XXX */
73 #include <vm/vm_extern.h>
75 #include <fs/fifofs/fifo.h>
77 #include <ufs/ufs/acl.h>
78 #include <ufs/ufs/extattr.h>
79 #include <ufs/ufs/quota.h>
80 #include <ufs/ufs/inode.h>
81 #include <ufs/ufs/dir.h>
82 #include <ufs/ufs/ufsmount.h>
83 #include <ufs/ufs/ufs_extern.h>
85 #include <ufs/ufs/dirhash.h>
88 #include <ufs/ufs/gjournal.h>
91 #include <ufs/ffs/ffs_extern.h>
93 static vop_accessx_t ufs_accessx;
94 static int ufs_chmod(struct vnode *, int, struct ucred *, struct thread *);
95 static int ufs_chown(struct vnode *, uid_t, gid_t, struct ucred *, struct thread *);
96 static vop_close_t ufs_close;
97 static vop_create_t ufs_create;
98 static vop_getattr_t ufs_getattr;
99 static vop_ioctl_t ufs_ioctl;
100 static vop_link_t ufs_link;
101 static int ufs_makeinode(int mode, struct vnode *, struct vnode **, struct componentname *);
102 static vop_markatime_t ufs_markatime;
103 static vop_mkdir_t ufs_mkdir;
104 static vop_mknod_t ufs_mknod;
105 static vop_open_t ufs_open;
106 static vop_pathconf_t ufs_pathconf;
107 static vop_print_t ufs_print;
108 static vop_readlink_t ufs_readlink;
109 static vop_remove_t ufs_remove;
110 static vop_rename_t ufs_rename;
111 static vop_rmdir_t ufs_rmdir;
112 static vop_setattr_t ufs_setattr;
113 static vop_strategy_t ufs_strategy;
114 static vop_symlink_t ufs_symlink;
115 static vop_whiteout_t ufs_whiteout;
116 static vop_close_t ufsfifo_close;
117 static vop_kqfilter_t ufsfifo_kqfilter;
118 static vop_pathconf_t ufsfifo_pathconf;
120 SYSCTL_NODE(_vfs, OID_AUTO, ufs, CTLFLAG_RD, 0, "UFS filesystem");
123 * A virgin directory (no blushing please).
125 static struct dirtemplate mastertemplate = {
126 0, 12, DT_DIR, 1, ".",
127 0, DIRBLKSIZ - 12, DT_DIR, 2, ".."
129 static struct odirtemplate omastertemplate = {
131 0, DIRBLKSIZ - 12, 2, ".."
135 ufs_itimes_locked(struct vnode *vp)
140 ASSERT_VI_LOCKED(vp, __func__);
145 if ((ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) == 0)
148 if ((vp->v_type == VBLK || vp->v_type == VCHR) && !DOINGSOFTDEP(vp))
149 ip->i_flag |= IN_LAZYMOD;
150 else if (((vp->v_mount->mnt_kern_flag &
151 (MNTK_SUSPENDED | MNTK_SUSPEND)) == 0) ||
152 (ip->i_flag & (IN_CHANGE | IN_UPDATE)))
153 ip->i_flag |= IN_MODIFIED;
154 else if (ip->i_flag & IN_ACCESS)
155 ip->i_flag |= IN_LAZYACCESS;
157 if (ip->i_flag & IN_ACCESS) {
158 DIP_SET(ip, i_atime, ts.tv_sec);
159 DIP_SET(ip, i_atimensec, ts.tv_nsec);
161 if (ip->i_flag & IN_UPDATE) {
162 DIP_SET(ip, i_mtime, ts.tv_sec);
163 DIP_SET(ip, i_mtimensec, ts.tv_nsec);
165 if (ip->i_flag & IN_CHANGE) {
166 DIP_SET(ip, i_ctime, ts.tv_sec);
167 DIP_SET(ip, i_ctimensec, ts.tv_nsec);
168 DIP_SET(ip, i_modrev, DIP(ip, i_modrev) + 1);
172 ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE);
176 ufs_itimes(struct vnode *vp)
180 ufs_itimes_locked(vp);
185 * Create a regular file
189 struct vop_create_args /* {
191 struct vnode **a_vpp;
192 struct componentname *a_cnp;
199 ufs_makeinode(MAKEIMODE(ap->a_vap->va_type, ap->a_vap->va_mode),
200 ap->a_dvp, ap->a_vpp, ap->a_cnp);
212 struct vop_mknod_args /* {
214 struct vnode **a_vpp;
215 struct componentname *a_cnp;
219 struct vattr *vap = ap->a_vap;
220 struct vnode **vpp = ap->a_vpp;
225 error = ufs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode),
226 ap->a_dvp, vpp, ap->a_cnp);
230 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
231 if (vap->va_rdev != VNOVAL) {
233 * Want to be able to use this to make badblock
234 * inodes, so don't truncate the dev number.
236 DIP_SET(ip, i_rdev, vap->va_rdev);
239 * Remove inode, then reload it through VFS_VGET so it is
240 * checked to see if it is an alias of an existing entry in
241 * the inode cache. XXX I don't believe this is necessary now.
243 (*vpp)->v_type = VNON;
244 ino = ip->i_number; /* Save this before vgone() invalidates ip. */
247 error = VFS_VGET(ap->a_dvp->v_mount, ino, LK_EXCLUSIVE, vpp);
260 ufs_open(struct vop_open_args *ap)
262 struct vnode *vp = ap->a_vp;
265 if (vp->v_type == VCHR || vp->v_type == VBLK)
270 * Files marked append-only must be opened for appending.
272 if ((ip->i_flags & APPEND) &&
273 (ap->a_mode & (FWRITE | O_APPEND)) == FWRITE)
275 vnode_create_vobject(vp, DIP(ip, i_size), ap->a_td);
282 * Update the times on the inode.
287 struct vop_close_args /* {
290 struct ucred *a_cred;
294 struct vnode *vp = ap->a_vp;
298 usecount = vp->v_usecount;
300 ufs_itimes_locked(vp);
307 struct vop_accessx_args /* {
310 struct ucred *a_cred;
314 struct vnode *vp = ap->a_vp;
315 struct inode *ip = VTOI(vp);
316 accmode_t accmode = ap->a_accmode;
327 * Disallow write attempts on read-only filesystems;
328 * unless the file is a socket, fifo, or a block or
329 * character device resident on the filesystem.
331 if (accmode & VMODIFY_PERMS) {
332 switch (vp->v_type) {
336 if (vp->v_mount->mnt_flag & MNT_RDONLY)
340 * Inode is accounted in the quotas only if struct
341 * dquot is attached to it. VOP_ACCESS() is called
342 * from vn_open_cred() and provides a convenient
343 * point to call getinoquota().
345 if (VOP_ISLOCKED(vp) != LK_EXCLUSIVE) {
348 * Upgrade vnode lock, since getinoquota()
349 * requires exclusive lock to modify inode.
353 vn_lock(vp, LK_UPGRADE | LK_RETRY);
355 if (vp->v_iflag & VI_DOOMED) {
363 error = getinoquota(ip);
366 vn_lock(vp, LK_DOWNGRADE | LK_RETRY);
377 * If immutable bit set, nobody gets to write it. "& ~VADMIN_PERMS"
378 * is here, because without it, * it would be impossible for the owner
379 * to remove the IMMUTABLE flag.
381 if ((accmode & (VMODIFY_PERMS & ~VADMIN_PERMS)) &&
382 (ip->i_flags & (IMMUTABLE | SF_SNAPSHOT)))
386 if ((vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS)) != 0) {
387 if (vp->v_mount->mnt_flag & MNT_NFS4ACLS)
388 type = ACL_TYPE_NFS4;
390 type = ACL_TYPE_ACCESS;
392 acl = acl_alloc(M_WAITOK);
393 if (type == ACL_TYPE_NFS4)
394 error = ufs_getacl_nfs4_internal(vp, acl, ap->a_td);
396 error = VOP_GETACL(vp, type, acl, ap->a_cred, ap->a_td);
399 if (type == ACL_TYPE_NFS4) {
400 error = vaccess_acl_nfs4(vp->v_type, ip->i_uid,
401 ip->i_gid, acl, accmode, ap->a_cred, NULL);
403 error = vfs_unixify_accmode(&accmode);
405 error = vaccess_acl_posix1e(vp->v_type, ip->i_uid,
406 ip->i_gid, acl, accmode, ap->a_cred, NULL);
410 if (error != EOPNOTSUPP)
412 "ufs_accessx(): Error retrieving ACL on object (%d).\n",
415 * XXX: Fall back until debugged. Should
416 * eventually possibly log an error, and return
419 error = vfs_unixify_accmode(&accmode);
421 error = vaccess(vp->v_type, ip->i_mode, ip->i_uid,
422 ip->i_gid, accmode, ap->a_cred, NULL);
428 #endif /* !UFS_ACL */
429 error = vfs_unixify_accmode(&accmode);
431 error = vaccess(vp->v_type, ip->i_mode, ip->i_uid, ip->i_gid,
432 accmode, ap->a_cred, NULL);
439 struct vop_getattr_args /* {
442 struct ucred *a_cred;
445 struct vnode *vp = ap->a_vp;
446 struct inode *ip = VTOI(vp);
447 struct vattr *vap = ap->a_vap;
450 ufs_itimes_locked(vp);
451 if (ip->i_ump->um_fstype == UFS1) {
452 vap->va_atime.tv_sec = ip->i_din1->di_atime;
453 vap->va_atime.tv_nsec = ip->i_din1->di_atimensec;
455 vap->va_atime.tv_sec = ip->i_din2->di_atime;
456 vap->va_atime.tv_nsec = ip->i_din2->di_atimensec;
460 * Copy from inode table
462 vap->va_fsid = dev2udev(ip->i_dev);
463 vap->va_fileid = ip->i_number;
464 vap->va_mode = ip->i_mode & ~IFMT;
465 vap->va_nlink = ip->i_effnlink;
466 vap->va_uid = ip->i_uid;
467 vap->va_gid = ip->i_gid;
468 if (ip->i_ump->um_fstype == UFS1) {
469 vap->va_rdev = ip->i_din1->di_rdev;
470 vap->va_size = ip->i_din1->di_size;
471 vap->va_mtime.tv_sec = ip->i_din1->di_mtime;
472 vap->va_mtime.tv_nsec = ip->i_din1->di_mtimensec;
473 vap->va_ctime.tv_sec = ip->i_din1->di_ctime;
474 vap->va_ctime.tv_nsec = ip->i_din1->di_ctimensec;
475 vap->va_bytes = dbtob((u_quad_t)ip->i_din1->di_blocks);
476 vap->va_filerev = ip->i_din1->di_modrev;
478 vap->va_rdev = ip->i_din2->di_rdev;
479 vap->va_size = ip->i_din2->di_size;
480 vap->va_mtime.tv_sec = ip->i_din2->di_mtime;
481 vap->va_mtime.tv_nsec = ip->i_din2->di_mtimensec;
482 vap->va_ctime.tv_sec = ip->i_din2->di_ctime;
483 vap->va_ctime.tv_nsec = ip->i_din2->di_ctimensec;
484 vap->va_birthtime.tv_sec = ip->i_din2->di_birthtime;
485 vap->va_birthtime.tv_nsec = ip->i_din2->di_birthnsec;
486 vap->va_bytes = dbtob((u_quad_t)ip->i_din2->di_blocks);
487 vap->va_filerev = ip->i_din2->di_modrev;
489 vap->va_flags = ip->i_flags;
490 vap->va_gen = ip->i_gen;
491 vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
492 vap->va_type = IFTOVT(ip->i_mode);
497 * Set attribute vnode op. called from several syscalls
501 struct vop_setattr_args /* {
504 struct ucred *a_cred;
507 struct vattr *vap = ap->a_vap;
508 struct vnode *vp = ap->a_vp;
509 struct inode *ip = VTOI(vp);
510 struct ucred *cred = ap->a_cred;
511 struct thread *td = curthread;
515 * Check for unsettable attributes.
517 if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
518 (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
519 (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
520 ((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
523 if (vap->va_flags != VNOVAL) {
524 if (vp->v_mount->mnt_flag & MNT_RDONLY)
527 * Callers may only modify the file flags on objects they
528 * have VADMIN rights for.
530 if ((error = VOP_ACCESS(vp, VADMIN, cred, td)))
533 * Unprivileged processes are not permitted to unset system
534 * flags, or modify flags if any system flags are set.
535 * Privileged non-jail processes may not modify system flags
536 * if securelevel > 0 and any existing system flags are set.
537 * Privileged jail processes behave like privileged non-jail
538 * processes if the security.jail.chflags_allowed sysctl is
539 * is non-zero; otherwise, they behave like unprivileged
542 if (!priv_check_cred(cred, PRIV_VFS_SYSFLAGS, 0)) {
544 & (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND)) {
545 error = securelevel_gt(cred, 0);
549 /* Snapshot flag cannot be set or cleared */
550 if (((vap->va_flags & SF_SNAPSHOT) != 0 &&
551 (ip->i_flags & SF_SNAPSHOT) == 0) ||
552 ((vap->va_flags & SF_SNAPSHOT) == 0 &&
553 (ip->i_flags & SF_SNAPSHOT) != 0))
555 ip->i_flags = vap->va_flags;
556 DIP_SET(ip, i_flags, vap->va_flags);
559 & (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND) ||
560 (vap->va_flags & UF_SETTABLE) != vap->va_flags)
562 ip->i_flags &= SF_SETTABLE;
563 ip->i_flags |= (vap->va_flags & UF_SETTABLE);
564 DIP_SET(ip, i_flags, ip->i_flags);
566 ip->i_flag |= IN_CHANGE;
567 error = UFS_UPDATE(vp, 0);
568 if (vap->va_flags & (IMMUTABLE | APPEND))
571 if (ip->i_flags & (IMMUTABLE | APPEND))
574 * Go through the fields and update iff not VNOVAL.
576 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
577 if (vp->v_mount->mnt_flag & MNT_RDONLY)
579 if ((error = ufs_chown(vp, vap->va_uid, vap->va_gid, cred,
583 if (vap->va_size != VNOVAL) {
585 * XXX most of the following special cases should be in
586 * callers instead of in N filesystems. The VDIR check
589 switch (vp->v_type) {
595 * Truncation should have an effect in these cases.
596 * Disallow it if the filesystem is read-only or
597 * the file is being snapshotted.
599 if (vp->v_mount->mnt_flag & MNT_RDONLY)
601 if ((ip->i_flags & SF_SNAPSHOT) != 0)
606 * According to POSIX, the result is unspecified
607 * for file types other than regular files,
608 * directories and shared memory objects. We
609 * don't support shared memory objects in the file
610 * system, and have dubious support for truncating
611 * symlinks. Just ignore the request in other cases.
615 if ((error = UFS_TRUNCATE(vp, vap->va_size, IO_NORMAL,
619 if (vap->va_atime.tv_sec != VNOVAL ||
620 vap->va_mtime.tv_sec != VNOVAL ||
621 vap->va_birthtime.tv_sec != VNOVAL) {
622 if (vp->v_mount->mnt_flag & MNT_RDONLY)
624 if ((ip->i_flags & SF_SNAPSHOT) != 0)
628 * If times is NULL, ... The caller must be the owner of
629 * the file, have permission to write the file, or be the
631 * If times is non-NULL, ... The caller must be the owner of
632 * the file or be the super-user.
634 * Possibly for historical reasons, try to use VADMIN in
635 * preference to VWRITE for a NULL timestamp. This means we
636 * will return EACCES in preference to EPERM if neither
639 if (vap->va_vaflags & VA_UTIMES_NULL) {
641 * NFSv4.1, draft 21, 6.2.1.3.1, Discussion of Mask Attributes
643 * "A user having ACL_WRITE_DATA or ACL_WRITE_ATTRIBUTES
644 * will be allowed to set the times [..] to the current
647 * XXX: Calling it four times seems a little excessive.
649 error = VOP_ACCESSX(vp, VWRITE_ATTRIBUTES, cred, td);
651 error = VOP_ACCESS(vp, VWRITE, cred, td);
653 error = VOP_ACCESSX(vp, VWRITE_ATTRIBUTES, cred, td);
656 if (vap->va_atime.tv_sec != VNOVAL)
657 ip->i_flag |= IN_ACCESS;
658 if (vap->va_mtime.tv_sec != VNOVAL)
659 ip->i_flag |= IN_CHANGE | IN_UPDATE;
660 if (vap->va_birthtime.tv_sec != VNOVAL &&
661 ip->i_ump->um_fstype == UFS2)
662 ip->i_flag |= IN_MODIFIED;
664 if (vap->va_atime.tv_sec != VNOVAL) {
665 DIP_SET(ip, i_atime, vap->va_atime.tv_sec);
666 DIP_SET(ip, i_atimensec, vap->va_atime.tv_nsec);
668 if (vap->va_mtime.tv_sec != VNOVAL) {
669 DIP_SET(ip, i_mtime, vap->va_mtime.tv_sec);
670 DIP_SET(ip, i_mtimensec, vap->va_mtime.tv_nsec);
672 if (vap->va_birthtime.tv_sec != VNOVAL &&
673 ip->i_ump->um_fstype == UFS2) {
674 ip->i_din2->di_birthtime = vap->va_birthtime.tv_sec;
675 ip->i_din2->di_birthnsec = vap->va_birthtime.tv_nsec;
677 error = UFS_UPDATE(vp, 0);
682 if (vap->va_mode != (mode_t)VNOVAL) {
683 if (vp->v_mount->mnt_flag & MNT_RDONLY)
685 if ((ip->i_flags & SF_SNAPSHOT) != 0 && (vap->va_mode &
686 (S_IXUSR | S_IWUSR | S_IXGRP | S_IWGRP | S_IXOTH | S_IWOTH)))
688 error = ufs_chmod(vp, (int)vap->va_mode, cred, td);
695 ufs_update_nfs4_acl_after_mode_change(struct vnode *vp, int mode,
696 int file_owner_id, struct ucred *cred, struct thread *td)
701 aclp = acl_alloc(M_WAITOK);
702 error = ufs_getacl_nfs4_internal(vp, aclp, td);
704 * We don't have to handle EOPNOTSUPP here, as the filesystem claims
710 acl_nfs4_sync_acl_from_mode(aclp, mode, file_owner_id);
711 error = ufs_setacl_nfs4_internal(vp, aclp, td);
720 * Mark this file's access time for update for vfs_mark_atime(). This
721 * is called from execve() and mmap().
725 struct vop_markatime_args /* {
729 struct vnode *vp = ap->a_vp;
730 struct inode *ip = VTOI(vp);
733 ip->i_flag |= IN_ACCESS;
736 * XXXKIB No UFS_UPDATE(ap->a_vp, 0) there.
742 * Change the mode on a file.
743 * Inode must be locked before calling.
746 ufs_chmod(vp, mode, cred, td)
752 struct inode *ip = VTOI(vp);
756 * To modify the permissions on a file, must possess VADMIN
759 if ((error = VOP_ACCESSX(vp, VWRITE_ACL, cred, td)))
762 * Privileged processes may set the sticky bit on non-directories,
763 * as well as set the setgid bit on a file with a group that the
764 * process is not a member of. Both of these are allowed in
767 if (vp->v_type != VDIR && (mode & S_ISTXT)) {
768 if (priv_check_cred(cred, PRIV_VFS_STICKYFILE, 0))
771 if (!groupmember(ip->i_gid, cred) && (mode & ISGID)) {
772 error = priv_check_cred(cred, PRIV_VFS_SETGID, 0);
778 * Deny setting setuid if we are not the file owner.
780 if ((mode & ISUID) && ip->i_uid != cred->cr_uid) {
781 error = priv_check_cred(cred, PRIV_VFS_ADMIN, 0);
786 ip->i_mode &= ~ALLPERMS;
787 ip->i_mode |= (mode & ALLPERMS);
788 DIP_SET(ip, i_mode, ip->i_mode);
789 ip->i_flag |= IN_CHANGE;
791 if ((vp->v_mount->mnt_flag & MNT_NFS4ACLS) != 0)
792 error = ufs_update_nfs4_acl_after_mode_change(vp, mode, ip->i_uid, cred, td);
794 if (error == 0 && (ip->i_flag & IN_CHANGE) != 0)
795 error = UFS_UPDATE(vp, 0);
801 * Perform chown operation on inode ip;
802 * inode must be locked prior to call.
805 ufs_chown(vp, uid, gid, cred, td)
812 struct inode *ip = VTOI(vp);
821 if (uid == (uid_t)VNOVAL)
823 if (gid == (gid_t)VNOVAL)
826 * To modify the ownership of a file, must possess VADMIN for that
829 if ((error = VOP_ACCESSX(vp, VWRITE_OWNER, cred, td)))
832 * To change the owner of a file, or change the group of a file to a
833 * group of which we are not a member, the caller must have
836 if (((uid != ip->i_uid && uid != cred->cr_uid) ||
837 (gid != ip->i_gid && !groupmember(gid, cred))) &&
838 (error = priv_check_cred(cred, PRIV_VFS_CHOWN, 0)))
843 if ((error = getinoquota(ip)) != 0)
846 dqrele(vp, ip->i_dquot[USRQUOTA]);
847 ip->i_dquot[USRQUOTA] = NODQUOT;
850 dqrele(vp, ip->i_dquot[GRPQUOTA]);
851 ip->i_dquot[GRPQUOTA] = NODQUOT;
853 change = DIP(ip, i_blocks);
854 (void) chkdq(ip, -change, cred, CHOWN);
855 (void) chkiq(ip, -1, cred, CHOWN);
856 for (i = 0; i < MAXQUOTAS; i++) {
857 dqrele(vp, ip->i_dquot[i]);
858 ip->i_dquot[i] = NODQUOT;
862 DIP_SET(ip, i_gid, gid);
864 DIP_SET(ip, i_uid, uid);
866 if ((error = getinoquota(ip)) == 0) {
868 dqrele(vp, ip->i_dquot[USRQUOTA]);
869 ip->i_dquot[USRQUOTA] = NODQUOT;
872 dqrele(vp, ip->i_dquot[GRPQUOTA]);
873 ip->i_dquot[GRPQUOTA] = NODQUOT;
875 if ((error = chkdq(ip, change, cred, CHOWN)) == 0) {
876 if ((error = chkiq(ip, 1, cred, CHOWN)) == 0)
879 (void) chkdq(ip, -change, cred, CHOWN|FORCE);
881 for (i = 0; i < MAXQUOTAS; i++) {
882 dqrele(vp, ip->i_dquot[i]);
883 ip->i_dquot[i] = NODQUOT;
887 DIP_SET(ip, i_gid, ogid);
889 DIP_SET(ip, i_uid, ouid);
890 if (getinoquota(ip) == 0) {
892 dqrele(vp, ip->i_dquot[USRQUOTA]);
893 ip->i_dquot[USRQUOTA] = NODQUOT;
896 dqrele(vp, ip->i_dquot[GRPQUOTA]);
897 ip->i_dquot[GRPQUOTA] = NODQUOT;
899 (void) chkdq(ip, change, cred, FORCE|CHOWN);
900 (void) chkiq(ip, 1, cred, FORCE|CHOWN);
901 (void) getinoquota(ip);
906 panic("ufs_chown: lost quota");
908 ip->i_flag |= IN_CHANGE;
909 if ((ip->i_mode & (ISUID | ISGID)) && (ouid != uid || ogid != gid)) {
910 if (priv_check_cred(cred, PRIV_VFS_RETAINSUGID, 0)) {
911 ip->i_mode &= ~(ISUID | ISGID);
912 DIP_SET(ip, i_mode, ip->i_mode);
915 error = UFS_UPDATE(vp, 0);
921 struct vop_remove_args /* {
924 struct componentname *a_cnp;
928 struct vnode *vp = ap->a_vp;
929 struct vnode *dvp = ap->a_dvp;
935 if ((ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
936 (VTOI(dvp)->i_flags & APPEND)) {
941 ufs_gjournal_orphan(vp);
943 error = ufs_dirremove(dvp, ip, ap->a_cnp->cn_flags, 0);
944 if (ip->i_nlink <= 0)
945 vp->v_vflag |= VV_NOSYNC;
946 if ((ip->i_flags & SF_SNAPSHOT) != 0) {
948 * Avoid deadlock where another thread is trying to
949 * update the inodeblock for dvp and is waiting on
950 * snaplk. Temporary unlock the vnode lock for the
951 * unlinked file and sync the directory. This should
952 * allow vput() of the directory to not block later on
953 * while holding the snapshot vnode locked, assuming
954 * that the directory hasn't been unlinked too.
957 (void) VOP_FSYNC(dvp, MNT_WAIT, td);
958 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
969 struct vop_link_args /* {
970 struct vnode *a_tdvp;
972 struct componentname *a_cnp;
975 struct vnode *vp = ap->a_vp;
976 struct vnode *tdvp = ap->a_tdvp;
977 struct componentname *cnp = ap->a_cnp;
979 struct direct newdir;
983 if ((cnp->cn_flags & HASBUF) == 0)
984 panic("ufs_link: no name");
986 if (tdvp->v_mount != vp->v_mount) {
991 if ((nlink_t)ip->i_nlink >= LINK_MAX) {
995 if (ip->i_flags & (IMMUTABLE | APPEND)) {
1001 DIP_SET(ip, i_nlink, ip->i_nlink);
1002 ip->i_flag |= IN_CHANGE;
1003 if (DOINGSOFTDEP(vp))
1004 softdep_change_linkcnt(ip);
1005 error = UFS_UPDATE(vp, !(DOINGSOFTDEP(vp) | DOINGASYNC(vp)));
1007 ufs_makedirentry(ip, cnp, &newdir);
1008 error = ufs_direnter(tdvp, vp, &newdir, cnp, NULL, 0);
1014 DIP_SET(ip, i_nlink, ip->i_nlink);
1015 ip->i_flag |= IN_CHANGE;
1016 if (DOINGSOFTDEP(vp))
1017 softdep_change_linkcnt(ip);
1024 * whiteout vnode call
1028 struct vop_whiteout_args /* {
1029 struct vnode *a_dvp;
1030 struct componentname *a_cnp;
1034 struct vnode *dvp = ap->a_dvp;
1035 struct componentname *cnp = ap->a_cnp;
1036 struct direct newdir;
1039 switch (ap->a_flags) {
1041 /* 4.4 format directories support whiteout operations */
1042 if (dvp->v_mount->mnt_maxsymlinklen > 0)
1044 return (EOPNOTSUPP);
1047 /* create a new directory whiteout */
1049 if ((cnp->cn_flags & SAVENAME) == 0)
1050 panic("ufs_whiteout: missing name");
1051 if (dvp->v_mount->mnt_maxsymlinklen <= 0)
1052 panic("ufs_whiteout: old format filesystem");
1055 newdir.d_ino = WINO;
1056 newdir.d_namlen = cnp->cn_namelen;
1057 bcopy(cnp->cn_nameptr, newdir.d_name, (unsigned)cnp->cn_namelen + 1);
1058 newdir.d_type = DT_WHT;
1059 error = ufs_direnter(dvp, NULL, &newdir, cnp, NULL, 0);
1063 /* remove an existing directory whiteout */
1065 if (dvp->v_mount->mnt_maxsymlinklen <= 0)
1066 panic("ufs_whiteout: old format filesystem");
1069 cnp->cn_flags &= ~DOWHITEOUT;
1070 error = ufs_dirremove(dvp, NULL, cnp->cn_flags, 0);
1073 panic("ufs_whiteout: unknown op");
1078 static volatile int rename_restarts;
1079 SYSCTL_INT(_vfs_ufs, OID_AUTO, rename_restarts, CTLFLAG_RD,
1080 __DEVOLATILE(int *, &rename_restarts), 0,
1081 "Times rename had to restart due to lock contention");
1084 * Rename system call.
1085 * rename("foo", "bar");
1088 * link("foo", "bar");
1090 * but ``atomically''. Can't do full commit without saving state in the
1091 * inode on disk which isn't feasible at this time. Best we can do is
1092 * always guarantee the target exists.
1094 * Basic algorithm is:
1096 * 1) Bump link count on source while we're linking it to the
1097 * target. This also ensure the inode won't be deleted out
1098 * from underneath us while we work (it may be truncated by
1099 * a concurrent `trunc' or `open' for creation).
1100 * 2) Link source to destination. If destination already exists,
1102 * 3) Unlink source reference to inode if still around. If a
1103 * directory was moved and the parent of the destination
1104 * is different from the source, patch the ".." entry in the
1109 struct vop_rename_args /* {
1110 struct vnode *a_fdvp;
1111 struct vnode *a_fvp;
1112 struct componentname *a_fcnp;
1113 struct vnode *a_tdvp;
1114 struct vnode *a_tvp;
1115 struct componentname *a_tcnp;
1118 struct vnode *tvp = ap->a_tvp;
1119 struct vnode *tdvp = ap->a_tdvp;
1120 struct vnode *fvp = ap->a_fvp;
1121 struct vnode *fdvp = ap->a_fdvp;
1123 struct componentname *tcnp = ap->a_tcnp;
1124 struct componentname *fcnp = ap->a_fcnp;
1125 struct thread *td = fcnp->cn_thread;
1126 struct inode *fip, *tip, *tdp, *fdp;
1127 struct direct newdir;
1129 int doingdirectory, newparent;
1130 int error = 0, ioflag;
1135 if ((tcnp->cn_flags & HASBUF) == 0 ||
1136 (fcnp->cn_flags & HASBUF) == 0)
1137 panic("ufs_rename: no name");
1141 VOP_UNLOCK(tdvp, 0);
1142 if (tvp && tvp != tdvp)
1145 * Check for cross-device rename.
1147 if ((fvp->v_mount != tdvp->v_mount) ||
1148 (tvp && (fvp->v_mount != tvp->v_mount))) {
1153 error = vfs_busy(mp, 0);
1160 * We need to acquire 2 to 4 locks depending on whether tvp is NULL
1161 * and fdvp and tdvp are the same directory. Subsequently we need
1162 * to double-check all paths and in the directory rename case we
1163 * need to verify that we are not creating a directory loop. To
1164 * handle this we acquire all but fdvp using non-blocking
1165 * acquisitions. If we fail to acquire any lock in the path we will
1166 * drop all held locks, acquire the new lock in a blocking fashion,
1167 * and then release it and restart the rename. This acquire/release
1168 * step ensures that we do not spin on a lock waiting for release.
1170 error = vn_lock(fdvp, LK_EXCLUSIVE);
1173 if (vn_lock(tdvp, LK_EXCLUSIVE | LK_NOWAIT) != 0) {
1174 VOP_UNLOCK(fdvp, 0);
1175 error = vn_lock(tdvp, LK_EXCLUSIVE);
1178 VOP_UNLOCK(tdvp, 0);
1179 atomic_add_int(&rename_restarts, 1);
1183 * Re-resolve fvp to be certain it still exists and fetch the
1186 error = ufs_lookup_ino(fdvp, NULL, fcnp, &ino);
1188 VOP_UNLOCK(fdvp, 0);
1189 VOP_UNLOCK(tdvp, 0);
1192 error = VFS_VGET(mp, ino, LK_EXCLUSIVE | LK_NOWAIT, &nvp);
1194 VOP_UNLOCK(fdvp, 0);
1195 VOP_UNLOCK(tdvp, 0);
1198 error = VFS_VGET(mp, ino, LK_EXCLUSIVE, &nvp);
1204 atomic_add_int(&rename_restarts, 1);
1210 * Re-resolve tvp and acquire the vnode lock if present.
1212 error = ufs_lookup_ino(tdvp, NULL, tcnp, &ino);
1213 if (error != 0 && error != EJUSTRETURN) {
1214 VOP_UNLOCK(fdvp, 0);
1215 VOP_UNLOCK(tdvp, 0);
1220 * If tvp disappeared we just carry on.
1222 if (error == EJUSTRETURN && tvp != NULL) {
1227 * Get the tvp ino if the lookup succeeded. We may have to restart
1228 * if the non-blocking acquire fails.
1232 error = VFS_VGET(mp, ino, LK_EXCLUSIVE | LK_NOWAIT, &nvp);
1237 VOP_UNLOCK(fdvp, 0);
1238 VOP_UNLOCK(tdvp, 0);
1242 error = VFS_VGET(mp, ino, LK_EXCLUSIVE, &nvp);
1246 atomic_add_int(&rename_restarts, 1);
1256 if (tvp && ((VTOI(tvp)->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
1257 (VTOI(tdvp)->i_flags & APPEND))) {
1262 * Renaming a file to itself has no effect. The upper layers should
1263 * not call us in that case. However, things could change after
1264 * we drop the locks above.
1272 ino = fip->i_number;
1273 if (fip->i_nlink >= LINK_MAX) {
1277 if ((fip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))
1278 || (fdp->i_flags & APPEND)) {
1282 if ((fip->i_mode & IFMT) == IFDIR) {
1284 * Avoid ".", "..", and aliases of "." for obvious reasons.
1286 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
1288 (fcnp->cn_flags | tcnp->cn_flags) & ISDOTDOT) {
1292 if (fdp->i_number != tdp->i_number)
1293 newparent = tdp->i_number;
1296 if ((fvp->v_type == VDIR && fvp->v_mountedhere != NULL) ||
1297 (tvp != NULL && tvp->v_type == VDIR &&
1298 tvp->v_mountedhere != NULL)) {
1304 * If ".." must be changed (ie the directory gets a new
1305 * parent) then the source directory must not be in the
1306 * directory hierarchy above the target, as this would
1307 * orphan everything below the source directory. Also
1308 * the user must have write permission in the source so
1309 * as to be able to change "..".
1311 if (doingdirectory && newparent) {
1312 error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_thread);
1315 error = ufs_checkpath(ino, fdp->i_number, tdp, tcnp->cn_cred,
1318 * We encountered a lock that we have to wait for. Unlock
1319 * everything else and VGET before restarting.
1322 VOP_UNLOCK(fdvp, 0);
1324 VOP_UNLOCK(tdvp, 0);
1327 error = VFS_VGET(mp, ino, LK_SHARED, &nvp);
1330 atomic_add_int(&rename_restarts, 1);
1335 if ((tcnp->cn_flags & SAVESTART) == 0)
1336 panic("ufs_rename: lost to startdir");
1338 if (fip->i_effnlink == 0 || fdp->i_effnlink == 0 ||
1339 tdp->i_effnlink == 0)
1340 panic("Bad effnlink fip %p, fdp %p, tdp %p", fip, fdp, tdp);
1343 * 1) Bump link count while we're moving stuff
1344 * around. If we crash somewhere before
1345 * completing our work, the link count
1346 * may be wrong, but correctable.
1350 DIP_SET(fip, i_nlink, fip->i_nlink);
1351 fip->i_flag |= IN_CHANGE;
1352 if (DOINGSOFTDEP(fvp))
1353 softdep_change_linkcnt(fip);
1354 error = UFS_UPDATE(fvp, !(DOINGSOFTDEP(fvp) | DOINGASYNC(fvp)));
1359 * 2) If target doesn't exist, link the target
1360 * to the source and unlink the source.
1361 * Otherwise, rewrite the target directory
1362 * entry to reference the source inode and
1363 * expunge the original entry's existence.
1366 if (tdp->i_dev != fip->i_dev)
1367 panic("ufs_rename: EXDEV");
1368 if (doingdirectory && newparent) {
1370 * Account for ".." in new directory.
1371 * When source and destination have the same
1372 * parent we don't adjust the link count. The
1373 * actual link modification is completed when
1374 * .. is rewritten below.
1376 if ((nlink_t)tdp->i_nlink >= LINK_MAX) {
1381 ufs_makedirentry(fip, tcnp, &newdir);
1382 error = ufs_direnter(tdvp, NULL, &newdir, tcnp, NULL, 1);
1385 /* Setup tdvp for directory compaction if needed. */
1386 if (tdp->i_count && tdp->i_endoff &&
1387 tdp->i_endoff < tdp->i_size)
1388 endoff = tdp->i_endoff;
1390 if (tip->i_dev != tdp->i_dev || tip->i_dev != fip->i_dev)
1391 panic("ufs_rename: EXDEV");
1393 * Short circuit rename(foo, foo).
1395 if (tip->i_number == fip->i_number)
1396 panic("ufs_rename: same file");
1398 * If the parent directory is "sticky", then the caller
1399 * must possess VADMIN for the parent directory, or the
1400 * destination of the rename. This implements append-only
1403 if ((tdp->i_mode & S_ISTXT) &&
1404 VOP_ACCESS(tdvp, VADMIN, tcnp->cn_cred, td) &&
1405 VOP_ACCESS(tvp, VADMIN, tcnp->cn_cred, td)) {
1410 * Target must be empty if a directory and have no links
1411 * to it. Also, ensure source and target are compatible
1412 * (both directories, or both not directories).
1414 if ((tip->i_mode & IFMT) == IFDIR) {
1415 if ((tip->i_effnlink > 2) ||
1416 !ufs_dirempty(tip, tdp->i_number, tcnp->cn_cred)) {
1420 if (!doingdirectory) {
1425 } else if (doingdirectory) {
1429 if (doingdirectory) {
1432 if (DOINGSOFTDEP(tdvp))
1433 softdep_change_linkcnt(tdp);
1436 if (DOINGSOFTDEP(tvp))
1437 softdep_change_linkcnt(tip);
1439 error = ufs_dirrewrite(tdp, tip, fip->i_number,
1440 IFTODT(fip->i_mode),
1441 (doingdirectory && newparent) ? newparent : doingdirectory);
1443 if (doingdirectory) {
1446 if (DOINGSOFTDEP(tdvp))
1447 softdep_change_linkcnt(tdp);
1450 if (DOINGSOFTDEP(tvp))
1451 softdep_change_linkcnt(tip);
1454 if (doingdirectory && !DOINGSOFTDEP(tvp)) {
1456 * Truncate inode. The only stuff left in the directory
1457 * is "." and "..". The "." reference is inconsequential
1458 * since we are quashing it. We have removed the "."
1459 * reference and the reference in the parent directory,
1460 * but there may be other hard links. The soft
1461 * dependency code will arrange to do these operations
1462 * after the parent directory entry has been deleted on
1463 * disk, so when running with that code we avoid doing
1468 DIP_SET(tdp, i_nlink, tdp->i_nlink);
1469 tdp->i_flag |= IN_CHANGE;
1472 DIP_SET(tip, i_nlink, tip->i_nlink);
1473 tip->i_flag |= IN_CHANGE;
1475 if (!DOINGASYNC(tvp))
1477 /* Don't go to bad here as the new link exists. */
1478 if ((error = UFS_TRUNCATE(tvp, (off_t)0, ioflag,
1479 tcnp->cn_cred, tcnp->cn_thread)) != 0)
1485 * 3) Unlink the source. We have to resolve the path again to
1486 * fixup the directory offset and count for ufs_dirremove.
1489 error = ufs_lookup_ino(fdvp, NULL, fcnp, &ino);
1491 panic("ufs_rename: from entry went away!");
1492 if (ino != fip->i_number)
1493 panic("ufs_rename: ino mismatch %d != %d\n", ino,
1497 * If the source is a directory with a
1498 * new parent, the link count of the old
1499 * parent directory must be decremented
1500 * and ".." set to point to the new parent.
1502 if (doingdirectory && newparent) {
1504 * If tip exists we simply use its link, otherwise we must
1510 DIP_SET(tdp, i_nlink, tdp->i_nlink);
1511 tdp->i_flag |= IN_CHANGE;
1512 if (DOINGSOFTDEP(tdvp))
1513 softdep_change_linkcnt(tdp);
1514 error = UFS_UPDATE(tdvp, !(DOINGSOFTDEP(tdvp) |
1516 /* Don't go to bad here as the new link exists. */
1520 fip->i_offset = mastertemplate.dot_reclen;
1521 ufs_dirrewrite(fip, fdp, newparent, DT_DIR, 0);
1524 error = ufs_dirremove(fdvp, fip, fcnp->cn_flags, 0);
1526 * The kern_renameat() looks up the fvp using the DELETE flag, which
1527 * causes the removal of the name cache entry for fvp.
1528 * As the relookup of the fvp is done in two steps:
1529 * ufs_lookup_ino() and then VFS_VGET(), another thread might do a
1530 * normal lookup of the from name just before the VFS_VGET() call,
1531 * causing the cache entry to be re-instantiated.
1533 * The same issue also applies to tvp if it exists as
1534 * otherwise we may have a stale name cache entry for the new
1535 * name that references the old i-node if it has other links
1536 * or open file descriptors.
1541 cache_purge_negative(tdvp);
1549 * If compaction or fsync was requested do it now that other locks
1550 * are no longer needed.
1552 if (error == 0 && endoff != 0) {
1554 if (tdp->i_dirhash != NULL)
1555 ufsdirhash_dirtrunc(tdp, endoff);
1557 UFS_TRUNCATE(tdvp, endoff, IO_NORMAL | IO_SYNC, tcnp->cn_cred,
1560 if (error == 0 && tdp->i_flag & IN_NEEDSYNC)
1561 error = VOP_FSYNC(tdvp, MNT_WAIT, td);
1570 DIP_SET(fip, i_nlink, fip->i_nlink);
1571 fip->i_flag |= IN_CHANGE;
1572 if (DOINGSOFTDEP(fvp))
1573 softdep_change_linkcnt(fip);
1590 ufs_do_posix1e_acl_inheritance_dir(struct vnode *dvp, struct vnode *tvp,
1591 mode_t dmode, struct ucred *cred, struct thread *td)
1594 struct inode *ip = VTOI(tvp);
1595 struct acl *dacl, *acl;
1597 acl = acl_alloc(M_WAITOK);
1598 dacl = acl_alloc(M_WAITOK);
1601 * Retrieve default ACL from parent, if any.
1603 error = VOP_GETACL(dvp, ACL_TYPE_DEFAULT, acl, cred, td);
1607 * Retrieved a default ACL, so merge mode and ACL if
1608 * necessary. If the ACL is empty, fall through to
1609 * the "not defined or available" case.
1611 if (acl->acl_cnt != 0) {
1612 dmode = acl_posix1e_newfilemode(dmode, acl);
1614 DIP_SET(ip, i_mode, dmode);
1616 ufs_sync_acl_from_inode(ip, acl);
1623 * Just use the mode as-is.
1626 DIP_SET(ip, i_mode, dmode);
1635 * XXX: If we abort now, will Soft Updates notify the extattr
1636 * code that the EAs for the file need to be released?
1638 error = VOP_SETACL(tvp, ACL_TYPE_ACCESS, acl, cred, td);
1640 error = VOP_SETACL(tvp, ACL_TYPE_DEFAULT, dacl, cred, td);
1647 * XXX: This should not happen, as EOPNOTSUPP above
1648 * was supposed to free acl.
1650 printf("ufs_mkdir: VOP_GETACL() but no VOP_SETACL()\n");
1652 panic("ufs_mkdir: VOP_GETACL() but no VOP_SETACL()");
1668 ufs_do_posix1e_acl_inheritance_file(struct vnode *dvp, struct vnode *tvp,
1669 mode_t mode, struct ucred *cred, struct thread *td)
1672 struct inode *ip = VTOI(tvp);
1675 acl = acl_alloc(M_WAITOK);
1678 * Retrieve default ACL for parent, if any.
1680 error = VOP_GETACL(dvp, ACL_TYPE_DEFAULT, acl, cred, td);
1684 * Retrieved a default ACL, so merge mode and ACL if
1687 if (acl->acl_cnt != 0) {
1689 * Two possible ways for default ACL to not
1690 * be present. First, the EA can be
1691 * undefined, or second, the default ACL can
1692 * be blank. If it's blank, fall through to
1693 * the it's not defined case.
1695 mode = acl_posix1e_newfilemode(mode, acl);
1697 DIP_SET(ip, i_mode, mode);
1698 ufs_sync_acl_from_inode(ip, acl);
1705 * Just use the mode as-is.
1708 DIP_SET(ip, i_mode, mode);
1717 * XXX: If we abort now, will Soft Updates notify the extattr
1718 * code that the EAs for the file need to be released?
1720 error = VOP_SETACL(tvp, ACL_TYPE_ACCESS, acl, cred, td);
1727 * XXX: This should not happen, as EOPNOTSUPP above was
1728 * supposed to free acl.
1730 printf("ufs_makeinode: VOP_GETACL() but no "
1732 /* panic("ufs_makeinode: VOP_GETACL() but no "
1747 ufs_do_nfs4_acl_inheritance(struct vnode *dvp, struct vnode *tvp,
1748 mode_t child_mode, struct ucred *cred, struct thread *td)
1751 struct acl *parent_aclp, *child_aclp;
1753 parent_aclp = acl_alloc(M_WAITOK);
1754 child_aclp = acl_alloc(M_WAITOK | M_ZERO);
1756 error = ufs_getacl_nfs4_internal(dvp, parent_aclp, td);
1759 acl_nfs4_compute_inherited_acl(parent_aclp, child_aclp,
1760 child_mode, VTOI(tvp)->i_uid, tvp->v_type == VDIR);
1761 error = ufs_setacl_nfs4_internal(tvp, child_aclp, td);
1765 acl_free(parent_aclp);
1766 acl_free(child_aclp);
1777 struct vop_mkdir_args /* {
1778 struct vnode *a_dvp;
1779 struct vnode **a_vpp;
1780 struct componentname *a_cnp;
1781 struct vattr *a_vap;
1784 struct vnode *dvp = ap->a_dvp;
1785 struct vattr *vap = ap->a_vap;
1786 struct componentname *cnp = ap->a_cnp;
1787 struct inode *ip, *dp;
1790 struct dirtemplate dirtemplate, *dtp;
1791 struct direct newdir;
1796 if ((cnp->cn_flags & HASBUF) == 0)
1797 panic("ufs_mkdir: no name");
1800 if ((nlink_t)dp->i_nlink >= LINK_MAX) {
1804 dmode = vap->va_mode & 0777;
1807 * Must simulate part of ufs_makeinode here to acquire the inode,
1808 * but not have it entered in the parent directory. The entry is
1809 * made later after writing "." and ".." entries.
1811 error = UFS_VALLOC(dvp, dmode, cnp->cn_cred, &tvp);
1815 ip->i_gid = dp->i_gid;
1816 DIP_SET(ip, i_gid, dp->i_gid);
1820 struct ucred ucred, *ucp;
1825 * If we are hacking owners here, (only do this where told to)
1826 * and we are not giving it TO root, (would subvert quotas)
1827 * then go ahead and give it to the other user.
1828 * The new directory also inherits the SUID bit.
1829 * If user's UID and dir UID are the same,
1830 * 'give it away' so that the SUID is still forced on.
1832 if ((dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
1833 (dp->i_mode & ISUID) && dp->i_uid) {
1835 ip->i_uid = dp->i_uid;
1836 DIP_SET(ip, i_uid, dp->i_uid);
1838 if (dp->i_uid != cnp->cn_cred->cr_uid) {
1840 * Make sure the correct user gets charged
1842 * Make a dummy credential for the victim.
1843 * XXX This seems to never be accessed out of
1844 * our context so a stack variable is ok.
1846 refcount_init(&ucred.cr_ref, 1);
1847 ucred.cr_uid = ip->i_uid;
1848 ucred.cr_ngroups = 1;
1849 ucred.cr_groups = &ucred_group;
1850 ucred.cr_groups[0] = dp->i_gid;
1855 ip->i_uid = cnp->cn_cred->cr_uid;
1856 DIP_SET(ip, i_uid, ip->i_uid);
1859 if ((error = getinoquota(ip)) ||
1860 (error = chkiq(ip, 1, ucp, 0))) {
1861 UFS_VFREE(tvp, ip->i_number, dmode);
1867 #else /* !SUIDDIR */
1868 ip->i_uid = cnp->cn_cred->cr_uid;
1869 DIP_SET(ip, i_uid, ip->i_uid);
1871 if ((error = getinoquota(ip)) ||
1872 (error = chkiq(ip, 1, cnp->cn_cred, 0))) {
1873 UFS_VFREE(tvp, ip->i_number, dmode);
1878 #endif /* !SUIDDIR */
1879 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
1881 DIP_SET(ip, i_mode, dmode);
1882 tvp->v_type = VDIR; /* Rest init'd in getnewvnode(). */
1885 DIP_SET(ip, i_nlink, 2);
1886 if (DOINGSOFTDEP(tvp))
1887 softdep_change_linkcnt(ip);
1888 if (cnp->cn_flags & ISWHITEOUT) {
1889 ip->i_flags |= UF_OPAQUE;
1890 DIP_SET(ip, i_flags, ip->i_flags);
1894 * Bump link count in parent directory to reflect work done below.
1895 * Should be done before reference is created so cleanup is
1896 * possible if we crash.
1900 DIP_SET(dp, i_nlink, dp->i_nlink);
1901 dp->i_flag |= IN_CHANGE;
1902 if (DOINGSOFTDEP(dvp))
1903 softdep_change_linkcnt(dp);
1904 error = UFS_UPDATE(tvp, !(DOINGSOFTDEP(dvp) | DOINGASYNC(dvp)));
1908 if (dvp->v_mount->mnt_flag & MNT_MULTILABEL) {
1909 error = mac_vnode_create_extattr(cnp->cn_cred, dvp->v_mount,
1916 if (dvp->v_mount->mnt_flag & MNT_ACLS) {
1917 error = ufs_do_posix1e_acl_inheritance_dir(dvp, tvp, dmode,
1918 cnp->cn_cred, cnp->cn_thread);
1921 } else if (dvp->v_mount->mnt_flag & MNT_NFS4ACLS) {
1922 error = ufs_do_nfs4_acl_inheritance(dvp, tvp, dmode,
1923 cnp->cn_cred, cnp->cn_thread);
1927 #endif /* !UFS_ACL */
1930 * Initialize directory with "." and ".." from static template.
1932 if (dvp->v_mount->mnt_maxsymlinklen > 0)
1933 dtp = &mastertemplate;
1935 dtp = (struct dirtemplate *)&omastertemplate;
1937 dirtemplate.dot_ino = ip->i_number;
1938 dirtemplate.dotdot_ino = dp->i_number;
1939 if ((error = UFS_BALLOC(tvp, (off_t)0, DIRBLKSIZ, cnp->cn_cred,
1940 BA_CLRBUF, &bp)) != 0)
1942 ip->i_size = DIRBLKSIZ;
1943 DIP_SET(ip, i_size, DIRBLKSIZ);
1944 ip->i_flag |= IN_CHANGE | IN_UPDATE;
1945 vnode_pager_setsize(tvp, (u_long)ip->i_size);
1946 bcopy((caddr_t)&dirtemplate, (caddr_t)bp->b_data, sizeof dirtemplate);
1947 if (DOINGSOFTDEP(tvp)) {
1949 * Ensure that the entire newly allocated block is a
1950 * valid directory so that future growth within the
1951 * block does not have to ensure that the block is
1952 * written before the inode.
1955 while (blkoff < bp->b_bcount) {
1957 (bp->b_data + blkoff))->d_reclen = DIRBLKSIZ;
1958 blkoff += DIRBLKSIZ;
1961 if ((error = UFS_UPDATE(tvp, !(DOINGSOFTDEP(tvp) |
1962 DOINGASYNC(tvp)))) != 0) {
1967 * Directory set up, now install its entry in the parent directory.
1969 * If we are not doing soft dependencies, then we must write out the
1970 * buffer containing the new directory body before entering the new
1971 * name in the parent. If we are doing soft dependencies, then the
1972 * buffer containing the new directory body will be passed to and
1973 * released in the soft dependency code after the code has attached
1974 * an appropriate ordering dependency to the buffer which ensures that
1975 * the buffer is written before the new name is written in the parent.
1977 if (DOINGASYNC(dvp))
1979 else if (!DOINGSOFTDEP(dvp) && ((error = bwrite(bp))))
1981 ufs_makedirentry(ip, cnp, &newdir);
1982 error = ufs_direnter(dvp, tvp, &newdir, cnp, bp, 0);
1990 DIP_SET(dp, i_nlink, dp->i_nlink);
1991 dp->i_flag |= IN_CHANGE;
1992 if (DOINGSOFTDEP(dvp))
1993 softdep_change_linkcnt(dp);
1995 * No need to do an explicit VOP_TRUNCATE here, vrele will
1996 * do this for us because we set the link count to 0.
2000 DIP_SET(ip, i_nlink, 0);
2001 ip->i_flag |= IN_CHANGE;
2002 if (DOINGSOFTDEP(tvp))
2003 softdep_change_linkcnt(ip);
2011 * Rmdir system call.
2015 struct vop_rmdir_args /* {
2016 struct vnode *a_dvp;
2018 struct componentname *a_cnp;
2021 struct vnode *vp = ap->a_vp;
2022 struct vnode *dvp = ap->a_dvp;
2023 struct componentname *cnp = ap->a_cnp;
2024 struct inode *ip, *dp;
2031 * Do not remove a directory that is in the process of being renamed.
2032 * Verify the directory is empty (and valid). Rmdir ".." will not be
2033 * valid since ".." will contain a reference to the current directory
2034 * and thus be non-empty. Do not allow the removal of mounted on
2035 * directories (this can happen when an NFS exported filesystem
2036 * tries to remove a locally mounted on directory).
2039 if (ip->i_effnlink < 2) {
2043 if (!ufs_dirempty(ip, dp->i_number, cnp->cn_cred)) {
2047 if ((dp->i_flags & APPEND)
2048 || (ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))) {
2052 if (vp->v_mountedhere != 0) {
2057 ufs_gjournal_orphan(vp);
2060 * Delete reference to directory before purging
2061 * inode. If we crash in between, the directory
2062 * will be reattached to lost+found,
2066 if (DOINGSOFTDEP(vp)) {
2067 softdep_change_linkcnt(dp);
2068 softdep_change_linkcnt(ip);
2070 error = ufs_dirremove(dvp, ip, cnp->cn_flags, 1);
2074 if (DOINGSOFTDEP(vp)) {
2075 softdep_change_linkcnt(dp);
2076 softdep_change_linkcnt(ip);
2082 * Truncate inode. The only stuff left in the directory is "." and
2083 * "..". The "." reference is inconsequential since we are quashing
2084 * it. The soft dependency code will arrange to do these operations
2085 * after the parent directory entry has been deleted on disk, so
2086 * when running with that code we avoid doing them now.
2088 if (!DOINGSOFTDEP(vp)) {
2090 DIP_SET(dp, i_nlink, dp->i_nlink);
2091 dp->i_flag |= IN_CHANGE;
2092 error = UFS_UPDATE(dvp, 0);
2094 DIP_SET(ip, i_nlink, ip->i_nlink);
2095 ip->i_flag |= IN_CHANGE;
2097 if (!DOINGASYNC(vp))
2099 error = UFS_TRUNCATE(vp, (off_t)0, ioflag, cnp->cn_cred,
2104 /* Kill any active hash; i_effnlink == 0, so it will not come back. */
2105 if (ip->i_dirhash != NULL)
2106 ufsdirhash_free(ip);
2113 * symlink -- make a symbolic link
2117 struct vop_symlink_args /* {
2118 struct vnode *a_dvp;
2119 struct vnode **a_vpp;
2120 struct componentname *a_cnp;
2121 struct vattr *a_vap;
2125 struct vnode *vp, **vpp = ap->a_vpp;
2129 error = ufs_makeinode(IFLNK | ap->a_vap->va_mode, ap->a_dvp,
2134 len = strlen(ap->a_target);
2135 if (len < vp->v_mount->mnt_maxsymlinklen) {
2137 bcopy(ap->a_target, SHORTLINK(ip), len);
2139 DIP_SET(ip, i_size, len);
2140 ip->i_flag |= IN_CHANGE | IN_UPDATE;
2141 error = UFS_UPDATE(vp, 0);
2143 error = vn_rdwr(UIO_WRITE, vp, ap->a_target, len, (off_t)0,
2144 UIO_SYSSPACE, IO_NODELOCKED | IO_NOMACCHECK,
2145 ap->a_cnp->cn_cred, NOCRED, NULL, NULL);
2152 * Vnode op for reading directories.
2154 * The routine below assumes that the on-disk format of a directory
2155 * is the same as that defined by <sys/dirent.h>. If the on-disk
2156 * format changes, then it will be necessary to do a conversion
2157 * from the on-disk format that read returns to the format defined
2158 * by <sys/dirent.h>.
2162 struct vop_readdir_args /* {
2165 struct ucred *a_cred;
2171 struct uio *uio = ap->a_uio;
2176 if (ap->a_ncookies != NULL)
2178 * Ensure that the block is aligned. The caller can use
2179 * the cookies to determine where in the block to start.
2181 uio->uio_offset &= ~(DIRBLKSIZ - 1);
2182 off = uio->uio_offset;
2183 count = uio->uio_resid;
2184 /* Make sure we don't return partial entries. */
2185 if (count <= ((uio->uio_offset + count) & (DIRBLKSIZ -1)))
2187 count -= (uio->uio_offset + count) & (DIRBLKSIZ -1);
2188 lost = uio->uio_resid - count;
2189 uio->uio_resid = count;
2190 uio->uio_iov->iov_len = count;
2191 # if (BYTE_ORDER == LITTLE_ENDIAN)
2192 if (ap->a_vp->v_mount->mnt_maxsymlinklen > 0) {
2193 error = VOP_READ(ap->a_vp, uio, 0, ap->a_cred);
2195 struct dirent *dp, *edp;
2203 auio.uio_iov = &aiov;
2204 auio.uio_iovcnt = 1;
2205 auio.uio_segflg = UIO_SYSSPACE;
2206 aiov.iov_len = count;
2207 dirbuf = malloc(count, M_TEMP, M_WAITOK);
2208 aiov.iov_base = dirbuf;
2209 error = VOP_READ(ap->a_vp, &auio, 0, ap->a_cred);
2211 readcnt = count - auio.uio_resid;
2212 edp = (struct dirent *)&dirbuf[readcnt];
2213 for (dp = (struct dirent *)dirbuf; dp < edp; ) {
2215 dp->d_namlen = dp->d_type;
2217 if (dp->d_reclen > 0) {
2218 dp = (struct dirent *)
2219 ((char *)dp + dp->d_reclen);
2226 error = uiomove(dirbuf, readcnt, uio);
2228 free(dirbuf, M_TEMP);
2231 error = VOP_READ(ap->a_vp, uio, 0, ap->a_cred);
2233 if (!error && ap->a_ncookies != NULL) {
2234 struct dirent* dpStart;
2235 struct dirent* dpEnd;
2241 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
2242 panic("ufs_readdir: unexpected uio from NFS server");
2243 dpStart = (struct dirent *)
2244 ((char *)uio->uio_iov->iov_base - (uio->uio_offset - off));
2245 dpEnd = (struct dirent *) uio->uio_iov->iov_base;
2246 for (dp = dpStart, ncookies = 0;
2248 dp = (struct dirent *)((caddr_t) dp + dp->d_reclen))
2250 cookies = malloc(ncookies * sizeof(u_long), M_TEMP,
2252 for (dp = dpStart, cookiep = cookies;
2254 dp = (struct dirent *)((caddr_t) dp + dp->d_reclen)) {
2255 off += dp->d_reclen;
2256 *cookiep++ = (u_long) off;
2258 *ap->a_ncookies = ncookies;
2259 *ap->a_cookies = cookies;
2261 uio->uio_resid += lost;
2263 *ap->a_eofflag = VTOI(ap->a_vp)->i_size <= uio->uio_offset;
2268 * Return target name of a symbolic link
2272 struct vop_readlink_args /* {
2275 struct ucred *a_cred;
2278 struct vnode *vp = ap->a_vp;
2279 struct inode *ip = VTOI(vp);
2283 if ((isize < vp->v_mount->mnt_maxsymlinklen) ||
2284 DIP(ip, i_blocks) == 0) { /* XXX - for old fastlink support */
2285 return (uiomove(SHORTLINK(ip), isize, ap->a_uio));
2287 return (VOP_READ(vp, ap->a_uio, 0, ap->a_cred));
2291 * Calculate the logical to physical mapping if not done already,
2292 * then call the device strategy routine.
2294 * In order to be able to swap to a file, the ufs_bmaparray() operation may not
2295 * deadlock on memory. See ufs_bmap() for details.
2299 struct vop_strategy_args /* {
2304 struct buf *bp = ap->a_bp;
2305 struct vnode *vp = ap->a_vp;
2312 if (bp->b_blkno == bp->b_lblkno) {
2313 error = ufs_bmaparray(vp, bp->b_lblkno, &blkno, bp, NULL, NULL);
2314 bp->b_blkno = blkno;
2316 bp->b_error = error;
2317 bp->b_ioflags |= BIO_ERROR;
2321 if ((long)bp->b_blkno == -1)
2324 if ((long)bp->b_blkno == -1) {
2328 bp->b_iooffset = dbtob(bp->b_blkno);
2329 bo = ip->i_umbufobj;
2330 BO_STRATEGY(bo, bp);
2335 * Print out the contents of an inode.
2339 struct vop_print_args /* {
2343 struct vnode *vp = ap->a_vp;
2344 struct inode *ip = VTOI(vp);
2346 printf("\tino %lu, on dev %s", (u_long)ip->i_number,
2347 devtoname(ip->i_dev));
2348 if (vp->v_type == VFIFO)
2355 * Close wrapper for fifos.
2357 * Update the times on the inode then do device close.
2361 struct vop_close_args /* {
2364 struct ucred *a_cred;
2365 struct thread *a_td;
2368 struct vnode *vp = ap->a_vp;
2372 usecount = vp->v_usecount;
2374 ufs_itimes_locked(vp);
2376 return (fifo_specops.vop_close(ap));
2380 * Kqfilter wrapper for fifos.
2382 * Fall through to ufs kqfilter routines if needed
2385 ufsfifo_kqfilter(ap)
2386 struct vop_kqfilter_args *ap;
2390 error = fifo_specops.vop_kqfilter(ap);
2392 error = vfs_kqfilter(ap);
2397 * Return POSIX pathconf information applicable to fifos.
2400 ufsfifo_pathconf(ap)
2401 struct vop_pathconf_args /* {
2408 switch (ap->a_name) {
2409 case _PC_ACL_EXTENDED:
2411 case _PC_ACL_PATH_MAX:
2412 case _PC_MAC_PRESENT:
2413 return (ufs_pathconf(ap));
2415 return (fifo_specops.vop_pathconf(ap));
2421 * Return POSIX pathconf information applicable to ufs filesystems.
2425 struct vop_pathconf_args /* {
2434 switch (ap->a_name) {
2436 *ap->a_retval = LINK_MAX;
2439 *ap->a_retval = NAME_MAX;
2442 *ap->a_retval = PATH_MAX;
2445 *ap->a_retval = PIPE_BUF;
2447 case _PC_CHOWN_RESTRICTED:
2453 case _PC_ACL_EXTENDED:
2455 if (ap->a_vp->v_mount->mnt_flag & MNT_ACLS)
2466 if (ap->a_vp->v_mount->mnt_flag & MNT_NFS4ACLS)
2475 case _PC_ACL_PATH_MAX:
2477 if (ap->a_vp->v_mount->mnt_flag & (MNT_ACLS | MNT_NFS4ACLS))
2478 *ap->a_retval = ACL_MAX_ENTRIES;
2485 case _PC_MAC_PRESENT:
2487 if (ap->a_vp->v_mount->mnt_flag & MNT_MULTILABEL)
2495 case _PC_MIN_HOLE_SIZE:
2496 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2499 /* _PC_ASYNC_IO should have been handled by upper layers. */
2500 KASSERT(0, ("_PC_ASYNC_IO should not get here"));
2509 case _PC_ALLOC_SIZE_MIN:
2510 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_bsize;
2512 case _PC_FILESIZEBITS:
2515 case _PC_REC_INCR_XFER_SIZE:
2516 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2518 case _PC_REC_MAX_XFER_SIZE:
2519 *ap->a_retval = -1; /* means ``unlimited'' */
2521 case _PC_REC_MIN_XFER_SIZE:
2522 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
2524 case _PC_REC_XFER_ALIGN:
2525 *ap->a_retval = PAGE_SIZE;
2527 case _PC_SYMLINK_MAX:
2528 *ap->a_retval = MAXPATHLEN;
2539 * Initialize the vnode associated with a new inode, handle aliased
2543 ufs_vinit(mntp, fifoops, vpp)
2545 struct vop_vector *fifoops;
2553 vp->v_type = IFTOVT(ip->i_mode);
2554 if (vp->v_type == VFIFO)
2556 ASSERT_VOP_LOCKED(vp, "ufs_vinit");
2557 if (ip->i_number == ROOTINO)
2558 vp->v_vflag |= VV_ROOT;
2564 * Allocate a new inode.
2565 * Vnode dvp must be locked.
2568 ufs_makeinode(mode, dvp, vpp, cnp)
2572 struct componentname *cnp;
2574 struct inode *ip, *pdir;
2575 struct direct newdir;
2581 if ((cnp->cn_flags & HASBUF) == 0)
2582 panic("ufs_makeinode: no name");
2585 if ((mode & IFMT) == 0)
2588 error = UFS_VALLOC(dvp, mode, cnp->cn_cred, &tvp);
2592 ip->i_gid = pdir->i_gid;
2593 DIP_SET(ip, i_gid, pdir->i_gid);
2597 struct ucred ucred, *ucp;
2602 * If we are not the owner of the directory,
2603 * and we are hacking owners here, (only do this where told to)
2604 * and we are not giving it TO root, (would subvert quotas)
2605 * then go ahead and give it to the other user.
2606 * Note that this drops off the execute bits for security.
2608 if ((dvp->v_mount->mnt_flag & MNT_SUIDDIR) &&
2609 (pdir->i_mode & ISUID) &&
2610 (pdir->i_uid != cnp->cn_cred->cr_uid) && pdir->i_uid) {
2611 ip->i_uid = pdir->i_uid;
2612 DIP_SET(ip, i_uid, ip->i_uid);
2616 * Make sure the correct user gets charged
2618 * Quickly knock up a dummy credential for the victim.
2619 * XXX This seems to never be accessed out of our
2620 * context so a stack variable is ok.
2622 refcount_init(&ucred.cr_ref, 1);
2623 ucred.cr_uid = ip->i_uid;
2624 ucred.cr_ngroups = 1;
2625 ucred.cr_groups = &ucred_group;
2626 ucred.cr_groups[0] = pdir->i_gid;
2630 ip->i_uid = cnp->cn_cred->cr_uid;
2631 DIP_SET(ip, i_uid, ip->i_uid);
2635 if ((error = getinoquota(ip)) ||
2636 (error = chkiq(ip, 1, ucp, 0))) {
2637 UFS_VFREE(tvp, ip->i_number, mode);
2643 #else /* !SUIDDIR */
2644 ip->i_uid = cnp->cn_cred->cr_uid;
2645 DIP_SET(ip, i_uid, ip->i_uid);
2647 if ((error = getinoquota(ip)) ||
2648 (error = chkiq(ip, 1, cnp->cn_cred, 0))) {
2649 UFS_VFREE(tvp, ip->i_number, mode);
2654 #endif /* !SUIDDIR */
2655 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
2657 DIP_SET(ip, i_mode, mode);
2658 tvp->v_type = IFTOVT(mode); /* Rest init'd in getnewvnode(). */
2661 DIP_SET(ip, i_nlink, 1);
2662 if (DOINGSOFTDEP(tvp))
2663 softdep_change_linkcnt(ip);
2664 if ((ip->i_mode & ISGID) && !groupmember(ip->i_gid, cnp->cn_cred) &&
2665 priv_check_cred(cnp->cn_cred, PRIV_VFS_SETGID, 0)) {
2666 ip->i_mode &= ~ISGID;
2667 DIP_SET(ip, i_mode, ip->i_mode);
2670 if (cnp->cn_flags & ISWHITEOUT) {
2671 ip->i_flags |= UF_OPAQUE;
2672 DIP_SET(ip, i_flags, ip->i_flags);
2676 * Make sure inode goes to disk before directory entry.
2678 error = UFS_UPDATE(tvp, !(DOINGSOFTDEP(tvp) | DOINGASYNC(tvp)));
2682 if (dvp->v_mount->mnt_flag & MNT_MULTILABEL) {
2683 error = mac_vnode_create_extattr(cnp->cn_cred, dvp->v_mount,
2690 if (dvp->v_mount->mnt_flag & MNT_ACLS) {
2691 error = ufs_do_posix1e_acl_inheritance_file(dvp, tvp, mode,
2692 cnp->cn_cred, cnp->cn_thread);
2695 } else if (dvp->v_mount->mnt_flag & MNT_NFS4ACLS) {
2696 error = ufs_do_nfs4_acl_inheritance(dvp, tvp, mode,
2697 cnp->cn_cred, cnp->cn_thread);
2701 #endif /* !UFS_ACL */
2702 ufs_makedirentry(ip, cnp, &newdir);
2703 error = ufs_direnter(dvp, tvp, &newdir, cnp, NULL, 0);
2711 * Write error occurred trying to update the inode
2712 * or the directory so must deallocate the inode.
2716 DIP_SET(ip, i_nlink, 0);
2717 ip->i_flag |= IN_CHANGE;
2718 if (DOINGSOFTDEP(tvp))
2719 softdep_change_linkcnt(ip);
2725 ufs_ioctl(struct vop_ioctl_args *ap)
2728 switch (ap->a_command) {
2731 return (vn_bmap_seekhole(ap->a_vp, ap->a_command,
2732 (off_t *)ap->a_data, ap->a_cred));
2738 /* Global vfs data structures for ufs. */
2739 struct vop_vector ufs_vnodeops = {
2740 .vop_default = &default_vnodeops,
2741 .vop_fsync = VOP_PANIC,
2742 .vop_read = VOP_PANIC,
2743 .vop_reallocblks = VOP_PANIC,
2744 .vop_write = VOP_PANIC,
2745 .vop_accessx = ufs_accessx,
2746 .vop_bmap = ufs_bmap,
2747 .vop_cachedlookup = ufs_lookup,
2748 .vop_close = ufs_close,
2749 .vop_create = ufs_create,
2750 .vop_getattr = ufs_getattr,
2751 .vop_inactive = ufs_inactive,
2752 .vop_ioctl = ufs_ioctl,
2753 .vop_link = ufs_link,
2754 .vop_lookup = vfs_cache_lookup,
2755 .vop_markatime = ufs_markatime,
2756 .vop_mkdir = ufs_mkdir,
2757 .vop_mknod = ufs_mknod,
2758 .vop_open = ufs_open,
2759 .vop_pathconf = ufs_pathconf,
2760 .vop_poll = vop_stdpoll,
2761 .vop_print = ufs_print,
2762 .vop_readdir = ufs_readdir,
2763 .vop_readlink = ufs_readlink,
2764 .vop_reclaim = ufs_reclaim,
2765 .vop_remove = ufs_remove,
2766 .vop_rename = ufs_rename,
2767 .vop_rmdir = ufs_rmdir,
2768 .vop_setattr = ufs_setattr,
2770 .vop_setlabel = vop_stdsetlabel_ea,
2772 .vop_strategy = ufs_strategy,
2773 .vop_symlink = ufs_symlink,
2774 .vop_whiteout = ufs_whiteout,
2776 .vop_getextattr = ufs_getextattr,
2777 .vop_deleteextattr = ufs_deleteextattr,
2778 .vop_setextattr = ufs_setextattr,
2781 .vop_getacl = ufs_getacl,
2782 .vop_setacl = ufs_setacl,
2783 .vop_aclcheck = ufs_aclcheck,
2787 struct vop_vector ufs_fifoops = {
2788 .vop_default = &fifo_specops,
2789 .vop_fsync = VOP_PANIC,
2790 .vop_accessx = ufs_accessx,
2791 .vop_close = ufsfifo_close,
2792 .vop_getattr = ufs_getattr,
2793 .vop_inactive = ufs_inactive,
2794 .vop_kqfilter = ufsfifo_kqfilter,
2795 .vop_markatime = ufs_markatime,
2796 .vop_pathconf = ufsfifo_pathconf,
2797 .vop_print = ufs_print,
2798 .vop_read = VOP_PANIC,
2799 .vop_reclaim = ufs_reclaim,
2800 .vop_setattr = ufs_setattr,
2802 .vop_setlabel = vop_stdsetlabel_ea,
2804 .vop_write = VOP_PANIC,
2806 .vop_getextattr = ufs_getextattr,
2807 .vop_deleteextattr = ufs_deleteextattr,
2808 .vop_setextattr = ufs_setextattr,
2811 .vop_getacl = ufs_getacl,
2812 .vop_setacl = ufs_setacl,
2813 .vop_aclcheck = ufs_aclcheck,