Home | History | Annotate | Line # | Download | only in lfs
lfs_vnops.c revision 1.65
      1  1.65  perseant /*	$NetBSD: lfs_vnops.c,v 1.65 2002/06/16 00:13:16 perseant Exp $	*/
      2   1.2       cgd 
      3  1.22  perseant /*-
      4  1.44  perseant  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
      5  1.22  perseant  * All rights reserved.
      6  1.22  perseant  *
      7  1.22  perseant  * This code is derived from software contributed to The NetBSD Foundation
      8  1.22  perseant  * by Konrad E. Schroder <perseant (at) hhhh.org>.
      9  1.22  perseant  *
     10  1.22  perseant  * Redistribution and use in source and binary forms, with or without
     11  1.22  perseant  * modification, are permitted provided that the following conditions
     12  1.22  perseant  * are met:
     13  1.22  perseant  * 1. Redistributions of source code must retain the above copyright
     14  1.22  perseant  *    notice, this list of conditions and the following disclaimer.
     15  1.22  perseant  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.22  perseant  *    notice, this list of conditions and the following disclaimer in the
     17  1.22  perseant  *    documentation and/or other materials provided with the distribution.
     18  1.22  perseant  * 3. All advertising materials mentioning features or use of this software
     19  1.22  perseant  *    must display the following acknowledgement:
     20  1.22  perseant  *      This product includes software developed by the NetBSD
     21  1.22  perseant  *      Foundation, Inc. and its contributors.
     22  1.22  perseant  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.22  perseant  *    contributors may be used to endorse or promote products derived
     24  1.22  perseant  *    from this software without specific prior written permission.
     25  1.22  perseant  *
     26  1.22  perseant  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.22  perseant  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.22  perseant  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.22  perseant  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.22  perseant  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.22  perseant  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.22  perseant  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.22  perseant  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.22  perseant  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.22  perseant  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.22  perseant  * POSSIBILITY OF SUCH DAMAGE.
     37  1.22  perseant  */
     38   1.1   mycroft /*
     39  1.15      fvdl  * Copyright (c) 1986, 1989, 1991, 1993, 1995
     40   1.1   mycroft  *	The Regents of the University of California.  All rights reserved.
     41   1.1   mycroft  *
     42   1.1   mycroft  * Redistribution and use in source and binary forms, with or without
     43   1.1   mycroft  * modification, are permitted provided that the following conditions
     44   1.1   mycroft  * are met:
     45   1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     46   1.1   mycroft  *    notice, this list of conditions and the following disclaimer.
     47   1.1   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     48   1.1   mycroft  *    notice, this list of conditions and the following disclaimer in the
     49   1.1   mycroft  *    documentation and/or other materials provided with the distribution.
     50   1.1   mycroft  * 3. All advertising materials mentioning features or use of this software
     51   1.1   mycroft  *    must display the following acknowledgement:
     52   1.1   mycroft  *	This product includes software developed by the University of
     53   1.1   mycroft  *	California, Berkeley and its contributors.
     54   1.1   mycroft  * 4. Neither the name of the University nor the names of its contributors
     55   1.1   mycroft  *    may be used to endorse or promote products derived from this software
     56   1.1   mycroft  *    without specific prior written permission.
     57   1.1   mycroft  *
     58   1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59   1.1   mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60   1.1   mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61   1.1   mycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62   1.1   mycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63   1.1   mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64   1.1   mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65   1.1   mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66   1.1   mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67   1.1   mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68   1.1   mycroft  * SUCH DAMAGE.
     69   1.1   mycroft  *
     70  1.15      fvdl  *	@(#)lfs_vnops.c	8.13 (Berkeley) 6/10/95
     71   1.1   mycroft  */
     72  1.58     lukem 
     73  1.58     lukem #include <sys/cdefs.h>
     74  1.65  perseant __KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.65 2002/06/16 00:13:16 perseant Exp $");
     75  1.17  sommerfe 
     76   1.1   mycroft #include <sys/param.h>
     77   1.1   mycroft #include <sys/systm.h>
     78   1.1   mycroft #include <sys/namei.h>
     79   1.1   mycroft #include <sys/resourcevar.h>
     80   1.1   mycroft #include <sys/kernel.h>
     81   1.1   mycroft #include <sys/file.h>
     82   1.1   mycroft #include <sys/stat.h>
     83   1.1   mycroft #include <sys/buf.h>
     84   1.1   mycroft #include <sys/proc.h>
     85   1.1   mycroft #include <sys/conf.h>
     86   1.1   mycroft #include <sys/mount.h>
     87   1.1   mycroft #include <sys/vnode.h>
     88   1.1   mycroft #include <sys/malloc.h>
     89  1.19   thorpej #include <sys/pool.h>
     90  1.10  christos #include <sys/signalvar.h>
     91   1.1   mycroft 
     92  1.12   mycroft #include <miscfs/fifofs/fifo.h>
     93  1.12   mycroft #include <miscfs/genfs/genfs.h>
     94   1.1   mycroft #include <miscfs/specfs/specdev.h>
     95   1.1   mycroft 
     96   1.1   mycroft #include <ufs/ufs/inode.h>
     97   1.1   mycroft #include <ufs/ufs/dir.h>
     98   1.1   mycroft #include <ufs/ufs/ufsmount.h>
     99   1.1   mycroft #include <ufs/ufs/ufs_extern.h>
    100   1.1   mycroft 
    101   1.1   mycroft #include <ufs/lfs/lfs.h>
    102   1.1   mycroft #include <ufs/lfs/lfs_extern.h>
    103   1.1   mycroft 
    104   1.1   mycroft /* Global vfs data structures for lfs. */
    105  1.51  perseant int (**lfs_vnodeop_p)(void *);
    106  1.50  jdolecek const struct vnodeopv_entry_desc lfs_vnodeop_entries[] = {
    107   1.1   mycroft 	{ &vop_default_desc, vn_default_error },
    108   1.1   mycroft 	{ &vop_lookup_desc, ufs_lookup },		/* lookup */
    109  1.22  perseant 	{ &vop_create_desc, lfs_create },		/* create */
    110  1.22  perseant 	{ &vop_whiteout_desc, lfs_whiteout },		/* whiteout */
    111  1.22  perseant 	{ &vop_mknod_desc, lfs_mknod },			/* mknod */
    112   1.1   mycroft 	{ &vop_open_desc, ufs_open },			/* open */
    113   1.1   mycroft 	{ &vop_close_desc, lfs_close },			/* close */
    114   1.1   mycroft 	{ &vop_access_desc, ufs_access },		/* access */
    115   1.1   mycroft 	{ &vop_getattr_desc, lfs_getattr },		/* getattr */
    116  1.61  perseant 	{ &vop_setattr_desc, lfs_setattr },		/* setattr */
    117   1.1   mycroft 	{ &vop_read_desc, lfs_read },			/* read */
    118   1.1   mycroft 	{ &vop_write_desc, lfs_write },			/* write */
    119   1.4   mycroft 	{ &vop_lease_desc, ufs_lease_check },		/* lease */
    120   1.1   mycroft 	{ &vop_ioctl_desc, ufs_ioctl },			/* ioctl */
    121  1.27  wrstuden 	{ &vop_fcntl_desc, ufs_fcntl },			/* fcntl */
    122  1.13   mycroft 	{ &vop_poll_desc, ufs_poll },			/* poll */
    123  1.15      fvdl 	{ &vop_revoke_desc, ufs_revoke },		/* revoke */
    124   1.1   mycroft 	{ &vop_mmap_desc, ufs_mmap },			/* mmap */
    125   1.1   mycroft 	{ &vop_fsync_desc, lfs_fsync },			/* fsync */
    126   1.1   mycroft 	{ &vop_seek_desc, ufs_seek },			/* seek */
    127  1.22  perseant 	{ &vop_remove_desc, lfs_remove },		/* remove */
    128  1.22  perseant 	{ &vop_link_desc, lfs_link },			/* link */
    129  1.22  perseant 	{ &vop_rename_desc, lfs_rename },		/* rename */
    130  1.22  perseant 	{ &vop_mkdir_desc, lfs_mkdir },			/* mkdir */
    131  1.22  perseant 	{ &vop_rmdir_desc, lfs_rmdir },			/* rmdir */
    132  1.22  perseant 	{ &vop_symlink_desc, lfs_symlink },		/* symlink */
    133   1.1   mycroft 	{ &vop_readdir_desc, ufs_readdir },		/* readdir */
    134   1.1   mycroft 	{ &vop_readlink_desc, ufs_readlink },		/* readlink */
    135   1.1   mycroft 	{ &vop_abortop_desc, ufs_abortop },		/* abortop */
    136  1.40  perseant 	{ &vop_inactive_desc, lfs_inactive },		/* inactive */
    137   1.1   mycroft 	{ &vop_reclaim_desc, lfs_reclaim },		/* reclaim */
    138   1.1   mycroft 	{ &vop_lock_desc, ufs_lock },			/* lock */
    139   1.1   mycroft 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
    140   1.1   mycroft 	{ &vop_bmap_desc, ufs_bmap },			/* bmap */
    141   1.1   mycroft 	{ &vop_strategy_desc, ufs_strategy },		/* strategy */
    142   1.1   mycroft 	{ &vop_print_desc, ufs_print },			/* print */
    143   1.1   mycroft 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
    144   1.1   mycroft 	{ &vop_pathconf_desc, ufs_pathconf },		/* pathconf */
    145   1.1   mycroft 	{ &vop_advlock_desc, ufs_advlock },		/* advlock */
    146   1.1   mycroft 	{ &vop_blkatoff_desc, lfs_blkatoff },		/* blkatoff */
    147   1.1   mycroft 	{ &vop_valloc_desc, lfs_valloc },		/* valloc */
    148  1.32      fvdl 	{ &vop_balloc_desc, lfs_balloc },		/* balloc */
    149   1.1   mycroft 	{ &vop_vfree_desc, lfs_vfree },			/* vfree */
    150   1.1   mycroft 	{ &vop_truncate_desc, lfs_truncate },		/* truncate */
    151   1.1   mycroft 	{ &vop_update_desc, lfs_update },		/* update */
    152   1.1   mycroft 	{ &vop_bwrite_desc, lfs_bwrite },		/* bwrite */
    153  1.60       chs 	{ &vop_getpages_desc, lfs_getpages },		/* getpages */
    154  1.60       chs 	{ &vop_putpages_desc, lfs_putpages },		/* putpages */
    155  1.53       chs 	{ NULL, NULL }
    156   1.1   mycroft };
    157  1.50  jdolecek const struct vnodeopv_desc lfs_vnodeop_opv_desc =
    158   1.1   mycroft 	{ &lfs_vnodeop_p, lfs_vnodeop_entries };
    159   1.1   mycroft 
    160  1.51  perseant int (**lfs_specop_p)(void *);
    161  1.50  jdolecek const struct vnodeopv_entry_desc lfs_specop_entries[] = {
    162   1.1   mycroft 	{ &vop_default_desc, vn_default_error },
    163   1.1   mycroft 	{ &vop_lookup_desc, spec_lookup },		/* lookup */
    164   1.1   mycroft 	{ &vop_create_desc, spec_create },		/* create */
    165   1.1   mycroft 	{ &vop_mknod_desc, spec_mknod },		/* mknod */
    166   1.1   mycroft 	{ &vop_open_desc, spec_open },			/* open */
    167  1.65  perseant 	{ &vop_close_desc, lfsspec_close },		/* close */
    168   1.1   mycroft 	{ &vop_access_desc, ufs_access },		/* access */
    169   1.1   mycroft 	{ &vop_getattr_desc, lfs_getattr },		/* getattr */
    170  1.61  perseant 	{ &vop_setattr_desc, lfs_setattr },		/* setattr */
    171   1.1   mycroft 	{ &vop_read_desc, ufsspec_read },		/* read */
    172   1.1   mycroft 	{ &vop_write_desc, ufsspec_write },		/* write */
    173   1.4   mycroft 	{ &vop_lease_desc, spec_lease_check },		/* lease */
    174   1.1   mycroft 	{ &vop_ioctl_desc, spec_ioctl },		/* ioctl */
    175  1.27  wrstuden 	{ &vop_fcntl_desc, ufs_fcntl },			/* fcntl */
    176  1.13   mycroft 	{ &vop_poll_desc, spec_poll },			/* poll */
    177  1.15      fvdl 	{ &vop_revoke_desc, spec_revoke },		/* revoke */
    178   1.1   mycroft 	{ &vop_mmap_desc, spec_mmap },			/* mmap */
    179   1.1   mycroft 	{ &vop_fsync_desc, spec_fsync },		/* fsync */
    180   1.1   mycroft 	{ &vop_seek_desc, spec_seek },			/* seek */
    181   1.1   mycroft 	{ &vop_remove_desc, spec_remove },		/* remove */
    182   1.1   mycroft 	{ &vop_link_desc, spec_link },			/* link */
    183   1.1   mycroft 	{ &vop_rename_desc, spec_rename },		/* rename */
    184   1.1   mycroft 	{ &vop_mkdir_desc, spec_mkdir },		/* mkdir */
    185   1.1   mycroft 	{ &vop_rmdir_desc, spec_rmdir },		/* rmdir */
    186   1.1   mycroft 	{ &vop_symlink_desc, spec_symlink },		/* symlink */
    187   1.1   mycroft 	{ &vop_readdir_desc, spec_readdir },		/* readdir */
    188   1.1   mycroft 	{ &vop_readlink_desc, spec_readlink },		/* readlink */
    189   1.1   mycroft 	{ &vop_abortop_desc, spec_abortop },		/* abortop */
    190  1.40  perseant 	{ &vop_inactive_desc, lfs_inactive },		/* inactive */
    191   1.1   mycroft 	{ &vop_reclaim_desc, lfs_reclaim },		/* reclaim */
    192   1.1   mycroft 	{ &vop_lock_desc, ufs_lock },			/* lock */
    193   1.1   mycroft 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
    194   1.1   mycroft 	{ &vop_bmap_desc, spec_bmap },			/* bmap */
    195   1.1   mycroft 	{ &vop_strategy_desc, spec_strategy },		/* strategy */
    196   1.1   mycroft 	{ &vop_print_desc, ufs_print },			/* print */
    197   1.1   mycroft 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
    198   1.1   mycroft 	{ &vop_pathconf_desc, spec_pathconf },		/* pathconf */
    199   1.1   mycroft 	{ &vop_advlock_desc, spec_advlock },		/* advlock */
    200   1.1   mycroft 	{ &vop_blkatoff_desc, spec_blkatoff },		/* blkatoff */
    201   1.1   mycroft 	{ &vop_valloc_desc, spec_valloc },		/* valloc */
    202   1.1   mycroft 	{ &vop_vfree_desc, lfs_vfree },			/* vfree */
    203   1.1   mycroft 	{ &vop_truncate_desc, spec_truncate },		/* truncate */
    204   1.1   mycroft 	{ &vop_update_desc, lfs_update },		/* update */
    205  1.28  perseant 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
    206  1.53       chs 	{ &vop_getpages_desc, spec_getpages },		/* getpages */
    207  1.53       chs 	{ &vop_putpages_desc, spec_putpages },		/* putpages */
    208  1.53       chs 	{ NULL, NULL }
    209   1.1   mycroft };
    210  1.50  jdolecek const struct vnodeopv_desc lfs_specop_opv_desc =
    211   1.1   mycroft 	{ &lfs_specop_p, lfs_specop_entries };
    212   1.1   mycroft 
    213  1.51  perseant int (**lfs_fifoop_p)(void *);
    214  1.50  jdolecek const struct vnodeopv_entry_desc lfs_fifoop_entries[] = {
    215   1.1   mycroft 	{ &vop_default_desc, vn_default_error },
    216   1.1   mycroft 	{ &vop_lookup_desc, fifo_lookup },		/* lookup */
    217   1.1   mycroft 	{ &vop_create_desc, fifo_create },		/* create */
    218   1.1   mycroft 	{ &vop_mknod_desc, fifo_mknod },		/* mknod */
    219   1.1   mycroft 	{ &vop_open_desc, fifo_open },			/* open */
    220  1.65  perseant 	{ &vop_close_desc, lfsfifo_close },		/* close */
    221   1.1   mycroft 	{ &vop_access_desc, ufs_access },		/* access */
    222   1.1   mycroft 	{ &vop_getattr_desc, lfs_getattr },		/* getattr */
    223  1.61  perseant 	{ &vop_setattr_desc, lfs_setattr },		/* setattr */
    224   1.1   mycroft 	{ &vop_read_desc, ufsfifo_read },		/* read */
    225   1.1   mycroft 	{ &vop_write_desc, ufsfifo_write },		/* write */
    226   1.4   mycroft 	{ &vop_lease_desc, fifo_lease_check },		/* lease */
    227   1.1   mycroft 	{ &vop_ioctl_desc, fifo_ioctl },		/* ioctl */
    228  1.27  wrstuden 	{ &vop_fcntl_desc, ufs_fcntl },			/* fcntl */
    229  1.13   mycroft 	{ &vop_poll_desc, fifo_poll },			/* poll */
    230  1.15      fvdl 	{ &vop_revoke_desc, fifo_revoke },		/* revoke */
    231   1.1   mycroft 	{ &vop_mmap_desc, fifo_mmap },			/* mmap */
    232   1.1   mycroft 	{ &vop_fsync_desc, fifo_fsync },		/* fsync */
    233   1.1   mycroft 	{ &vop_seek_desc, fifo_seek },			/* seek */
    234   1.1   mycroft 	{ &vop_remove_desc, fifo_remove },		/* remove */
    235   1.1   mycroft 	{ &vop_link_desc, fifo_link },			/* link */
    236   1.1   mycroft 	{ &vop_rename_desc, fifo_rename },		/* rename */
    237   1.1   mycroft 	{ &vop_mkdir_desc, fifo_mkdir },		/* mkdir */
    238   1.1   mycroft 	{ &vop_rmdir_desc, fifo_rmdir },		/* rmdir */
    239   1.1   mycroft 	{ &vop_symlink_desc, fifo_symlink },		/* symlink */
    240   1.1   mycroft 	{ &vop_readdir_desc, fifo_readdir },		/* readdir */
    241   1.1   mycroft 	{ &vop_readlink_desc, fifo_readlink },		/* readlink */
    242   1.1   mycroft 	{ &vop_abortop_desc, fifo_abortop },		/* abortop */
    243  1.40  perseant 	{ &vop_inactive_desc, lfs_inactive },		/* inactive */
    244   1.1   mycroft 	{ &vop_reclaim_desc, lfs_reclaim },		/* reclaim */
    245   1.1   mycroft 	{ &vop_lock_desc, ufs_lock },			/* lock */
    246   1.1   mycroft 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
    247   1.1   mycroft 	{ &vop_bmap_desc, fifo_bmap },			/* bmap */
    248   1.1   mycroft 	{ &vop_strategy_desc, fifo_strategy },		/* strategy */
    249   1.1   mycroft 	{ &vop_print_desc, ufs_print },			/* print */
    250   1.1   mycroft 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
    251   1.1   mycroft 	{ &vop_pathconf_desc, fifo_pathconf },		/* pathconf */
    252   1.1   mycroft 	{ &vop_advlock_desc, fifo_advlock },		/* advlock */
    253   1.1   mycroft 	{ &vop_blkatoff_desc, fifo_blkatoff },		/* blkatoff */
    254   1.1   mycroft 	{ &vop_valloc_desc, fifo_valloc },		/* valloc */
    255   1.1   mycroft 	{ &vop_vfree_desc, lfs_vfree },			/* vfree */
    256   1.1   mycroft 	{ &vop_truncate_desc, fifo_truncate },		/* truncate */
    257   1.1   mycroft 	{ &vop_update_desc, lfs_update },		/* update */
    258   1.1   mycroft 	{ &vop_bwrite_desc, lfs_bwrite },		/* bwrite */
    259  1.56  sommerfe 	{ &vop_putpages_desc, fifo_putpages }, 		/* putpages */
    260  1.53       chs 	{ NULL, NULL }
    261   1.1   mycroft };
    262  1.50  jdolecek const struct vnodeopv_desc lfs_fifoop_opv_desc =
    263   1.1   mycroft 	{ &lfs_fifoop_p, lfs_fifoop_entries };
    264   1.1   mycroft 
    265  1.43  perseant /*
    266  1.43  perseant  * A function version of LFS_ITIMES, for the UFS functions which call ITIMES
    267  1.43  perseant  */
    268  1.43  perseant void
    269  1.51  perseant lfs_itimes(struct inode *ip, struct timespec *acc, struct timespec *mod, struct timespec *cre)
    270  1.43  perseant {
    271  1.43  perseant 	LFS_ITIMES(ip, acc, mod, cre);
    272  1.43  perseant }
    273  1.43  perseant 
    274   1.1   mycroft #define	LFS_READWRITE
    275   1.1   mycroft #include <ufs/ufs/ufs_readwrite.c>
    276   1.1   mycroft #undef	LFS_READWRITE
    277   1.1   mycroft 
    278   1.1   mycroft /*
    279   1.1   mycroft  * Synch an open file.
    280   1.1   mycroft  */
    281   1.1   mycroft /* ARGSUSED */
    282  1.10  christos int
    283  1.51  perseant lfs_fsync(void *v)
    284  1.10  christos {
    285   1.1   mycroft 	struct vop_fsync_args /* {
    286   1.1   mycroft 		struct vnode *a_vp;
    287   1.1   mycroft 		struct ucred *a_cred;
    288  1.22  perseant 		int a_flags;
    289  1.49    toshii 		off_t offlo;
    290  1.49    toshii 		off_t offhi;
    291   1.1   mycroft 		struct proc *a_p;
    292  1.10  christos 	} */ *ap = v;
    293  1.60       chs 	struct vnode *vp = ap->a_vp;
    294  1.60       chs 	int error;
    295  1.22  perseant 
    296  1.47  perseant 	/* Ignore the trickle syncer */
    297  1.47  perseant 	if (ap->a_flags & FSYNC_LAZY)
    298  1.47  perseant 		return 0;
    299  1.47  perseant 
    300  1.60       chs 	simple_lock(&vp->v_interlock);
    301  1.62  perseant 	error = VOP_PUTPAGES(vp, trunc_page(ap->a_offlo),
    302  1.62  perseant                     round_page(ap->a_offhi), PGO_CLEANIT | PGO_SYNCIO);
    303  1.63  perseant 	if (error)
    304  1.60       chs 		return error;
    305  1.63  perseant 	error = VOP_UPDATE(vp, NULL, NULL,
    306  1.63  perseant 			   (ap->a_flags & FSYNC_WAIT) != 0 ? UPDATE_WAIT : 0);
    307  1.63  perseant #ifdef DEBUG
    308  1.63  perseant 	/*
    309  1.63  perseant 	 * If we were called from vinvalbuf and lfs_update
    310  1.63  perseant 	 * didn't flush all our buffers, we're in trouble.
    311  1.63  perseant 	 */
    312  1.64  perseant 	if ((ap->a_flags & FSYNC_WAIT) && LIST_FIRST(&vp->v_dirtyblkhd) != NULL) {
    313  1.63  perseant 		struct buf *bp;
    314  1.63  perseant 
    315  1.64  perseant 		bp = LIST_FIRST(&vp->v_dirtyblkhd);
    316  1.63  perseant 		printf("lfs_fsync: ino %d failed to sync", VTOI(vp)->i_number);
    317  1.63  perseant 		printf("lfs_fsync: iocount = %d\n", VTOI(vp)->i_lfs->lfs_iocount);
    318  1.63  perseant 		printf("lfs_fsync: flags are 0x%x, numoutput=%d\n",
    319  1.63  perseant 			VTOI(vp)->i_flag, vp->v_numoutput);
    320  1.63  perseant 		printf("lfs_fsync: writecount=%ld\n", vp->v_writecount);
    321  1.63  perseant 		printf("lfs_fsync: first bp: %p, flags=0x%lx, lbn=%d\n",
    322  1.63  perseant 			bp, bp->b_flags, bp->b_lblkno);
    323  1.60       chs 	}
    324  1.63  perseant #endif
    325  1.63  perseant 	return error;
    326   1.1   mycroft }
    327   1.1   mycroft 
    328   1.1   mycroft /*
    329  1.40  perseant  * Take IN_ADIROP off, then call ufs_inactive.
    330  1.40  perseant  */
    331  1.40  perseant int
    332  1.51  perseant lfs_inactive(void *v)
    333  1.40  perseant {
    334  1.40  perseant 	struct vop_inactive_args /* {
    335  1.40  perseant 		struct vnode *a_vp;
    336  1.40  perseant 		struct proc *a_p;
    337  1.40  perseant 	} */ *ap = v;
    338  1.40  perseant 	struct inode *ip = VTOI(ap->a_vp);
    339  1.40  perseant 
    340  1.40  perseant 	if (ip->i_flag & IN_ADIROP)
    341  1.40  perseant 		--ip->i_lfs->lfs_nadirop;
    342  1.40  perseant 	ip->i_flag &= ~IN_ADIROP;
    343  1.40  perseant 	return ufs_inactive(v);
    344  1.40  perseant }
    345  1.40  perseant 
    346  1.40  perseant /*
    347   1.1   mycroft  * These macros are used to bracket UFS directory ops, so that we can
    348   1.1   mycroft  * identify all the pages touched during directory ops which need to
    349   1.1   mycroft  * be ordered and flushed atomically, so that they may be recovered.
    350   1.1   mycroft  */
    351  1.22  perseant /*
    352  1.22  perseant  * XXX KS - Because we have to mark nodes VDIROP in order to prevent
    353  1.22  perseant  * the cache from reclaiming them while a dirop is in progress, we must
    354  1.22  perseant  * also manage the number of nodes so marked (otherwise we can run out).
    355  1.22  perseant  * We do this by setting lfs_dirvcount to the number of marked vnodes; it
    356  1.22  perseant  * is decremented during segment write, when VDIROP is taken off.
    357  1.22  perseant  */
    358  1.40  perseant #define	SET_DIROP(vp) lfs_set_dirop(vp)
    359  1.51  perseant static int lfs_set_dirop(struct vnode *);
    360  1.31  perseant extern int lfs_dirvcount;
    361  1.24  perseant 
    362  1.46  perseant static int
    363  1.51  perseant lfs_set_dirop(struct vnode *vp)
    364  1.40  perseant {
    365  1.24  perseant 	struct lfs *fs;
    366  1.24  perseant 	int error;
    367  1.24  perseant 
    368  1.40  perseant 	fs = VTOI(vp)->i_lfs;
    369  1.44  perseant 	/*
    370  1.44  perseant 	 * We might need one directory block plus supporting indirect blocks,
    371  1.44  perseant 	 * plus an inode block and ifile page for the new vnode.
    372  1.44  perseant 	 */
    373  1.51  perseant 	if ((error = lfs_reserve(fs, vp, btofsb(fs, (NIADDR + 3) << fs->lfs_bshift))) != 0)
    374  1.44  perseant 		return (error);
    375  1.40  perseant 	if (fs->lfs_dirops == 0)
    376  1.40  perseant 		lfs_check(vp, LFS_UNUSED_LBN, 0);
    377  1.40  perseant 	while (fs->lfs_writer || lfs_dirvcount > LFS_MAXDIROP) {
    378  1.59       chs 		if (fs->lfs_writer)
    379  1.63  perseant 			tsleep(&fs->lfs_dirops, PRIBIO + 1, "lfs_sdirop", 0);
    380  1.59       chs 		if (lfs_dirvcount > LFS_MAXDIROP && fs->lfs_dirops == 0) {
    381  1.33  perseant                 	++fs->lfs_writer;
    382  1.33  perseant                 	lfs_flush(fs, 0);
    383  1.59       chs                 	if (--fs->lfs_writer == 0)
    384  1.33  perseant                         	wakeup(&fs->lfs_dirops);
    385  1.33  perseant 		}
    386  1.33  perseant 
    387  1.59       chs 		if (lfs_dirvcount > LFS_MAXDIROP) {
    388  1.24  perseant #ifdef DEBUG_LFS
    389  1.44  perseant 			printf("lfs_set_dirop: sleeping with dirops=%d, "
    390  1.44  perseant 			       "dirvcount=%d\n", fs->lfs_dirops,
    391  1.44  perseant 			       lfs_dirvcount);
    392  1.24  perseant #endif
    393  1.59       chs 			if ((error = tsleep(&lfs_dirvcount, PCATCH|PUSER,
    394  1.59       chs 					   "lfs_maxdirop", 0)) != 0) {
    395  1.51  perseant 				lfs_reserve(fs, vp, -btofsb(fs, (NIADDR + 3) << fs->lfs_bshift));
    396  1.24  perseant 				return error;
    397  1.44  perseant 			}
    398  1.24  perseant 		}
    399  1.24  perseant 	}
    400  1.24  perseant 	++fs->lfs_dirops;
    401  1.24  perseant 	fs->lfs_doifile = 1;
    402  1.24  perseant 
    403  1.46  perseant 	/* Hold a reference so SET_ENDOP will be happy */
    404  1.46  perseant 	lfs_vref(vp);
    405  1.46  perseant 
    406  1.24  perseant 	return 0;
    407   1.1   mycroft }
    408   1.1   mycroft 
    409  1.26  perseant #define	SET_ENDOP(fs,vp,str) {						\
    410   1.1   mycroft 	--(fs)->lfs_dirops;						\
    411  1.22  perseant 	if (!(fs)->lfs_dirops) {					\
    412  1.40  perseant 		if ((fs)->lfs_nadirop) {				\
    413  1.40  perseant 			panic("SET_ENDOP: %s: no dirops but nadirop=%d\n", \
    414  1.40  perseant 			      (str), (fs)->lfs_nadirop);		\
    415  1.40  perseant 		}							\
    416   1.1   mycroft 		wakeup(&(fs)->lfs_writer);				\
    417  1.26  perseant 		lfs_check((vp),LFS_UNUSED_LBN,0);			\
    418  1.22  perseant 	}								\
    419  1.51  perseant 	lfs_reserve((fs), vp, -btofsb((fs), (NIADDR + 3) << (fs)->lfs_bshift)); /* XXX */	\
    420  1.46  perseant 	lfs_vunref(vp);							\
    421   1.1   mycroft }
    422   1.1   mycroft 
    423  1.22  perseant #define	MARK_VNODE(dvp)  do {                                           \
    424  1.37  perseant         if (!((dvp)->v_flag & VDIROP)) {				\
    425  1.39  perseant                 (void)lfs_vref(dvp);					\
    426  1.31  perseant 		++lfs_dirvcount;					\
    427  1.22  perseant 	}								\
    428  1.22  perseant         (dvp)->v_flag |= VDIROP;					\
    429  1.37  perseant 	if (!(VTOI(dvp)->i_flag & IN_ADIROP)) {				\
    430  1.37  perseant 		++VTOI(dvp)->i_lfs->lfs_nadirop;			\
    431  1.37  perseant 	}								\
    432  1.37  perseant 	VTOI(dvp)->i_flag |= IN_ADIROP;					\
    433  1.59       chs } while (0)
    434  1.37  perseant 
    435  1.40  perseant #define UNMARK_VNODE(vp) lfs_unmark_vnode(vp)
    436  1.40  perseant 
    437  1.51  perseant void lfs_unmark_vnode(struct vnode *vp)
    438  1.40  perseant {
    439  1.40  perseant 	struct inode *ip;
    440  1.40  perseant 
    441  1.40  perseant 	ip = VTOI(vp);
    442  1.40  perseant 
    443  1.40  perseant 	if (ip->i_flag & IN_ADIROP)
    444  1.40  perseant 		--ip->i_lfs->lfs_nadirop;
    445  1.40  perseant 	ip->i_flag &= ~IN_ADIROP;
    446  1.40  perseant }
    447  1.15      fvdl 
    448   1.1   mycroft int
    449  1.51  perseant lfs_symlink(void *v)
    450  1.10  christos {
    451   1.1   mycroft 	struct vop_symlink_args /* {
    452   1.1   mycroft 		struct vnode *a_dvp;
    453   1.1   mycroft 		struct vnode **a_vpp;
    454   1.1   mycroft 		struct componentname *a_cnp;
    455   1.1   mycroft 		struct vattr *a_vap;
    456   1.1   mycroft 		char *a_target;
    457  1.10  christos 	} */ *ap = v;
    458  1.37  perseant 	int error;
    459   1.1   mycroft 
    460  1.40  perseant 	if ((error = SET_DIROP(ap->a_dvp)) != 0) {
    461  1.34  perseant 		vput(ap->a_dvp);
    462  1.37  perseant 		return error;
    463  1.34  perseant 	}
    464   1.1   mycroft 	MARK_VNODE(ap->a_dvp);
    465  1.37  perseant 	error = ufs_symlink(ap);
    466  1.37  perseant 	UNMARK_VNODE(ap->a_dvp);
    467  1.40  perseant 	if (*(ap->a_vpp))
    468  1.37  perseant 		UNMARK_VNODE(*(ap->a_vpp));
    469  1.37  perseant 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"symlink");
    470  1.37  perseant 	return (error);
    471   1.1   mycroft }
    472   1.1   mycroft 
    473   1.1   mycroft int
    474  1.51  perseant lfs_mknod(void *v)
    475  1.10  christos {
    476  1.22  perseant 	struct vop_mknod_args	/* {
    477   1.1   mycroft 		struct vnode *a_dvp;
    478   1.1   mycroft 		struct vnode **a_vpp;
    479   1.1   mycroft 		struct componentname *a_cnp;
    480   1.1   mycroft 		struct vattr *a_vap;
    481  1.22  perseant 		} */ *ap = v;
    482  1.28  perseant         struct vattr *vap = ap->a_vap;
    483  1.28  perseant         struct vnode **vpp = ap->a_vpp;
    484  1.28  perseant         struct inode *ip;
    485  1.28  perseant         int error;
    486  1.52     assar 	struct mount	*mp;
    487  1.52     assar 	ino_t		ino;
    488   1.1   mycroft 
    489  1.40  perseant 	if ((error = SET_DIROP(ap->a_dvp)) != 0) {
    490  1.34  perseant 		vput(ap->a_dvp);
    491  1.28  perseant 		return error;
    492  1.34  perseant 	}
    493   1.1   mycroft 	MARK_VNODE(ap->a_dvp);
    494  1.28  perseant 	error = ufs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode),
    495  1.28  perseant             ap->a_dvp, vpp, ap->a_cnp);
    496  1.37  perseant 	UNMARK_VNODE(ap->a_dvp);
    497  1.40  perseant         if (*(ap->a_vpp))
    498  1.37  perseant                 UNMARK_VNODE(*(ap->a_vpp));
    499  1.28  perseant 
    500  1.28  perseant 	/* Either way we're done with the dirop at this point */
    501  1.26  perseant 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"mknod");
    502  1.28  perseant 
    503  1.28  perseant         if (error)
    504  1.28  perseant 		return (error);
    505  1.28  perseant 
    506  1.28  perseant         ip = VTOI(*vpp);
    507  1.52     assar 	mp  = (*vpp)->v_mount;
    508  1.52     assar 	ino = ip->i_number;
    509  1.28  perseant         ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
    510  1.28  perseant         if (vap->va_rdev != VNOVAL) {
    511  1.28  perseant                 /*
    512  1.28  perseant                  * Want to be able to use this to make badblock
    513  1.28  perseant                  * inodes, so don't truncate the dev number.
    514  1.28  perseant                  */
    515  1.28  perseant #if 0
    516  1.28  perseant                 ip->i_ffs_rdev = ufs_rw32(vap->va_rdev,
    517  1.28  perseant                     UFS_MPNEEDSWAP((*vpp)->v_mount));
    518  1.28  perseant #else
    519  1.28  perseant                 ip->i_ffs_rdev = vap->va_rdev;
    520  1.28  perseant #endif
    521  1.28  perseant         }
    522  1.28  perseant 	/*
    523  1.28  perseant 	 * Call fsync to write the vnode so that we don't have to deal with
    524  1.28  perseant 	 * flushing it when it's marked VDIROP|VXLOCK.
    525  1.28  perseant 	 *
    526  1.28  perseant 	 * XXX KS - If we can't flush we also can't call vgone(), so must
    527  1.28  perseant 	 * return.  But, that leaves this vnode in limbo, also not good.
    528  1.28  perseant 	 * Can this ever happen (barring hardware failure)?
    529  1.28  perseant 	 */
    530  1.49    toshii 	if ((error = VOP_FSYNC(*vpp, NOCRED, FSYNC_WAIT, 0, 0, curproc)) != 0) {
    531  1.40  perseant 		printf("Couldn't fsync in mknod (ino %d)---what do I do?\n",
    532  1.40  perseant 		       VTOI(*vpp)->i_number);
    533  1.28  perseant 		return (error);
    534  1.40  perseant 	}
    535  1.28  perseant         /*
    536  1.40  perseant          * Remove vnode so that it will be reloaded by VFS_VGET and
    537  1.28  perseant          * checked to see if it is an alias of an existing entry in
    538  1.28  perseant          * the inode cache.
    539  1.28  perseant          */
    540  1.28  perseant 	/* Used to be vput, but that causes us to call VOP_INACTIVE twice. */
    541  1.40  perseant 	VOP_UNLOCK(*vpp, 0);
    542  1.28  perseant 	lfs_vunref(*vpp);
    543  1.28  perseant         (*vpp)->v_type = VNON;
    544  1.28  perseant         vgone(*vpp);
    545  1.52     assar 	error = VFS_VGET(mp, ino, vpp);
    546  1.52     assar 	if (error != 0) {
    547  1.52     assar 		*vpp = NULL;
    548  1.52     assar 		return (error);
    549  1.52     assar 	}
    550  1.28  perseant         return (0);
    551   1.1   mycroft }
    552   1.1   mycroft 
    553   1.1   mycroft int
    554  1.51  perseant lfs_create(void *v)
    555  1.10  christos {
    556  1.22  perseant 	struct vop_create_args	/* {
    557   1.1   mycroft 		struct vnode *a_dvp;
    558   1.1   mycroft 		struct vnode **a_vpp;
    559   1.1   mycroft 		struct componentname *a_cnp;
    560   1.1   mycroft 		struct vattr *a_vap;
    561  1.10  christos 	} */ *ap = v;
    562  1.37  perseant 	int error;
    563   1.1   mycroft 
    564  1.59       chs 	if ((error = SET_DIROP(ap->a_dvp)) != 0) {
    565  1.34  perseant 		vput(ap->a_dvp);
    566  1.37  perseant 		return error;
    567  1.34  perseant 	}
    568   1.1   mycroft 	MARK_VNODE(ap->a_dvp);
    569  1.37  perseant 	error = ufs_create(ap);
    570  1.37  perseant 	UNMARK_VNODE(ap->a_dvp);
    571  1.40  perseant         if (*(ap->a_vpp))
    572  1.37  perseant                 UNMARK_VNODE(*(ap->a_vpp));
    573  1.26  perseant 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"create");
    574  1.37  perseant 	return (error);
    575   1.1   mycroft }
    576   1.1   mycroft 
    577   1.1   mycroft int
    578  1.51  perseant lfs_whiteout(void *v)
    579  1.22  perseant {
    580  1.22  perseant 	struct vop_whiteout_args /* {
    581  1.22  perseant 		struct vnode *a_dvp;
    582  1.22  perseant 		struct componentname *a_cnp;
    583  1.22  perseant 		int a_flags;
    584  1.22  perseant 	} */ *ap = v;
    585  1.37  perseant 	int error;
    586  1.22  perseant 
    587  1.40  perseant 	if ((error = SET_DIROP(ap->a_dvp)) != 0)
    588  1.34  perseant 		/* XXX no unlock here? */
    589  1.37  perseant 		return error;
    590  1.22  perseant 	MARK_VNODE(ap->a_dvp);
    591  1.37  perseant 	error = ufs_whiteout(ap);
    592  1.37  perseant 	UNMARK_VNODE(ap->a_dvp);
    593  1.26  perseant 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"whiteout");
    594  1.37  perseant 	return (error);
    595  1.22  perseant }
    596  1.22  perseant 
    597  1.22  perseant int
    598  1.51  perseant lfs_mkdir(void *v)
    599  1.10  christos {
    600  1.22  perseant 	struct vop_mkdir_args	/* {
    601   1.1   mycroft 		struct vnode *a_dvp;
    602   1.1   mycroft 		struct vnode **a_vpp;
    603   1.1   mycroft 		struct componentname *a_cnp;
    604   1.1   mycroft 		struct vattr *a_vap;
    605  1.10  christos 	} */ *ap = v;
    606  1.37  perseant 	int error;
    607   1.1   mycroft 
    608  1.59       chs 	if ((error = SET_DIROP(ap->a_dvp)) != 0) {
    609  1.34  perseant 		vput(ap->a_dvp);
    610  1.37  perseant 		return error;
    611  1.34  perseant 	}
    612   1.1   mycroft 	MARK_VNODE(ap->a_dvp);
    613  1.37  perseant 	error = ufs_mkdir(ap);
    614  1.37  perseant 	UNMARK_VNODE(ap->a_dvp);
    615  1.40  perseant         if (*(ap->a_vpp))
    616  1.37  perseant                 UNMARK_VNODE(*(ap->a_vpp));
    617  1.26  perseant 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"mkdir");
    618  1.37  perseant 	return (error);
    619   1.1   mycroft }
    620   1.1   mycroft 
    621   1.1   mycroft int
    622  1.51  perseant lfs_remove(void *v)
    623  1.10  christos {
    624  1.22  perseant 	struct vop_remove_args	/* {
    625   1.1   mycroft 		struct vnode *a_dvp;
    626   1.1   mycroft 		struct vnode *a_vp;
    627   1.1   mycroft 		struct componentname *a_cnp;
    628  1.10  christos 	} */ *ap = v;
    629  1.34  perseant 	struct vnode *dvp, *vp;
    630  1.37  perseant 	int error;
    631  1.34  perseant 
    632  1.34  perseant 	dvp = ap->a_dvp;
    633  1.34  perseant 	vp = ap->a_vp;
    634  1.40  perseant 	if ((error = SET_DIROP(dvp)) != 0) {
    635  1.34  perseant 		if (dvp == vp)
    636  1.34  perseant 			vrele(vp);
    637  1.34  perseant 		else
    638  1.34  perseant 			vput(vp);
    639  1.34  perseant 		vput(dvp);
    640  1.37  perseant 		return error;
    641  1.34  perseant 	}
    642  1.34  perseant 	MARK_VNODE(dvp);
    643  1.34  perseant 	MARK_VNODE(vp);
    644  1.37  perseant 	error = ufs_remove(ap);
    645  1.37  perseant 	UNMARK_VNODE(dvp);
    646  1.37  perseant 	UNMARK_VNODE(vp);
    647  1.40  perseant 
    648  1.40  perseant 	/*
    649  1.40  perseant 	 * If ufs_remove failed, vp doesn't need to be VDIROP any more.
    650  1.40  perseant 	 * If it succeeded, we can go ahead and wipe out vp, since
    651  1.40  perseant 	 * its loss won't appear on disk until checkpoint, and by then
    652  1.40  perseant 	 * dvp will have been written, completing the dirop.
    653  1.40  perseant 	 */
    654  1.40  perseant 	--lfs_dirvcount;
    655  1.40  perseant 	vp->v_flag &= ~VDIROP;
    656  1.40  perseant 	wakeup(&lfs_dirvcount);
    657  1.40  perseant 	vrele(vp);
    658  1.40  perseant 
    659  1.42  perseant 	SET_ENDOP(VTOI(dvp)->i_lfs,dvp,"remove");
    660  1.37  perseant 	return (error);
    661   1.1   mycroft }
    662   1.1   mycroft 
    663   1.1   mycroft int
    664  1.51  perseant lfs_rmdir(void *v)
    665  1.10  christos {
    666  1.22  perseant 	struct vop_rmdir_args	/* {
    667   1.1   mycroft 		struct vnodeop_desc *a_desc;
    668   1.1   mycroft 		struct vnode *a_dvp;
    669   1.1   mycroft 		struct vnode *a_vp;
    670   1.1   mycroft 		struct componentname *a_cnp;
    671  1.10  christos 	} */ *ap = v;
    672  1.37  perseant 	int error;
    673   1.1   mycroft 
    674  1.40  perseant 	if ((error = SET_DIROP(ap->a_dvp)) != 0) {
    675  1.34  perseant 		vrele(ap->a_dvp);
    676  1.34  perseant 		if (ap->a_vp->v_mountedhere != NULL)
    677  1.34  perseant 			VOP_UNLOCK(ap->a_dvp, 0);
    678  1.34  perseant 		vput(ap->a_vp);
    679  1.37  perseant 		return error;
    680  1.34  perseant 	}
    681   1.1   mycroft 	MARK_VNODE(ap->a_dvp);
    682   1.1   mycroft 	MARK_VNODE(ap->a_vp);
    683  1.37  perseant 	error = ufs_rmdir(ap);
    684  1.37  perseant 	UNMARK_VNODE(ap->a_dvp);
    685  1.37  perseant 	UNMARK_VNODE(ap->a_vp);
    686  1.40  perseant 
    687  1.40  perseant 	/*
    688  1.40  perseant 	 * If ufs_rmdir failed, vp doesn't need to be VDIROP any more.
    689  1.40  perseant 	 * If it succeeded, we can go ahead and wipe out vp, since
    690  1.40  perseant 	 * its loss won't appear on disk until checkpoint, and by then
    691  1.40  perseant 	 * dvp will have been written, completing the dirop.
    692  1.40  perseant 	 */
    693  1.40  perseant 	--lfs_dirvcount;
    694  1.40  perseant 	ap->a_vp->v_flag &= ~VDIROP;
    695  1.40  perseant 	wakeup(&lfs_dirvcount);
    696  1.40  perseant 	vrele(ap->a_vp);
    697  1.40  perseant 
    698  1.42  perseant 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"rmdir");
    699  1.37  perseant 	return (error);
    700   1.1   mycroft }
    701   1.1   mycroft 
    702   1.1   mycroft int
    703  1.51  perseant lfs_link(void *v)
    704  1.10  christos {
    705  1.22  perseant 	struct vop_link_args	/* {
    706   1.9   mycroft 		struct vnode *a_dvp;
    707   1.1   mycroft 		struct vnode *a_vp;
    708   1.1   mycroft 		struct componentname *a_cnp;
    709  1.10  christos 	} */ *ap = v;
    710  1.37  perseant 	int error;
    711   1.1   mycroft 
    712  1.40  perseant 	if ((error = SET_DIROP(ap->a_dvp)) != 0) {
    713  1.34  perseant 		vput(ap->a_dvp);
    714  1.37  perseant 		return error;
    715  1.34  perseant 	}
    716   1.9   mycroft 	MARK_VNODE(ap->a_dvp);
    717  1.37  perseant 	error = ufs_link(ap);
    718  1.37  perseant 	UNMARK_VNODE(ap->a_dvp);
    719  1.26  perseant 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"link");
    720  1.37  perseant 	return (error);
    721   1.1   mycroft }
    722  1.22  perseant 
    723   1.1   mycroft int
    724  1.51  perseant lfs_rename(void *v)
    725  1.10  christos {
    726  1.22  perseant 	struct vop_rename_args	/* {
    727   1.1   mycroft 		struct vnode *a_fdvp;
    728   1.1   mycroft 		struct vnode *a_fvp;
    729   1.1   mycroft 		struct componentname *a_fcnp;
    730   1.1   mycroft 		struct vnode *a_tdvp;
    731   1.1   mycroft 		struct vnode *a_tvp;
    732   1.1   mycroft 		struct componentname *a_tcnp;
    733  1.10  christos 	} */ *ap = v;
    734  1.30  perseant 	struct vnode *tvp, *fvp, *tdvp, *fdvp;
    735  1.30  perseant 	int error;
    736  1.29  perseant 	struct lfs *fs;
    737  1.29  perseant 
    738  1.29  perseant 	fs = VTOI(ap->a_fdvp)->i_lfs;
    739  1.30  perseant 	tvp = ap->a_tvp;
    740  1.30  perseant 	tdvp = ap->a_tdvp;
    741  1.30  perseant 	fvp = ap->a_fvp;
    742  1.30  perseant 	fdvp = ap->a_fdvp;
    743  1.30  perseant 
    744  1.30  perseant 	/*
    745  1.30  perseant 	 * Check for cross-device rename.
    746  1.30  perseant 	 * If it is, we don't want to set dirops, just error out.
    747  1.30  perseant 	 * (In particular note that MARK_VNODE(tdvp) will DTWT on
    748  1.30  perseant 	 * a cross-device rename.)
    749  1.30  perseant 	 *
    750  1.30  perseant 	 * Copied from ufs_rename.
    751  1.30  perseant 	 */
    752  1.30  perseant 	if ((fvp->v_mount != tdvp->v_mount) ||
    753  1.30  perseant 	    (tvp && (fvp->v_mount != tvp->v_mount))) {
    754  1.30  perseant 		error = EXDEV;
    755  1.34  perseant 		goto errout;
    756  1.30  perseant 	}
    757  1.59       chs 	if ((error = SET_DIROP(fdvp)) != 0)
    758  1.34  perseant 		goto errout;
    759  1.30  perseant 	MARK_VNODE(fdvp);
    760  1.30  perseant 	MARK_VNODE(tdvp);
    761  1.30  perseant 	error = ufs_rename(ap);
    762  1.37  perseant 	UNMARK_VNODE(fdvp);
    763  1.37  perseant 	UNMARK_VNODE(tdvp);
    764  1.30  perseant 	SET_ENDOP(fs,fdvp,"rename");
    765  1.34  perseant 	return (error);
    766  1.34  perseant 
    767  1.34  perseant     errout:
    768  1.34  perseant 	VOP_ABORTOP(tdvp, ap->a_tcnp); /* XXX, why not in NFS? */
    769  1.34  perseant 	if (tdvp == tvp)
    770  1.34  perseant 		vrele(tdvp);
    771  1.34  perseant 	else
    772  1.34  perseant 		vput(tdvp);
    773  1.34  perseant 	if (tvp)
    774  1.34  perseant 		vput(tvp);
    775  1.34  perseant 	VOP_ABORTOP(fdvp, ap->a_fcnp); /* XXX, why not in NFS? */
    776  1.34  perseant 	vrele(fdvp);
    777  1.34  perseant 	vrele(fvp);
    778  1.30  perseant 	return (error);
    779   1.1   mycroft }
    780  1.22  perseant 
    781   1.1   mycroft /* XXX hack to avoid calling ITIMES in getattr */
    782   1.1   mycroft int
    783  1.51  perseant lfs_getattr(void *v)
    784  1.10  christos {
    785   1.1   mycroft 	struct vop_getattr_args /* {
    786   1.1   mycroft 		struct vnode *a_vp;
    787   1.1   mycroft 		struct vattr *a_vap;
    788   1.1   mycroft 		struct ucred *a_cred;
    789   1.1   mycroft 		struct proc *a_p;
    790  1.10  christos 	} */ *ap = v;
    791  1.35  augustss 	struct vnode *vp = ap->a_vp;
    792  1.35  augustss 	struct inode *ip = VTOI(vp);
    793  1.35  augustss 	struct vattr *vap = ap->a_vap;
    794  1.51  perseant 	struct lfs *fs = ip->i_lfs;
    795   1.1   mycroft 	/*
    796   1.1   mycroft 	 * Copy from inode table
    797   1.1   mycroft 	 */
    798   1.1   mycroft 	vap->va_fsid = ip->i_dev;
    799   1.1   mycroft 	vap->va_fileid = ip->i_number;
    800  1.14    bouyer 	vap->va_mode = ip->i_ffs_mode & ~IFMT;
    801  1.14    bouyer 	vap->va_nlink = ip->i_ffs_nlink;
    802  1.14    bouyer 	vap->va_uid = ip->i_ffs_uid;
    803  1.14    bouyer 	vap->va_gid = ip->i_ffs_gid;
    804  1.14    bouyer 	vap->va_rdev = (dev_t)ip->i_ffs_rdev;
    805  1.55       chs 	vap->va_size = vp->v_size;
    806  1.14    bouyer 	vap->va_atime.tv_sec = ip->i_ffs_atime;
    807  1.14    bouyer 	vap->va_atime.tv_nsec = ip->i_ffs_atimensec;
    808  1.14    bouyer 	vap->va_mtime.tv_sec = ip->i_ffs_mtime;
    809  1.14    bouyer 	vap->va_mtime.tv_nsec = ip->i_ffs_mtimensec;
    810  1.14    bouyer 	vap->va_ctime.tv_sec = ip->i_ffs_ctime;
    811  1.14    bouyer 	vap->va_ctime.tv_nsec = ip->i_ffs_ctimensec;
    812  1.14    bouyer 	vap->va_flags = ip->i_ffs_flags;
    813  1.14    bouyer 	vap->va_gen = ip->i_ffs_gen;
    814   1.1   mycroft 	/* this doesn't belong here */
    815   1.1   mycroft 	if (vp->v_type == VBLK)
    816   1.1   mycroft 		vap->va_blocksize = BLKDEV_IOSIZE;
    817   1.1   mycroft 	else if (vp->v_type == VCHR)
    818   1.1   mycroft 		vap->va_blocksize = MAXBSIZE;
    819   1.1   mycroft 	else
    820   1.1   mycroft 		vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
    821  1.51  perseant 	vap->va_bytes = fsbtob(fs, (u_quad_t)ip->i_ffs_blocks);
    822   1.1   mycroft 	vap->va_type = vp->v_type;
    823   1.1   mycroft 	vap->va_filerev = ip->i_modrev;
    824   1.1   mycroft 	return (0);
    825  1.61  perseant }
    826  1.61  perseant 
    827  1.61  perseant /*
    828  1.61  perseant  * Check to make sure the inode blocks won't choke the buffer
    829  1.61  perseant  * cache, then call ufs_setattr as usual.
    830  1.61  perseant  */
    831  1.61  perseant int
    832  1.61  perseant lfs_setattr(void *v)
    833  1.61  perseant {
    834  1.61  perseant 	struct vop_getattr_args /* {
    835  1.61  perseant 		struct vnode *a_vp;
    836  1.61  perseant 		struct vattr *a_vap;
    837  1.61  perseant 		struct ucred *a_cred;
    838  1.61  perseant 		struct proc *a_p;
    839  1.61  perseant 	} */ *ap = v;
    840  1.61  perseant 	struct vnode *vp = ap->a_vp;
    841  1.61  perseant 
    842  1.61  perseant 	lfs_check(vp, LFS_UNUSED_LBN, 0);
    843  1.61  perseant 	return ufs_setattr(v);
    844   1.1   mycroft }
    845  1.22  perseant 
    846   1.1   mycroft /*
    847   1.1   mycroft  * Close called
    848   1.1   mycroft  *
    849   1.1   mycroft  * XXX -- we were using ufs_close, but since it updates the
    850   1.1   mycroft  * times on the inode, we might need to bump the uinodes
    851   1.1   mycroft  * count.
    852   1.1   mycroft  */
    853   1.1   mycroft /* ARGSUSED */
    854   1.1   mycroft int
    855  1.51  perseant lfs_close(void *v)
    856  1.10  christos {
    857   1.1   mycroft 	struct vop_close_args /* {
    858   1.1   mycroft 		struct vnode *a_vp;
    859   1.1   mycroft 		int  a_fflag;
    860   1.1   mycroft 		struct ucred *a_cred;
    861   1.1   mycroft 		struct proc *a_p;
    862  1.10  christos 	} */ *ap = v;
    863  1.35  augustss 	struct vnode *vp = ap->a_vp;
    864  1.35  augustss 	struct inode *ip = VTOI(vp);
    865  1.12   mycroft 	struct timespec ts;
    866   1.1   mycroft 
    867  1.15      fvdl 	if (vp->v_usecount > 1) {
    868  1.12   mycroft 		TIMEVAL_TO_TIMESPEC(&time, &ts);
    869  1.22  perseant 		LFS_ITIMES(ip, &ts, &ts, &ts);
    870   1.1   mycroft 	}
    871   1.1   mycroft 	return (0);
    872  1.65  perseant }
    873  1.65  perseant 
    874  1.65  perseant /*
    875  1.65  perseant  * Close wrapper for special devices.
    876  1.65  perseant  *
    877  1.65  perseant  * Update the times on the inode then do device close.
    878  1.65  perseant  */
    879  1.65  perseant int
    880  1.65  perseant lfsspec_close(void *v)
    881  1.65  perseant {
    882  1.65  perseant 	struct vop_close_args /* {
    883  1.65  perseant 		struct vnode	*a_vp;
    884  1.65  perseant 		int		a_fflag;
    885  1.65  perseant 		struct ucred	*a_cred;
    886  1.65  perseant 		struct proc	*a_p;
    887  1.65  perseant 	} */ *ap = v;
    888  1.65  perseant 	struct vnode	*vp;
    889  1.65  perseant 	struct inode	*ip;
    890  1.65  perseant 	struct timespec	ts;
    891  1.65  perseant 
    892  1.65  perseant 	vp = ap->a_vp;
    893  1.65  perseant 	ip = VTOI(vp);
    894  1.65  perseant 	if (vp->v_usecount > 1) {
    895  1.65  perseant 		TIMEVAL_TO_TIMESPEC(&time, &ts);
    896  1.65  perseant 		LFS_ITIMES(ip, &ts, &ts, &ts);
    897  1.65  perseant 	}
    898  1.65  perseant 	return (VOCALL (spec_vnodeop_p, VOFFSET(vop_close), ap));
    899  1.65  perseant }
    900  1.65  perseant 
    901  1.65  perseant /*
    902  1.65  perseant  * Close wrapper for fifo's.
    903  1.65  perseant  *
    904  1.65  perseant  * Update the times on the inode then do device close.
    905  1.65  perseant  */
    906  1.65  perseant int
    907  1.65  perseant lfsfifo_close(void *v)
    908  1.65  perseant {
    909  1.65  perseant 	struct vop_close_args /* {
    910  1.65  perseant 		struct vnode	*a_vp;
    911  1.65  perseant 		int		a_fflag;
    912  1.65  perseant 		struct ucred	*a_cred;
    913  1.65  perseant 		struct proc	*a_p;
    914  1.65  perseant 	} */ *ap = v;
    915  1.65  perseant 	struct vnode	*vp;
    916  1.65  perseant 	struct inode	*ip;
    917  1.65  perseant 	struct timespec	ts;
    918  1.65  perseant 
    919  1.65  perseant 	vp = ap->a_vp;
    920  1.65  perseant 	ip = VTOI(vp);
    921  1.65  perseant 	if (ap->a_vp->v_usecount > 1) {
    922  1.65  perseant 		TIMEVAL_TO_TIMESPEC(&time, &ts);
    923  1.65  perseant 		LFS_ITIMES(ip, &ts, &ts, &ts);
    924  1.65  perseant 	}
    925  1.65  perseant 	return (VOCALL (fifo_vnodeop_p, VOFFSET(vop_close), ap));
    926   1.1   mycroft }
    927   1.1   mycroft 
    928   1.1   mycroft /*
    929  1.15      fvdl  * Reclaim an inode so that it can be used for other purposes.
    930   1.1   mycroft  */
    931   1.1   mycroft int lfs_no_inactive = 0;
    932   1.1   mycroft 
    933   1.1   mycroft int
    934  1.51  perseant lfs_reclaim(void *v)
    935  1.10  christos {
    936   1.1   mycroft 	struct vop_reclaim_args /* {
    937   1.1   mycroft 		struct vnode *a_vp;
    938  1.15      fvdl 		struct proc *a_p;
    939  1.10  christos 	} */ *ap = v;
    940  1.15      fvdl 	struct vnode *vp = ap->a_vp;
    941   1.1   mycroft 	int error;
    942   1.1   mycroft 
    943  1.43  perseant 	LFS_CLR_UINO(VTOI(vp), IN_ALLMOD);
    944  1.15      fvdl 	if ((error = ufs_reclaim(vp, ap->a_p)))
    945   1.1   mycroft 		return (error);
    946  1.19   thorpej 	pool_put(&lfs_inode_pool, vp->v_data);
    947   1.1   mycroft 	vp->v_data = NULL;
    948   1.1   mycroft 	return (0);
    949  1.60       chs }
    950  1.60       chs 
    951  1.60       chs int
    952  1.60       chs lfs_getpages(void *v)
    953  1.60       chs {
    954  1.60       chs 	struct vop_getpages_args /* {
    955  1.60       chs 		struct vnode *a_vp;
    956  1.60       chs 		voff_t a_offset;
    957  1.60       chs 		struct vm_page **a_m;
    958  1.60       chs 		int *a_count;
    959  1.60       chs 		int a_centeridx;
    960  1.60       chs 		vm_prot_t a_access_type;
    961  1.60       chs 		int a_advice;
    962  1.60       chs 		int a_flags;
    963  1.60       chs 	} */ *ap = v;
    964  1.60       chs 
    965  1.60       chs 	if ((ap->a_access_type & VM_PROT_WRITE) != 0) {
    966  1.60       chs 		LFS_SET_UINO(VTOI(ap->a_vp), IN_MODIFIED);
    967  1.60       chs 	}
    968  1.60       chs 	return genfs_compat_getpages(v);
    969  1.60       chs }
    970  1.60       chs 
    971  1.60       chs int
    972  1.60       chs lfs_putpages(void *v)
    973  1.60       chs {
    974  1.60       chs 	int error;
    975  1.60       chs 
    976  1.60       chs 	error = genfs_putpages(v);
    977  1.60       chs 	return error;
    978   1.1   mycroft }
    979