1139776Simp/*-
21541Srgrimes * Copyright (c) 1989, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 4. Neither the name of the University nor the names of its contributors
141541Srgrimes *    may be used to endorse or promote products derived from this software
151541Srgrimes *    without specific prior written permission.
161541Srgrimes *
171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271541Srgrimes * SUCH DAMAGE.
281541Srgrimes *
291541Srgrimes *	@(#)dead_vnops.c	8.1 (Berkeley) 6/10/93
3050477Speter * $FreeBSD: releng/11.0/sys/fs/deadfs/dead_vnops.c 273132 2014-10-15 13:22:33Z kib $
311541Srgrimes */
321541Srgrimes
331541Srgrimes#include <sys/param.h>
341541Srgrimes#include <sys/systm.h>
352946Swollman#include <sys/kernel.h>
3631561Sbde#include <sys/lock.h>
3776166Smarkm#include <sys/mutex.h>
3876166Smarkm#include <sys/poll.h>
391541Srgrimes#include <sys/vnode.h>
401541Srgrimes
411541Srgrimes/*
421541Srgrimes * Prototypes for dead operations on vnodes.
431541Srgrimes */
44138270Sphkstatic vop_lookup_t	dead_lookup;
45138270Sphkstatic vop_open_t	dead_open;
46155896Sjeffstatic vop_getwritemount_t dead_getwritemount;
47166167Skibstatic vop_rename_t	dead_rename;
481541Srgrimes
49138290Sphkstruct vop_vector dead_vnodeops = {
50138290Sphk	.vop_default =		&default_vnodeops,
51140196Sphk
52138290Sphk	.vop_access =		VOP_EBADF,
53138290Sphk	.vop_advlock =		VOP_EBADF,
54240464Skib	.vop_bmap =		VOP_EBADF,
55138290Sphk	.vop_create =		VOP_PANIC,
56138290Sphk	.vop_getattr =		VOP_EBADF,
57155896Sjeff	.vop_getwritemount =	dead_getwritemount,
58138290Sphk	.vop_inactive =		VOP_NULL,
59240464Skib	.vop_ioctl =		VOP_EBADF,
60138290Sphk	.vop_link =		VOP_PANIC,
61138290Sphk	.vop_lookup =		dead_lookup,
62138290Sphk	.vop_mkdir =		VOP_PANIC,
63138290Sphk	.vop_mknod =		VOP_PANIC,
64138290Sphk	.vop_open =		dead_open,
65138290Sphk	.vop_pathconf =		VOP_EBADF,	/* per pathconf(2) */
66138290Sphk	.vop_poll =		dead_poll,
67138290Sphk	.vop_read =		dead_read,
68138290Sphk	.vop_readdir =		VOP_EBADF,
69138290Sphk	.vop_readlink =		VOP_EBADF,
70138290Sphk	.vop_reclaim =		VOP_NULL,
71138290Sphk	.vop_remove =		VOP_PANIC,
72166167Skib	.vop_rename =		dead_rename,
73138290Sphk	.vop_rmdir =		VOP_PANIC,
74138290Sphk	.vop_setattr =		VOP_EBADF,
75138290Sphk	.vop_symlink =		VOP_PANIC,
76185958Smarcus	.vop_vptocnp =		VOP_EBADF,
77138290Sphk	.vop_write =		dead_write,
781541Srgrimes};
791541Srgrimes
80155896Sjeffstatic int
81273132Skibdead_getwritemount(struct vop_getwritemount_args *ap)
82155896Sjeff{
83273132Skib
84155896Sjeff	*(ap->a_mpp) = NULL;
85155896Sjeff	return (0);
86155896Sjeff}
87155896Sjeff
881541Srgrimes/*
891541Srgrimes * Trivial lookup routine that always fails.
901541Srgrimes */
9112570Sphkstatic int
92273132Skibdead_lookup(struct vop_lookup_args *ap)
931541Srgrimes{
941541Srgrimes
951541Srgrimes	*ap->a_vpp = NULL;
961541Srgrimes	return (ENOTDIR);
971541Srgrimes}
981541Srgrimes
991541Srgrimes/*
1001541Srgrimes * Open always fails as if device did not exist.
1011541Srgrimes */
10212570Sphkstatic int
103273132Skibdead_open(struct vop_open_args *ap)
1041541Srgrimes{
1051541Srgrimes
1061541Srgrimes	return (ENXIO);
1071541Srgrimes}
1081541Srgrimes
109273131Skibint
110273132Skibdead_read(struct vop_read_args *ap)
1111541Srgrimes{
112273132Skib
1131541Srgrimes	/*
11422521Sdyson	 * Return EOF for tty devices, EIO for others
11522521Sdyson	 */
116101308Sjeff	if ((ap->a_vp->v_vflag & VV_ISTTY) == 0)
11722521Sdyson		return (EIO);
1181541Srgrimes	return (0);
1191541Srgrimes}
1201541Srgrimes
121273131Skibint
122273132Skibdead_write(struct vop_write_args *ap)
1231541Srgrimes{
124273132Skib
1251541Srgrimes	return (EIO);
1261541Srgrimes}
1271541Srgrimes
128273131Skibint
129273132Skibdead_poll(struct vop_poll_args *ap)
13031727Swollman{
131273130Skib
132273130Skib	if (ap->a_events & ~POLLSTANDARD)
133273130Skib		return (POLLNVAL);
134273130Skib
135273130Skib	/*
136273130Skib	 * Let the user find out that the descriptor is gone.
137273130Skib	 */
138273130Skib	return (POLLHUP | ((POLLIN | POLLRDNORM) & ap->a_events));
139273130Skib
14031727Swollman}
141166167Skib
142166167Skibstatic int
143273132Skibdead_rename(struct vop_rename_args *ap)
144166167Skib{
145206093Skib
146206093Skib	vop_rename_fail(ap);
147166167Skib	return (EXDEV);
148166167Skib}
149