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 * $FreeBSD: releng/12.0/sys/fs/deadfs/dead_vnops.c 326023 2017-11-20 19:43:44Z pfg $
33 */
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/lock.h>
39 #include <sys/mutex.h>
40 #include <sys/poll.h>
41 #include <sys/vnode.h>
42
43 /*
44 * Prototypes for dead operations on vnodes.
45 */
46 static vop_lookup_t dead_lookup;
47 static vop_open_t dead_open;
48 static vop_getwritemount_t dead_getwritemount;
49 static vop_rename_t dead_rename;
50
51 struct vop_vector dead_vnodeops = {
52 .vop_default = &default_vnodeops,
53
54 .vop_access = VOP_EBADF,
55 .vop_advlock = VOP_EBADF,
56 .vop_bmap = VOP_EBADF,
57 .vop_create = VOP_PANIC,
58 .vop_getattr = VOP_EBADF,
59 .vop_getwritemount = dead_getwritemount,
60 .vop_inactive = VOP_NULL,
61 .vop_ioctl = VOP_EBADF,
62 .vop_link = VOP_PANIC,
63 .vop_lookup = dead_lookup,
64 .vop_mkdir = VOP_PANIC,
65 .vop_mknod = VOP_PANIC,
66 .vop_open = dead_open,
67 .vop_pathconf = VOP_EBADF, /* per pathconf(2) */
68 .vop_poll = dead_poll,
69 .vop_read = dead_read,
70 .vop_readdir = VOP_EBADF,
71 .vop_readlink = VOP_EBADF,
72 .vop_reclaim = VOP_NULL,
73 .vop_remove = VOP_PANIC,
74 .vop_rename = dead_rename,
75 .vop_rmdir = VOP_PANIC,
76 .vop_setattr = VOP_EBADF,
77 .vop_symlink = VOP_PANIC,
78 .vop_vptocnp = VOP_EBADF,
79 .vop_write = dead_write,
80 };
81
82 static int
83 dead_getwritemount(struct vop_getwritemount_args *ap)
84 {
85
86 *(ap->a_mpp) = NULL;
87 return (0);
88 }
89
90 /*
91 * Trivial lookup routine that always fails.
92 */
93 static int
94 dead_lookup(struct vop_lookup_args *ap)
95 {
96
97 *ap->a_vpp = NULL;
98 return (ENOTDIR);
99 }
100
101 /*
102 * Open always fails as if device did not exist.
103 */
104 static int
105 dead_open(struct vop_open_args *ap)
106 {
107
108 return (ENXIO);
109 }
110
111 int
112 dead_read(struct vop_read_args *ap)
113 {
114
115 /*
116 * Return EOF for tty devices, EIO for others
117 */
118 if ((ap->a_vp->v_vflag & VV_ISTTY) == 0)
119 return (EIO);
120 return (0);
121 }
122
123 int
124 dead_write(struct vop_write_args *ap)
125 {
126
127 return (EIO);
128 }
129
130 int
131 dead_poll(struct vop_poll_args *ap)
132 {
133
134 if (ap->a_events & ~POLLSTANDARD)
135 return (POLLNVAL);
136
137 /*
138 * Let the user find out that the descriptor is gone.
139 */
140 return (POLLHUP | ((POLLIN | POLLRDNORM) & ap->a_events));
141
142 }
143
144 static int
145 dead_rename(struct vop_rename_args *ap)
146 {
147
148 vop_rename_fail(ap);
149 return (EXDEV);
150 }
Cache object: d222bf9db52eb0feb521580140eaf7b8
|