patch(1): sync with FreeBSD to version 2.0-12u11
[dragonfly.git] / sys / vfs / deadfs / dead_vnops.c
CommitLineData
984263bc
MD
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.
dc71b7ab 13 * 3. Neither the name of the University nor the names of its contributors
984263bc
MD
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: src/sys/miscfs/deadfs/dead_vnops.c,v 1.26 1999/08/28 00:46:42 peter Exp $
08daea96 31 * $DragonFly: src/sys/vfs/deadfs/dead_vnops.c,v 1.20 2007/08/13 17:31:56 dillon Exp $
984263bc
MD
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/vnode.h>
8ddc6004 39#include <sys/fcntl.h>
984263bc 40#include <sys/buf.h>
984263bc 41
984263bc
MD
42/*
43 * Prototypes for dead operations on vnodes.
44 */
a6ee311a
RG
45static int dead_badop (void);
46static int dead_bmap (struct vop_bmap_args *);
47static int dead_ioctl (struct vop_ioctl_args *);
e62afb5f 48static int dead_lookup (struct vop_old_lookup_args *);
a6ee311a 49static int dead_open (struct vop_open_args *);
8ddc6004 50static int dead_close (struct vop_close_args *);
a6ee311a
RG
51static int dead_print (struct vop_print_args *);
52static int dead_read (struct vop_read_args *);
53static int dead_write (struct vop_write_args *);
984263bc 54
66a1ddf5
MD
55struct vop_ops dead_vnode_vops = {
56 .vop_default = vop_defaultop,
57 .vop_access = (void *)vop_ebadf,
58 .vop_advlock = (void *)vop_ebadf,
59 .vop_bmap = dead_bmap,
60 .vop_old_create = (void *)dead_badop,
61 .vop_getattr = (void *)vop_ebadf,
62 .vop_inactive = (void *)vop_null,
63 .vop_ioctl = dead_ioctl,
64 .vop_old_link = (void *)dead_badop,
65 .vop_old_lookup = dead_lookup,
66 .vop_old_mkdir = (void *)dead_badop,
67 .vop_old_mknod = (void *)dead_badop,
66a1ddf5
MD
68 .vop_open = dead_open,
69 .vop_close = dead_close,
70 .vop_pathconf = (void *)vop_ebadf, /* per pathconf(2) */
66a1ddf5
MD
71 .vop_print = dead_print,
72 .vop_read = dead_read,
73 .vop_readdir = (void *)vop_ebadf,
74 .vop_readlink = (void *)vop_ebadf,
75 .vop_reclaim = (void *)vop_null,
76 .vop_old_remove = (void *)dead_badop,
77 .vop_old_rename = (void *)dead_badop,
78 .vop_old_rmdir = (void *)dead_badop,
79 .vop_setattr = (void *)vop_ebadf,
80 .vop_old_symlink = (void *)dead_badop,
81 .vop_write = dead_write
984263bc 82};
984263bc 83
66a1ddf5
MD
84struct vop_ops *dead_vnode_vops_p = &dead_vnode_vops;
85
86VNODEOP_SET(dead_vnode_vops);
984263bc
MD
87
88/*
89 * Trivial lookup routine that always fails.
a7918111
CP
90 *
91 * dead_lookup(struct vnode *a_dvp, struct vnode **a_vpp,
92 * struct componentname *a_cnp)
984263bc
MD
93 */
94/* ARGSUSED */
95static int
e62afb5f 96dead_lookup(struct vop_old_lookup_args *ap)
984263bc 97{
984263bc
MD
98 *ap->a_vpp = NULL;
99 return (ENOTDIR);
100}
101
102/*
103 * Open always fails as if device did not exist.
a7918111
CP
104 *
105 * dead_open(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
106 * struct proc *a_p)
984263bc
MD
107 */
108/* ARGSUSED */
109static int
a7918111 110dead_open(struct vop_open_args *ap)
984263bc 111{
984263bc
MD
112 return (ENXIO);
113}
114
8ddc6004
MD
115/*
116 * Close always succeeds, and does not warn or panic if v_opencount or
117 * v_writecount is incorrect, because a forced unmount or revocation
118 * might have closed the file out from under the descriptor.
119 */
120static int
121dead_close(struct vop_close_args *ap)
122{
123 struct vnode *vp = ap->a_vp;
124
12cdc371 125 vn_lock(vp, LK_UPGRADE | LK_RETRY); /* safety */
8ddc6004
MD
126 if (vp->v_opencount > 0) {
127 if ((ap->a_fflag & FWRITE) && vp->v_writecount > 0)
12cdc371
MD
128 atomic_add_int(&vp->v_writecount, -1);
129 atomic_add_int(&vp->v_opencount, -1);
8ddc6004
MD
130 }
131 return (0);
132}
133
984263bc
MD
134/*
135 * Vnode op for read
a7918111
CP
136 *
137 * dead_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
138 * struct ucred *a_cred)
984263bc
MD
139 */
140/* ARGSUSED */
141static int
a7918111 142dead_read(struct vop_read_args *ap)
984263bc 143{
984263bc
MD
144 /*
145 * Return EOF for tty devices, EIO for others
146 */
147 if ((ap->a_vp->v_flag & VISTTY) == 0)
148 return (EIO);
149 return (0);
150}
151
152/*
153 * Vnode op for write
a7918111
CP
154 *
155 * dead_write(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
156 * struct ucred *a_cred)
984263bc
MD
157 */
158/* ARGSUSED */
159static int
a7918111 160dead_write(struct vop_write_args *ap)
984263bc 161{
984263bc
MD
162 return (EIO);
163}
164
165/*
166 * Device ioctl operation.
a7918111
CP
167 *
168 * dead_ioctl(struct vnode *a_vp, int a_command, caddr_t a_data, int a_fflag,
169 * struct ucred *a_cred, struct proc *a_p)
984263bc
MD
170 */
171/* ARGSUSED */
172static int
a7918111 173dead_ioctl(struct vop_ioctl_args *ap)
984263bc 174{
5fd012e0 175 return (ENOTTY);
984263bc
MD
176}
177
984263bc
MD
178/*
179 * Wait until the vnode has finished changing state.
a7918111 180 *
08daea96 181 * dead_bmap(struct vnode *a_vp, off_t a_loffset,
54078292 182 * off_t *a_doffsetp, int *a_runp, int *a_runb)
984263bc
MD
183 */
184static int
a7918111 185dead_bmap(struct vop_bmap_args *ap)
984263bc 186{
5fd012e0 187 return (EIO);
984263bc
MD
188}
189
190/*
191 * Print out the contents of a dead vnode.
a7918111
CP
192 *
193 * dead_print(struct vnode *a_vp)
984263bc
MD
194 */
195/* ARGSUSED */
196static int
a7918111 197dead_print(struct vop_print_args *ap)
984263bc 198{
086c1d7e 199 kprintf("tag VT_NON, dead vnode\n");
984263bc
MD
200 return (0);
201}
202
203/*
204 * Empty vnode bad operation
205 */
206static int
a7918111 207dead_badop(void)
984263bc 208{
984263bc
MD
209 panic("dead_badop called");
210 /* NOTREACHED */
211}