Home | History | Annotate | Line # | Download | only in deadfs
      1  1.67  riastrad /*	$NetBSD: dead_vnops.c,v 1.67 2022/10/26 23:39:43 riastradh Exp $	*/
      2   1.9       cgd 
      3   1.1       cgd /*
      4   1.8   mycroft  * Copyright (c) 1989, 1993
      5   1.8   mycroft  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15  1.33       agc  * 3. Neither the name of the University nor the names of its contributors
     16   1.1       cgd  *    may be used to endorse or promote products derived from this software
     17   1.1       cgd  *    without specific prior written permission.
     18   1.1       cgd  *
     19   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29   1.1       cgd  * SUCH DAMAGE.
     30   1.1       cgd  *
     31  1.13   mycroft  *	@(#)dead_vnops.c	8.2 (Berkeley) 11/21/94
     32   1.1       cgd  */
     33  1.31     lukem 
     34  1.31     lukem #include <sys/cdefs.h>
     35  1.67  riastrad __KERNEL_RCSID(0, "$NetBSD: dead_vnops.c,v 1.67 2022/10/26 23:39:43 riastradh Exp $");
     36   1.1       cgd 
     37   1.6   mycroft #include <sys/param.h>
     38   1.6   mycroft #include <sys/systm.h>
     39   1.6   mycroft #include <sys/time.h>
     40   1.6   mycroft #include <sys/vnode.h>
     41   1.6   mycroft #include <sys/errno.h>
     42   1.6   mycroft #include <sys/namei.h>
     43   1.6   mycroft #include <sys/buf.h>
     44  1.14  christos #include <sys/proc.h>
     45   1.1       cgd 
     46  1.67  riastrad #include <miscfs/deadfs/deadfs.h>
     47  1.17   mycroft #include <miscfs/genfs/genfs.h>
     48  1.17   mycroft 
     49   1.1       cgd /*
     50   1.1       cgd  * Prototypes for dead operations on vnodes.
     51   1.1       cgd  */
     52  1.52   hannken int	dead_lookup(void *);
     53  1.36   xtraeme int	dead_open(void *);
     54  1.36   xtraeme int	dead_read(void *);
     55  1.36   xtraeme int	dead_write(void *);
     56  1.36   xtraeme int	dead_ioctl(void *);
     57  1.36   xtraeme int	dead_poll(void *);
     58  1.52   hannken int	dead_remove(void *);
     59  1.52   hannken int	dead_link(void *);
     60  1.52   hannken int	dead_rename(void *);
     61  1.52   hannken int	dead_rmdir(void *);
     62  1.52   hannken int	dead_inactive(void *);
     63  1.36   xtraeme int	dead_bmap(void *);
     64  1.36   xtraeme int	dead_strategy(void *);
     65  1.36   xtraeme int	dead_print(void *);
     66  1.43     pooka int	dead_getpages(void *);
     67  1.52   hannken int	dead_putpages(void *);
     68  1.14  christos 
     69  1.42       chs int	dead_default_error(void *);
     70  1.14  christos 
     71  1.36   xtraeme int (**dead_vnodeop_p)(void *);
     72   1.8   mycroft 
     73  1.67  riastrad static const struct vnodeopv_entry_desc dead_vnodeop_entries[] = {
     74  1.42       chs 	{ &vop_default_desc, dead_default_error },
     75  1.65  dholland 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
     76  1.64  dholland 	{ &vop_parsepath_desc, genfs_parsepath },	/* parsepath */
     77  1.52   hannken 	{ &vop_lookup_desc, dead_lookup },		/* lookup */
     78  1.17   mycroft 	{ &vop_open_desc, dead_open },			/* open */
     79  1.65  dholland 	{ &vop_close_desc, genfs_nullop },		/* close */
     80  1.17   mycroft 	{ &vop_read_desc, dead_read },			/* read */
     81  1.17   mycroft 	{ &vop_write_desc, dead_write },		/* write */
     82  1.57  dholland 	{ &vop_fallocate_desc, genfs_eopnotsupp },	/* fallocate */
     83  1.57  dholland 	{ &vop_fdiscard_desc, genfs_eopnotsupp },	/* fdiscard */
     84  1.65  dholland 	{ &vop_fcntl_desc, genfs_nullop },		/* fcntl */
     85  1.17   mycroft 	{ &vop_ioctl_desc, dead_ioctl },		/* ioctl */
     86  1.19   mycroft 	{ &vop_poll_desc, dead_poll },			/* poll */
     87  1.52   hannken 	{ &vop_remove_desc, dead_remove },		/* remove */
     88  1.52   hannken 	{ &vop_link_desc, dead_link },			/* link */
     89  1.52   hannken 	{ &vop_rename_desc, dead_rename },		/* rename */
     90  1.52   hannken 	{ &vop_rmdir_desc, dead_rmdir },		/* rmdir */
     91  1.65  dholland 	{ &vop_fsync_desc, genfs_nullop },		/* fsync */
     92  1.65  dholland 	{ &vop_seek_desc, genfs_nullop },		/* seek */
     93  1.17   mycroft 	{ &vop_inactive_desc, dead_inactive },		/* inactive */
     94  1.65  dholland 	{ &vop_reclaim_desc, genfs_nullop },		/* reclaim */
     95  1.65  dholland 	{ &vop_lock_desc, genfs_deadlock },		/* lock */
     96  1.65  dholland 	{ &vop_unlock_desc, genfs_deadunlock },		/* unlock */
     97  1.17   mycroft 	{ &vop_bmap_desc, dead_bmap },			/* bmap */
     98  1.17   mycroft 	{ &vop_strategy_desc, dead_strategy },		/* strategy */
     99  1.17   mycroft 	{ &vop_print_desc, dead_print },		/* print */
    100  1.65  dholland 	{ &vop_islocked_desc, genfs_deadislocked },	/* islocked */
    101  1.65  dholland 	{ &vop_revoke_desc, genfs_nullop },		/* revoke */
    102  1.43     pooka 	{ &vop_getpages_desc, dead_getpages },		/* getpages */
    103  1.32       chs 	{ &vop_putpages_desc, dead_putpages },		/* putpages */
    104  1.32       chs 	{ NULL, NULL }
    105   1.1       cgd };
    106  1.30  jdolecek const struct vnodeopv_desc dead_vnodeop_opv_desc =
    107   1.8   mycroft 	{ &dead_vnodeop_p, dead_vnodeop_entries };
    108   1.1       cgd 
    109  1.52   hannken /* ARGSUSED */
    110   1.3    andrew int
    111  1.42       chs dead_default_error(void *v)
    112  1.14  christos {
    113   1.1       cgd 
    114  1.42       chs 	return EBADF;
    115   1.1       cgd }
    116   1.1       cgd 
    117  1.52   hannken int
    118  1.52   hannken dead_bmap(void *v)
    119  1.52   hannken {
    120  1.59  riastrad 	struct vop_bmap_args /* {
    121  1.52   hannken 		struct vnode *a_vp;
    122  1.52   hannken 		daddr_t  a_bn;
    123  1.52   hannken 		struct vnode **a_vpp;
    124  1.52   hannken 		daddr_t *a_bnp;
    125  1.52   hannken 		int *a_runp;
    126  1.59  riastrad 	} */ *ap = v;
    127  1.59  riastrad 
    128  1.59  riastrad 	(void)ap;
    129  1.52   hannken 
    130  1.52   hannken 	return (EIO);
    131  1.52   hannken }
    132  1.52   hannken 
    133  1.52   hannken int
    134  1.52   hannken dead_lookup(void *v)
    135  1.52   hannken {
    136  1.54   hannken 	struct vop_lookup_v2_args /* {
    137  1.52   hannken 		struct vnode *a_dvp;
    138  1.52   hannken 		struct vnode **a_vpp;
    139  1.52   hannken 		struct componentname *a_cnp;
    140  1.52   hannken 	} */ *ap = v;
    141  1.52   hannken 
    142  1.52   hannken 	*(ap->a_vpp) = NULL;
    143  1.52   hannken 
    144  1.55   hannken 	return ENOENT;
    145  1.52   hannken }
    146  1.52   hannken 
    147  1.14  christos int
    148  1.41  christos dead_open(void *v)
    149   1.1       cgd {
    150  1.59  riastrad 	struct vop_open_args /* {
    151  1.52   hannken 		struct vnode *a_vp;
    152  1.52   hannken 		int a_mode;
    153  1.52   hannken 		kauth_cred_t a_cred;
    154  1.59  riastrad 	} */ *ap = v;
    155  1.59  riastrad 
    156  1.59  riastrad 	(void)ap;
    157   1.1       cgd 
    158   1.1       cgd 	return (ENXIO);
    159   1.1       cgd }
    160   1.1       cgd 
    161  1.14  christos int
    162  1.48       dsl dead_read(void *v)
    163  1.14  christos {
    164   1.8   mycroft 	struct vop_read_args /* {
    165   1.8   mycroft 		struct vnode *a_vp;
    166   1.8   mycroft 		struct uio *a_uio;
    167   1.8   mycroft 		int  a_ioflag;
    168  1.39      elad 		kauth_cred_t a_cred;
    169  1.14  christos 	} */ *ap = v;
    170   1.1       cgd 
    171   1.1       cgd 	/*
    172  1.13   mycroft 	 * Return EOF for tty devices, EIO for others
    173   1.1       cgd 	 */
    174  1.45        ad 	if ((ap->a_vp->v_vflag & VV_ISTTY) == 0)
    175   1.1       cgd 		return (EIO);
    176   1.1       cgd 	return (0);
    177   1.1       cgd }
    178   1.1       cgd 
    179  1.14  christos int
    180  1.48       dsl dead_write(void *v)
    181  1.14  christos {
    182  1.59  riastrad 	struct vop_write_args /* {
    183   1.8   mycroft 		struct vnode *a_vp;
    184   1.8   mycroft 		struct uio *a_uio;
    185   1.8   mycroft 		int  a_ioflag;
    186  1.39      elad 		kauth_cred_t a_cred;
    187  1.59  riastrad 	} */ *ap = v;
    188  1.59  riastrad 
    189  1.59  riastrad 	(void)ap;
    190   1.1       cgd 
    191   1.1       cgd 	return (EIO);
    192   1.1       cgd }
    193   1.1       cgd 
    194  1.14  christos int
    195  1.48       dsl dead_ioctl(void *v)
    196  1.14  christos {
    197  1.59  riastrad 	struct vop_ioctl_args /* {
    198   1.8   mycroft 		struct vnode *a_vp;
    199  1.10       cgd 		u_long a_command;
    200  1.35       jrf 		void *a_data;
    201   1.8   mycroft 		int  a_fflag;
    202  1.39      elad 		kauth_cred_t a_cred;
    203  1.38  christos 		struct lwp *a_l;
    204  1.59  riastrad 	} */ *ap = v;
    205  1.59  riastrad 
    206  1.59  riastrad 	(void)ap;
    207   1.1       cgd 
    208  1.52   hannken 	return (EBADF);
    209   1.1       cgd }
    210   1.1       cgd 
    211  1.14  christos int
    212  1.48       dsl dead_poll(void *v)
    213   1.1       cgd {
    214  1.19   mycroft 	struct vop_poll_args /* {
    215  1.17   mycroft 		struct vnode *a_vp;
    216  1.19   mycroft 		int a_events;
    217  1.38  christos 		struct lwp *a_l;
    218  1.17   mycroft 	} */ *ap = v;
    219  1.17   mycroft 
    220   1.1       cgd 	/*
    221   1.1       cgd 	 * Let the user find out that the descriptor is gone.
    222   1.1       cgd 	 */
    223  1.19   mycroft 	return (ap->a_events);
    224   1.1       cgd }
    225   1.1       cgd 
    226  1.14  christos int
    227  1.52   hannken dead_remove(void *v)
    228  1.52   hannken {
    229  1.66   thorpej 	struct vop_remove_v3_args /* {
    230  1.52   hannken 		struct vnode *a_dvp;
    231  1.52   hannken 		struct vnode *a_vp;
    232  1.52   hannken 		struct componentname *a_cnp;
    233  1.66   thorpej 		nlink_t ctx_vp_new_nlink;
    234  1.52   hannken 	} */ *ap = v;
    235  1.52   hannken 
    236  1.52   hannken 	vput(ap->a_vp);
    237  1.52   hannken 
    238  1.52   hannken 	return EIO;
    239  1.52   hannken }
    240  1.52   hannken 
    241  1.52   hannken int
    242  1.52   hannken dead_link(void *v)
    243  1.52   hannken {
    244  1.58  riastrad 	struct vop_link_v2_args /* {
    245  1.52   hannken 		struct vnode *a_dvp;
    246  1.52   hannken 		struct vnode *a_vp;
    247  1.52   hannken 		struct componentname *a_cnp;
    248  1.52   hannken 	} */ *ap = v;
    249  1.52   hannken 
    250  1.58  riastrad 	(void)ap;
    251  1.52   hannken 
    252  1.52   hannken 	return EIO;
    253  1.52   hannken }
    254  1.52   hannken 
    255  1.52   hannken int
    256  1.52   hannken dead_rename(void *v)
    257  1.52   hannken {
    258  1.52   hannken 	struct vop_rename_args /* {
    259  1.52   hannken 		struct vnode *a_fdvp;
    260  1.52   hannken 		struct vnode *a_fvp;
    261  1.52   hannken 		struct componentname *a_fcnp;
    262  1.52   hannken 		struct vnode *a_tdvp;
    263  1.52   hannken 		struct vnode *a_tvp;
    264  1.52   hannken 		struct componentname *a_tcnp;
    265  1.52   hannken 	} */ *ap = v;
    266  1.52   hannken 
    267  1.52   hannken 	vrele(ap->a_fdvp);
    268  1.52   hannken 	vrele(ap->a_fvp);
    269  1.52   hannken 	if (ap->a_tvp != NULL && ap->a_tvp != ap->a_tdvp)
    270  1.52   hannken 		VOP_UNLOCK(ap->a_tvp);
    271  1.52   hannken 	vput(ap->a_tdvp);
    272  1.52   hannken 	if (ap->a_tvp != NULL)
    273  1.52   hannken 		vrele(ap->a_tvp);
    274  1.52   hannken 
    275  1.52   hannken 	return EIO;
    276  1.52   hannken }
    277  1.52   hannken 
    278  1.52   hannken int
    279  1.52   hannken dead_rmdir(void *v)
    280  1.52   hannken {
    281  1.61  riastrad 	struct vop_rmdir_v2_args /* {
    282  1.52   hannken 		struct vnode *a_dvp;
    283  1.34   hannken 		struct vnode *a_vp;
    284  1.52   hannken 		struct componentname *a_cnp;
    285  1.52   hannken 	} */ *ap = v;
    286  1.52   hannken 
    287  1.52   hannken 	vput(ap->a_vp);
    288  1.52   hannken 
    289  1.52   hannken 	return EIO;
    290  1.52   hannken }
    291  1.52   hannken 
    292  1.52   hannken int
    293  1.52   hannken dead_inactive(void *v)
    294  1.14  christos {
    295  1.60  riastrad 	struct vop_inactive_v2_args /* {
    296   1.8   mycroft 		struct vnode *a_vp;
    297  1.52   hannken 		bool *a_recycle;
    298  1.14  christos 	} */ *ap = v;
    299   1.1       cgd 
    300  1.52   hannken 	*ap->a_recycle = false;
    301  1.52   hannken 
    302  1.52   hannken 	return 0;
    303   1.1       cgd }
    304   1.1       cgd 
    305  1.14  christos int
    306  1.52   hannken dead_strategy(void *v)
    307  1.14  christos {
    308  1.52   hannken 	struct vop_strategy_args /* {
    309   1.8   mycroft 		struct vnode *a_vp;
    310  1.52   hannken 		struct buf *a_bp;
    311  1.14  christos 	} */ *ap = v;
    312  1.52   hannken 	struct buf *bp;
    313   1.1       cgd 
    314  1.52   hannken 	bp = ap->a_bp;
    315  1.52   hannken 	bp->b_error = EIO;
    316  1.52   hannken 	bp->b_resid = bp->b_bcount;
    317  1.52   hannken 	biodone(ap->a_bp);
    318  1.52   hannken 	return (EIO);
    319   1.1       cgd }
    320   1.1       cgd 
    321   1.1       cgd /* ARGSUSED */
    322  1.14  christos int
    323  1.41  christos dead_print(void *v)
    324   1.1       cgd {
    325  1.21  christos 	printf("tag VT_NON, dead vnode\n");
    326  1.14  christos 	return 0;
    327   1.1       cgd }
    328   1.1       cgd 
    329  1.43     pooka int
    330  1.43     pooka dead_getpages(void *v)
    331  1.43     pooka {
    332  1.43     pooka 	struct vop_getpages_args /* {
    333  1.43     pooka 		struct vnode *a_vp;
    334  1.43     pooka 		voff_t a_offset;
    335  1.43     pooka 		struct vm_page **a_m;
    336  1.43     pooka 		int *a_count;
    337  1.43     pooka 		int a_centeridx;
    338  1.43     pooka 		vm_prot_t a_access_type;
    339  1.43     pooka 		int a_advice;
    340  1.43     pooka 		int a_flags;
    341  1.43     pooka 	} */ *ap = v;
    342  1.43     pooka 
    343  1.43     pooka 	if ((ap->a_flags & PGO_LOCKED) == 0)
    344  1.63        ad 		rw_exit(ap->a_vp->v_uobj.vmobjlock);
    345  1.43     pooka 
    346  1.43     pooka 	return (EFAULT);
    347  1.43     pooka }
    348  1.43     pooka 
    349  1.14  christos int
    350  1.52   hannken dead_putpages(void *v)
    351   1.1       cgd {
    352  1.52   hannken         struct vop_putpages_args /* {
    353  1.59  riastrad 		struct vnode *a_vp;
    354  1.52   hannken 		voff_t a_offlo;
    355  1.52   hannken 		voff_t a_offhi;
    356  1.52   hannken 		int a_flags;
    357  1.52   hannken 	} */ *ap = v;
    358   1.1       cgd 
    359  1.63        ad 	rw_exit(ap->a_vp->v_uobj.vmobjlock);
    360  1.52   hannken 	return (EFAULT);
    361   1.1       cgd }
    362