Home | History | Annotate | Line # | Download | only in ffs
ffs_vnops.c revision 1.99.2.1
      1  1.99.2.1  wrstuden /*	$NetBSD: ffs_vnops.c,v 1.99.2.1 2008/09/18 04:37:05 wrstuden Exp $	*/
      2  1.99.2.1  wrstuden 
      3  1.99.2.1  wrstuden /*-
      4  1.99.2.1  wrstuden  * Copyright (c) 2008 The NetBSD Foundation, Inc.
      5  1.99.2.1  wrstuden  * All rights reserved.
      6  1.99.2.1  wrstuden  *
      7  1.99.2.1  wrstuden  * This code is derived from software contributed to The NetBSD Foundation
      8  1.99.2.1  wrstuden  * by Wasabi Systems, Inc.
      9  1.99.2.1  wrstuden  *
     10  1.99.2.1  wrstuden  * Redistribution and use in source and binary forms, with or without
     11  1.99.2.1  wrstuden  * modification, are permitted provided that the following conditions
     12  1.99.2.1  wrstuden  * are met:
     13  1.99.2.1  wrstuden  * 1. Redistributions of source code must retain the above copyright
     14  1.99.2.1  wrstuden  *    notice, this list of conditions and the following disclaimer.
     15  1.99.2.1  wrstuden  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.99.2.1  wrstuden  *    notice, this list of conditions and the following disclaimer in the
     17  1.99.2.1  wrstuden  *    documentation and/or other materials provided with the distribution.
     18  1.99.2.1  wrstuden  *
     19  1.99.2.1  wrstuden  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.99.2.1  wrstuden  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.99.2.1  wrstuden  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.99.2.1  wrstuden  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.99.2.1  wrstuden  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.99.2.1  wrstuden  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.99.2.1  wrstuden  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.99.2.1  wrstuden  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.99.2.1  wrstuden  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.99.2.1  wrstuden  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.99.2.1  wrstuden  * POSSIBILITY OF SUCH DAMAGE.
     30  1.99.2.1  wrstuden  */
     31       1.3       cgd 
     32       1.1   mycroft /*
     33       1.1   mycroft  * Copyright (c) 1982, 1986, 1989, 1993
     34       1.1   mycroft  *	The Regents of the University of California.  All rights reserved.
     35       1.1   mycroft  *
     36       1.1   mycroft  * Redistribution and use in source and binary forms, with or without
     37       1.1   mycroft  * modification, are permitted provided that the following conditions
     38       1.1   mycroft  * are met:
     39       1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     40       1.1   mycroft  *    notice, this list of conditions and the following disclaimer.
     41       1.1   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     42       1.1   mycroft  *    notice, this list of conditions and the following disclaimer in the
     43       1.1   mycroft  *    documentation and/or other materials provided with the distribution.
     44      1.60       agc  * 3. Neither the name of the University nor the names of its contributors
     45       1.1   mycroft  *    may be used to endorse or promote products derived from this software
     46       1.1   mycroft  *    without specific prior written permission.
     47       1.1   mycroft  *
     48       1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     49       1.1   mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     50       1.1   mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     51       1.1   mycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     52       1.1   mycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     53       1.1   mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     54       1.1   mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     55       1.1   mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     56       1.1   mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     57       1.1   mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     58       1.1   mycroft  * SUCH DAMAGE.
     59       1.1   mycroft  *
     60      1.12      fvdl  *	@(#)ffs_vnops.c	8.15 (Berkeley) 5/14/95
     61       1.1   mycroft  */
     62      1.44     lukem 
     63      1.44     lukem #include <sys/cdefs.h>
     64  1.99.2.1  wrstuden __KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.99.2.1 2008/09/18 04:37:05 wrstuden Exp $");
     65  1.99.2.1  wrstuden 
     66  1.99.2.1  wrstuden #if defined(_KERNEL_OPT)
     67  1.99.2.1  wrstuden #include "opt_ffs.h"
     68  1.99.2.1  wrstuden #include "opt_wapbl.h"
     69  1.99.2.1  wrstuden #endif
     70      1.11       mrg 
     71       1.1   mycroft #include <sys/param.h>
     72       1.1   mycroft #include <sys/systm.h>
     73       1.1   mycroft #include <sys/resourcevar.h>
     74       1.1   mycroft #include <sys/kernel.h>
     75       1.1   mycroft #include <sys/file.h>
     76       1.1   mycroft #include <sys/stat.h>
     77       1.1   mycroft #include <sys/buf.h>
     78      1.50  jdolecek #include <sys/event.h>
     79       1.1   mycroft #include <sys/proc.h>
     80       1.1   mycroft #include <sys/mount.h>
     81       1.1   mycroft #include <sys/vnode.h>
     82      1.16   thorpej #include <sys/pool.h>
     83       1.6  christos #include <sys/signalvar.h>
     84      1.80      elad #include <sys/kauth.h>
     85  1.99.2.1  wrstuden #include <sys/wapbl.h>
     86      1.84   hannken #include <sys/fstrans.h>
     87       1.1   mycroft 
     88       1.8   mycroft #include <miscfs/fifofs/fifo.h>
     89       1.8   mycroft #include <miscfs/genfs/genfs.h>
     90       1.1   mycroft #include <miscfs/specfs/specdev.h>
     91       1.1   mycroft 
     92       1.1   mycroft #include <ufs/ufs/inode.h>
     93       1.1   mycroft #include <ufs/ufs/dir.h>
     94       1.1   mycroft #include <ufs/ufs/ufs_extern.h>
     95       1.2   mycroft #include <ufs/ufs/ufsmount.h>
     96  1.99.2.1  wrstuden #include <ufs/ufs/ufs_wapbl.h>
     97       1.1   mycroft 
     98       1.1   mycroft #include <ufs/ffs/fs.h>
     99       1.1   mycroft #include <ufs/ffs/ffs_extern.h>
    100       1.1   mycroft 
    101      1.49       chs #include <uvm/uvm.h>
    102      1.49       chs 
    103       1.1   mycroft /* Global vfs data structures for ufs. */
    104      1.74   xtraeme int (**ffs_vnodeop_p)(void *);
    105      1.37  jdolecek const struct vnodeopv_entry_desc ffs_vnodeop_entries[] = {
    106       1.1   mycroft 	{ &vop_default_desc, vn_default_error },
    107       1.1   mycroft 	{ &vop_lookup_desc, ufs_lookup },		/* lookup */
    108       1.1   mycroft 	{ &vop_create_desc, ufs_create },		/* create */
    109       1.5   mycroft 	{ &vop_whiteout_desc, ufs_whiteout },		/* whiteout */
    110       1.1   mycroft 	{ &vop_mknod_desc, ufs_mknod },			/* mknod */
    111       1.1   mycroft 	{ &vop_open_desc, ufs_open },			/* open */
    112       1.1   mycroft 	{ &vop_close_desc, ufs_close },			/* close */
    113       1.1   mycroft 	{ &vop_access_desc, ufs_access },		/* access */
    114       1.1   mycroft 	{ &vop_getattr_desc, ufs_getattr },		/* getattr */
    115       1.1   mycroft 	{ &vop_setattr_desc, ufs_setattr },		/* setattr */
    116       1.1   mycroft 	{ &vop_read_desc, ffs_read },			/* read */
    117       1.1   mycroft 	{ &vop_write_desc, ffs_write },			/* write */
    118       1.1   mycroft 	{ &vop_ioctl_desc, ufs_ioctl },			/* ioctl */
    119      1.19  wrstuden 	{ &vop_fcntl_desc, ufs_fcntl },			/* fcntl */
    120       1.9   mycroft 	{ &vop_poll_desc, ufs_poll },			/* poll */
    121      1.50  jdolecek 	{ &vop_kqfilter_desc, genfs_kqfilter },		/* kqfilter */
    122      1.12      fvdl 	{ &vop_revoke_desc, ufs_revoke },		/* revoke */
    123       1.1   mycroft 	{ &vop_mmap_desc, ufs_mmap },			/* mmap */
    124       1.1   mycroft 	{ &vop_fsync_desc, ffs_fsync },			/* fsync */
    125       1.1   mycroft 	{ &vop_seek_desc, ufs_seek },			/* seek */
    126       1.1   mycroft 	{ &vop_remove_desc, ufs_remove },		/* remove */
    127       1.1   mycroft 	{ &vop_link_desc, ufs_link },			/* link */
    128       1.1   mycroft 	{ &vop_rename_desc, ufs_rename },		/* rename */
    129       1.1   mycroft 	{ &vop_mkdir_desc, ufs_mkdir },			/* mkdir */
    130       1.1   mycroft 	{ &vop_rmdir_desc, ufs_rmdir },			/* rmdir */
    131       1.1   mycroft 	{ &vop_symlink_desc, ufs_symlink },		/* symlink */
    132       1.1   mycroft 	{ &vop_readdir_desc, ufs_readdir },		/* readdir */
    133       1.1   mycroft 	{ &vop_readlink_desc, ufs_readlink },		/* readlink */
    134       1.1   mycroft 	{ &vop_abortop_desc, ufs_abortop },		/* abortop */
    135       1.1   mycroft 	{ &vop_inactive_desc, ufs_inactive },		/* inactive */
    136       1.1   mycroft 	{ &vop_reclaim_desc, ffs_reclaim },		/* reclaim */
    137      1.90   hannken 	{ &vop_lock_desc, ffs_lock },			/* lock */
    138      1.90   hannken 	{ &vop_unlock_desc, ffs_unlock },		/* unlock */
    139       1.1   mycroft 	{ &vop_bmap_desc, ufs_bmap },			/* bmap */
    140       1.1   mycroft 	{ &vop_strategy_desc, ufs_strategy },		/* strategy */
    141       1.1   mycroft 	{ &vop_print_desc, ufs_print },			/* print */
    142      1.90   hannken 	{ &vop_islocked_desc, ffs_islocked },		/* islocked */
    143       1.1   mycroft 	{ &vop_pathconf_desc, ufs_pathconf },		/* pathconf */
    144       1.1   mycroft 	{ &vop_advlock_desc, ufs_advlock },		/* advlock */
    145       1.8   mycroft 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
    146      1.88      yamt 	{ &vop_getpages_desc, genfs_getpages },		/* getpages */
    147      1.75      yamt 	{ &vop_putpages_desc, genfs_putpages },		/* putpages */
    148      1.73   thorpej 	{ &vop_openextattr_desc, ffs_openextattr },	/* openextattr */
    149      1.73   thorpej 	{ &vop_closeextattr_desc, ffs_closeextattr },	/* closeextattr */
    150      1.73   thorpej 	{ &vop_getextattr_desc, ffs_getextattr },	/* getextattr */
    151      1.73   thorpej 	{ &vop_setextattr_desc, ffs_setextattr },	/* setextattr */
    152      1.73   thorpej 	{ &vop_listextattr_desc, ffs_listextattr },	/* listextattr */
    153      1.73   thorpej 	{ &vop_deleteextattr_desc, ffs_deleteextattr },	/* deleteextattr */
    154      1.35       chs 	{ NULL, NULL }
    155       1.1   mycroft };
    156      1.37  jdolecek const struct vnodeopv_desc ffs_vnodeop_opv_desc =
    157       1.1   mycroft 	{ &ffs_vnodeop_p, ffs_vnodeop_entries };
    158       1.1   mycroft 
    159      1.74   xtraeme int (**ffs_specop_p)(void *);
    160      1.37  jdolecek const struct vnodeopv_entry_desc ffs_specop_entries[] = {
    161       1.1   mycroft 	{ &vop_default_desc, vn_default_error },
    162       1.1   mycroft 	{ &vop_lookup_desc, spec_lookup },		/* lookup */
    163       1.1   mycroft 	{ &vop_create_desc, spec_create },		/* create */
    164       1.1   mycroft 	{ &vop_mknod_desc, spec_mknod },		/* mknod */
    165       1.1   mycroft 	{ &vop_open_desc, spec_open },			/* open */
    166       1.1   mycroft 	{ &vop_close_desc, ufsspec_close },		/* close */
    167       1.1   mycroft 	{ &vop_access_desc, ufs_access },		/* access */
    168       1.1   mycroft 	{ &vop_getattr_desc, ufs_getattr },		/* getattr */
    169       1.1   mycroft 	{ &vop_setattr_desc, ufs_setattr },		/* setattr */
    170       1.1   mycroft 	{ &vop_read_desc, ufsspec_read },		/* read */
    171       1.1   mycroft 	{ &vop_write_desc, ufsspec_write },		/* write */
    172       1.1   mycroft 	{ &vop_ioctl_desc, spec_ioctl },		/* ioctl */
    173      1.19  wrstuden 	{ &vop_fcntl_desc, ufs_fcntl },			/* fcntl */
    174       1.9   mycroft 	{ &vop_poll_desc, spec_poll },			/* poll */
    175      1.50  jdolecek 	{ &vop_kqfilter_desc, spec_kqfilter },		/* kqfilter */
    176      1.12      fvdl 	{ &vop_revoke_desc, spec_revoke },		/* revoke */
    177       1.1   mycroft 	{ &vop_mmap_desc, spec_mmap },			/* mmap */
    178       1.1   mycroft 	{ &vop_fsync_desc, ffs_fsync },			/* fsync */
    179       1.1   mycroft 	{ &vop_seek_desc, spec_seek },			/* seek */
    180       1.1   mycroft 	{ &vop_remove_desc, spec_remove },		/* remove */
    181       1.1   mycroft 	{ &vop_link_desc, spec_link },			/* link */
    182       1.1   mycroft 	{ &vop_rename_desc, spec_rename },		/* rename */
    183       1.1   mycroft 	{ &vop_mkdir_desc, spec_mkdir },		/* mkdir */
    184       1.1   mycroft 	{ &vop_rmdir_desc, spec_rmdir },		/* rmdir */
    185       1.1   mycroft 	{ &vop_symlink_desc, spec_symlink },		/* symlink */
    186       1.1   mycroft 	{ &vop_readdir_desc, spec_readdir },		/* readdir */
    187       1.1   mycroft 	{ &vop_readlink_desc, spec_readlink },		/* readlink */
    188       1.1   mycroft 	{ &vop_abortop_desc, spec_abortop },		/* abortop */
    189       1.1   mycroft 	{ &vop_inactive_desc, ufs_inactive },		/* inactive */
    190       1.1   mycroft 	{ &vop_reclaim_desc, ffs_reclaim },		/* reclaim */
    191      1.90   hannken 	{ &vop_lock_desc, ffs_lock },			/* lock */
    192      1.90   hannken 	{ &vop_unlock_desc, ffs_unlock },		/* unlock */
    193       1.1   mycroft 	{ &vop_bmap_desc, spec_bmap },			/* bmap */
    194       1.1   mycroft 	{ &vop_strategy_desc, spec_strategy },		/* strategy */
    195       1.1   mycroft 	{ &vop_print_desc, ufs_print },			/* print */
    196      1.90   hannken 	{ &vop_islocked_desc, ffs_islocked },		/* islocked */
    197       1.1   mycroft 	{ &vop_pathconf_desc, spec_pathconf },		/* pathconf */
    198       1.1   mycroft 	{ &vop_advlock_desc, spec_advlock },		/* advlock */
    199       1.8   mycroft 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
    200      1.38       chs 	{ &vop_getpages_desc, spec_getpages },		/* getpages */
    201      1.38       chs 	{ &vop_putpages_desc, spec_putpages },		/* putpages */
    202      1.73   thorpej 	{ &vop_openextattr_desc, ffs_openextattr },	/* openextattr */
    203      1.73   thorpej 	{ &vop_closeextattr_desc, ffs_closeextattr },	/* closeextattr */
    204      1.73   thorpej 	{ &vop_getextattr_desc, ffs_getextattr },	/* getextattr */
    205      1.73   thorpej 	{ &vop_setextattr_desc, ffs_setextattr },	/* setextattr */
    206      1.73   thorpej 	{ &vop_listextattr_desc, ffs_listextattr },	/* listextattr */
    207      1.73   thorpej 	{ &vop_deleteextattr_desc, ffs_deleteextattr },	/* deleteextattr */
    208      1.35       chs 	{ NULL, NULL }
    209       1.1   mycroft };
    210      1.37  jdolecek const struct vnodeopv_desc ffs_specop_opv_desc =
    211       1.1   mycroft 	{ &ffs_specop_p, ffs_specop_entries };
    212       1.1   mycroft 
    213      1.74   xtraeme int (**ffs_fifoop_p)(void *);
    214      1.37  jdolecek const struct vnodeopv_entry_desc ffs_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.1   mycroft 	{ &vop_close_desc, ufsfifo_close },		/* close */
    221       1.1   mycroft 	{ &vop_access_desc, ufs_access },		/* access */
    222       1.1   mycroft 	{ &vop_getattr_desc, ufs_getattr },		/* getattr */
    223       1.1   mycroft 	{ &vop_setattr_desc, ufs_setattr },		/* setattr */
    224       1.1   mycroft 	{ &vop_read_desc, ufsfifo_read },		/* read */
    225       1.1   mycroft 	{ &vop_write_desc, ufsfifo_write },		/* write */
    226       1.1   mycroft 	{ &vop_ioctl_desc, fifo_ioctl },		/* ioctl */
    227      1.19  wrstuden 	{ &vop_fcntl_desc, ufs_fcntl },			/* fcntl */
    228       1.9   mycroft 	{ &vop_poll_desc, fifo_poll },			/* poll */
    229      1.50  jdolecek 	{ &vop_kqfilter_desc, fifo_kqfilter },		/* kqfilter */
    230      1.12      fvdl 	{ &vop_revoke_desc, fifo_revoke },		/* revoke */
    231       1.1   mycroft 	{ &vop_mmap_desc, fifo_mmap },			/* mmap */
    232       1.1   mycroft 	{ &vop_fsync_desc, ffs_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.1   mycroft 	{ &vop_inactive_desc, ufs_inactive },		/* inactive */
    244       1.1   mycroft 	{ &vop_reclaim_desc, ffs_reclaim },		/* reclaim */
    245      1.90   hannken 	{ &vop_lock_desc, ffs_lock },			/* lock */
    246      1.90   hannken 	{ &vop_unlock_desc, ffs_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.90   hannken 	{ &vop_islocked_desc, ffs_islocked },		/* islocked */
    251       1.1   mycroft 	{ &vop_pathconf_desc, fifo_pathconf },		/* pathconf */
    252       1.1   mycroft 	{ &vop_advlock_desc, fifo_advlock },		/* advlock */
    253       1.8   mycroft 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
    254      1.40  sommerfe 	{ &vop_putpages_desc, fifo_putpages }, 		/* putpages */
    255      1.73   thorpej 	{ &vop_openextattr_desc, ffs_openextattr },	/* openextattr */
    256      1.73   thorpej 	{ &vop_closeextattr_desc, ffs_closeextattr },	/* closeextattr */
    257      1.73   thorpej 	{ &vop_getextattr_desc, ffs_getextattr },	/* getextattr */
    258      1.73   thorpej 	{ &vop_setextattr_desc, ffs_setextattr },	/* setextattr */
    259      1.73   thorpej 	{ &vop_listextattr_desc, ffs_listextattr },	/* listextattr */
    260      1.73   thorpej 	{ &vop_deleteextattr_desc, ffs_deleteextattr },	/* deleteextattr */
    261      1.35       chs 	{ NULL, NULL }
    262       1.1   mycroft };
    263      1.37  jdolecek const struct vnodeopv_desc ffs_fifoop_opv_desc =
    264       1.1   mycroft 	{ &ffs_fifoop_p, ffs_fifoop_entries };
    265       1.1   mycroft 
    266       1.1   mycroft #include <ufs/ufs/ufs_readwrite.c>
    267      1.20      fvdl 
    268      1.33      fvdl int
    269      1.70   thorpej ffs_fsync(void *v)
    270      1.33      fvdl {
    271      1.33      fvdl 	struct vop_fsync_args /* {
    272      1.33      fvdl 		struct vnode *a_vp;
    273      1.80      elad 		kauth_cred_t a_cred;
    274      1.33      fvdl 		int a_flags;
    275      1.46       chs 		off_t a_offlo;
    276      1.46       chs 		off_t a_offhi;
    277      1.77  christos 		struct lwp *a_l;
    278      1.33      fvdl 	} */ *ap = v;
    279      1.35       chs 	struct buf *bp;
    280      1.94        ad 	int num, error, i;
    281      1.33      fvdl 	struct indir ia[NIADDR + 1];
    282      1.33      fvdl 	int bsize;
    283      1.45    simonb 	daddr_t blk_high;
    284      1.33      fvdl 	struct vnode *vp;
    285  1.99.2.1  wrstuden #ifdef WAPBL
    286  1.99.2.1  wrstuden 	struct mount *mp;
    287  1.99.2.1  wrstuden #endif
    288      1.33      fvdl 
    289      1.84   hannken 	vp = ap->a_vp;
    290      1.84   hannken 
    291      1.87   hannken 	fstrans_start(vp->v_mount, FSTRANS_LAZY);
    292      1.33      fvdl 	/*
    293      1.33      fvdl 	 * XXX no easy way to sync a range in a file with softdep.
    294      1.33      fvdl 	 */
    295      1.84   hannken 	if ((ap->a_offlo == 0 && ap->a_offhi == 0) || DOINGSOFTDEP(vp) ||
    296      1.84   hannken 	    (vp->v_type != VREG)) {
    297  1.99.2.1  wrstuden 		int flags = ap->a_flags;
    298  1.99.2.1  wrstuden 
    299  1.99.2.1  wrstuden 		if (vp->v_type == VBLK)
    300  1.99.2.1  wrstuden 			flags |= FSYNC_VFS;
    301  1.99.2.1  wrstuden 		error = ffs_full_fsync(vp, flags);
    302      1.84   hannken 		goto out;
    303      1.84   hannken 	}
    304      1.33      fvdl 
    305      1.84   hannken 	bsize = vp->v_mount->mnt_stat.f_iosize;
    306      1.33      fvdl 	blk_high = ap->a_offhi / bsize;
    307      1.33      fvdl 	if (ap->a_offhi % bsize != 0)
    308      1.33      fvdl 		blk_high++;
    309      1.33      fvdl 
    310      1.33      fvdl 	/*
    311      1.35       chs 	 * First, flush all pages in range.
    312      1.33      fvdl 	 */
    313      1.35       chs 
    314      1.94        ad 	mutex_enter(&vp->v_interlock);
    315      1.64       dbj 	error = VOP_PUTPAGES(vp, trunc_page(ap->a_offlo),
    316      1.64       dbj 	    round_page(ap->a_offhi), PGO_CLEANIT |
    317      1.64       dbj 	    ((ap->a_flags & FSYNC_WAIT) ? PGO_SYNCIO : 0));
    318      1.64       dbj 	if (error) {
    319      1.84   hannken 		goto out;
    320      1.39       chs 	}
    321      1.33      fvdl 
    322  1.99.2.1  wrstuden #ifdef WAPBL
    323  1.99.2.1  wrstuden 	mp = wapbl_vptomp(vp);
    324  1.99.2.1  wrstuden 	if (mp->mnt_wapbl) {
    325  1.99.2.1  wrstuden 		if (ap->a_flags & FSYNC_DATAONLY) {
    326  1.99.2.1  wrstuden 			fstrans_done(vp->v_mount);
    327  1.99.2.1  wrstuden 			return 0;
    328  1.99.2.1  wrstuden 		}
    329  1.99.2.1  wrstuden 		error = 0;
    330  1.99.2.1  wrstuden 		if (vp->v_tag == VT_UFS && VTOI(vp)->i_flag &
    331  1.99.2.1  wrstuden 		    (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY |
    332  1.99.2.1  wrstuden 				 IN_MODIFIED | IN_ACCESSED)) {
    333  1.99.2.1  wrstuden 			error = UFS_WAPBL_BEGIN(mp);
    334  1.99.2.1  wrstuden 			if (error) {
    335  1.99.2.1  wrstuden 				fstrans_done(vp->v_mount);
    336  1.99.2.1  wrstuden 				return error;
    337  1.99.2.1  wrstuden 			}
    338  1.99.2.1  wrstuden 			error = ffs_update(vp, NULL, NULL,
    339  1.99.2.1  wrstuden 				(ap->a_flags & FSYNC_WAIT) ? UPDATE_WAIT : 0);
    340  1.99.2.1  wrstuden 			UFS_WAPBL_END(mp);
    341  1.99.2.1  wrstuden 		}
    342  1.99.2.1  wrstuden 		if (error || (ap->a_flags & FSYNC_NOLOG)) {
    343  1.99.2.1  wrstuden 			fstrans_done(vp->v_mount);
    344  1.99.2.1  wrstuden 			return error;
    345  1.99.2.1  wrstuden 		}
    346  1.99.2.1  wrstuden 		error = wapbl_flush(mp->mnt_wapbl, 0);
    347  1.99.2.1  wrstuden 		fstrans_done(vp->v_mount);
    348  1.99.2.1  wrstuden 		return error;
    349  1.99.2.1  wrstuden 	}
    350  1.99.2.1  wrstuden #endif /* WAPBL */
    351  1.99.2.1  wrstuden 
    352      1.33      fvdl 	/*
    353      1.35       chs 	 * Then, flush indirect blocks.
    354      1.33      fvdl 	 */
    355      1.35       chs 
    356      1.61    kleink 	if (blk_high >= NDADDR) {
    357      1.33      fvdl 		error = ufs_getlbns(vp, blk_high, ia, &num);
    358      1.94        ad 		if (error)
    359      1.84   hannken 			goto out;
    360      1.94        ad 
    361      1.94        ad 		mutex_enter(&bufcache_lock);
    362      1.33      fvdl 		for (i = 0; i < num; i++) {
    363      1.94        ad 			if ((bp = incore(vp, ia[i].in_lbn)) == NULL)
    364      1.94        ad 				continue;
    365      1.94        ad 			if ((bp->b_cflags & BC_BUSY) != 0 ||
    366      1.94        ad 			    (bp->b_oflags & BO_DELWRI) == 0)
    367      1.94        ad 				continue;
    368      1.94        ad 			bp->b_cflags |= BC_BUSY | BC_VFLUSH;
    369      1.94        ad 			mutex_exit(&bufcache_lock);
    370      1.94        ad 			bawrite(bp);
    371      1.94        ad 			mutex_enter(&bufcache_lock);
    372      1.33      fvdl 		}
    373      1.94        ad 		mutex_exit(&bufcache_lock);
    374      1.33      fvdl 	}
    375      1.33      fvdl 
    376      1.33      fvdl 	if (ap->a_flags & FSYNC_WAIT) {
    377      1.94        ad 		mutex_enter(&vp->v_interlock);
    378      1.94        ad 		while (vp->v_numoutput > 0)
    379      1.94        ad 			cv_wait(&vp->v_cv, &vp->v_interlock);
    380      1.94        ad 		mutex_exit(&vp->v_interlock);
    381      1.33      fvdl 	}
    382      1.33      fvdl 
    383      1.76      yamt 	error = ffs_update(vp, NULL, NULL,
    384      1.66   thorpej 	    ((ap->a_flags & (FSYNC_WAIT | FSYNC_DATAONLY)) == FSYNC_WAIT)
    385      1.67  wrstuden 	    ? UPDATE_WAIT : 0);
    386      1.67  wrstuden 
    387      1.67  wrstuden 	if (error == 0 && ap->a_flags & FSYNC_CACHE) {
    388      1.67  wrstuden 		int l = 0;
    389      1.67  wrstuden 		VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &l, FWRITE,
    390      1.93     pooka 			curlwp->l_cred);
    391      1.67  wrstuden 	}
    392      1.67  wrstuden 
    393      1.84   hannken out:
    394      1.84   hannken 	fstrans_done(vp->v_mount);
    395      1.67  wrstuden 	return error;
    396      1.33      fvdl }
    397      1.33      fvdl 
    398      1.20      fvdl /*
    399      1.20      fvdl  * Synch an open file.
    400      1.20      fvdl  */
    401      1.20      fvdl /* ARGSUSED */
    402      1.94        ad int
    403      1.94        ad ffs_full_fsync(struct vnode *vp, int flags)
    404      1.20      fvdl {
    405      1.20      fvdl 	struct buf *bp, *nbp;
    406      1.94        ad 	int error, passes, skipmeta, inodedeps_only, waitfor;
    407      1.99        ad 	struct mount *mp;
    408      1.99        ad 
    409      1.99        ad 	error = 0;
    410      1.24      fvdl 
    411      1.20      fvdl 	if (vp->v_type == VBLK &&
    412      1.20      fvdl 	    vp->v_specmountpoint != NULL &&
    413      1.20      fvdl 	    (vp->v_specmountpoint->mnt_flag & MNT_SOFTDEP))
    414      1.20      fvdl 		softdep_fsync_mountdev(vp);
    415      1.21  perseant 
    416      1.94        ad 	mutex_enter(&vp->v_interlock);
    417      1.94        ad 
    418      1.94        ad 	inodedeps_only = DOINGSOFTDEP(vp) && (flags & FSYNC_RECLAIM)
    419      1.89     pooka 	    && UVM_OBJ_IS_CLEAN(&vp->v_uobj) && LIST_EMPTY(&vp->v_dirtyblkhd);
    420      1.47      fvdl 
    421      1.35       chs 	/*
    422      1.35       chs 	 * Flush all dirty data associated with a vnode.
    423      1.20      fvdl 	 */
    424      1.35       chs 
    425      1.72      yamt 	if (vp->v_type == VREG || vp->v_type == VBLK) {
    426  1.99.2.1  wrstuden 		int pflags = PGO_ALLPAGES | PGO_CLEANIT;
    427  1.99.2.1  wrstuden 
    428  1.99.2.1  wrstuden 		if ((flags & FSYNC_VFS) != 0 && vp->v_specmountpoint != NULL)
    429      1.99        ad 			mp = vp->v_specmountpoint;
    430      1.99        ad 		else
    431      1.99        ad 			mp = vp->v_mount;
    432  1.99.2.1  wrstuden 
    433  1.99.2.1  wrstuden 		if ((flags & FSYNC_WAIT))
    434  1.99.2.1  wrstuden 			pflags |= PGO_SYNCIO;
    435  1.99.2.1  wrstuden 		if (vp->v_type == VREG &&
    436  1.99.2.1  wrstuden 		    fstrans_getstate(mp) == FSTRANS_SUSPENDING)
    437  1.99.2.1  wrstuden 			pflags |= PGO_FREE;
    438  1.99.2.1  wrstuden 		error = VOP_PUTPAGES(vp, 0, 0, pflags);
    439      1.99        ad 		if (error)
    440      1.39       chs 			return error;
    441  1.99.2.1  wrstuden 	} else {
    442  1.99.2.1  wrstuden 		mp = vp->v_mount;
    443      1.94        ad 		mutex_exit(&vp->v_interlock);
    444  1.99.2.1  wrstuden 	}
    445  1.99.2.1  wrstuden 
    446  1.99.2.1  wrstuden #ifdef WAPBL
    447  1.99.2.1  wrstuden 	if (mp && mp->mnt_wapbl) {
    448  1.99.2.1  wrstuden 		error = 0;
    449  1.99.2.1  wrstuden 		if (flags & FSYNC_DATAONLY)
    450  1.99.2.1  wrstuden 			return error;
    451  1.99.2.1  wrstuden 
    452  1.99.2.1  wrstuden 		if (VTOI(vp) && (VTOI(vp)->i_flag &
    453  1.99.2.1  wrstuden 		    (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY |
    454  1.99.2.1  wrstuden 				 IN_MODIFIED | IN_ACCESSED))) {
    455  1.99.2.1  wrstuden 			error = UFS_WAPBL_BEGIN(mp);
    456  1.99.2.1  wrstuden 			if (error)
    457  1.99.2.1  wrstuden 				return error;
    458  1.99.2.1  wrstuden 			error = ffs_update(vp, NULL, NULL,
    459  1.99.2.1  wrstuden 				(flags & FSYNC_WAIT) ? UPDATE_WAIT : 0);
    460  1.99.2.1  wrstuden 			UFS_WAPBL_END(mp);
    461  1.99.2.1  wrstuden 		}
    462  1.99.2.1  wrstuden 		if (error || (flags & FSYNC_NOLOG))
    463  1.99.2.1  wrstuden 			return error;
    464  1.99.2.1  wrstuden 		/*
    465  1.99.2.1  wrstuden 		 * Don't flush the log if the vnode being flushed
    466  1.99.2.1  wrstuden 		 * contains no dirty buffers that could be in the log.
    467  1.99.2.1  wrstuden 		 */
    468  1.99.2.1  wrstuden 		if (!((flags & FSYNC_RECLAIM) &&
    469  1.99.2.1  wrstuden 		    LIST_EMPTY(&vp->v_dirtyblkhd))) {
    470  1.99.2.1  wrstuden 			error = wapbl_flush(mp->mnt_wapbl, 0);
    471  1.99.2.1  wrstuden 			if (error)
    472  1.99.2.1  wrstuden 				return error;
    473  1.99.2.1  wrstuden 		}
    474  1.99.2.1  wrstuden 
    475  1.99.2.1  wrstuden 		/*
    476  1.99.2.1  wrstuden 		 * XXX temporary workaround for "dirty bufs" panic in
    477  1.99.2.1  wrstuden 		 * vinvalbuf.  need a full fix for the v_numoutput
    478  1.99.2.1  wrstuden 		 * waiters issues.
    479  1.99.2.1  wrstuden 		 */
    480  1.99.2.1  wrstuden 		if (flags & FSYNC_WAIT) {
    481  1.99.2.1  wrstuden 			mutex_enter(&vp->v_interlock);
    482  1.99.2.1  wrstuden 			while (vp->v_numoutput)
    483  1.99.2.1  wrstuden 				cv_wait(&vp->v_cv, &vp->v_interlock);
    484  1.99.2.1  wrstuden 			mutex_exit(&vp->v_interlock);
    485  1.99.2.1  wrstuden 		}
    486  1.99.2.1  wrstuden 
    487  1.99.2.1  wrstuden 		return error;
    488  1.99.2.1  wrstuden 	}
    489  1.99.2.1  wrstuden #endif /* WAPBL */
    490      1.35       chs 
    491      1.20      fvdl 	passes = NIADDR + 1;
    492      1.20      fvdl 	skipmeta = 0;
    493      1.94        ad 	if (flags & FSYNC_WAIT)
    494      1.20      fvdl 		skipmeta = 1;
    495      1.35       chs 
    496      1.20      fvdl loop:
    497      1.94        ad 	mutex_enter(&bufcache_lock);
    498      1.94        ad 	LIST_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs) {
    499      1.94        ad 		bp->b_cflags &= ~BC_SCANNED;
    500      1.94        ad 	}
    501      1.29   mycroft 	for (bp = LIST_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
    502      1.29   mycroft 		nbp = LIST_NEXT(bp, b_vnbufs);
    503      1.94        ad 		if (bp->b_cflags & (BC_BUSY | BC_SCANNED))
    504      1.20      fvdl 			continue;
    505      1.94        ad 		if ((bp->b_oflags & BO_DELWRI) == 0)
    506      1.20      fvdl 			panic("ffs_fsync: not dirty");
    507      1.94        ad 		if (skipmeta && bp->b_lblkno < 0)
    508      1.20      fvdl 			continue;
    509      1.94        ad 		bp->b_cflags |= BC_BUSY | BC_VFLUSH | BC_SCANNED;
    510      1.94        ad 		mutex_exit(&bufcache_lock);
    511      1.20      fvdl 		/*
    512      1.20      fvdl 		 * On our final pass through, do all I/O synchronously
    513      1.20      fvdl 		 * so that we can find out if our flush is failing
    514      1.20      fvdl 		 * because of write errors.
    515      1.20      fvdl 		 */
    516      1.94        ad 		if (passes > 0 || !(flags & FSYNC_WAIT))
    517      1.20      fvdl 			(void) bawrite(bp);
    518      1.20      fvdl 		else if ((error = bwrite(bp)) != 0)
    519      1.20      fvdl 			return (error);
    520      1.20      fvdl 		/*
    521      1.94        ad 		 * Since we unlocked during the I/O, we need
    522      1.20      fvdl 		 * to start from a known point.
    523      1.20      fvdl 		 */
    524      1.94        ad 		mutex_enter(&bufcache_lock);
    525      1.29   mycroft 		nbp = LIST_FIRST(&vp->v_dirtyblkhd);
    526      1.20      fvdl 	}
    527      1.94        ad 	mutex_exit(&bufcache_lock);
    528      1.61    kleink 	if (skipmeta) {
    529      1.20      fvdl 		skipmeta = 0;
    530      1.20      fvdl 		goto loop;
    531      1.20      fvdl 	}
    532      1.94        ad 
    533      1.94        ad 	if (flags & FSYNC_WAIT) {
    534      1.94        ad 		mutex_enter(&vp->v_interlock);
    535      1.20      fvdl 		while (vp->v_numoutput) {
    536      1.94        ad 			cv_wait(&vp->v_cv, &vp->v_interlock);
    537      1.20      fvdl 		}
    538      1.94        ad 		mutex_exit(&vp->v_interlock);
    539      1.20      fvdl 
    540      1.69     perry 		/*
    541      1.20      fvdl 		 * Ensure that any filesystem metadata associated
    542      1.20      fvdl 		 * with the vnode has been written.
    543      1.20      fvdl 		 */
    544      1.94        ad 		if ((error = softdep_sync_metadata(vp)) != 0)
    545      1.20      fvdl 			return (error);
    546      1.29   mycroft 
    547      1.29   mycroft 		if (!LIST_EMPTY(&vp->v_dirtyblkhd)) {
    548      1.29   mycroft 			/*
    549      1.29   mycroft 			* Block devices associated with filesystems may
    550      1.29   mycroft 			* have new I/O requests posted for them even if
    551      1.29   mycroft 			* the vnode is locked, so no amount of trying will
    552      1.29   mycroft 			* get them clean. Thus we give block devices a
    553      1.29   mycroft 			* good effort, then just give up. For all other file
    554      1.29   mycroft 			* types, go around and try again until it is clean.
    555      1.29   mycroft 			*/
    556      1.29   mycroft 			if (passes > 0) {
    557      1.29   mycroft 				passes--;
    558      1.29   mycroft 				goto loop;
    559      1.29   mycroft 			}
    560      1.20      fvdl #ifdef DIAGNOSTIC
    561      1.29   mycroft 			if (vp->v_type != VBLK)
    562      1.29   mycroft 				vprint("ffs_fsync: dirty", vp);
    563      1.20      fvdl #endif
    564      1.29   mycroft 		}
    565      1.29   mycroft 	}
    566      1.47      fvdl 
    567      1.47      fvdl 	if (inodedeps_only)
    568      1.47      fvdl 		waitfor = 0;
    569      1.47      fvdl 	else
    570      1.94        ad 		waitfor = (flags & FSYNC_WAIT) ? UPDATE_WAIT : 0;
    571      1.99        ad 
    572      1.99        ad 	if (vp->v_tag == VT_UFS)
    573      1.99        ad 		error = ffs_update(vp, NULL, NULL, waitfor);
    574      1.99        ad 	else {
    575      1.99        ad 		KASSERT(vp->v_type == VBLK);
    576      1.99        ad 		KASSERT((flags & FSYNC_VFS) != 0);
    577      1.99        ad 	}
    578      1.67  wrstuden 
    579      1.94        ad 	if (error == 0 && flags & FSYNC_CACHE) {
    580      1.67  wrstuden 		int i = 0;
    581  1.99.2.1  wrstuden 		if ((flags & FSYNC_VFS) == 0) {
    582  1.99.2.1  wrstuden 			KASSERT(VTOI(vp) != NULL);
    583      1.99        ad 			vp = VTOI(vp)->i_devvp;
    584  1.99.2.1  wrstuden 		}
    585      1.99        ad 		VOP_IOCTL(vp, DIOCCACHESYNC, &i, FWRITE, curlwp->l_cred);
    586      1.67  wrstuden 	}
    587      1.67  wrstuden 
    588      1.67  wrstuden 	return error;
    589      1.20      fvdl }
    590       1.1   mycroft 
    591       1.1   mycroft /*
    592       1.1   mycroft  * Reclaim an inode so that it can be used for other purposes.
    593       1.1   mycroft  */
    594       1.1   mycroft int
    595      1.70   thorpej ffs_reclaim(void *v)
    596       1.6  christos {
    597       1.1   mycroft 	struct vop_reclaim_args /* {
    598       1.1   mycroft 		struct vnode *a_vp;
    599      1.77  christos 		struct lwp *a_l;
    600       1.6  christos 	} */ *ap = v;
    601      1.26  augustss 	struct vnode *vp = ap->a_vp;
    602      1.56      fvdl 	struct inode *ip = VTOI(vp);
    603      1.84   hannken 	struct mount *mp = vp->v_mount;
    604      1.56      fvdl 	struct ufsmount *ump = ip->i_ump;
    605      1.94        ad 	void *data;
    606       1.1   mycroft 	int error;
    607       1.1   mycroft 
    608      1.87   hannken 	fstrans_start(mp, FSTRANS_LAZY);
    609      1.93     pooka 	if ((error = ufs_reclaim(vp)) != 0) {
    610      1.84   hannken 		fstrans_done(mp);
    611       1.1   mycroft 		return (error);
    612      1.84   hannken 	}
    613      1.57      fvdl 	if (ip->i_din.ffs1_din != NULL) {
    614      1.57      fvdl 		if (ump->um_fstype == UFS1)
    615      1.95        ad 			pool_cache_put(ffs_dinode1_cache, ip->i_din.ffs1_din);
    616      1.57      fvdl 		else
    617      1.95        ad 			pool_cache_put(ffs_dinode2_cache, ip->i_din.ffs2_din);
    618      1.57      fvdl 	}
    619      1.16   thorpej 	/*
    620      1.94        ad 	 * To interlock with ffs_sync().
    621      1.94        ad 	 */
    622      1.94        ad 	genfs_node_destroy(vp);
    623      1.94        ad 	mutex_enter(&vp->v_interlock);
    624      1.94        ad 	data = vp->v_data;
    625      1.94        ad 	vp->v_data = NULL;
    626      1.94        ad 	mutex_exit(&vp->v_interlock);
    627      1.94        ad 
    628      1.94        ad 	/*
    629      1.16   thorpej 	 * XXX MFS ends up here, too, to free an inode.  Should we create
    630      1.16   thorpej 	 * XXX a separate pool for MFS inodes?
    631      1.16   thorpej 	 */
    632      1.95        ad 	pool_cache_put(ffs_inode_cache, data);
    633      1.84   hannken 	fstrans_done(mp);
    634       1.1   mycroft 	return (0);
    635      1.35       chs }
    636      1.35       chs 
    637      1.88      yamt #if 0
    638      1.39       chs int
    639      1.39       chs ffs_getpages(void *v)
    640      1.39       chs {
    641      1.39       chs 	struct vop_getpages_args /* {
    642      1.39       chs 		struct vnode *a_vp;
    643      1.39       chs 		voff_t a_offset;
    644      1.39       chs 		struct vm_page **a_m;
    645      1.39       chs 		int *a_count;
    646      1.39       chs 		int a_centeridx;
    647      1.39       chs 		vm_prot_t a_access_type;
    648      1.39       chs 		int a_advice;
    649      1.39       chs 		int a_flags;
    650      1.39       chs 	} */ *ap = v;
    651      1.39       chs 	struct vnode *vp = ap->a_vp;
    652      1.39       chs 	struct inode *ip = VTOI(vp);
    653      1.39       chs 	struct fs *fs = ip->i_fs;
    654      1.39       chs 
    655      1.39       chs 	/*
    656      1.39       chs 	 * don't allow a softdep write to create pages for only part of a block.
    657      1.39       chs 	 * the dependency tracking requires that all pages be in memory for
    658      1.39       chs 	 * a block involved in a dependency.
    659      1.39       chs 	 */
    660      1.39       chs 
    661      1.39       chs 	if (ap->a_flags & PGO_OVERWRITE &&
    662      1.39       chs 	    (blkoff(fs, ap->a_offset) != 0 ||
    663      1.39       chs 	     blkoff(fs, *ap->a_count << PAGE_SHIFT) != 0) &&
    664      1.39       chs 	    DOINGSOFTDEP(ap->a_vp)) {
    665      1.39       chs 		if ((ap->a_flags & PGO_LOCKED) == 0) {
    666      1.94        ad 			mutex_exit(&vp->v_interlock);
    667      1.39       chs 		}
    668      1.39       chs 		return EINVAL;
    669      1.39       chs 	}
    670      1.39       chs 	return genfs_getpages(v);
    671      1.49       chs }
    672      1.88      yamt #endif
    673      1.49       chs 
    674      1.35       chs /*
    675      1.35       chs  * Return the last logical file offset that should be written for this file
    676      1.35       chs  * if we're doing a write that ends at "size".
    677      1.35       chs  */
    678      1.39       chs 
    679      1.39       chs void
    680      1.83  christos ffs_gop_size(struct vnode *vp, off_t size, off_t *eobp, int flags)
    681      1.35       chs {
    682      1.39       chs 	struct inode *ip = VTOI(vp);
    683      1.35       chs 	struct fs *fs = ip->i_fs;
    684      1.52      fvdl 	daddr_t olbn, nlbn;
    685      1.55  perseant 
    686      1.56      fvdl 	olbn = lblkno(fs, ip->i_size);
    687      1.39       chs 	nlbn = lblkno(fs, size);
    688      1.35       chs 	if (nlbn < NDADDR && olbn <= nlbn) {
    689      1.39       chs 		*eobp = fragroundup(fs, size);
    690      1.35       chs 	} else {
    691      1.39       chs 		*eobp = blkroundup(fs, size);
    692      1.35       chs 	}
    693       1.1   mycroft }
    694      1.73   thorpej 
    695      1.73   thorpej int
    696  1.99.2.1  wrstuden ffs_gop_write(struct vnode *vp, struct vm_page **pgs, int npages, int flags)
    697  1.99.2.1  wrstuden {
    698  1.99.2.1  wrstuden 	int error;
    699  1.99.2.1  wrstuden 	const bool need_wapbl = (curlwp != uvm.pagedaemon_lwp &&
    700  1.99.2.1  wrstuden 	    vp->v_mount->mnt_wapbl && (flags & PGO_JOURNALLOCKED) == 0);
    701  1.99.2.1  wrstuden 
    702  1.99.2.1  wrstuden 	if (need_wapbl) {
    703  1.99.2.1  wrstuden 		error = UFS_WAPBL_BEGIN(vp->v_mount);
    704  1.99.2.1  wrstuden 		if (error)
    705  1.99.2.1  wrstuden 			return error;
    706  1.99.2.1  wrstuden 	}
    707  1.99.2.1  wrstuden 	error = genfs_gop_write(vp, pgs, npages, flags);
    708  1.99.2.1  wrstuden 	if (need_wapbl)
    709  1.99.2.1  wrstuden 		UFS_WAPBL_END(vp->v_mount);
    710  1.99.2.1  wrstuden 	return error;
    711  1.99.2.1  wrstuden }
    712  1.99.2.1  wrstuden 
    713  1.99.2.1  wrstuden int
    714      1.73   thorpej ffs_openextattr(void *v)
    715      1.73   thorpej {
    716      1.73   thorpej 	struct vop_openextattr_args /* {
    717      1.73   thorpej 		struct vnode *a_vp;
    718      1.80      elad 		kauth_cred_t a_cred;
    719      1.73   thorpej 		struct proc *a_p;
    720      1.73   thorpej 	} */ *ap = v;
    721      1.73   thorpej 	struct inode *ip = VTOI(ap->a_vp);
    722      1.73   thorpej 	struct fs *fs = ip->i_fs;
    723      1.73   thorpej 
    724      1.73   thorpej 	/* Not supported for UFS1 file systems. */
    725      1.73   thorpej 	if (fs->fs_magic == FS_UFS1_MAGIC)
    726      1.73   thorpej 		return (EOPNOTSUPP);
    727      1.73   thorpej 
    728      1.73   thorpej 	/* XXX Not implemented for UFS2 file systems. */
    729      1.73   thorpej 	return (EOPNOTSUPP);
    730      1.73   thorpej }
    731      1.73   thorpej 
    732      1.73   thorpej int
    733      1.73   thorpej ffs_closeextattr(void *v)
    734      1.73   thorpej {
    735      1.73   thorpej 	struct vop_closeextattr_args /* {
    736      1.73   thorpej 		struct vnode *a_vp;
    737      1.73   thorpej 		int a_commit;
    738      1.80      elad 		kauth_cred_t a_cred;
    739      1.73   thorpej 		struct proc *a_p;
    740      1.73   thorpej 	} */ *ap = v;
    741      1.73   thorpej 	struct inode *ip = VTOI(ap->a_vp);
    742      1.73   thorpej 	struct fs *fs = ip->i_fs;
    743      1.73   thorpej 
    744      1.73   thorpej 	/* Not supported for UFS1 file systems. */
    745      1.73   thorpej 	if (fs->fs_magic == FS_UFS1_MAGIC)
    746      1.73   thorpej 		return (EOPNOTSUPP);
    747      1.73   thorpej 
    748      1.73   thorpej 	/* XXX Not implemented for UFS2 file systems. */
    749      1.73   thorpej 	return (EOPNOTSUPP);
    750      1.73   thorpej }
    751      1.73   thorpej 
    752      1.73   thorpej int
    753      1.73   thorpej ffs_getextattr(void *v)
    754      1.73   thorpej {
    755      1.73   thorpej 	struct vop_getextattr_args /* {
    756      1.73   thorpej 		struct vnode *a_vp;
    757      1.73   thorpej 		int a_attrnamespace;
    758      1.73   thorpej 		const char *a_name;
    759      1.73   thorpej 		struct uio *a_uio;
    760      1.73   thorpej 		size_t *a_size;
    761      1.80      elad 		kauth_cred_t a_cred;
    762      1.73   thorpej 		struct proc *a_p;
    763      1.73   thorpej 	} */ *ap = v;
    764      1.84   hannken 	struct vnode *vp = ap->a_vp;
    765      1.84   hannken 	struct inode *ip = VTOI(vp);
    766      1.73   thorpej 	struct fs *fs = ip->i_fs;
    767      1.73   thorpej 
    768      1.73   thorpej 	if (fs->fs_magic == FS_UFS1_MAGIC) {
    769      1.73   thorpej #ifdef UFS_EXTATTR
    770      1.84   hannken 		int error;
    771      1.84   hannken 
    772      1.87   hannken 		fstrans_start(vp->v_mount, FSTRANS_SHARED);
    773      1.84   hannken 		error = ufs_getextattr(ap);
    774      1.84   hannken 		fstrans_done(vp->v_mount);
    775      1.84   hannken 		return error;
    776      1.73   thorpej #else
    777      1.73   thorpej 		return (EOPNOTSUPP);
    778      1.73   thorpej #endif
    779      1.73   thorpej 	}
    780      1.73   thorpej 
    781      1.73   thorpej 	/* XXX Not implemented for UFS2 file systems. */
    782      1.73   thorpej 	return (EOPNOTSUPP);
    783      1.73   thorpej }
    784      1.73   thorpej 
    785      1.73   thorpej int
    786      1.73   thorpej ffs_setextattr(void *v)
    787      1.73   thorpej {
    788      1.73   thorpej 	struct vop_setextattr_args /* {
    789      1.73   thorpej 		struct vnode *a_vp;
    790      1.73   thorpej 		int a_attrnamespace;
    791      1.73   thorpej 		const char *a_name;
    792      1.73   thorpej 		struct uio *a_uio;
    793      1.80      elad 		kauth_cred_t a_cred;
    794      1.73   thorpej 		struct proc *a_p;
    795      1.73   thorpej 	} */ *ap = v;
    796      1.84   hannken 	struct vnode *vp = ap->a_vp;
    797      1.84   hannken 	struct inode *ip = VTOI(vp);
    798      1.73   thorpej 	struct fs *fs = ip->i_fs;
    799      1.73   thorpej 
    800      1.73   thorpej 	if (fs->fs_magic == FS_UFS1_MAGIC) {
    801      1.73   thorpej #ifdef UFS_EXTATTR
    802      1.84   hannken 		int error;
    803      1.84   hannken 
    804      1.87   hannken 		fstrans_start(vp->v_mount, FSTRANS_SHARED);
    805      1.84   hannken 		error = ufs_setextattr(ap);
    806      1.84   hannken 		fstrans_done(vp->v_mount);
    807      1.84   hannken 		return error;
    808      1.73   thorpej #else
    809      1.73   thorpej 		return (EOPNOTSUPP);
    810      1.73   thorpej #endif
    811      1.73   thorpej 	}
    812      1.73   thorpej 
    813      1.73   thorpej 	/* XXX Not implemented for UFS2 file systems. */
    814      1.73   thorpej 	return (EOPNOTSUPP);
    815      1.73   thorpej }
    816      1.73   thorpej 
    817      1.73   thorpej int
    818      1.73   thorpej ffs_listextattr(void *v)
    819      1.73   thorpej {
    820      1.73   thorpej 	struct vop_listextattr_args /* {
    821      1.73   thorpej 		struct vnode *a_vp;
    822      1.73   thorpej 		int a_attrnamespace;
    823      1.73   thorpej 		struct uio *a_uio;
    824      1.73   thorpej 		size_t *a_size;
    825      1.80      elad 		kauth_cred_t a_cred;
    826      1.73   thorpej 		struct proc *a_p;
    827      1.73   thorpej 	} */ *ap = v;
    828      1.73   thorpej 	struct inode *ip = VTOI(ap->a_vp);
    829      1.73   thorpej 	struct fs *fs = ip->i_fs;
    830      1.73   thorpej 
    831      1.73   thorpej 	/* Not supported for UFS1 file systems. */
    832      1.73   thorpej 	if (fs->fs_magic == FS_UFS1_MAGIC)
    833      1.73   thorpej 		return (EOPNOTSUPP);
    834      1.73   thorpej 
    835      1.73   thorpej 	/* XXX Not implemented for UFS2 file systems. */
    836      1.73   thorpej 	return (EOPNOTSUPP);
    837      1.73   thorpej }
    838      1.73   thorpej 
    839      1.73   thorpej int
    840      1.73   thorpej ffs_deleteextattr(void *v)
    841      1.73   thorpej {
    842      1.73   thorpej 	struct vop_deleteextattr_args /* {
    843      1.73   thorpej 		struct vnode *a_vp;
    844      1.73   thorpej 		int a_attrnamespace;
    845      1.80      elad 		kauth_cred_t a_cred;
    846      1.73   thorpej 		struct proc *a_p;
    847      1.73   thorpej 	} */ *ap = v;
    848      1.84   hannken 	struct vnode *vp = ap->a_vp;
    849      1.84   hannken 	struct inode *ip = VTOI(vp);
    850      1.73   thorpej 	struct fs *fs = ip->i_fs;
    851      1.73   thorpej 
    852      1.73   thorpej 	if (fs->fs_magic == FS_UFS1_MAGIC) {
    853      1.73   thorpej #ifdef UFS_EXTATTR
    854      1.84   hannken 		int error;
    855      1.84   hannken 
    856      1.87   hannken 		fstrans_start(vp->v_mount, FSTRANS_SHARED);
    857      1.84   hannken 		error = ufs_deleteextattr(ap);
    858      1.84   hannken 		fstrans_done(vp->v_mount);
    859      1.84   hannken 		return error;
    860      1.73   thorpej #else
    861      1.73   thorpej 		return (EOPNOTSUPP);
    862      1.73   thorpej #endif
    863      1.73   thorpej 	}
    864      1.73   thorpej 
    865      1.73   thorpej 	/* XXX Not implemented for UFS2 file systems. */
    866      1.73   thorpej 	return (EOPNOTSUPP);
    867      1.73   thorpej }
    868      1.90   hannken 
    869      1.90   hannken /*
    870      1.90   hannken  * Lock the node.
    871      1.90   hannken  */
    872      1.90   hannken int
    873      1.90   hannken ffs_lock(void *v)
    874      1.90   hannken {
    875      1.90   hannken 	struct vop_lock_args /* {
    876      1.90   hannken 		struct vnode *a_vp;
    877      1.90   hannken 		int a_flags;
    878      1.90   hannken 	} */ *ap = v;
    879      1.90   hannken 	struct vnode *vp = ap->a_vp;
    880      1.90   hannken 	struct mount *mp = vp->v_mount;
    881      1.91   hannken 	int flags = ap->a_flags;
    882      1.90   hannken 
    883      1.98        ad 	if ((flags & LK_INTERLOCK) != 0) {
    884      1.98        ad 		mutex_exit(&vp->v_interlock);
    885      1.98        ad 		flags &= ~LK_INTERLOCK;
    886      1.98        ad 	}
    887      1.98        ad 
    888      1.90   hannken 	/*
    889      1.90   hannken 	 * Fake lock during file system suspension.
    890      1.90   hannken 	 */
    891      1.90   hannken 	if ((vp->v_type == VREG || vp->v_type == VDIR) &&
    892      1.90   hannken 	    fstrans_is_owner(mp) &&
    893      1.90   hannken 	    fstrans_getstate(mp) == FSTRANS_SUSPENDING) {
    894      1.90   hannken 		return 0;
    895      1.90   hannken 	}
    896      1.91   hannken 
    897  1.99.2.1  wrstuden 	return (vlockmgr(vp->v_vnlock, flags));
    898      1.90   hannken }
    899      1.90   hannken 
    900      1.90   hannken /*
    901      1.90   hannken  * Unlock the node.
    902      1.90   hannken  */
    903      1.90   hannken int
    904      1.90   hannken ffs_unlock(void *v)
    905      1.90   hannken {
    906      1.90   hannken 	struct vop_unlock_args /* {
    907      1.90   hannken 		struct vnode *a_vp;
    908      1.90   hannken 		int a_flags;
    909      1.90   hannken 	} */ *ap = v;
    910      1.90   hannken 	struct vnode *vp = ap->a_vp;
    911      1.90   hannken 	struct mount *mp = vp->v_mount;
    912      1.90   hannken 
    913      1.98        ad 	KASSERT(ap->a_flags == 0);
    914      1.98        ad 
    915      1.90   hannken 	/*
    916      1.90   hannken 	 * Fake unlock during file system suspension.
    917      1.90   hannken 	 */
    918      1.90   hannken 	if ((vp->v_type == VREG || vp->v_type == VDIR) &&
    919      1.90   hannken 	    fstrans_is_owner(mp) &&
    920      1.90   hannken 	    fstrans_getstate(mp) == FSTRANS_SUSPENDING) {
    921      1.90   hannken 		return 0;
    922      1.90   hannken 	}
    923      1.98        ad 	return (vlockmgr(vp->v_vnlock, LK_RELEASE));
    924      1.90   hannken }
    925      1.90   hannken 
    926      1.90   hannken /*
    927      1.90   hannken  * Return whether or not the node is locked.
    928      1.90   hannken  */
    929      1.90   hannken int
    930      1.90   hannken ffs_islocked(void *v)
    931      1.90   hannken {
    932      1.90   hannken 	struct vop_islocked_args /* {
    933      1.90   hannken 		struct vnode *a_vp;
    934      1.90   hannken 	} */ *ap = v;
    935      1.90   hannken 	struct vnode *vp = ap->a_vp;
    936      1.90   hannken 
    937      1.98        ad 	return (vlockstatus(vp->v_vnlock));
    938      1.90   hannken }
    939