xref: /freebsd/sys/fs/deadfs/dead_vnops.c (revision f4b37ed0f8b307b1f3f0f630ca725d68f1dff30d)
1 /*-
2  * Copyright (c) 1989, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 4. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  *	@(#)dead_vnops.c	8.1 (Berkeley) 6/10/93
30  * $FreeBSD$
31  */
32 
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/lock.h>
37 #include <sys/mutex.h>
38 #include <sys/poll.h>
39 #include <sys/vnode.h>
40 
41 /*
42  * Prototypes for dead operations on vnodes.
43  */
44 static vop_lookup_t	dead_lookup;
45 static vop_open_t	dead_open;
46 static vop_getwritemount_t dead_getwritemount;
47 static vop_rename_t	dead_rename;
48 
49 struct vop_vector dead_vnodeops = {
50 	.vop_default =		&default_vnodeops,
51 
52 	.vop_access =		VOP_EBADF,
53 	.vop_advlock =		VOP_EBADF,
54 	.vop_bmap =		VOP_EBADF,
55 	.vop_create =		VOP_PANIC,
56 	.vop_getattr =		VOP_EBADF,
57 	.vop_getwritemount =	dead_getwritemount,
58 	.vop_inactive =		VOP_NULL,
59 	.vop_ioctl =		VOP_EBADF,
60 	.vop_link =		VOP_PANIC,
61 	.vop_lookup =		dead_lookup,
62 	.vop_mkdir =		VOP_PANIC,
63 	.vop_mknod =		VOP_PANIC,
64 	.vop_open =		dead_open,
65 	.vop_pathconf =		VOP_EBADF,	/* per pathconf(2) */
66 	.vop_poll =		dead_poll,
67 	.vop_read =		dead_read,
68 	.vop_readdir =		VOP_EBADF,
69 	.vop_readlink =		VOP_EBADF,
70 	.vop_reclaim =		VOP_NULL,
71 	.vop_remove =		VOP_PANIC,
72 	.vop_rename =		dead_rename,
73 	.vop_rmdir =		VOP_PANIC,
74 	.vop_setattr =		VOP_EBADF,
75 	.vop_symlink =		VOP_PANIC,
76 	.vop_vptocnp =		VOP_EBADF,
77 	.vop_write =		dead_write,
78 };
79 
80 static int
81 dead_getwritemount(struct vop_getwritemount_args *ap)
82 {
83 
84 	*(ap->a_mpp) = NULL;
85 	return (0);
86 }
87 
88 /*
89  * Trivial lookup routine that always fails.
90  */
91 static int
92 dead_lookup(struct vop_lookup_args *ap)
93 {
94 
95 	*ap->a_vpp = NULL;
96 	return (ENOTDIR);
97 }
98 
99 /*
100  * Open always fails as if device did not exist.
101  */
102 static int
103 dead_open(struct vop_open_args *ap)
104 {
105 
106 	return (ENXIO);
107 }
108 
109 int
110 dead_read(struct vop_read_args *ap)
111 {
112 
113 	/*
114 	 * Return EOF for tty devices, EIO for others
115 	 */
116 	if ((ap->a_vp->v_vflag & VV_ISTTY) == 0)
117 		return (EIO);
118 	return (0);
119 }
120 
121 int
122 dead_write(struct vop_write_args *ap)
123 {
124 
125 	return (EIO);
126 }
127 
128 int
129 dead_poll(struct vop_poll_args *ap)
130 {
131 
132 	if (ap->a_events & ~POLLSTANDARD)
133 		return (POLLNVAL);
134 
135 	/*
136 	 * Let the user find out that the descriptor is gone.
137 	 */
138 	return (POLLHUP | ((POLLIN | POLLRDNORM) & ap->a_events));
139 
140 }
141 
142 static int
143 dead_rename(struct vop_rename_args *ap)
144 {
145 
146 	vop_rename_fail(ap);
147 	return (EXDEV);
148 }
149