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