Commit | Line | Data |
---|---|---|
23aa42f4 WJ |
1 | /* |
2 | * Copyright (c) 1989 The Regents of the University of California. | |
3 | * 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 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | * | |
33 | * @(#)mfs_vnops.c 7.22 (Berkeley) 4/16/91 | |
34 | */ | |
35 | ||
36 | #include "param.h" | |
37 | #include "systm.h" | |
38 | #include "time.h" | |
39 | #include "kernel.h" | |
40 | #include "proc.h" | |
41 | #include "buf.h" | |
42 | #include "vnode.h" | |
43 | ||
44 | #include "mfsnode.h" | |
45 | #include "mfsiom.h" | |
46 | ||
47 | #include "machine/vmparam.h" | |
48 | ||
49 | /* | |
50 | * mfs vnode operations. | |
51 | */ | |
52 | struct vnodeops mfs_vnodeops = { | |
53 | mfs_lookup, /* lookup */ | |
54 | mfs_create, /* create */ | |
55 | mfs_mknod, /* mknod */ | |
56 | mfs_open, /* open */ | |
57 | mfs_close, /* close */ | |
58 | mfs_access, /* access */ | |
59 | mfs_getattr, /* getattr */ | |
60 | mfs_setattr, /* setattr */ | |
61 | mfs_read, /* read */ | |
62 | mfs_write, /* write */ | |
63 | mfs_ioctl, /* ioctl */ | |
64 | mfs_select, /* select */ | |
65 | mfs_mmap, /* mmap */ | |
66 | mfs_fsync, /* fsync */ | |
67 | mfs_seek, /* seek */ | |
68 | mfs_remove, /* remove */ | |
69 | mfs_link, /* link */ | |
70 | mfs_rename, /* rename */ | |
71 | mfs_mkdir, /* mkdir */ | |
72 | mfs_rmdir, /* rmdir */ | |
73 | mfs_symlink, /* symlink */ | |
74 | mfs_readdir, /* readdir */ | |
75 | mfs_readlink, /* readlink */ | |
76 | mfs_abortop, /* abortop */ | |
77 | mfs_inactive, /* inactive */ | |
78 | mfs_reclaim, /* reclaim */ | |
79 | mfs_lock, /* lock */ | |
80 | mfs_unlock, /* unlock */ | |
81 | mfs_bmap, /* bmap */ | |
82 | mfs_strategy, /* strategy */ | |
83 | mfs_print, /* print */ | |
84 | mfs_islocked, /* islocked */ | |
85 | mfs_advlock, /* advlock */ | |
86 | }; | |
87 | ||
88 | /* | |
89 | * Vnode Operations. | |
90 | * | |
91 | * Open called to allow memory filesystem to initialize and | |
92 | * validate before actual IO. Record our process identifier | |
93 | * so we can tell when we are doing I/O to ourself. | |
94 | */ | |
95 | /* ARGSUSED */ | |
96 | mfs_open(vp, mode, cred, p) | |
97 | register struct vnode *vp; | |
98 | int mode; | |
99 | struct ucred *cred; | |
100 | struct proc *p; | |
101 | { | |
102 | ||
103 | if (vp->v_type != VBLK) { | |
104 | panic("mfs_ioctl not VBLK"); | |
105 | /* NOTREACHED */ | |
106 | } | |
107 | return (0); | |
108 | } | |
109 | ||
110 | /* | |
111 | * Ioctl operation. | |
112 | */ | |
113 | /* ARGSUSED */ | |
114 | mfs_ioctl(vp, com, data, fflag, cred, p) | |
115 | struct vnode *vp; | |
116 | int com; | |
117 | caddr_t data; | |
118 | int fflag; | |
119 | struct ucred *cred; | |
120 | struct proc *p; | |
121 | { | |
122 | ||
123 | return (-1); | |
124 | } | |
125 | ||
126 | /* | |
127 | * Pass I/O requests to the memory filesystem process. | |
128 | */ | |
129 | mfs_strategy(bp) | |
130 | register struct buf *bp; | |
131 | { | |
132 | register struct mfsnode *mfsp; | |
133 | struct vnode *vp; | |
134 | struct proc *p = curproc; /* XXX */ | |
135 | ||
136 | if (vfinddev(bp->b_dev, VBLK, &vp) || vp->v_usecount == 0) | |
137 | panic("mfs_strategy: bad dev"); | |
138 | mfsp = VTOMFS(vp); | |
139 | if (mfsp->mfs_pid == p->p_pid) { | |
140 | mfs_doio(bp, mfsp->mfs_baseoff); | |
141 | } else { | |
142 | bp->av_forw = mfsp->mfs_buflist; | |
143 | mfsp->mfs_buflist = bp; | |
144 | wakeup((caddr_t)vp); | |
145 | } | |
146 | return (0); | |
147 | } | |
148 | ||
149 | /* | |
150 | * Memory file system I/O. | |
151 | * | |
152 | * Trivial since buffer has already been mapping into KVA space. | |
153 | */ | |
154 | mfs_doio(bp, base) | |
155 | register struct buf *bp; | |
156 | caddr_t base; | |
157 | { | |
158 | base += (bp->b_blkno << DEV_BSHIFT); | |
159 | if (bp->b_flags & B_READ) | |
160 | bp->b_error = copyin(base, bp->b_un.b_addr, bp->b_bcount); | |
161 | else | |
162 | bp->b_error = copyout(bp->b_un.b_addr, base, bp->b_bcount); | |
163 | if (bp->b_error) | |
164 | bp->b_flags |= B_ERROR; | |
165 | biodone(bp); | |
166 | } | |
167 | ||
168 | /* | |
169 | * This is a noop, simply returning what one has been given. | |
170 | */ | |
171 | mfs_bmap(vp, bn, vpp, bnp) | |
172 | struct vnode *vp; | |
173 | daddr_t bn; | |
174 | struct vnode **vpp; | |
175 | daddr_t *bnp; | |
176 | { | |
177 | ||
178 | if (vpp != NULL) | |
179 | *vpp = vp; | |
180 | if (bnp != NULL) | |
181 | *bnp = bn; | |
182 | return (0); | |
183 | } | |
184 | ||
185 | /* | |
186 | * Memory filesystem close routine | |
187 | */ | |
188 | /* ARGSUSED */ | |
189 | mfs_close(vp, flag, cred, p) | |
190 | register struct vnode *vp; | |
191 | int flag; | |
192 | struct ucred *cred; | |
193 | struct proc *p; | |
194 | { | |
195 | register struct mfsnode *mfsp = VTOMFS(vp); | |
196 | register struct buf *bp; | |
197 | ||
198 | /* | |
199 | * Finish any pending I/O requests. | |
200 | */ | |
201 | while (bp = mfsp->mfs_buflist) { | |
202 | mfsp->mfs_buflist = bp->av_forw; | |
203 | mfs_doio(bp, mfsp->mfs_baseoff); | |
204 | wakeup((caddr_t)bp); | |
205 | } | |
206 | /* | |
207 | * On last close of a memory filesystem | |
208 | * we must invalidate any in core blocks, so that | |
209 | * we can, free up its vnode. | |
210 | */ | |
211 | vflushbuf(vp, 0); | |
212 | if (vinvalbuf(vp, 1)) | |
213 | return (0); | |
214 | /* | |
215 | * There should be no way to have any more uses of this | |
216 | * vnode, so if we find any other uses, it is a panic. | |
217 | */ | |
218 | if (vp->v_usecount > 1) | |
219 | printf("mfs_close: ref count %d > 1\n", vp->v_usecount); | |
220 | if (vp->v_usecount > 1 || mfsp->mfs_buflist) | |
221 | panic("mfs_close"); | |
222 | /* | |
223 | * Send a request to the filesystem server to exit. | |
224 | */ | |
225 | mfsp->mfs_buflist = (struct buf *)(-1); | |
226 | wakeup((caddr_t)vp); | |
227 | return (0); | |
228 | } | |
229 | ||
230 | /* | |
231 | * Memory filesystem inactive routine | |
232 | */ | |
233 | /* ARGSUSED */ | |
234 | mfs_inactive(vp, p) | |
235 | struct vnode *vp; | |
236 | struct proc *p; | |
237 | { | |
238 | ||
239 | if (VTOMFS(vp)->mfs_buflist != (struct buf *)(-1)) | |
240 | panic("mfs_inactive: not inactive"); | |
241 | return (0); | |
242 | } | |
243 | ||
244 | /* | |
245 | * Print out the contents of an mfsnode. | |
246 | */ | |
247 | mfs_print(vp) | |
248 | struct vnode *vp; | |
249 | { | |
250 | register struct mfsnode *mfsp = VTOMFS(vp); | |
251 | ||
252 | printf("tag VT_MFS, pid %d, base %d, size %d\n", mfsp->mfs_pid, | |
253 | mfsp->mfs_baseoff, mfsp->mfs_size); | |
254 | } | |
255 | ||
256 | /* | |
257 | * Block device bad operation | |
258 | */ | |
259 | mfs_badop() | |
260 | { | |
261 | ||
262 | panic("mfs_badop called\n"); | |
263 | /* NOTREACHED */ | |
264 | } | |
265 | ||
266 | /* | |
267 | * Memory based filesystem initialization. | |
268 | */ | |
269 | mfs_init() | |
270 | { | |
271 | ||
272 | } |