1 .\" Copyright (c) 1990 The Regents of the University of California.
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)A.t 5.1 (Berkeley) 4/16/91
38 Appendix A - Implementation Details
43 * This structure defines the control data for the memory
47 struct vnode *mfs_vnode; /* vnode associated with this mfsnode */
48 caddr_t mfs_baseoff; /* base of file system in memory */
49 long mfs_size; /* size of memory file system */
50 pid_t mfs_pid; /* supporting process pid */
51 struct buf *mfs_buflist; /* list of I/O requests */
55 * Convert between mfsnode pointers and vnode pointers
57 #define VTOMFS(vp) ((struct mfsnode *)(vp)->v_data)
58 #define MFSTOV(mfsp) ((mfsp)->mfs_vnode)
59 #define MFS_EXIT (struct buf *)-1
62 * Arguments to mount MFS
65 char *name; /* name to export for statfs */
66 caddr_t base; /* base address of file system in memory */
67 u_long size; /* size of file system */
71 * Mount an MFS filesystem.
73 mfs_mount(mp, path, data)
84 * Create a block device to represent the disk.
86 devvp = getnewvnode(VT_MFS, VBLK, &mfs_vnodeops);
89 * Save base address of the filesystem from the supporting process.
91 copyin(data, &args, (sizeof mfs_args));
92 mfsp->mfs_baseoff = args.base;
93 mfsp->mfs_size = args.size;
95 * Record the process identifier of the supporting process.
97 mfsp->mfs_pid = u.u_procp->p_pid;
99 * Mount the filesystem.
101 mfsp->mfs_buflist = NULL;
104 * Loop processing I/O requests.
106 while (mfsp->mfs_buflist != MFS_EXIT) {
107 while (mfsp->mfs_buflist != NULL) {
108 bp = mfsp->mfs_buflist;
109 mfsp->mfs_buflist = bp->av_forw;
110 offset = mfsp->mfs_baseoff + (bp->b_blkno * DEV_BSIZE);
111 if (bp->b_flags & B_READ)
112 copyin(offset, bp->b_un.b_addr, bp->b_bcount);
113 else /* write_request */
114 copyout(bp->b_un.b_addr, offset, bp->b_bcount);
117 sleep((caddr_t)devvp, PWAIT);
122 * If the MFS process requests the I/O then we must do it directly.
123 * Otherwise put the request on the list and request the MFS process
130 struct mfsnode *mfsp;
134 mfsp = VTOMFS(devvp);
135 if (mfsp->mfs_pid == u.u_procp->p_pid) {
136 offset = mfsp->mfs_baseoff + (bp->b_blkno * DEV_BSIZE);
137 if (bp->b_flags & B_READ)
138 copyin(offset, bp->b_un.b_addr, bp->b_bcount);
139 else /* write_request */
140 copyout(bp->b_un.b_addr, offset, bp->b_bcount);
143 bp->av_forw = mfsp->mfs_buflist;
144 mfsp->mfs_buflist = bp;
145 wakeup((caddr_t)bp->b_vp);
150 * The close routine is called by unmount after the filesystem
151 * has been successfully unmounted.
156 struct mfsnode *mfsp = VTOMFS(vp);
160 * Finish any pending I/O requests.
162 while (bp = mfsp->mfs_buflist) {
163 mfsp->mfs_buflist = bp->av_forw;
164 mfs_doio(bp, mfsp->mfs_baseoff);
168 * Send a request to the filesystem server to exit.
170 mfsp->mfs_buflist = MFS_EXIT;