xref: /original-bsd/sys/ufs/mfs/mfs_vfsops.c (revision 95a66346)
1 /*
2  * Copyright (c) 1989, 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)mfs_vfsops.c	7.18 (Berkeley) 03/19/91
8  */
9 
10 #include "param.h"
11 #include "time.h"
12 #include "kernel.h"
13 #include "proc.h"
14 #include "buf.h"
15 #include "mount.h"
16 #include "signalvar.h"
17 #include "vnode.h"
18 
19 #include "quota.h"
20 #include "inode.h"
21 #include "ufsmount.h"
22 #include "mfsnode.h"
23 #include "fs.h"
24 
25 extern struct vnodeops mfs_vnodeops;
26 
27 /*
28  * mfs vfs operations.
29  */
30 int mfs_mount();
31 int mfs_start();
32 int ufs_unmount();
33 int ufs_root();
34 int ufs_quotactl();
35 int mfs_statfs();
36 int ufs_sync();
37 int ufs_fhtovp();
38 int ufs_vptofh();
39 int mfs_init();
40 
41 struct vfsops mfs_vfsops = {
42 	mfs_mount,
43 	mfs_start,
44 	ufs_unmount,
45 	ufs_root,
46 	ufs_quotactl,
47 	mfs_statfs,
48 	ufs_sync,
49 	ufs_fhtovp,
50 	ufs_vptofh,
51 	mfs_init,
52 };
53 
54 /*
55  * VFS Operations.
56  *
57  * mount system call
58  */
59 /* ARGSUSED */
60 mfs_mount(mp, path, data, ndp)
61 	register struct mount *mp;
62 	char *path;
63 	caddr_t data;
64 	struct nameidata *ndp;
65 {
66 	struct vnode *devvp;
67 	struct mfs_args args;
68 	struct ufsmount *ump;
69 	register struct fs *fs;
70 	register struct mfsnode *mfsp;
71 	static int mfs_minor;
72 	u_int size;
73 	int error;
74 
75 	if (mp->mnt_flag & MNT_UPDATE) {
76 		ump = VFSTOUFS(mp);
77 		fs = ump->um_fs;
78 		if (fs->fs_ronly && (mp->mnt_flag & MNT_RDONLY) == 0)
79 			fs->fs_ronly = 0;
80 		return (0);
81 	}
82 	if (error = copyin(data, (caddr_t)&args, sizeof (struct mfs_args)))
83 		return (error);
84 	error = getnewvnode(VT_MFS, (struct mount *)0, &mfs_vnodeops, &devvp);
85 	if (error)
86 		return (error);
87 	devvp->v_type = VBLK;
88 	if (checkalias(devvp, makedev(255, mfs_minor++), (struct mount *)0))
89 		panic("mfs_mount: dup dev");
90 	mfsp = VTOMFS(devvp);
91 	mfsp->mfs_baseoff = args.base;
92 	mfsp->mfs_size = args.size;
93 	mfsp->mfs_vnode = devvp;
94 	mfsp->mfs_pid = curproc->p_pid;
95 	mfsp->mfs_buflist = (struct buf *)0;
96 	if (error = mountfs(devvp, mp)) {
97 		mfsp->mfs_buflist = (struct buf *)-1;
98 		vrele(devvp);
99 		return (error);
100 	}
101 	ump = VFSTOUFS(mp);
102 	fs = ump->um_fs;
103 	(void) copyinstr(path, fs->fs_fsmnt, sizeof(fs->fs_fsmnt) - 1, &size);
104 	bzero(fs->fs_fsmnt + size, sizeof(fs->fs_fsmnt) - size);
105 	bcopy((caddr_t)fs->fs_fsmnt, (caddr_t)mp->mnt_stat.f_mntonname,
106 		MNAMELEN);
107 	(void) copyinstr(args.name, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
108 		&size);
109 	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
110 	(void) mfs_statfs(mp, &mp->mnt_stat);
111 	return (0);
112 }
113 
114 int	mfs_pri = PWAIT | PCATCH;		/* XXX prob. temp */
115 
116 /*
117  * Used to grab the process and keep it in the kernel to service
118  * memory filesystem I/O requests.
119  *
120  * Loop servicing I/O requests.
121  * Copy the requested data into or out of the memory filesystem
122  * address space.
123  */
124 /* ARGSUSED */
125 mfs_start(mp, flags)
126 	struct mount *mp;
127 	int flags;
128 {
129 	register struct vnode *vp = VFSTOUFS(mp)->um_devvp;
130 	register struct mfsnode *mfsp = VTOMFS(vp);
131 	register struct buf *bp;
132 	register caddr_t base;
133 	struct proc *p = curproc;
134 	int error = 0;
135 
136 	base = mfsp->mfs_baseoff;
137 	while (mfsp->mfs_buflist != (struct buf *)(-1)) {
138 		while (bp = mfsp->mfs_buflist) {
139 			mfsp->mfs_buflist = bp->av_forw;
140 			mfs_doio(bp, base);
141 			wakeup((caddr_t)bp);
142 		}
143 		/*
144 		 * If a non-ignored signal is received, try to unmount.
145 		 * If that fails, clear the signal (it has been "processed"),
146 		 * otherwise we will loop here, as tsleep will always return
147 		 * EINTR/ERESTART.
148 		 */
149 		if (error = tsleep((caddr_t)vp, mfs_pri, "mfsidl", 0))
150 			if (dounmount(mp, MNT_NOFORCE) != 0)
151 				CLRSIG(p, CURSIG(p));
152 	}
153 	return (error);
154 }
155 
156 /*
157  * Get file system statistics.
158  */
159 mfs_statfs(mp, sbp)
160 	struct mount *mp;
161 	struct statfs *sbp;
162 {
163 	int error;
164 
165 	error = ufs_statfs(mp, sbp);
166 	sbp->f_type = MOUNT_MFS;
167 	return (error);
168 }
169