BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / ufs / mfs_vfsops.c
CommitLineData
d37d3579 1/*
96f07863 2 * Copyright (c) 1989, 1990 The Regents of the University of California.
d37d3579
KM
3 * All rights reserved.
4 *
af359dea
C
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.
d37d3579 20 *
af359dea
C
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_vfsops.c 7.19 (Berkeley) 4/16/91
d37d3579
KM
34 */
35
36#include "param.h"
ba72b75d 37#include "time.h"
8b0349f4 38#include "kernel.h"
ba72b75d 39#include "proc.h"
d37d3579
KM
40#include "buf.h"
41#include "mount.h"
c6f5111d 42#include "signalvar.h"
d37d3579 43#include "vnode.h"
c6f5111d
MK
44
45#include "quota.h"
46#include "inode.h"
47#include "ufsmount.h"
48#include "mfsnode.h"
49#include "fs.h"
d37d3579 50
d37d3579
KM
51extern struct vnodeops mfs_vnodeops;
52
53/*
54 * mfs vfs operations.
55 */
56int mfs_mount();
57int mfs_start();
58int ufs_unmount();
59int ufs_root();
85eb05b7 60int ufs_quotactl();
c2e4318a 61int mfs_statfs();
d37d3579
KM
62int ufs_sync();
63int ufs_fhtovp();
64int ufs_vptofh();
13b2a169 65int mfs_init();
d37d3579
KM
66
67struct vfsops mfs_vfsops = {
68 mfs_mount,
69 mfs_start,
70 ufs_unmount,
71 ufs_root,
85eb05b7 72 ufs_quotactl,
c2e4318a 73 mfs_statfs,
d37d3579
KM
74 ufs_sync,
75 ufs_fhtovp,
76 ufs_vptofh,
13b2a169 77 mfs_init,
d37d3579
KM
78};
79
80/*
81 * VFS Operations.
82 *
83 * mount system call
84 */
a3e73aa4 85/* ARGSUSED */
5ec911fb 86mfs_mount(mp, path, data, ndp, p)
bd9b3f52 87 register struct mount *mp;
d37d3579
KM
88 char *path;
89 caddr_t data;
90 struct nameidata *ndp;
5ec911fb 91 struct proc *p;
d37d3579
KM
92{
93 struct vnode *devvp;
94 struct mfs_args args;
95 struct ufsmount *ump;
96 register struct fs *fs;
a3e73aa4 97 register struct mfsnode *mfsp;
d37d3579
KM
98 static int mfs_minor;
99 u_int size;
100 int error;
101
82161bc8 102 if (mp->mnt_flag & MNT_UPDATE) {
413e9235
KM
103 ump = VFSTOUFS(mp);
104 fs = ump->um_fs;
82161bc8 105 if (fs->fs_ronly && (mp->mnt_flag & MNT_RDONLY) == 0)
413e9235
KM
106 fs->fs_ronly = 0;
107 return (0);
108 }
d37d3579
KM
109 if (error = copyin(data, (caddr_t)&args, sizeof (struct mfs_args)))
110 return (error);
a3e73aa4
KM
111 error = getnewvnode(VT_MFS, (struct mount *)0, &mfs_vnodeops, &devvp);
112 if (error)
d37d3579 113 return (error);
a3e73aa4 114 devvp->v_type = VBLK;
43fc727e 115 if (checkalias(devvp, makedev(255, mfs_minor++), (struct mount *)0))
13b2a169 116 panic("mfs_mount: dup dev");
a3e73aa4
KM
117 mfsp = VTOMFS(devvp);
118 mfsp->mfs_baseoff = args.base;
119 mfsp->mfs_size = args.size;
120 mfsp->mfs_vnode = devvp;
5ec911fb 121 mfsp->mfs_pid = p->p_pid;
a3e73aa4 122 mfsp->mfs_buflist = (struct buf *)0;
bd9b3f52 123 if (error = mountfs(devvp, mp)) {
edb9fbd0 124 mfsp->mfs_buflist = (struct buf *)-1;
d37d3579
KM
125 vrele(devvp);
126 return (error);
127 }
128 ump = VFSTOUFS(mp);
129 fs = ump->um_fs;
130 (void) copyinstr(path, fs->fs_fsmnt, sizeof(fs->fs_fsmnt) - 1, &size);
131 bzero(fs->fs_fsmnt + size, sizeof(fs->fs_fsmnt) - size);
82161bc8
KM
132 bcopy((caddr_t)fs->fs_fsmnt, (caddr_t)mp->mnt_stat.f_mntonname,
133 MNAMELEN);
134 (void) copyinstr(args.name, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
bd9b3f52 135 &size);
82161bc8
KM
136 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
137 (void) mfs_statfs(mp, &mp->mnt_stat);
d37d3579
KM
138 return (0);
139}
140
96f07863
MK
141int mfs_pri = PWAIT | PCATCH; /* XXX prob. temp */
142
d37d3579
KM
143/*
144 * Used to grab the process and keep it in the kernel to service
145 * memory filesystem I/O requests.
146 *
147 * Loop servicing I/O requests.
148 * Copy the requested data into or out of the memory filesystem
149 * address space.
150 */
151/* ARGSUSED */
5ec911fb 152mfs_start(mp, flags, p)
d37d3579
KM
153 struct mount *mp;
154 int flags;
5ec911fb 155 struct proc *p;
d37d3579
KM
156{
157 register struct vnode *vp = VFSTOUFS(mp)->um_devvp;
a3e73aa4 158 register struct mfsnode *mfsp = VTOMFS(vp);
d37d3579
KM
159 register struct buf *bp;
160 register caddr_t base;
96f07863 161 int error = 0;
d37d3579 162
a3e73aa4 163 base = mfsp->mfs_baseoff;
a3e73aa4
KM
164 while (mfsp->mfs_buflist != (struct buf *)(-1)) {
165 while (bp = mfsp->mfs_buflist) {
166 mfsp->mfs_buflist = bp->av_forw;
ba72b75d
KM
167 mfs_doio(bp, base);
168 wakeup((caddr_t)bp);
169 }
17a10355
MK
170 /*
171 * If a non-ignored signal is received, try to unmount.
172 * If that fails, clear the signal (it has been "processed"),
173 * otherwise we will loop here, as tsleep will always return
174 * EINTR/ERESTART.
175 */
176 if (error = tsleep((caddr_t)vp, mfs_pri, "mfsidl", 0))
5ec911fb 177 if (dounmount(mp, MNT_NOFORCE, p) != 0)
17a10355 178 CLRSIG(p, CURSIG(p));
d37d3579 179 }
96f07863 180 return (error);
d37d3579 181}
c2e4318a
KM
182
183/*
184 * Get file system statistics.
185 */
5ec911fb 186mfs_statfs(mp, sbp, p)
c2e4318a
KM
187 struct mount *mp;
188 struct statfs *sbp;
5ec911fb 189 struct proc *p;
c2e4318a
KM
190{
191 int error;
192
5ec911fb 193 error = ufs_statfs(mp, sbp, p);
c2e4318a
KM
194 sbp->f_type = MOUNT_MFS;
195 return (error);
196}