]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
d7e50217 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
d7e50217 A |
8 | * This file contains Original Code and/or Modifications of Original Code |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
d7e50217 A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ | |
26 | /* | |
27 | * Copyright (c) 1989, 1990, 1993, 1994 | |
28 | * The Regents of the University of California. All rights reserved. | |
29 | * | |
30 | * Redistribution and use in source and binary forms, with or without | |
31 | * modification, are permitted provided that the following conditions | |
32 | * are met: | |
33 | * 1. Redistributions of source code must retain the above copyright | |
34 | * notice, this list of conditions and the following disclaimer. | |
35 | * 2. Redistributions in binary form must reproduce the above copyright | |
36 | * notice, this list of conditions and the following disclaimer in the | |
37 | * documentation and/or other materials provided with the distribution. | |
38 | * 3. All advertising materials mentioning features or use of this software | |
39 | * must display the following acknowledgement: | |
40 | * This product includes software developed by the University of | |
41 | * California, Berkeley and its contributors. | |
42 | * 4. Neither the name of the University nor the names of its contributors | |
43 | * may be used to endorse or promote products derived from this software | |
44 | * without specific prior written permission. | |
45 | * | |
46 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
47 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
48 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
49 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
50 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
51 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
52 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
53 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
54 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
55 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
56 | * SUCH DAMAGE. | |
57 | * | |
58 | * @(#)mfs_vfsops.c 8.4 (Berkeley) 4/16/94 | |
59 | */ | |
60 | ||
61 | #include <sys/param.h> | |
62 | #include <sys/systm.h> | |
63 | #include <sys/time.h> | |
64 | #include <sys/kernel.h> | |
65 | #include <sys/proc.h> | |
66 | #include <sys/buf.h> | |
67 | #include <sys/mount.h> | |
68 | #include <sys/signalvar.h> | |
69 | #include <sys/vnode.h> | |
70 | #include <sys/malloc.h> | |
71 | ||
72 | #include <ufs/ufs/quota.h> | |
73 | #include <ufs/ufs/inode.h> | |
74 | #include <ufs/ufs/ufsmount.h> | |
75 | #include <ufs/ufs/ufs_extern.h> | |
76 | ||
77 | #include <ufs/ffs/fs.h> | |
78 | #include <ufs/ffs/ffs_extern.h> | |
79 | ||
80 | #include <ufs/mfs/mfsnode.h> | |
81 | #include <ufs/mfs/mfs_extern.h> | |
82 | ||
83 | caddr_t mfs_rootbase; /* address of mini-root in kernel virtual memory */ | |
84 | u_long mfs_rootsize; /* size of mini-root in bytes */ | |
85 | ||
86 | static int mfs_minor; /* used for building internal dev_t */ | |
87 | ||
88 | extern int (**mfs_vnodeop_p)(void *); | |
89 | ||
90 | /* | |
91 | * mfs vfs operations. | |
92 | */ | |
93 | struct vfsops mfs_vfsops = { | |
94 | MOUNT_MFS, | |
95 | mfs_mount, | |
96 | mfs_start, | |
97 | ffs_unmount, | |
98 | ufs_root, | |
99 | ufs_quotactl, | |
100 | mfs_statfs, | |
101 | ffs_sync, | |
102 | ffs_vget, | |
103 | ffs_fhtovp, | |
104 | ffs_vptofh, | |
105 | mfs_init, | |
106 | }; | |
107 | ||
108 | /* | |
109 | * Called by main() when mfs is going to be mounted as root. | |
110 | * | |
111 | * Name is updated by mount(8) after booting. | |
112 | */ | |
113 | #define ROOTNAME "mfs_root" | |
114 | ||
115 | mfs_mountroot() | |
116 | { | |
117 | extern struct vnode *rootvp; | |
118 | register struct fs *fs; | |
119 | register struct mount *mp; | |
120 | struct proc *p = kernel_proc; /* XXX - WMG*/ | |
121 | struct ufsmount *ump; | |
122 | struct mfsnode *mfsp; | |
123 | size_t size; | |
124 | int error; | |
125 | ||
126 | /* | |
127 | * Get vnodes for swapdev and rootdev. | |
128 | */ | |
129 | #if 0 | |
130 | if (bdevvp(swapdev, &swapdev_vp) || bdevvp(rootdev, &rootvp)) | |
131 | panic("mfs_mountroot: can't setup bdevvp's"); | |
132 | #else | |
133 | if ( bdevvp(rootdev, &rootvp)) | |
134 | panic("mfs_mountroot: can't setup bdevvp's"); | |
135 | ||
136 | #endif | |
137 | MALLOC_ZONE(mp, struct mount *, | |
138 | sizeof(struct mount), M_MOUNT, M_WAITOK); | |
139 | bzero((char *)mp, (u_long)sizeof(struct mount)); | |
0b4e3aa0 A |
140 | |
141 | /* Initialize the default IO constraints */ | |
142 | mp->mnt_maxreadcnt = mp->mnt_maxwritecnt = MAXPHYS; | |
143 | mp->mnt_segreadcnt = mp->mnt_segwritecnt = 32; | |
144 | ||
1c79356b A |
145 | mp->mnt_op = &mfs_vfsops; |
146 | mp->mnt_flag = MNT_RDONLY; | |
147 | MALLOC(mfsp, struct mfsnode *, sizeof(struct mfsnode), M_MFSNODE, M_WAITOK); | |
148 | rootvp->v_data = mfsp; | |
149 | rootvp->v_op = mfs_vnodeop_p; | |
150 | rootvp->v_tag = VT_MFS; | |
151 | mfsp->mfs_baseoff = mfs_rootbase; | |
152 | mfsp->mfs_size = mfs_rootsize; | |
153 | mfsp->mfs_vnode = rootvp; | |
154 | mfsp->mfs_pid = p->p_pid; | |
155 | mfsp->mfs_buflist = (struct buf *)0; | |
156 | if (error = ffs_mountfs(rootvp, mp, p)) { | |
9bccf70c | 157 | vrele(rootvp); /* release the reference from bdevvp() */ |
1c79356b A |
158 | _FREE_ZONE(mp, sizeof (struct mount), M_MOUNT); |
159 | _FREE(mfsp, M_MFSNODE); | |
160 | return (error); | |
161 | } | |
162 | if (error = vfs_lock(mp)) { | |
163 | (void)ffs_unmount(mp, 0, p); | |
164 | _FREE_ZONE(mp, sizeof (struct mount), M_MOUNT); | |
165 | _FREE(mfsp, M_MFSNODE); | |
166 | return (error); | |
167 | } | |
168 | CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list); | |
169 | mp->mnt_vnodecovered = NULLVP; | |
170 | ump = VFSTOUFS(mp); | |
171 | fs = ump->um_fs; | |
172 | bzero(fs->fs_fsmnt, sizeof(fs->fs_fsmnt)); | |
173 | fs->fs_fsmnt[0] = '/'; | |
174 | bcopy(fs->fs_fsmnt, mp->mnt_stat.f_mntonname, MNAMELEN); | |
175 | (void) copystr(ROOTNAME, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, | |
176 | &size); | |
177 | bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size); | |
178 | (void)ffs_statfs(mp, &mp->mnt_stat, p); | |
179 | vfs_unlock(mp); | |
180 | inittodr((time_t)0); | |
181 | return (0); | |
182 | } | |
183 | ||
184 | /* | |
185 | * This is called early in boot to set the base address and size | |
186 | * of the mini-root. | |
187 | */ | |
188 | mfs_initminiroot(base) | |
189 | caddr_t base; | |
190 | { | |
191 | struct fs *fs = (struct fs *)(base + SBOFF); | |
192 | extern int (*mountroot)(); | |
193 | ||
194 | /* check for valid super block */ | |
195 | if (fs->fs_magic != FS_MAGIC || fs->fs_bsize > MAXBSIZE || | |
196 | fs->fs_bsize < sizeof(struct fs)) | |
197 | return (0); | |
198 | mountroot = mfs_mountroot; | |
199 | mfs_rootbase = base; | |
200 | mfs_rootsize = fs->fs_fsize * fs->fs_size; | |
201 | rootdev = makedev(255, mfs_minor++); | |
202 | return (mfs_rootsize); | |
203 | } | |
204 | ||
205 | /* | |
206 | * VFS Operations. | |
207 | * | |
208 | * mount system call | |
209 | */ | |
210 | /* ARGSUSED */ | |
211 | int | |
212 | mfs_mount(mp, path, data, ndp, p) | |
213 | register struct mount *mp; | |
214 | char *path; | |
215 | caddr_t data; | |
216 | struct nameidata *ndp; | |
217 | struct proc *p; | |
218 | { | |
219 | struct vnode *devvp; | |
220 | struct mfs_args args; | |
221 | struct ufsmount *ump; | |
222 | register struct fs *fs; | |
223 | register struct mfsnode *mfsp; | |
224 | size_t size; | |
225 | int flags, error; | |
226 | ||
227 | if (error = copyin(data, (caddr_t)&args, sizeof (struct mfs_args))) | |
228 | return (error); | |
229 | ||
230 | /* | |
231 | * If updating, check whether changing from read-only to | |
232 | * read/write; if there is no device name, that's all we do. | |
233 | */ | |
234 | if (mp->mnt_flag & MNT_UPDATE) { | |
235 | ump = VFSTOUFS(mp); | |
236 | fs = ump->um_fs; | |
237 | if (fs->fs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) { | |
238 | flags = WRITECLOSE; | |
239 | if (mp->mnt_flag & MNT_FORCE) | |
240 | flags |= FORCECLOSE; | |
241 | if (vfs_busy(mp)) | |
242 | return (EBUSY); | |
243 | error = ffs_flushfiles(mp, flags, p); | |
244 | vfs_unbusy(mp); | |
245 | if (error) | |
246 | return (error); | |
247 | } | |
248 | if (fs->fs_ronly && (mp->mnt_kern_flag & MNTK_WANTRDWR)) | |
249 | fs->fs_ronly = 0; | |
250 | #ifdef EXPORTMFS | |
251 | if (args.fspec == 0) | |
252 | return (vfs_export(mp, &ump->um_export, &args.export)); | |
253 | #endif | |
254 | return (0); | |
255 | } | |
256 | MALLOC(mfsp, struct mfsnode *, sizeof(struct mfsnode), M_MFSNODE, M_WAITOK); | |
257 | error = getnewvnode(VT_MFS, (struct mount *)0, mfs_vnodeop_p, &devvp); | |
258 | if (error) { | |
259 | FREE(mfsp, M_MFSNODE); | |
260 | return (error); | |
261 | } | |
262 | devvp->v_type = VBLK; | |
263 | if (checkalias(devvp, makedev(255, mfs_minor++), (struct mount *)0)) | |
264 | panic("mfs_mount: dup dev"); | |
265 | devvp->v_data = mfsp; | |
266 | mfsp->mfs_baseoff = args.base; | |
267 | mfsp->mfs_size = args.size; | |
268 | mfsp->mfs_vnode = devvp; | |
269 | mfsp->mfs_pid = p->p_pid; | |
270 | mfsp->mfs_buflist = (struct buf *)0; | |
271 | if (error = ffs_mountfs(devvp, mp, p)) { | |
272 | mfsp->mfs_buflist = (struct buf *)-1; | |
273 | vrele(devvp); | |
274 | return (error); | |
275 | } | |
276 | ump = VFSTOUFS(mp); | |
277 | fs = ump->um_fs; | |
278 | (void) copyinstr(path, fs->fs_fsmnt, sizeof(fs->fs_fsmnt) - 1, &size); | |
279 | bzero(fs->fs_fsmnt + size, sizeof(fs->fs_fsmnt) - size); | |
280 | bcopy(fs->fs_fsmnt, mp->mnt_stat.f_mntonname, MNAMELEN); | |
281 | (void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, | |
282 | &size); | |
283 | bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size); | |
284 | return (0); | |
285 | } | |
286 | ||
287 | int mfs_pri = PWAIT | PCATCH; /* XXX prob. temp */ | |
288 | ||
289 | /* | |
290 | * Used to grab the process and keep it in the kernel to service | |
291 | * memory filesystem I/O requests. | |
292 | * | |
293 | * Loop servicing I/O requests. | |
294 | * Copy the requested data into or out of the memory filesystem | |
295 | * address space. | |
296 | */ | |
297 | /* ARGSUSED */ | |
298 | int | |
299 | mfs_start(mp, flags, p) | |
300 | struct mount *mp; | |
301 | int flags; | |
302 | struct proc *p; | |
303 | { | |
304 | register struct vnode *vp = VFSTOUFS(mp)->um_devvp; | |
305 | register struct mfsnode *mfsp = VTOMFS(vp); | |
306 | register struct buf *bp; | |
307 | register caddr_t base; | |
308 | int error = 0; | |
309 | ||
310 | base = mfsp->mfs_baseoff; | |
311 | while (mfsp->mfs_buflist != (struct buf *)(-1)) { | |
312 | while (bp = mfsp->mfs_buflist) { | |
313 | mfsp->mfs_buflist = bp->b_actf; | |
314 | mfs_doio(bp, base); | |
315 | wakeup((caddr_t)bp); | |
316 | } | |
317 | /* | |
318 | * If a non-ignored signal is received, try to unmount. | |
319 | * If that fails, clear the signal (it has been "processed"), | |
320 | * otherwise we will loop here, as tsleep will always return | |
321 | * EINTR/ERESTART. | |
322 | */ | |
323 | if (error = tsleep((caddr_t)vp, mfs_pri, "mfsidl", 0)) | |
324 | if (dounmount(mp, 0, p) != 0) | |
325 | CLRSIG(p, CURSIG(p)); | |
326 | } | |
327 | return (error); | |
328 | } | |
329 | ||
330 | /* | |
331 | * Get file system statistics. | |
332 | */ | |
333 | mfs_statfs(mp, sbp, p) | |
334 | struct mount *mp; | |
335 | struct statfs *sbp; | |
336 | struct proc *p; | |
337 | { | |
338 | int error; | |
339 | ||
340 | error = ffs_statfs(mp, sbp, p); | |
341 | #ifdef COMPAT_09 | |
342 | sbp->f_type = 3; | |
343 | #else | |
344 | sbp->f_type = 0; | |
345 | #endif | |
346 | strncpy(&sbp->f_fstypename[0], mp->mnt_op->vfs_name, MFSNAMELEN); | |
347 | sbp->f_fstypename[MFSNAMELEN] = '\0'; | |
348 | return (error); | |
349 | } |