Home | History | Annotate | Line # | Download | only in lfs
lfs_vnops.c revision 1.42
      1  1.42  perseant /*	$NetBSD: lfs_vnops.c,v 1.42 2000/07/01 19:03:57 perseant Exp $	*/
      2   1.2       cgd 
      3  1.22  perseant /*-
      4  1.22  perseant  * Copyright (c) 1999 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.17  sommerfe 
     73   1.1   mycroft #include <sys/param.h>
     74   1.1   mycroft #include <sys/systm.h>
     75   1.1   mycroft #include <sys/namei.h>
     76   1.1   mycroft #include <sys/resourcevar.h>
     77   1.1   mycroft #include <sys/kernel.h>
     78   1.1   mycroft #include <sys/file.h>
     79   1.1   mycroft #include <sys/stat.h>
     80   1.1   mycroft #include <sys/buf.h>
     81   1.1   mycroft #include <sys/proc.h>
     82   1.1   mycroft #include <sys/conf.h>
     83   1.1   mycroft #include <sys/mount.h>
     84   1.1   mycroft #include <sys/vnode.h>
     85   1.1   mycroft #include <sys/malloc.h>
     86  1.19   thorpej #include <sys/pool.h>
     87  1.10  christos #include <sys/signalvar.h>
     88   1.1   mycroft 
     89  1.12   mycroft #include <miscfs/fifofs/fifo.h>
     90  1.12   mycroft #include <miscfs/genfs/genfs.h>
     91   1.1   mycroft #include <miscfs/specfs/specdev.h>
     92   1.1   mycroft 
     93   1.1   mycroft #include <ufs/ufs/quota.h>
     94   1.1   mycroft #include <ufs/ufs/inode.h>
     95   1.1   mycroft #include <ufs/ufs/dir.h>
     96   1.1   mycroft #include <ufs/ufs/ufsmount.h>
     97   1.1   mycroft #include <ufs/ufs/ufs_extern.h>
     98   1.1   mycroft 
     99   1.1   mycroft #include <ufs/lfs/lfs.h>
    100   1.1   mycroft #include <ufs/lfs/lfs_extern.h>
    101   1.1   mycroft 
    102   1.1   mycroft /* Global vfs data structures for lfs. */
    103  1.10  christos int (**lfs_vnodeop_p) __P((void *));
    104   1.1   mycroft struct vnodeopv_entry_desc lfs_vnodeop_entries[] = {
    105   1.1   mycroft 	{ &vop_default_desc, vn_default_error },
    106   1.1   mycroft 	{ &vop_lookup_desc, ufs_lookup },		/* lookup */
    107  1.22  perseant 	{ &vop_create_desc, lfs_create },		/* create */
    108  1.22  perseant 	{ &vop_whiteout_desc, lfs_whiteout },		/* whiteout */
    109  1.22  perseant 	{ &vop_mknod_desc, lfs_mknod },			/* mknod */
    110   1.1   mycroft 	{ &vop_open_desc, ufs_open },			/* open */
    111   1.1   mycroft 	{ &vop_close_desc, lfs_close },			/* close */
    112   1.1   mycroft 	{ &vop_access_desc, ufs_access },		/* access */
    113   1.1   mycroft 	{ &vop_getattr_desc, lfs_getattr },		/* getattr */
    114   1.1   mycroft 	{ &vop_setattr_desc, ufs_setattr },		/* setattr */
    115   1.1   mycroft 	{ &vop_read_desc, lfs_read },			/* read */
    116   1.1   mycroft 	{ &vop_write_desc, lfs_write },			/* write */
    117   1.4   mycroft 	{ &vop_lease_desc, ufs_lease_check },		/* lease */
    118   1.1   mycroft 	{ &vop_ioctl_desc, ufs_ioctl },			/* ioctl */
    119  1.27  wrstuden 	{ &vop_fcntl_desc, ufs_fcntl },			/* fcntl */
    120  1.13   mycroft 	{ &vop_poll_desc, ufs_poll },			/* poll */
    121  1.15      fvdl 	{ &vop_revoke_desc, ufs_revoke },		/* revoke */
    122   1.1   mycroft 	{ &vop_mmap_desc, ufs_mmap },			/* mmap */
    123   1.1   mycroft 	{ &vop_fsync_desc, lfs_fsync },			/* fsync */
    124   1.1   mycroft 	{ &vop_seek_desc, ufs_seek },			/* seek */
    125  1.22  perseant 	{ &vop_remove_desc, lfs_remove },		/* remove */
    126  1.22  perseant 	{ &vop_link_desc, lfs_link },			/* link */
    127  1.22  perseant 	{ &vop_rename_desc, lfs_rename },		/* rename */
    128  1.22  perseant 	{ &vop_mkdir_desc, lfs_mkdir },			/* mkdir */
    129  1.22  perseant 	{ &vop_rmdir_desc, lfs_rmdir },			/* rmdir */
    130  1.22  perseant 	{ &vop_symlink_desc, lfs_symlink },		/* symlink */
    131   1.1   mycroft 	{ &vop_readdir_desc, ufs_readdir },		/* readdir */
    132   1.1   mycroft 	{ &vop_readlink_desc, ufs_readlink },		/* readlink */
    133   1.1   mycroft 	{ &vop_abortop_desc, ufs_abortop },		/* abortop */
    134  1.40  perseant 	{ &vop_inactive_desc, lfs_inactive },		/* inactive */
    135   1.1   mycroft 	{ &vop_reclaim_desc, lfs_reclaim },		/* reclaim */
    136   1.1   mycroft 	{ &vop_lock_desc, ufs_lock },			/* lock */
    137   1.1   mycroft 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
    138   1.1   mycroft 	{ &vop_bmap_desc, ufs_bmap },			/* bmap */
    139   1.1   mycroft 	{ &vop_strategy_desc, ufs_strategy },		/* strategy */
    140   1.1   mycroft 	{ &vop_print_desc, ufs_print },			/* print */
    141   1.1   mycroft 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
    142   1.1   mycroft 	{ &vop_pathconf_desc, ufs_pathconf },		/* pathconf */
    143   1.1   mycroft 	{ &vop_advlock_desc, ufs_advlock },		/* advlock */
    144   1.1   mycroft 	{ &vop_blkatoff_desc, lfs_blkatoff },		/* blkatoff */
    145   1.1   mycroft 	{ &vop_valloc_desc, lfs_valloc },		/* valloc */
    146  1.32      fvdl 	{ &vop_balloc_desc, lfs_balloc },		/* balloc */
    147   1.1   mycroft 	{ &vop_vfree_desc, lfs_vfree },			/* vfree */
    148   1.1   mycroft 	{ &vop_truncate_desc, lfs_truncate },		/* truncate */
    149   1.1   mycroft 	{ &vop_update_desc, lfs_update },		/* update */
    150   1.1   mycroft 	{ &vop_bwrite_desc, lfs_bwrite },		/* bwrite */
    151  1.10  christos 	{ (struct vnodeop_desc*)NULL, (int(*) __P((void *)))NULL }
    152   1.1   mycroft };
    153   1.1   mycroft struct vnodeopv_desc lfs_vnodeop_opv_desc =
    154   1.1   mycroft 	{ &lfs_vnodeop_p, lfs_vnodeop_entries };
    155   1.1   mycroft 
    156  1.10  christos int (**lfs_specop_p) __P((void *));
    157   1.1   mycroft struct vnodeopv_entry_desc lfs_specop_entries[] = {
    158   1.1   mycroft 	{ &vop_default_desc, vn_default_error },
    159   1.1   mycroft 	{ &vop_lookup_desc, spec_lookup },		/* lookup */
    160   1.1   mycroft 	{ &vop_create_desc, spec_create },		/* create */
    161   1.1   mycroft 	{ &vop_mknod_desc, spec_mknod },		/* mknod */
    162   1.1   mycroft 	{ &vop_open_desc, spec_open },			/* open */
    163   1.1   mycroft 	{ &vop_close_desc, ufsspec_close },		/* close */
    164   1.1   mycroft 	{ &vop_access_desc, ufs_access },		/* access */
    165   1.1   mycroft 	{ &vop_getattr_desc, lfs_getattr },		/* getattr */
    166   1.1   mycroft 	{ &vop_setattr_desc, ufs_setattr },		/* setattr */
    167   1.1   mycroft 	{ &vop_read_desc, ufsspec_read },		/* read */
    168   1.1   mycroft 	{ &vop_write_desc, ufsspec_write },		/* write */
    169   1.4   mycroft 	{ &vop_lease_desc, spec_lease_check },		/* lease */
    170   1.1   mycroft 	{ &vop_ioctl_desc, spec_ioctl },		/* ioctl */
    171  1.27  wrstuden 	{ &vop_fcntl_desc, ufs_fcntl },			/* fcntl */
    172  1.13   mycroft 	{ &vop_poll_desc, spec_poll },			/* poll */
    173  1.15      fvdl 	{ &vop_revoke_desc, spec_revoke },		/* revoke */
    174   1.1   mycroft 	{ &vop_mmap_desc, spec_mmap },			/* mmap */
    175   1.1   mycroft 	{ &vop_fsync_desc, spec_fsync },		/* fsync */
    176   1.1   mycroft 	{ &vop_seek_desc, spec_seek },			/* seek */
    177   1.1   mycroft 	{ &vop_remove_desc, spec_remove },		/* remove */
    178   1.1   mycroft 	{ &vop_link_desc, spec_link },			/* link */
    179   1.1   mycroft 	{ &vop_rename_desc, spec_rename },		/* rename */
    180   1.1   mycroft 	{ &vop_mkdir_desc, spec_mkdir },		/* mkdir */
    181   1.1   mycroft 	{ &vop_rmdir_desc, spec_rmdir },		/* rmdir */
    182   1.1   mycroft 	{ &vop_symlink_desc, spec_symlink },		/* symlink */
    183   1.1   mycroft 	{ &vop_readdir_desc, spec_readdir },		/* readdir */
    184   1.1   mycroft 	{ &vop_readlink_desc, spec_readlink },		/* readlink */
    185   1.1   mycroft 	{ &vop_abortop_desc, spec_abortop },		/* abortop */
    186  1.40  perseant 	{ &vop_inactive_desc, lfs_inactive },		/* inactive */
    187   1.1   mycroft 	{ &vop_reclaim_desc, lfs_reclaim },		/* reclaim */
    188   1.1   mycroft 	{ &vop_lock_desc, ufs_lock },			/* lock */
    189   1.1   mycroft 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
    190   1.1   mycroft 	{ &vop_bmap_desc, spec_bmap },			/* bmap */
    191   1.1   mycroft 	{ &vop_strategy_desc, spec_strategy },		/* strategy */
    192   1.1   mycroft 	{ &vop_print_desc, ufs_print },			/* print */
    193   1.1   mycroft 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
    194   1.1   mycroft 	{ &vop_pathconf_desc, spec_pathconf },		/* pathconf */
    195   1.1   mycroft 	{ &vop_advlock_desc, spec_advlock },		/* advlock */
    196   1.1   mycroft 	{ &vop_blkatoff_desc, spec_blkatoff },		/* blkatoff */
    197   1.1   mycroft 	{ &vop_valloc_desc, spec_valloc },		/* valloc */
    198   1.1   mycroft 	{ &vop_vfree_desc, lfs_vfree },			/* vfree */
    199   1.1   mycroft 	{ &vop_truncate_desc, spec_truncate },		/* truncate */
    200   1.1   mycroft 	{ &vop_update_desc, lfs_update },		/* update */
    201  1.28  perseant 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
    202  1.10  christos 	{ (struct vnodeop_desc*)NULL, (int(*) __P((void *)))NULL }
    203   1.1   mycroft };
    204   1.1   mycroft struct vnodeopv_desc lfs_specop_opv_desc =
    205   1.1   mycroft 	{ &lfs_specop_p, lfs_specop_entries };
    206   1.1   mycroft 
    207  1.10  christos int (**lfs_fifoop_p) __P((void *));
    208   1.1   mycroft struct vnodeopv_entry_desc lfs_fifoop_entries[] = {
    209   1.1   mycroft 	{ &vop_default_desc, vn_default_error },
    210   1.1   mycroft 	{ &vop_lookup_desc, fifo_lookup },		/* lookup */
    211   1.1   mycroft 	{ &vop_create_desc, fifo_create },		/* create */
    212   1.1   mycroft 	{ &vop_mknod_desc, fifo_mknod },		/* mknod */
    213   1.1   mycroft 	{ &vop_open_desc, fifo_open },			/* open */
    214   1.1   mycroft 	{ &vop_close_desc, ufsfifo_close },		/* close */
    215   1.1   mycroft 	{ &vop_access_desc, ufs_access },		/* access */
    216   1.1   mycroft 	{ &vop_getattr_desc, lfs_getattr },		/* getattr */
    217   1.1   mycroft 	{ &vop_setattr_desc, ufs_setattr },		/* setattr */
    218   1.1   mycroft 	{ &vop_read_desc, ufsfifo_read },		/* read */
    219   1.1   mycroft 	{ &vop_write_desc, ufsfifo_write },		/* write */
    220   1.4   mycroft 	{ &vop_lease_desc, fifo_lease_check },		/* lease */
    221   1.1   mycroft 	{ &vop_ioctl_desc, fifo_ioctl },		/* ioctl */
    222  1.27  wrstuden 	{ &vop_fcntl_desc, ufs_fcntl },			/* fcntl */
    223  1.13   mycroft 	{ &vop_poll_desc, fifo_poll },			/* poll */
    224  1.15      fvdl 	{ &vop_revoke_desc, fifo_revoke },		/* revoke */
    225   1.1   mycroft 	{ &vop_mmap_desc, fifo_mmap },			/* mmap */
    226   1.1   mycroft 	{ &vop_fsync_desc, fifo_fsync },		/* fsync */
    227   1.1   mycroft 	{ &vop_seek_desc, fifo_seek },			/* seek */
    228   1.1   mycroft 	{ &vop_remove_desc, fifo_remove },		/* remove */
    229   1.1   mycroft 	{ &vop_link_desc, fifo_link },			/* link */
    230   1.1   mycroft 	{ &vop_rename_desc, fifo_rename },		/* rename */
    231   1.1   mycroft 	{ &vop_mkdir_desc, fifo_mkdir },		/* mkdir */
    232   1.1   mycroft 	{ &vop_rmdir_desc, fifo_rmdir },		/* rmdir */
    233   1.1   mycroft 	{ &vop_symlink_desc, fifo_symlink },		/* symlink */
    234   1.1   mycroft 	{ &vop_readdir_desc, fifo_readdir },		/* readdir */
    235   1.1   mycroft 	{ &vop_readlink_desc, fifo_readlink },		/* readlink */
    236   1.1   mycroft 	{ &vop_abortop_desc, fifo_abortop },		/* abortop */
    237  1.40  perseant 	{ &vop_inactive_desc, lfs_inactive },		/* inactive */
    238   1.1   mycroft 	{ &vop_reclaim_desc, lfs_reclaim },		/* reclaim */
    239   1.1   mycroft 	{ &vop_lock_desc, ufs_lock },			/* lock */
    240   1.1   mycroft 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
    241   1.1   mycroft 	{ &vop_bmap_desc, fifo_bmap },			/* bmap */
    242   1.1   mycroft 	{ &vop_strategy_desc, fifo_strategy },		/* strategy */
    243   1.1   mycroft 	{ &vop_print_desc, ufs_print },			/* print */
    244   1.1   mycroft 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
    245   1.1   mycroft 	{ &vop_pathconf_desc, fifo_pathconf },		/* pathconf */
    246   1.1   mycroft 	{ &vop_advlock_desc, fifo_advlock },		/* advlock */
    247   1.1   mycroft 	{ &vop_blkatoff_desc, fifo_blkatoff },		/* blkatoff */
    248   1.1   mycroft 	{ &vop_valloc_desc, fifo_valloc },		/* valloc */
    249   1.1   mycroft 	{ &vop_vfree_desc, lfs_vfree },			/* vfree */
    250   1.1   mycroft 	{ &vop_truncate_desc, fifo_truncate },		/* truncate */
    251   1.1   mycroft 	{ &vop_update_desc, lfs_update },		/* update */
    252   1.1   mycroft 	{ &vop_bwrite_desc, lfs_bwrite },		/* bwrite */
    253  1.10  christos 	{ (struct vnodeop_desc*)NULL, (int(*) __P((void *)))NULL }
    254   1.1   mycroft };
    255   1.1   mycroft struct vnodeopv_desc lfs_fifoop_opv_desc =
    256   1.1   mycroft 	{ &lfs_fifoop_p, lfs_fifoop_entries };
    257   1.1   mycroft 
    258   1.1   mycroft #define	LFS_READWRITE
    259   1.1   mycroft #include <ufs/ufs/ufs_readwrite.c>
    260   1.1   mycroft #undef	LFS_READWRITE
    261   1.1   mycroft 
    262   1.1   mycroft /*
    263   1.1   mycroft  * Synch an open file.
    264   1.1   mycroft  */
    265   1.1   mycroft /* ARGSUSED */
    266  1.10  christos int
    267  1.10  christos lfs_fsync(v)
    268  1.10  christos 	void *v;
    269  1.10  christos {
    270   1.1   mycroft 	struct vop_fsync_args /* {
    271   1.1   mycroft 		struct vnode *a_vp;
    272   1.1   mycroft 		struct ucred *a_cred;
    273  1.22  perseant 		int a_flags;
    274   1.1   mycroft 		struct proc *a_p;
    275  1.10  christos 	} */ *ap = v;
    276  1.22  perseant 
    277  1.21   mycroft 	return (VOP_UPDATE(ap->a_vp, NULL, NULL,
    278  1.37  perseant 			   (ap->a_flags & FSYNC_WAIT) != 0 ? UPDATE_WAIT : 0));
    279   1.1   mycroft }
    280   1.1   mycroft 
    281   1.1   mycroft /*
    282  1.40  perseant  * Take IN_ADIROP off, then call ufs_inactive.
    283  1.40  perseant  */
    284  1.40  perseant int
    285  1.40  perseant lfs_inactive(v)
    286  1.40  perseant 	void *v;
    287  1.40  perseant {
    288  1.40  perseant 	struct vop_inactive_args /* {
    289  1.40  perseant 		struct vnode *a_vp;
    290  1.40  perseant 		struct proc *a_p;
    291  1.40  perseant 	} */ *ap = v;
    292  1.40  perseant 	struct inode *ip = VTOI(ap->a_vp);
    293  1.40  perseant 
    294  1.40  perseant 	if (ip->i_flag & IN_ADIROP)
    295  1.40  perseant 		--ip->i_lfs->lfs_nadirop;
    296  1.40  perseant 	ip->i_flag &= ~IN_ADIROP;
    297  1.40  perseant 	return ufs_inactive(v);
    298  1.40  perseant }
    299  1.40  perseant 
    300  1.40  perseant /*
    301   1.1   mycroft  * These macros are used to bracket UFS directory ops, so that we can
    302   1.1   mycroft  * identify all the pages touched during directory ops which need to
    303   1.1   mycroft  * be ordered and flushed atomically, so that they may be recovered.
    304   1.1   mycroft  */
    305  1.22  perseant /*
    306  1.22  perseant  * XXX KS - Because we have to mark nodes VDIROP in order to prevent
    307  1.22  perseant  * the cache from reclaiming them while a dirop is in progress, we must
    308  1.22  perseant  * also manage the number of nodes so marked (otherwise we can run out).
    309  1.22  perseant  * We do this by setting lfs_dirvcount to the number of marked vnodes; it
    310  1.22  perseant  * is decremented during segment write, when VDIROP is taken off.
    311  1.22  perseant  */
    312  1.40  perseant #define	SET_DIROP(vp) lfs_set_dirop(vp)
    313  1.40  perseant static int lfs_set_dirop __P((struct vnode *));
    314  1.31  perseant extern int lfs_dirvcount;
    315  1.24  perseant 
    316  1.40  perseant static int lfs_set_dirop(vp)
    317  1.40  perseant 	struct vnode *vp;
    318  1.40  perseant {
    319  1.24  perseant 	struct lfs *fs;
    320  1.24  perseant 	int error;
    321  1.24  perseant 
    322  1.40  perseant 	fs = VTOI(vp)->i_lfs;
    323  1.40  perseant 	if (fs->lfs_dirops == 0)
    324  1.40  perseant 		lfs_check(vp, LFS_UNUSED_LBN, 0);
    325  1.40  perseant 	while (fs->lfs_writer || lfs_dirvcount > LFS_MAXDIROP) {
    326  1.24  perseant 		if(fs->lfs_writer)
    327  1.24  perseant 			tsleep(&fs->lfs_dirops, PRIBIO + 1, "lfs_dirop", 0);
    328  1.33  perseant 		if(lfs_dirvcount > LFS_MAXDIROP && fs->lfs_dirops==0) {
    329  1.33  perseant                 	++fs->lfs_writer;
    330  1.33  perseant                 	lfs_flush(fs, 0);
    331  1.33  perseant                 	if(--fs->lfs_writer==0)
    332  1.33  perseant                         	wakeup(&fs->lfs_dirops);
    333  1.33  perseant 		}
    334  1.33  perseant 
    335  1.31  perseant 		if(lfs_dirvcount > LFS_MAXDIROP) {
    336  1.24  perseant #ifdef DEBUG_LFS
    337  1.33  perseant 			printf("lfs_set_dirop: sleeping with dirops=%d, dirvcount=%d\n",fs->lfs_dirops,lfs_dirvcount);
    338  1.24  perseant #endif
    339  1.37  perseant 			if((error = tsleep(&lfs_dirvcount, PCATCH|PUSER, "lfs_maxdirop", 0)) !=0)
    340  1.24  perseant 				return error;
    341  1.24  perseant 		}
    342  1.24  perseant 	}
    343  1.24  perseant 	++fs->lfs_dirops;
    344  1.24  perseant 	fs->lfs_doifile = 1;
    345  1.24  perseant 
    346  1.24  perseant 	return 0;
    347   1.1   mycroft }
    348   1.1   mycroft 
    349  1.26  perseant #define	SET_ENDOP(fs,vp,str) {						\
    350   1.1   mycroft 	--(fs)->lfs_dirops;						\
    351  1.22  perseant 	if (!(fs)->lfs_dirops) {					\
    352  1.40  perseant 		if ((fs)->lfs_nadirop) {				\
    353  1.40  perseant 			panic("SET_ENDOP: %s: no dirops but nadirop=%d\n", \
    354  1.40  perseant 			      (str), (fs)->lfs_nadirop);		\
    355  1.40  perseant 		}							\
    356   1.1   mycroft 		wakeup(&(fs)->lfs_writer);				\
    357  1.26  perseant 		lfs_check((vp),LFS_UNUSED_LBN,0);			\
    358  1.22  perseant 	}								\
    359   1.1   mycroft }
    360   1.1   mycroft 
    361  1.22  perseant #define	MARK_VNODE(dvp)  do {                                           \
    362  1.37  perseant         if (!((dvp)->v_flag & VDIROP)) {				\
    363  1.39  perseant                 (void)lfs_vref(dvp);					\
    364  1.31  perseant 		++lfs_dirvcount;					\
    365  1.22  perseant 	}								\
    366  1.22  perseant         (dvp)->v_flag |= VDIROP;					\
    367  1.37  perseant 	if (!(VTOI(dvp)->i_flag & IN_ADIROP)) {				\
    368  1.37  perseant 		++VTOI(dvp)->i_lfs->lfs_nadirop;			\
    369  1.37  perseant 	}								\
    370  1.37  perseant 	VTOI(dvp)->i_flag |= IN_ADIROP;					\
    371  1.37  perseant } while(0)
    372  1.37  perseant 
    373  1.40  perseant #define UNMARK_VNODE(vp) lfs_unmark_vnode(vp)
    374  1.40  perseant 
    375  1.40  perseant void lfs_unmark_vnode(vp)
    376  1.40  perseant 	struct vnode *vp;
    377  1.40  perseant {
    378  1.40  perseant 	struct inode *ip;
    379  1.40  perseant 
    380  1.40  perseant 	ip = VTOI(vp);
    381  1.40  perseant 
    382  1.40  perseant 	if (ip->i_flag & IN_ADIROP)
    383  1.40  perseant 		--ip->i_lfs->lfs_nadirop;
    384  1.40  perseant 	ip->i_flag &= ~IN_ADIROP;
    385  1.40  perseant }
    386  1.15      fvdl 
    387   1.1   mycroft int
    388  1.10  christos lfs_symlink(v)
    389  1.10  christos 	void *v;
    390  1.10  christos {
    391   1.1   mycroft 	struct vop_symlink_args /* {
    392   1.1   mycroft 		struct vnode *a_dvp;
    393   1.1   mycroft 		struct vnode **a_vpp;
    394   1.1   mycroft 		struct componentname *a_cnp;
    395   1.1   mycroft 		struct vattr *a_vap;
    396   1.1   mycroft 		char *a_target;
    397  1.10  christos 	} */ *ap = v;
    398  1.37  perseant 	int error;
    399   1.1   mycroft 
    400  1.40  perseant 	if ((error = SET_DIROP(ap->a_dvp)) != 0) {
    401  1.34  perseant 		vput(ap->a_dvp);
    402  1.37  perseant 		return error;
    403  1.34  perseant 	}
    404   1.1   mycroft 	MARK_VNODE(ap->a_dvp);
    405  1.37  perseant 	error = ufs_symlink(ap);
    406  1.37  perseant 	UNMARK_VNODE(ap->a_dvp);
    407  1.40  perseant 	if (*(ap->a_vpp))
    408  1.37  perseant 		UNMARK_VNODE(*(ap->a_vpp));
    409  1.37  perseant 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"symlink");
    410  1.37  perseant 	return (error);
    411   1.1   mycroft }
    412   1.1   mycroft 
    413   1.1   mycroft int
    414  1.10  christos lfs_mknod(v)
    415  1.10  christos 	void *v;
    416  1.10  christos {
    417  1.22  perseant 	struct vop_mknod_args	/* {
    418   1.1   mycroft 		struct vnode *a_dvp;
    419   1.1   mycroft 		struct vnode **a_vpp;
    420   1.1   mycroft 		struct componentname *a_cnp;
    421   1.1   mycroft 		struct vattr *a_vap;
    422  1.22  perseant 		} */ *ap = v;
    423  1.28  perseant         struct vattr *vap = ap->a_vap;
    424  1.28  perseant         struct vnode **vpp = ap->a_vpp;
    425  1.28  perseant         struct inode *ip;
    426  1.28  perseant         int error;
    427   1.1   mycroft 
    428  1.40  perseant 	if ((error = SET_DIROP(ap->a_dvp)) != 0) {
    429  1.34  perseant 		vput(ap->a_dvp);
    430  1.28  perseant 		return error;
    431  1.34  perseant 	}
    432   1.1   mycroft 	MARK_VNODE(ap->a_dvp);
    433  1.28  perseant 	error = ufs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode),
    434  1.28  perseant             ap->a_dvp, vpp, ap->a_cnp);
    435  1.37  perseant 	UNMARK_VNODE(ap->a_dvp);
    436  1.40  perseant         if (*(ap->a_vpp))
    437  1.37  perseant                 UNMARK_VNODE(*(ap->a_vpp));
    438  1.28  perseant 
    439  1.28  perseant 	/* Either way we're done with the dirop at this point */
    440  1.26  perseant 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"mknod");
    441  1.28  perseant 
    442  1.28  perseant         if (error)
    443  1.28  perseant 		return (error);
    444  1.28  perseant 
    445  1.28  perseant         ip = VTOI(*vpp);
    446  1.28  perseant         ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
    447  1.28  perseant         if (vap->va_rdev != VNOVAL) {
    448  1.28  perseant                 /*
    449  1.28  perseant                  * Want to be able to use this to make badblock
    450  1.28  perseant                  * inodes, so don't truncate the dev number.
    451  1.28  perseant                  */
    452  1.28  perseant #if 0
    453  1.28  perseant                 ip->i_ffs_rdev = ufs_rw32(vap->va_rdev,
    454  1.28  perseant                     UFS_MPNEEDSWAP((*vpp)->v_mount));
    455  1.28  perseant #else
    456  1.28  perseant                 ip->i_ffs_rdev = vap->va_rdev;
    457  1.28  perseant #endif
    458  1.28  perseant         }
    459  1.28  perseant 	/*
    460  1.28  perseant 	 * Call fsync to write the vnode so that we don't have to deal with
    461  1.28  perseant 	 * flushing it when it's marked VDIROP|VXLOCK.
    462  1.28  perseant 	 *
    463  1.28  perseant 	 * XXX KS - If we can't flush we also can't call vgone(), so must
    464  1.28  perseant 	 * return.  But, that leaves this vnode in limbo, also not good.
    465  1.28  perseant 	 * Can this ever happen (barring hardware failure)?
    466  1.28  perseant 	 */
    467  1.40  perseant 	if ((error = VOP_FSYNC(*vpp, NOCRED, FSYNC_WAIT, curproc)) != 0) {
    468  1.40  perseant 		printf("Couldn't fsync in mknod (ino %d)---what do I do?\n",
    469  1.40  perseant 		       VTOI(*vpp)->i_number);
    470  1.28  perseant 		return (error);
    471  1.40  perseant 	}
    472  1.28  perseant         /*
    473  1.40  perseant          * Remove vnode so that it will be reloaded by VFS_VGET and
    474  1.28  perseant          * checked to see if it is an alias of an existing entry in
    475  1.28  perseant          * the inode cache.
    476  1.28  perseant          */
    477  1.28  perseant 	/* Used to be vput, but that causes us to call VOP_INACTIVE twice. */
    478  1.40  perseant 	VOP_UNLOCK(*vpp, 0);
    479  1.28  perseant 	lfs_vunref(*vpp);
    480  1.28  perseant         (*vpp)->v_type = VNON;
    481  1.28  perseant         vgone(*vpp);
    482  1.28  perseant         *vpp = 0;
    483  1.28  perseant         return (0);
    484   1.1   mycroft }
    485   1.1   mycroft 
    486   1.1   mycroft int
    487  1.10  christos lfs_create(v)
    488  1.10  christos 	void *v;
    489  1.10  christos {
    490  1.22  perseant 	struct vop_create_args	/* {
    491   1.1   mycroft 		struct vnode *a_dvp;
    492   1.1   mycroft 		struct vnode **a_vpp;
    493   1.1   mycroft 		struct componentname *a_cnp;
    494   1.1   mycroft 		struct vattr *a_vap;
    495  1.10  christos 	} */ *ap = v;
    496  1.37  perseant 	int error;
    497   1.1   mycroft 
    498  1.40  perseant 	if((error = SET_DIROP(ap->a_dvp)) != 0) {
    499  1.34  perseant 		vput(ap->a_dvp);
    500  1.37  perseant 		return error;
    501  1.34  perseant 	}
    502   1.1   mycroft 	MARK_VNODE(ap->a_dvp);
    503  1.37  perseant 	error = ufs_create(ap);
    504  1.37  perseant 	UNMARK_VNODE(ap->a_dvp);
    505  1.40  perseant         if (*(ap->a_vpp))
    506  1.37  perseant                 UNMARK_VNODE(*(ap->a_vpp));
    507  1.26  perseant 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"create");
    508  1.37  perseant 	return (error);
    509   1.1   mycroft }
    510   1.1   mycroft 
    511   1.1   mycroft int
    512  1.22  perseant lfs_whiteout(v)
    513  1.22  perseant 	void *v;
    514  1.22  perseant {
    515  1.22  perseant 	struct vop_whiteout_args /* {
    516  1.22  perseant 		struct vnode *a_dvp;
    517  1.22  perseant 		struct componentname *a_cnp;
    518  1.22  perseant 		int a_flags;
    519  1.22  perseant 	} */ *ap = v;
    520  1.37  perseant 	int error;
    521  1.22  perseant 
    522  1.40  perseant 	if ((error = SET_DIROP(ap->a_dvp)) != 0)
    523  1.34  perseant 		/* XXX no unlock here? */
    524  1.37  perseant 		return error;
    525  1.22  perseant 	MARK_VNODE(ap->a_dvp);
    526  1.37  perseant 	error = ufs_whiteout(ap);
    527  1.37  perseant 	UNMARK_VNODE(ap->a_dvp);
    528  1.26  perseant 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"whiteout");
    529  1.37  perseant 	return (error);
    530  1.22  perseant }
    531  1.22  perseant 
    532  1.22  perseant int
    533  1.10  christos lfs_mkdir(v)
    534  1.10  christos 	void *v;
    535  1.10  christos {
    536  1.22  perseant 	struct vop_mkdir_args	/* {
    537   1.1   mycroft 		struct vnode *a_dvp;
    538   1.1   mycroft 		struct vnode **a_vpp;
    539   1.1   mycroft 		struct componentname *a_cnp;
    540   1.1   mycroft 		struct vattr *a_vap;
    541  1.10  christos 	} */ *ap = v;
    542  1.37  perseant 	int error;
    543   1.1   mycroft 
    544  1.40  perseant 	if((error = SET_DIROP(ap->a_dvp)) != 0) {
    545  1.34  perseant 		vput(ap->a_dvp);
    546  1.37  perseant 		return error;
    547  1.34  perseant 	}
    548   1.1   mycroft 	MARK_VNODE(ap->a_dvp);
    549  1.37  perseant 	error = ufs_mkdir(ap);
    550  1.37  perseant 	UNMARK_VNODE(ap->a_dvp);
    551  1.40  perseant         if (*(ap->a_vpp))
    552  1.37  perseant                 UNMARK_VNODE(*(ap->a_vpp));
    553  1.26  perseant 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"mkdir");
    554  1.37  perseant 	return (error);
    555   1.1   mycroft }
    556   1.1   mycroft 
    557   1.1   mycroft int
    558  1.10  christos lfs_remove(v)
    559  1.10  christos 	void *v;
    560  1.10  christos {
    561  1.22  perseant 	struct vop_remove_args	/* {
    562   1.1   mycroft 		struct vnode *a_dvp;
    563   1.1   mycroft 		struct vnode *a_vp;
    564   1.1   mycroft 		struct componentname *a_cnp;
    565  1.10  christos 	} */ *ap = v;
    566  1.34  perseant 	struct vnode *dvp, *vp;
    567  1.37  perseant 	int error;
    568  1.34  perseant 
    569  1.34  perseant 	dvp = ap->a_dvp;
    570  1.34  perseant 	vp = ap->a_vp;
    571  1.40  perseant 	if ((error = SET_DIROP(dvp)) != 0) {
    572  1.34  perseant 		if (dvp == vp)
    573  1.34  perseant 			vrele(vp);
    574  1.34  perseant 		else
    575  1.34  perseant 			vput(vp);
    576  1.34  perseant 		vput(dvp);
    577  1.37  perseant 		return error;
    578  1.34  perseant 	}
    579  1.34  perseant 	MARK_VNODE(dvp);
    580  1.34  perseant 	MARK_VNODE(vp);
    581  1.37  perseant 	error = ufs_remove(ap);
    582  1.37  perseant 	UNMARK_VNODE(dvp);
    583  1.37  perseant 	UNMARK_VNODE(vp);
    584  1.40  perseant 
    585  1.40  perseant 	/*
    586  1.40  perseant 	 * If ufs_remove failed, vp doesn't need to be VDIROP any more.
    587  1.40  perseant 	 * If it succeeded, we can go ahead and wipe out vp, since
    588  1.40  perseant 	 * its loss won't appear on disk until checkpoint, and by then
    589  1.40  perseant 	 * dvp will have been written, completing the dirop.
    590  1.40  perseant 	 */
    591  1.40  perseant 	--lfs_dirvcount;
    592  1.40  perseant 	vp->v_flag &= ~VDIROP;
    593  1.40  perseant 	wakeup(&lfs_dirvcount);
    594  1.40  perseant 	vrele(vp);
    595  1.40  perseant 
    596  1.42  perseant 	SET_ENDOP(VTOI(dvp)->i_lfs,dvp,"remove");
    597  1.37  perseant 	return (error);
    598   1.1   mycroft }
    599   1.1   mycroft 
    600   1.1   mycroft int
    601  1.10  christos lfs_rmdir(v)
    602  1.10  christos 	void *v;
    603  1.10  christos {
    604  1.22  perseant 	struct vop_rmdir_args	/* {
    605   1.1   mycroft 		struct vnodeop_desc *a_desc;
    606   1.1   mycroft 		struct vnode *a_dvp;
    607   1.1   mycroft 		struct vnode *a_vp;
    608   1.1   mycroft 		struct componentname *a_cnp;
    609  1.10  christos 	} */ *ap = v;
    610  1.37  perseant 	int error;
    611   1.1   mycroft 
    612  1.40  perseant 	if ((error = SET_DIROP(ap->a_dvp)) != 0) {
    613  1.34  perseant 		vrele(ap->a_dvp);
    614  1.34  perseant 		if (ap->a_vp->v_mountedhere != NULL)
    615  1.34  perseant 			VOP_UNLOCK(ap->a_dvp, 0);
    616  1.34  perseant 		vput(ap->a_vp);
    617  1.37  perseant 		return error;
    618  1.34  perseant 	}
    619   1.1   mycroft 	MARK_VNODE(ap->a_dvp);
    620   1.1   mycroft 	MARK_VNODE(ap->a_vp);
    621  1.37  perseant 	error = ufs_rmdir(ap);
    622  1.37  perseant 	UNMARK_VNODE(ap->a_dvp);
    623  1.37  perseant 	UNMARK_VNODE(ap->a_vp);
    624  1.40  perseant 
    625  1.40  perseant 	/*
    626  1.40  perseant 	 * If ufs_rmdir failed, vp doesn't need to be VDIROP any more.
    627  1.40  perseant 	 * If it succeeded, we can go ahead and wipe out vp, since
    628  1.40  perseant 	 * its loss won't appear on disk until checkpoint, and by then
    629  1.40  perseant 	 * dvp will have been written, completing the dirop.
    630  1.40  perseant 	 */
    631  1.40  perseant 	--lfs_dirvcount;
    632  1.40  perseant 	ap->a_vp->v_flag &= ~VDIROP;
    633  1.40  perseant 	wakeup(&lfs_dirvcount);
    634  1.40  perseant 	vrele(ap->a_vp);
    635  1.40  perseant 
    636  1.42  perseant 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"rmdir");
    637  1.37  perseant 	return (error);
    638   1.1   mycroft }
    639   1.1   mycroft 
    640   1.1   mycroft int
    641  1.10  christos lfs_link(v)
    642  1.10  christos 	void *v;
    643  1.10  christos {
    644  1.22  perseant 	struct vop_link_args	/* {
    645   1.9   mycroft 		struct vnode *a_dvp;
    646   1.1   mycroft 		struct vnode *a_vp;
    647   1.1   mycroft 		struct componentname *a_cnp;
    648  1.10  christos 	} */ *ap = v;
    649  1.37  perseant 	int error;
    650   1.1   mycroft 
    651  1.40  perseant 	if ((error = SET_DIROP(ap->a_dvp)) != 0) {
    652  1.34  perseant 		vput(ap->a_dvp);
    653  1.37  perseant 		return error;
    654  1.34  perseant 	}
    655   1.9   mycroft 	MARK_VNODE(ap->a_dvp);
    656  1.37  perseant 	error = ufs_link(ap);
    657  1.37  perseant 	UNMARK_VNODE(ap->a_dvp);
    658  1.26  perseant 	SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"link");
    659  1.37  perseant 	return (error);
    660   1.1   mycroft }
    661  1.22  perseant 
    662   1.1   mycroft int
    663  1.10  christos lfs_rename(v)
    664  1.10  christos 	void *v;
    665  1.10  christos {
    666  1.22  perseant 	struct vop_rename_args	/* {
    667   1.1   mycroft 		struct vnode *a_fdvp;
    668   1.1   mycroft 		struct vnode *a_fvp;
    669   1.1   mycroft 		struct componentname *a_fcnp;
    670   1.1   mycroft 		struct vnode *a_tdvp;
    671   1.1   mycroft 		struct vnode *a_tvp;
    672   1.1   mycroft 		struct componentname *a_tcnp;
    673  1.10  christos 	} */ *ap = v;
    674  1.30  perseant 	struct vnode *tvp, *fvp, *tdvp, *fdvp;
    675  1.30  perseant 	int error;
    676  1.29  perseant 	struct lfs *fs;
    677  1.29  perseant 
    678  1.29  perseant 	fs = VTOI(ap->a_fdvp)->i_lfs;
    679  1.30  perseant 	tvp = ap->a_tvp;
    680  1.30  perseant 	tdvp = ap->a_tdvp;
    681  1.30  perseant 	fvp = ap->a_fvp;
    682  1.30  perseant 	fdvp = ap->a_fdvp;
    683  1.30  perseant 
    684  1.30  perseant 	/*
    685  1.30  perseant 	 * Check for cross-device rename.
    686  1.30  perseant 	 * If it is, we don't want to set dirops, just error out.
    687  1.30  perseant 	 * (In particular note that MARK_VNODE(tdvp) will DTWT on
    688  1.30  perseant 	 * a cross-device rename.)
    689  1.30  perseant 	 *
    690  1.30  perseant 	 * Copied from ufs_rename.
    691  1.30  perseant 	 */
    692  1.30  perseant 	if ((fvp->v_mount != tdvp->v_mount) ||
    693  1.30  perseant 	    (tvp && (fvp->v_mount != tvp->v_mount))) {
    694  1.30  perseant 		error = EXDEV;
    695  1.34  perseant 		goto errout;
    696  1.30  perseant 	}
    697  1.40  perseant 	if ((error = SET_DIROP(fdvp))!=0)
    698  1.34  perseant 		goto errout;
    699  1.30  perseant 	MARK_VNODE(fdvp);
    700  1.30  perseant 	MARK_VNODE(tdvp);
    701  1.30  perseant 	error = ufs_rename(ap);
    702  1.37  perseant 	UNMARK_VNODE(fdvp);
    703  1.37  perseant 	UNMARK_VNODE(tdvp);
    704  1.30  perseant 	SET_ENDOP(fs,fdvp,"rename");
    705  1.34  perseant 	return (error);
    706  1.34  perseant 
    707  1.34  perseant     errout:
    708  1.34  perseant 	VOP_ABORTOP(tdvp, ap->a_tcnp); /* XXX, why not in NFS? */
    709  1.34  perseant 	if (tdvp == tvp)
    710  1.34  perseant 		vrele(tdvp);
    711  1.34  perseant 	else
    712  1.34  perseant 		vput(tdvp);
    713  1.34  perseant 	if (tvp)
    714  1.34  perseant 		vput(tvp);
    715  1.34  perseant 	VOP_ABORTOP(fdvp, ap->a_fcnp); /* XXX, why not in NFS? */
    716  1.34  perseant 	vrele(fdvp);
    717  1.34  perseant 	vrele(fvp);
    718  1.30  perseant 	return (error);
    719   1.1   mycroft }
    720  1.22  perseant 
    721   1.1   mycroft /* XXX hack to avoid calling ITIMES in getattr */
    722   1.1   mycroft int
    723  1.10  christos lfs_getattr(v)
    724  1.10  christos 	void *v;
    725  1.10  christos {
    726   1.1   mycroft 	struct vop_getattr_args /* {
    727   1.1   mycroft 		struct vnode *a_vp;
    728   1.1   mycroft 		struct vattr *a_vap;
    729   1.1   mycroft 		struct ucred *a_cred;
    730   1.1   mycroft 		struct proc *a_p;
    731  1.10  christos 	} */ *ap = v;
    732  1.35  augustss 	struct vnode *vp = ap->a_vp;
    733  1.35  augustss 	struct inode *ip = VTOI(vp);
    734  1.35  augustss 	struct vattr *vap = ap->a_vap;
    735   1.1   mycroft 	/*
    736   1.1   mycroft 	 * Copy from inode table
    737   1.1   mycroft 	 */
    738   1.1   mycroft 	vap->va_fsid = ip->i_dev;
    739   1.1   mycroft 	vap->va_fileid = ip->i_number;
    740  1.14    bouyer 	vap->va_mode = ip->i_ffs_mode & ~IFMT;
    741  1.14    bouyer 	vap->va_nlink = ip->i_ffs_nlink;
    742  1.14    bouyer 	vap->va_uid = ip->i_ffs_uid;
    743  1.14    bouyer 	vap->va_gid = ip->i_ffs_gid;
    744  1.14    bouyer 	vap->va_rdev = (dev_t)ip->i_ffs_rdev;
    745  1.14    bouyer 	vap->va_size = ip->i_ffs_size;
    746  1.14    bouyer 	vap->va_atime.tv_sec = ip->i_ffs_atime;
    747  1.14    bouyer 	vap->va_atime.tv_nsec = ip->i_ffs_atimensec;
    748  1.14    bouyer 	vap->va_mtime.tv_sec = ip->i_ffs_mtime;
    749  1.14    bouyer 	vap->va_mtime.tv_nsec = ip->i_ffs_mtimensec;
    750  1.14    bouyer 	vap->va_ctime.tv_sec = ip->i_ffs_ctime;
    751  1.14    bouyer 	vap->va_ctime.tv_nsec = ip->i_ffs_ctimensec;
    752  1.14    bouyer 	vap->va_flags = ip->i_ffs_flags;
    753  1.14    bouyer 	vap->va_gen = ip->i_ffs_gen;
    754   1.1   mycroft 	/* this doesn't belong here */
    755   1.1   mycroft 	if (vp->v_type == VBLK)
    756   1.1   mycroft 		vap->va_blocksize = BLKDEV_IOSIZE;
    757   1.1   mycroft 	else if (vp->v_type == VCHR)
    758   1.1   mycroft 		vap->va_blocksize = MAXBSIZE;
    759   1.1   mycroft 	else
    760   1.1   mycroft 		vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
    761  1.20       cgd 	vap->va_bytes = dbtob((u_quad_t)ip->i_ffs_blocks);
    762   1.1   mycroft 	vap->va_type = vp->v_type;
    763   1.1   mycroft 	vap->va_filerev = ip->i_modrev;
    764   1.1   mycroft 	return (0);
    765   1.1   mycroft }
    766  1.22  perseant 
    767   1.1   mycroft /*
    768   1.1   mycroft  * Close called
    769   1.1   mycroft  *
    770   1.1   mycroft  * XXX -- we were using ufs_close, but since it updates the
    771   1.1   mycroft  * times on the inode, we might need to bump the uinodes
    772   1.1   mycroft  * count.
    773   1.1   mycroft  */
    774   1.1   mycroft /* ARGSUSED */
    775   1.1   mycroft int
    776  1.10  christos lfs_close(v)
    777  1.10  christos 	void *v;
    778  1.10  christos {
    779   1.1   mycroft 	struct vop_close_args /* {
    780   1.1   mycroft 		struct vnode *a_vp;
    781   1.1   mycroft 		int  a_fflag;
    782   1.1   mycroft 		struct ucred *a_cred;
    783   1.1   mycroft 		struct proc *a_p;
    784  1.10  christos 	} */ *ap = v;
    785  1.35  augustss 	struct vnode *vp = ap->a_vp;
    786  1.35  augustss 	struct inode *ip = VTOI(vp);
    787   1.1   mycroft 	int mod;
    788  1.12   mycroft 	struct timespec ts;
    789   1.1   mycroft 
    790  1.15      fvdl 	simple_lock(&vp->v_interlock);
    791  1.15      fvdl 	if (vp->v_usecount > 1) {
    792  1.38  perseant 		mod = ip->i_flag & (IN_MODIFIED | IN_ACCESSED);
    793  1.12   mycroft 		TIMEVAL_TO_TIMESPEC(&time, &ts);
    794  1.22  perseant 		LFS_ITIMES(ip, &ts, &ts, &ts);
    795  1.38  perseant 		if (!mod && (ip->i_flag & (IN_MODIFIED | IN_ACCESSED)))
    796   1.1   mycroft 			ip->i_lfs->lfs_uinodes++;
    797   1.1   mycroft 	}
    798  1.15      fvdl 	simple_unlock(&vp->v_interlock);
    799   1.1   mycroft 	return (0);
    800   1.1   mycroft }
    801   1.1   mycroft 
    802   1.1   mycroft /*
    803  1.15      fvdl  * Reclaim an inode so that it can be used for other purposes.
    804   1.1   mycroft  */
    805   1.1   mycroft int lfs_no_inactive = 0;
    806   1.1   mycroft 
    807   1.1   mycroft int
    808  1.10  christos lfs_reclaim(v)
    809  1.10  christos 	void *v;
    810  1.10  christos {
    811   1.1   mycroft 	struct vop_reclaim_args /* {
    812   1.1   mycroft 		struct vnode *a_vp;
    813  1.15      fvdl 		struct proc *a_p;
    814  1.10  christos 	} */ *ap = v;
    815  1.15      fvdl 	struct vnode *vp = ap->a_vp;
    816   1.1   mycroft 	int error;
    817   1.1   mycroft 
    818  1.15      fvdl 	if ((error = ufs_reclaim(vp, ap->a_p)))
    819   1.1   mycroft 		return (error);
    820  1.19   thorpej 	pool_put(&lfs_inode_pool, vp->v_data);
    821   1.1   mycroft 	vp->v_data = NULL;
    822   1.1   mycroft 	return (0);
    823   1.1   mycroft }
    824