xref: /freebsd/sys/ufs/ffs/ffs_vfsops.c (revision 0957b409)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1989, 1991, 1993, 1994
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  *	@(#)ffs_vfsops.c	8.31 (Berkeley) 5/20/95
32  */
33 
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
36 
37 #include "opt_quota.h"
38 #include "opt_ufs.h"
39 #include "opt_ffs.h"
40 #include "opt_ddb.h"
41 
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/namei.h>
45 #include <sys/priv.h>
46 #include <sys/proc.h>
47 #include <sys/taskqueue.h>
48 #include <sys/kernel.h>
49 #include <sys/vnode.h>
50 #include <sys/mount.h>
51 #include <sys/bio.h>
52 #include <sys/buf.h>
53 #include <sys/conf.h>
54 #include <sys/fcntl.h>
55 #include <sys/ioccom.h>
56 #include <sys/malloc.h>
57 #include <sys/mutex.h>
58 #include <sys/rwlock.h>
59 #include <sys/vmmeter.h>
60 
61 #include <security/mac/mac_framework.h>
62 
63 #include <ufs/ufs/dir.h>
64 #include <ufs/ufs/extattr.h>
65 #include <ufs/ufs/gjournal.h>
66 #include <ufs/ufs/quota.h>
67 #include <ufs/ufs/ufsmount.h>
68 #include <ufs/ufs/inode.h>
69 #include <ufs/ufs/ufs_extern.h>
70 
71 #include <ufs/ffs/fs.h>
72 #include <ufs/ffs/ffs_extern.h>
73 
74 #include <vm/vm.h>
75 #include <vm/uma.h>
76 #include <vm/vm_page.h>
77 
78 #include <geom/geom.h>
79 #include <geom/geom_vfs.h>
80 
81 #include <ddb/ddb.h>
82 
83 static uma_zone_t uma_inode, uma_ufs1, uma_ufs2;
84 
85 static int	ffs_mountfs(struct vnode *, struct mount *, struct thread *);
86 static void	ffs_oldfscompat_read(struct fs *, struct ufsmount *,
87 		    ufs2_daddr_t);
88 static void	ffs_ifree(struct ufsmount *ump, struct inode *ip);
89 static int	ffs_sync_lazy(struct mount *mp);
90 static int	ffs_use_bread(void *devfd, off_t loc, void **bufp, int size);
91 static int	ffs_use_bwrite(void *devfd, off_t loc, void *buf, int size);
92 
93 static vfs_init_t ffs_init;
94 static vfs_uninit_t ffs_uninit;
95 static vfs_extattrctl_t ffs_extattrctl;
96 static vfs_cmount_t ffs_cmount;
97 static vfs_unmount_t ffs_unmount;
98 static vfs_mount_t ffs_mount;
99 static vfs_statfs_t ffs_statfs;
100 static vfs_fhtovp_t ffs_fhtovp;
101 static vfs_sync_t ffs_sync;
102 
103 static struct vfsops ufs_vfsops = {
104 	.vfs_extattrctl =	ffs_extattrctl,
105 	.vfs_fhtovp =		ffs_fhtovp,
106 	.vfs_init =		ffs_init,
107 	.vfs_mount =		ffs_mount,
108 	.vfs_cmount =		ffs_cmount,
109 	.vfs_quotactl =		ufs_quotactl,
110 	.vfs_root =		ufs_root,
111 	.vfs_statfs =		ffs_statfs,
112 	.vfs_sync =		ffs_sync,
113 	.vfs_uninit =		ffs_uninit,
114 	.vfs_unmount =		ffs_unmount,
115 	.vfs_vget =		ffs_vget,
116 	.vfs_susp_clean =	process_deferred_inactive,
117 };
118 
119 VFS_SET(ufs_vfsops, ufs, 0);
120 MODULE_VERSION(ufs, 1);
121 
122 static b_strategy_t ffs_geom_strategy;
123 static b_write_t ffs_bufwrite;
124 
125 static struct buf_ops ffs_ops = {
126 	.bop_name =	"FFS",
127 	.bop_write =	ffs_bufwrite,
128 	.bop_strategy =	ffs_geom_strategy,
129 	.bop_sync =	bufsync,
130 #ifdef NO_FFS_SNAPSHOT
131 	.bop_bdflush =	bufbdflush,
132 #else
133 	.bop_bdflush =	ffs_bdflush,
134 #endif
135 };
136 
137 /*
138  * Note that userquota and groupquota options are not currently used
139  * by UFS/FFS code and generally mount(8) does not pass those options
140  * from userland, but they can be passed by loader(8) via
141  * vfs.root.mountfrom.options.
142  */
143 static const char *ffs_opts[] = { "acls", "async", "noatime", "noclusterr",
144     "noclusterw", "noexec", "export", "force", "from", "groupquota",
145     "multilabel", "nfsv4acls", "fsckpid", "snapshot", "nosuid", "suiddir",
146     "nosymfollow", "sync", "union", "userquota", NULL };
147 
148 static int
149 ffs_mount(struct mount *mp)
150 {
151 	struct vnode *devvp;
152 	struct thread *td;
153 	struct ufsmount *ump = NULL;
154 	struct fs *fs;
155 	pid_t fsckpid = 0;
156 	int error, error1, flags;
157 	uint64_t mntorflags;
158 	accmode_t accmode;
159 	struct nameidata ndp;
160 	char *fspec;
161 
162 	td = curthread;
163 	if (vfs_filteropt(mp->mnt_optnew, ffs_opts))
164 		return (EINVAL);
165 	if (uma_inode == NULL) {
166 		uma_inode = uma_zcreate("FFS inode",
167 		    sizeof(struct inode), NULL, NULL, NULL, NULL,
168 		    UMA_ALIGN_PTR, 0);
169 		uma_ufs1 = uma_zcreate("FFS1 dinode",
170 		    sizeof(struct ufs1_dinode), NULL, NULL, NULL, NULL,
171 		    UMA_ALIGN_PTR, 0);
172 		uma_ufs2 = uma_zcreate("FFS2 dinode",
173 		    sizeof(struct ufs2_dinode), NULL, NULL, NULL, NULL,
174 		    UMA_ALIGN_PTR, 0);
175 	}
176 
177 	vfs_deleteopt(mp->mnt_optnew, "groupquota");
178 	vfs_deleteopt(mp->mnt_optnew, "userquota");
179 
180 	fspec = vfs_getopts(mp->mnt_optnew, "from", &error);
181 	if (error)
182 		return (error);
183 
184 	mntorflags = 0;
185 	if (vfs_getopt(mp->mnt_optnew, "acls", NULL, NULL) == 0)
186 		mntorflags |= MNT_ACLS;
187 
188 	if (vfs_getopt(mp->mnt_optnew, "snapshot", NULL, NULL) == 0) {
189 		mntorflags |= MNT_SNAPSHOT;
190 		/*
191 		 * Once we have set the MNT_SNAPSHOT flag, do not
192 		 * persist "snapshot" in the options list.
193 		 */
194 		vfs_deleteopt(mp->mnt_optnew, "snapshot");
195 		vfs_deleteopt(mp->mnt_opt, "snapshot");
196 	}
197 
198 	if (vfs_getopt(mp->mnt_optnew, "fsckpid", NULL, NULL) == 0 &&
199 	    vfs_scanopt(mp->mnt_optnew, "fsckpid", "%d", &fsckpid) == 1) {
200 		/*
201 		 * Once we have set the restricted PID, do not
202 		 * persist "fsckpid" in the options list.
203 		 */
204 		vfs_deleteopt(mp->mnt_optnew, "fsckpid");
205 		vfs_deleteopt(mp->mnt_opt, "fsckpid");
206 		if (mp->mnt_flag & MNT_UPDATE) {
207 			if (VFSTOUFS(mp)->um_fs->fs_ronly == 0 &&
208 			     vfs_flagopt(mp->mnt_optnew, "ro", NULL, 0) == 0) {
209 				vfs_mount_error(mp,
210 				    "Checker enable: Must be read-only");
211 				return (EINVAL);
212 			}
213 		} else if (vfs_flagopt(mp->mnt_optnew, "ro", NULL, 0) == 0) {
214 			vfs_mount_error(mp,
215 			    "Checker enable: Must be read-only");
216 			return (EINVAL);
217 		}
218 		/* Set to -1 if we are done */
219 		if (fsckpid == 0)
220 			fsckpid = -1;
221 	}
222 
223 	if (vfs_getopt(mp->mnt_optnew, "nfsv4acls", NULL, NULL) == 0) {
224 		if (mntorflags & MNT_ACLS) {
225 			vfs_mount_error(mp,
226 			    "\"acls\" and \"nfsv4acls\" options "
227 			    "are mutually exclusive");
228 			return (EINVAL);
229 		}
230 		mntorflags |= MNT_NFS4ACLS;
231 	}
232 
233 	MNT_ILOCK(mp);
234 	mp->mnt_flag |= mntorflags;
235 	MNT_IUNLOCK(mp);
236 	/*
237 	 * If updating, check whether changing from read-only to
238 	 * read/write; if there is no device name, that's all we do.
239 	 */
240 	if (mp->mnt_flag & MNT_UPDATE) {
241 		ump = VFSTOUFS(mp);
242 		fs = ump->um_fs;
243 		devvp = ump->um_devvp;
244 		if (fsckpid == -1 && ump->um_fsckpid > 0) {
245 			if ((error = ffs_flushfiles(mp, WRITECLOSE, td)) != 0 ||
246 			    (error = ffs_sbupdate(ump, MNT_WAIT, 0)) != 0)
247 				return (error);
248 			g_topology_lock();
249 			/*
250 			 * Return to normal read-only mode.
251 			 */
252 			error = g_access(ump->um_cp, 0, -1, 0);
253 			g_topology_unlock();
254 			ump->um_fsckpid = 0;
255 		}
256 		if (fs->fs_ronly == 0 &&
257 		    vfs_flagopt(mp->mnt_optnew, "ro", NULL, 0)) {
258 			/*
259 			 * Flush any dirty data and suspend filesystem.
260 			 */
261 			if ((error = vn_start_write(NULL, &mp, V_WAIT)) != 0)
262 				return (error);
263 			error = vfs_write_suspend_umnt(mp);
264 			if (error != 0)
265 				return (error);
266 			/*
267 			 * Check for and optionally get rid of files open
268 			 * for writing.
269 			 */
270 			flags = WRITECLOSE;
271 			if (mp->mnt_flag & MNT_FORCE)
272 				flags |= FORCECLOSE;
273 			if (MOUNTEDSOFTDEP(mp)) {
274 				error = softdep_flushfiles(mp, flags, td);
275 			} else {
276 				error = ffs_flushfiles(mp, flags, td);
277 			}
278 			if (error) {
279 				vfs_write_resume(mp, 0);
280 				return (error);
281 			}
282 			if (fs->fs_pendingblocks != 0 ||
283 			    fs->fs_pendinginodes != 0) {
284 				printf("WARNING: %s Update error: blocks %jd "
285 				    "files %d\n", fs->fs_fsmnt,
286 				    (intmax_t)fs->fs_pendingblocks,
287 				    fs->fs_pendinginodes);
288 				fs->fs_pendingblocks = 0;
289 				fs->fs_pendinginodes = 0;
290 			}
291 			if ((fs->fs_flags & (FS_UNCLEAN | FS_NEEDSFSCK)) == 0)
292 				fs->fs_clean = 1;
293 			if ((error = ffs_sbupdate(ump, MNT_WAIT, 0)) != 0) {
294 				fs->fs_ronly = 0;
295 				fs->fs_clean = 0;
296 				vfs_write_resume(mp, 0);
297 				return (error);
298 			}
299 			if (MOUNTEDSOFTDEP(mp))
300 				softdep_unmount(mp);
301 			g_topology_lock();
302 			/*
303 			 * Drop our write and exclusive access.
304 			 */
305 			g_access(ump->um_cp, 0, -1, -1);
306 			g_topology_unlock();
307 			fs->fs_ronly = 1;
308 			MNT_ILOCK(mp);
309 			mp->mnt_flag |= MNT_RDONLY;
310 			MNT_IUNLOCK(mp);
311 			/*
312 			 * Allow the writers to note that filesystem
313 			 * is ro now.
314 			 */
315 			vfs_write_resume(mp, 0);
316 		}
317 		if ((mp->mnt_flag & MNT_RELOAD) &&
318 		    (error = ffs_reload(mp, td, 0)) != 0)
319 			return (error);
320 		if (fs->fs_ronly &&
321 		    !vfs_flagopt(mp->mnt_optnew, "ro", NULL, 0)) {
322 			/*
323 			 * If we are running a checker, do not allow upgrade.
324 			 */
325 			if (ump->um_fsckpid > 0) {
326 				vfs_mount_error(mp,
327 				    "Active checker, cannot upgrade to write");
328 				return (EINVAL);
329 			}
330 			/*
331 			 * If upgrade to read-write by non-root, then verify
332 			 * that user has necessary permissions on the device.
333 			 */
334 			vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
335 			error = VOP_ACCESS(devvp, VREAD | VWRITE,
336 			    td->td_ucred, td);
337 			if (error)
338 				error = priv_check(td, PRIV_VFS_MOUNT_PERM);
339 			if (error) {
340 				VOP_UNLOCK(devvp, 0);
341 				return (error);
342 			}
343 			VOP_UNLOCK(devvp, 0);
344 			fs->fs_flags &= ~FS_UNCLEAN;
345 			if (fs->fs_clean == 0) {
346 				fs->fs_flags |= FS_UNCLEAN;
347 				if ((mp->mnt_flag & MNT_FORCE) ||
348 				    ((fs->fs_flags &
349 				     (FS_SUJ | FS_NEEDSFSCK)) == 0 &&
350 				     (fs->fs_flags & FS_DOSOFTDEP))) {
351 					printf("WARNING: %s was not properly "
352 					   "dismounted\n", fs->fs_fsmnt);
353 				} else {
354 					vfs_mount_error(mp,
355 					   "R/W mount of %s denied. %s.%s",
356 					   fs->fs_fsmnt,
357 					   "Filesystem is not clean - run fsck",
358 					   (fs->fs_flags & FS_SUJ) == 0 ? "" :
359 					   " Forced mount will invalidate"
360 					   " journal contents");
361 					return (EPERM);
362 				}
363 			}
364 			g_topology_lock();
365 			/*
366 			 * Request exclusive write access.
367 			 */
368 			error = g_access(ump->um_cp, 0, 1, 1);
369 			g_topology_unlock();
370 			if (error)
371 				return (error);
372 			if ((error = vn_start_write(NULL, &mp, V_WAIT)) != 0)
373 				return (error);
374 			fs->fs_ronly = 0;
375 			MNT_ILOCK(mp);
376 			mp->mnt_flag &= ~MNT_RDONLY;
377 			MNT_IUNLOCK(mp);
378 			fs->fs_mtime = time_second;
379 			/* check to see if we need to start softdep */
380 			if ((fs->fs_flags & FS_DOSOFTDEP) &&
381 			    (error = softdep_mount(devvp, mp, fs, td->td_ucred))){
382 				vn_finished_write(mp);
383 				return (error);
384 			}
385 			fs->fs_clean = 0;
386 			if ((error = ffs_sbupdate(ump, MNT_WAIT, 0)) != 0) {
387 				vn_finished_write(mp);
388 				return (error);
389 			}
390 			if (fs->fs_snapinum[0] != 0)
391 				ffs_snapshot_mount(mp);
392 			vn_finished_write(mp);
393 		}
394 		/*
395 		 * Soft updates is incompatible with "async",
396 		 * so if we are doing softupdates stop the user
397 		 * from setting the async flag in an update.
398 		 * Softdep_mount() clears it in an initial mount
399 		 * or ro->rw remount.
400 		 */
401 		if (MOUNTEDSOFTDEP(mp)) {
402 			/* XXX: Reset too late ? */
403 			MNT_ILOCK(mp);
404 			mp->mnt_flag &= ~MNT_ASYNC;
405 			MNT_IUNLOCK(mp);
406 		}
407 		/*
408 		 * Keep MNT_ACLS flag if it is stored in superblock.
409 		 */
410 		if ((fs->fs_flags & FS_ACLS) != 0) {
411 			/* XXX: Set too late ? */
412 			MNT_ILOCK(mp);
413 			mp->mnt_flag |= MNT_ACLS;
414 			MNT_IUNLOCK(mp);
415 		}
416 
417 		if ((fs->fs_flags & FS_NFS4ACLS) != 0) {
418 			/* XXX: Set too late ? */
419 			MNT_ILOCK(mp);
420 			mp->mnt_flag |= MNT_NFS4ACLS;
421 			MNT_IUNLOCK(mp);
422 		}
423 		/*
424 		 * If this is a request from fsck to clean up the filesystem,
425 		 * then allow the specified pid to proceed.
426 		 */
427 		if (fsckpid > 0) {
428 			if (ump->um_fsckpid != 0) {
429 				vfs_mount_error(mp,
430 				    "Active checker already running on %s",
431 				    fs->fs_fsmnt);
432 				return (EINVAL);
433 			}
434 			KASSERT(MOUNTEDSOFTDEP(mp) == 0,
435 			    ("soft updates enabled on read-only file system"));
436 			g_topology_lock();
437 			/*
438 			 * Request write access.
439 			 */
440 			error = g_access(ump->um_cp, 0, 1, 0);
441 			g_topology_unlock();
442 			if (error) {
443 				vfs_mount_error(mp,
444 				    "Checker activation failed on %s",
445 				    fs->fs_fsmnt);
446 				return (error);
447 			}
448 			ump->um_fsckpid = fsckpid;
449 			if (fs->fs_snapinum[0] != 0)
450 				ffs_snapshot_mount(mp);
451 			fs->fs_mtime = time_second;
452 			fs->fs_fmod = 1;
453 			fs->fs_clean = 0;
454 			(void) ffs_sbupdate(ump, MNT_WAIT, 0);
455 		}
456 
457 		/*
458 		 * If this is a snapshot request, take the snapshot.
459 		 */
460 		if (mp->mnt_flag & MNT_SNAPSHOT)
461 			return (ffs_snapshot(mp, fspec));
462 
463 		/*
464 		 * Must not call namei() while owning busy ref.
465 		 */
466 		vfs_unbusy(mp);
467 	}
468 
469 	/*
470 	 * Not an update, or updating the name: look up the name
471 	 * and verify that it refers to a sensible disk device.
472 	 */
473 	NDINIT(&ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, fspec, td);
474 	error = namei(&ndp);
475 	if ((mp->mnt_flag & MNT_UPDATE) != 0) {
476 		/*
477 		 * Unmount does not start if MNT_UPDATE is set.  Mount
478 		 * update busies mp before setting MNT_UPDATE.  We
479 		 * must be able to retain our busy ref succesfully,
480 		 * without sleep.
481 		 */
482 		error1 = vfs_busy(mp, MBF_NOWAIT);
483 		MPASS(error1 == 0);
484 	}
485 	if (error != 0)
486 		return (error);
487 	NDFREE(&ndp, NDF_ONLY_PNBUF);
488 	devvp = ndp.ni_vp;
489 	if (!vn_isdisk(devvp, &error)) {
490 		vput(devvp);
491 		return (error);
492 	}
493 
494 	/*
495 	 * If mount by non-root, then verify that user has necessary
496 	 * permissions on the device.
497 	 */
498 	accmode = VREAD;
499 	if ((mp->mnt_flag & MNT_RDONLY) == 0)
500 		accmode |= VWRITE;
501 	error = VOP_ACCESS(devvp, accmode, td->td_ucred, td);
502 	if (error)
503 		error = priv_check(td, PRIV_VFS_MOUNT_PERM);
504 	if (error) {
505 		vput(devvp);
506 		return (error);
507 	}
508 
509 	if (mp->mnt_flag & MNT_UPDATE) {
510 		/*
511 		 * Update only
512 		 *
513 		 * If it's not the same vnode, or at least the same device
514 		 * then it's not correct.
515 		 */
516 
517 		if (devvp->v_rdev != ump->um_devvp->v_rdev)
518 			error = EINVAL;	/* needs translation */
519 		vput(devvp);
520 		if (error)
521 			return (error);
522 	} else {
523 		/*
524 		 * New mount
525 		 *
526 		 * We need the name for the mount point (also used for
527 		 * "last mounted on") copied in. If an error occurs,
528 		 * the mount point is discarded by the upper level code.
529 		 * Note that vfs_mount_alloc() populates f_mntonname for us.
530 		 */
531 		if ((error = ffs_mountfs(devvp, mp, td)) != 0) {
532 			vrele(devvp);
533 			return (error);
534 		}
535 		if (fsckpid > 0) {
536 			KASSERT(MOUNTEDSOFTDEP(mp) == 0,
537 			    ("soft updates enabled on read-only file system"));
538 			ump = VFSTOUFS(mp);
539 			fs = ump->um_fs;
540 			g_topology_lock();
541 			/*
542 			 * Request write access.
543 			 */
544 			error = g_access(ump->um_cp, 0, 1, 0);
545 			g_topology_unlock();
546 			if (error) {
547 				printf("WARNING: %s: Checker activation "
548 				    "failed\n", fs->fs_fsmnt);
549 			} else {
550 				ump->um_fsckpid = fsckpid;
551 				if (fs->fs_snapinum[0] != 0)
552 					ffs_snapshot_mount(mp);
553 				fs->fs_mtime = time_second;
554 				fs->fs_clean = 0;
555 				(void) ffs_sbupdate(ump, MNT_WAIT, 0);
556 			}
557 		}
558 	}
559 	vfs_mountedfrom(mp, fspec);
560 	return (0);
561 }
562 
563 /*
564  * Compatibility with old mount system call.
565  */
566 
567 static int
568 ffs_cmount(struct mntarg *ma, void *data, uint64_t flags)
569 {
570 	struct ufs_args args;
571 	struct export_args exp;
572 	int error;
573 
574 	if (data == NULL)
575 		return (EINVAL);
576 	error = copyin(data, &args, sizeof args);
577 	if (error)
578 		return (error);
579 	vfs_oexport_conv(&args.export, &exp);
580 
581 	ma = mount_argsu(ma, "from", args.fspec, MAXPATHLEN);
582 	ma = mount_arg(ma, "export", &exp, sizeof(exp));
583 	error = kernel_mount(ma, flags);
584 
585 	return (error);
586 }
587 
588 /*
589  * Reload all incore data for a filesystem (used after running fsck on
590  * the root filesystem and finding things to fix). If the 'force' flag
591  * is 0, the filesystem must be mounted read-only.
592  *
593  * Things to do to update the mount:
594  *	1) invalidate all cached meta-data.
595  *	2) re-read superblock from disk.
596  *	3) re-read summary information from disk.
597  *	4) invalidate all inactive vnodes.
598  *	5) clear MNTK_SUSPEND2 and MNTK_SUSPENDED flags, allowing secondary
599  *	   writers, if requested.
600  *	6) invalidate all cached file data.
601  *	7) re-read inode data for all active vnodes.
602  */
603 int
604 ffs_reload(struct mount *mp, struct thread *td, int flags)
605 {
606 	struct vnode *vp, *mvp, *devvp;
607 	struct inode *ip;
608 	void *space;
609 	struct buf *bp;
610 	struct fs *fs, *newfs;
611 	struct ufsmount *ump;
612 	ufs2_daddr_t sblockloc;
613 	int i, blks, error;
614 	u_long size;
615 	int32_t *lp;
616 
617 	ump = VFSTOUFS(mp);
618 
619 	MNT_ILOCK(mp);
620 	if ((mp->mnt_flag & MNT_RDONLY) == 0 && (flags & FFSR_FORCE) == 0) {
621 		MNT_IUNLOCK(mp);
622 		return (EINVAL);
623 	}
624 	MNT_IUNLOCK(mp);
625 
626 	/*
627 	 * Step 1: invalidate all cached meta-data.
628 	 */
629 	devvp = VFSTOUFS(mp)->um_devvp;
630 	vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
631 	if (vinvalbuf(devvp, 0, 0, 0) != 0)
632 		panic("ffs_reload: dirty1");
633 	VOP_UNLOCK(devvp, 0);
634 
635 	/*
636 	 * Step 2: re-read superblock from disk.
637 	 */
638 	fs = VFSTOUFS(mp)->um_fs;
639 	if ((error = bread(devvp, btodb(fs->fs_sblockloc), fs->fs_sbsize,
640 	    NOCRED, &bp)) != 0)
641 		return (error);
642 	newfs = (struct fs *)bp->b_data;
643 	if ((newfs->fs_magic != FS_UFS1_MAGIC &&
644 	     newfs->fs_magic != FS_UFS2_MAGIC) ||
645 	    newfs->fs_bsize > MAXBSIZE ||
646 	    newfs->fs_bsize < sizeof(struct fs)) {
647 			brelse(bp);
648 			return (EIO);		/* XXX needs translation */
649 	}
650 	/*
651 	 * Copy pointer fields back into superblock before copying in	XXX
652 	 * new superblock. These should really be in the ufsmount.	XXX
653 	 * Note that important parameters (eg fs_ncg) are unchanged.
654 	 */
655 	newfs->fs_csp = fs->fs_csp;
656 	newfs->fs_maxcluster = fs->fs_maxcluster;
657 	newfs->fs_contigdirs = fs->fs_contigdirs;
658 	newfs->fs_active = fs->fs_active;
659 	newfs->fs_ronly = fs->fs_ronly;
660 	sblockloc = fs->fs_sblockloc;
661 	bcopy(newfs, fs, (u_int)fs->fs_sbsize);
662 	brelse(bp);
663 	mp->mnt_maxsymlinklen = fs->fs_maxsymlinklen;
664 	ffs_oldfscompat_read(fs, VFSTOUFS(mp), sblockloc);
665 	UFS_LOCK(ump);
666 	if (fs->fs_pendingblocks != 0 || fs->fs_pendinginodes != 0) {
667 		printf("WARNING: %s: reload pending error: blocks %jd "
668 		    "files %d\n", fs->fs_fsmnt, (intmax_t)fs->fs_pendingblocks,
669 		    fs->fs_pendinginodes);
670 		fs->fs_pendingblocks = 0;
671 		fs->fs_pendinginodes = 0;
672 	}
673 	UFS_UNLOCK(ump);
674 
675 	/*
676 	 * Step 3: re-read summary information from disk.
677 	 */
678 	size = fs->fs_cssize;
679 	blks = howmany(size, fs->fs_fsize);
680 	if (fs->fs_contigsumsize > 0)
681 		size += fs->fs_ncg * sizeof(int32_t);
682 	size += fs->fs_ncg * sizeof(u_int8_t);
683 	free(fs->fs_csp, M_UFSMNT);
684 	space = malloc(size, M_UFSMNT, M_WAITOK);
685 	fs->fs_csp = space;
686 	for (i = 0; i < blks; i += fs->fs_frag) {
687 		size = fs->fs_bsize;
688 		if (i + fs->fs_frag > blks)
689 			size = (blks - i) * fs->fs_fsize;
690 		error = bread(devvp, fsbtodb(fs, fs->fs_csaddr + i), size,
691 		    NOCRED, &bp);
692 		if (error)
693 			return (error);
694 		bcopy(bp->b_data, space, (u_int)size);
695 		space = (char *)space + size;
696 		brelse(bp);
697 	}
698 	/*
699 	 * We no longer know anything about clusters per cylinder group.
700 	 */
701 	if (fs->fs_contigsumsize > 0) {
702 		fs->fs_maxcluster = lp = space;
703 		for (i = 0; i < fs->fs_ncg; i++)
704 			*lp++ = fs->fs_contigsumsize;
705 		space = lp;
706 	}
707 	size = fs->fs_ncg * sizeof(u_int8_t);
708 	fs->fs_contigdirs = (u_int8_t *)space;
709 	bzero(fs->fs_contigdirs, size);
710 	if ((flags & FFSR_UNSUSPEND) != 0) {
711 		MNT_ILOCK(mp);
712 		mp->mnt_kern_flag &= ~(MNTK_SUSPENDED | MNTK_SUSPEND2);
713 		wakeup(&mp->mnt_flag);
714 		MNT_IUNLOCK(mp);
715 	}
716 
717 loop:
718 	MNT_VNODE_FOREACH_ALL(vp, mp, mvp) {
719 		/*
720 		 * Skip syncer vnode.
721 		 */
722 		if (vp->v_type == VNON) {
723 			VI_UNLOCK(vp);
724 			continue;
725 		}
726 		/*
727 		 * Step 4: invalidate all cached file data.
728 		 */
729 		if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, td)) {
730 			MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
731 			goto loop;
732 		}
733 		if (vinvalbuf(vp, 0, 0, 0))
734 			panic("ffs_reload: dirty2");
735 		/*
736 		 * Step 5: re-read inode data for all active vnodes.
737 		 */
738 		ip = VTOI(vp);
739 		error =
740 		    bread(devvp, fsbtodb(fs, ino_to_fsba(fs, ip->i_number)),
741 		    (int)fs->fs_bsize, NOCRED, &bp);
742 		if (error) {
743 			vput(vp);
744 			MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
745 			return (error);
746 		}
747 		if ((error = ffs_load_inode(bp, ip, fs, ip->i_number)) != 0) {
748 			brelse(bp);
749 			vput(vp);
750 			MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
751 			return (error);
752 		}
753 		ip->i_effnlink = ip->i_nlink;
754 		brelse(bp);
755 		vput(vp);
756 	}
757 	return (0);
758 }
759 
760 /*
761  * Common code for mount and mountroot
762  */
763 static int
764 ffs_mountfs(devvp, mp, td)
765 	struct vnode *devvp;
766 	struct mount *mp;
767 	struct thread *td;
768 {
769 	struct ufsmount *ump;
770 	struct fs *fs;
771 	struct cdev *dev;
772 	int error, i, len, ronly;
773 	struct ucred *cred;
774 	struct g_consumer *cp;
775 	struct mount *nmp;
776 	int candelete;
777 	off_t loc;
778 
779 	fs = NULL;
780 	ump = NULL;
781 	cred = td ? td->td_ucred : NOCRED;
782 	ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
783 
784 	KASSERT(devvp->v_type == VCHR, ("reclaimed devvp"));
785 	dev = devvp->v_rdev;
786 	if (atomic_cmpset_acq_ptr((uintptr_t *)&dev->si_mountpt, 0,
787 	    (uintptr_t)mp) == 0) {
788 		VOP_UNLOCK(devvp, 0);
789 		return (EBUSY);
790 	}
791 	g_topology_lock();
792 	error = g_vfs_open(devvp, &cp, "ffs", ronly ? 0 : 1);
793 	g_topology_unlock();
794 	if (error != 0) {
795 		atomic_store_rel_ptr((uintptr_t *)&dev->si_mountpt, 0);
796 		VOP_UNLOCK(devvp, 0);
797 		return (error);
798 	}
799 	dev_ref(dev);
800 	devvp->v_bufobj.bo_ops = &ffs_ops;
801 	VOP_UNLOCK(devvp, 0);
802 	if (dev->si_iosize_max != 0)
803 		mp->mnt_iosize_max = dev->si_iosize_max;
804 	if (mp->mnt_iosize_max > MAXPHYS)
805 		mp->mnt_iosize_max = MAXPHYS;
806 	if ((SBLOCKSIZE % cp->provider->sectorsize) != 0) {
807 		error = EINVAL;
808 		vfs_mount_error(mp,
809 		    "Invalid sectorsize %d for superblock size %d",
810 		    cp->provider->sectorsize, SBLOCKSIZE);
811 		goto out;
812 	}
813 	/* fetch the superblock and summary information */
814 	loc = STDSB;
815 	if ((mp->mnt_flag & MNT_ROOTFS) != 0)
816 		loc = STDSB_NOHASHFAIL;
817 	if ((error = ffs_sbget(devvp, &fs, loc, M_UFSMNT, ffs_use_bread)) != 0)
818 		goto out;
819 	/* none of these types of check-hashes are maintained by this kernel */
820 	fs->fs_metackhash &= ~(CK_INDIR | CK_DIR);
821 	/* no support for any undefined flags */
822 	fs->fs_flags &= FS_SUPPORTED;
823 	fs->fs_flags &= ~FS_UNCLEAN;
824 	if (fs->fs_clean == 0) {
825 		fs->fs_flags |= FS_UNCLEAN;
826 		if (ronly || (mp->mnt_flag & MNT_FORCE) ||
827 		    ((fs->fs_flags & (FS_SUJ | FS_NEEDSFSCK)) == 0 &&
828 		     (fs->fs_flags & FS_DOSOFTDEP))) {
829 			printf("WARNING: %s was not properly dismounted\n",
830 			    fs->fs_fsmnt);
831 		} else {
832 			vfs_mount_error(mp, "R/W mount of %s denied. %s%s",
833 			    fs->fs_fsmnt, "Filesystem is not clean - run fsck.",
834 			    (fs->fs_flags & FS_SUJ) == 0 ? "" :
835 			    " Forced mount will invalidate journal contents");
836 			error = EPERM;
837 			goto out;
838 		}
839 		if ((fs->fs_pendingblocks != 0 || fs->fs_pendinginodes != 0) &&
840 		    (mp->mnt_flag & MNT_FORCE)) {
841 			printf("WARNING: %s: lost blocks %jd files %d\n",
842 			    fs->fs_fsmnt, (intmax_t)fs->fs_pendingblocks,
843 			    fs->fs_pendinginodes);
844 			fs->fs_pendingblocks = 0;
845 			fs->fs_pendinginodes = 0;
846 		}
847 	}
848 	if (fs->fs_pendingblocks != 0 || fs->fs_pendinginodes != 0) {
849 		printf("WARNING: %s: mount pending error: blocks %jd "
850 		    "files %d\n", fs->fs_fsmnt, (intmax_t)fs->fs_pendingblocks,
851 		    fs->fs_pendinginodes);
852 		fs->fs_pendingblocks = 0;
853 		fs->fs_pendinginodes = 0;
854 	}
855 	if ((fs->fs_flags & FS_GJOURNAL) != 0) {
856 #ifdef UFS_GJOURNAL
857 		/*
858 		 * Get journal provider name.
859 		 */
860 		len = 1024;
861 		mp->mnt_gjprovider = malloc((u_long)len, M_UFSMNT, M_WAITOK);
862 		if (g_io_getattr("GJOURNAL::provider", cp, &len,
863 		    mp->mnt_gjprovider) == 0) {
864 			mp->mnt_gjprovider = realloc(mp->mnt_gjprovider, len,
865 			    M_UFSMNT, M_WAITOK);
866 			MNT_ILOCK(mp);
867 			mp->mnt_flag |= MNT_GJOURNAL;
868 			MNT_IUNLOCK(mp);
869 		} else {
870 			printf("WARNING: %s: GJOURNAL flag on fs "
871 			    "but no gjournal provider below\n",
872 			    mp->mnt_stat.f_mntonname);
873 			free(mp->mnt_gjprovider, M_UFSMNT);
874 			mp->mnt_gjprovider = NULL;
875 		}
876 #else
877 		printf("WARNING: %s: GJOURNAL flag on fs but no "
878 		    "UFS_GJOURNAL support\n", mp->mnt_stat.f_mntonname);
879 #endif
880 	} else {
881 		mp->mnt_gjprovider = NULL;
882 	}
883 	ump = malloc(sizeof *ump, M_UFSMNT, M_WAITOK | M_ZERO);
884 	ump->um_cp = cp;
885 	ump->um_bo = &devvp->v_bufobj;
886 	ump->um_fs = fs;
887 	if (fs->fs_magic == FS_UFS1_MAGIC) {
888 		ump->um_fstype = UFS1;
889 		ump->um_balloc = ffs_balloc_ufs1;
890 	} else {
891 		ump->um_fstype = UFS2;
892 		ump->um_balloc = ffs_balloc_ufs2;
893 	}
894 	ump->um_blkatoff = ffs_blkatoff;
895 	ump->um_truncate = ffs_truncate;
896 	ump->um_update = ffs_update;
897 	ump->um_valloc = ffs_valloc;
898 	ump->um_vfree = ffs_vfree;
899 	ump->um_ifree = ffs_ifree;
900 	ump->um_rdonly = ffs_rdonly;
901 	ump->um_snapgone = ffs_snapgone;
902 	mtx_init(UFS_MTX(ump), "FFS", "FFS Lock", MTX_DEF);
903 	ffs_oldfscompat_read(fs, ump, fs->fs_sblockloc);
904 	fs->fs_ronly = ronly;
905 	fs->fs_active = NULL;
906 	mp->mnt_data = ump;
907 	mp->mnt_stat.f_fsid.val[0] = fs->fs_id[0];
908 	mp->mnt_stat.f_fsid.val[1] = fs->fs_id[1];
909 	nmp = NULL;
910 	if (fs->fs_id[0] == 0 || fs->fs_id[1] == 0 ||
911 	    (nmp = vfs_getvfs(&mp->mnt_stat.f_fsid))) {
912 		if (nmp)
913 			vfs_rel(nmp);
914 		vfs_getnewfsid(mp);
915 	}
916 	mp->mnt_maxsymlinklen = fs->fs_maxsymlinklen;
917 	MNT_ILOCK(mp);
918 	mp->mnt_flag |= MNT_LOCAL;
919 	MNT_IUNLOCK(mp);
920 	if ((fs->fs_flags & FS_MULTILABEL) != 0) {
921 #ifdef MAC
922 		MNT_ILOCK(mp);
923 		mp->mnt_flag |= MNT_MULTILABEL;
924 		MNT_IUNLOCK(mp);
925 #else
926 		printf("WARNING: %s: multilabel flag on fs but "
927 		    "no MAC support\n", mp->mnt_stat.f_mntonname);
928 #endif
929 	}
930 	if ((fs->fs_flags & FS_ACLS) != 0) {
931 #ifdef UFS_ACL
932 		MNT_ILOCK(mp);
933 
934 		if (mp->mnt_flag & MNT_NFS4ACLS)
935 			printf("WARNING: %s: ACLs flag on fs conflicts with "
936 			    "\"nfsv4acls\" mount option; option ignored\n",
937 			    mp->mnt_stat.f_mntonname);
938 		mp->mnt_flag &= ~MNT_NFS4ACLS;
939 		mp->mnt_flag |= MNT_ACLS;
940 
941 		MNT_IUNLOCK(mp);
942 #else
943 		printf("WARNING: %s: ACLs flag on fs but no ACLs support\n",
944 		    mp->mnt_stat.f_mntonname);
945 #endif
946 	}
947 	if ((fs->fs_flags & FS_NFS4ACLS) != 0) {
948 #ifdef UFS_ACL
949 		MNT_ILOCK(mp);
950 
951 		if (mp->mnt_flag & MNT_ACLS)
952 			printf("WARNING: %s: NFSv4 ACLs flag on fs conflicts "
953 			    "with \"acls\" mount option; option ignored\n",
954 			    mp->mnt_stat.f_mntonname);
955 		mp->mnt_flag &= ~MNT_ACLS;
956 		mp->mnt_flag |= MNT_NFS4ACLS;
957 
958 		MNT_IUNLOCK(mp);
959 #else
960 		printf("WARNING: %s: NFSv4 ACLs flag on fs but no "
961 		    "ACLs support\n", mp->mnt_stat.f_mntonname);
962 #endif
963 	}
964 	if ((fs->fs_flags & FS_TRIM) != 0) {
965 		len = sizeof(int);
966 		if (g_io_getattr("GEOM::candelete", cp, &len,
967 		    &candelete) == 0) {
968 			if (candelete)
969 				ump->um_flags |= UM_CANDELETE;
970 			else
971 				printf("WARNING: %s: TRIM flag on fs but disk "
972 				    "does not support TRIM\n",
973 				    mp->mnt_stat.f_mntonname);
974 		} else {
975 			printf("WARNING: %s: TRIM flag on fs but disk does "
976 			    "not confirm that it supports TRIM\n",
977 			    mp->mnt_stat.f_mntonname);
978 		}
979 		if (((ump->um_flags) & UM_CANDELETE) != 0) {
980 			ump->um_trim_tq = taskqueue_create("trim", M_WAITOK,
981 			    taskqueue_thread_enqueue, &ump->um_trim_tq);
982 			taskqueue_start_threads(&ump->um_trim_tq, 1, PVFS,
983 			    "%s trim", mp->mnt_stat.f_mntonname);
984 			ump->um_trimhash = hashinit(MAXTRIMIO, M_TRIM,
985 			    &ump->um_trimlisthashsize);
986 		}
987 	}
988 
989 	ump->um_mountp = mp;
990 	ump->um_dev = dev;
991 	ump->um_devvp = devvp;
992 	ump->um_nindir = fs->fs_nindir;
993 	ump->um_bptrtodb = fs->fs_fsbtodb;
994 	ump->um_seqinc = fs->fs_frag;
995 	for (i = 0; i < MAXQUOTAS; i++)
996 		ump->um_quotas[i] = NULLVP;
997 #ifdef UFS_EXTATTR
998 	ufs_extattr_uepm_init(&ump->um_extattr);
999 #endif
1000 	/*
1001 	 * Set FS local "last mounted on" information (NULL pad)
1002 	 */
1003 	bzero(fs->fs_fsmnt, MAXMNTLEN);
1004 	strlcpy(fs->fs_fsmnt, mp->mnt_stat.f_mntonname, MAXMNTLEN);
1005 	mp->mnt_stat.f_iosize = fs->fs_bsize;
1006 
1007 	if (mp->mnt_flag & MNT_ROOTFS) {
1008 		/*
1009 		 * Root mount; update timestamp in mount structure.
1010 		 * this will be used by the common root mount code
1011 		 * to update the system clock.
1012 		 */
1013 		mp->mnt_time = fs->fs_time;
1014 	}
1015 
1016 	if (ronly == 0) {
1017 		fs->fs_mtime = time_second;
1018 		if ((fs->fs_flags & FS_DOSOFTDEP) &&
1019 		    (error = softdep_mount(devvp, mp, fs, cred)) != 0) {
1020 			ffs_flushfiles(mp, FORCECLOSE, td);
1021 			goto out;
1022 		}
1023 		if (fs->fs_snapinum[0] != 0)
1024 			ffs_snapshot_mount(mp);
1025 		fs->fs_fmod = 1;
1026 		fs->fs_clean = 0;
1027 		(void) ffs_sbupdate(ump, MNT_WAIT, 0);
1028 	}
1029 	/*
1030 	 * Initialize filesystem state information in mount struct.
1031 	 */
1032 	MNT_ILOCK(mp);
1033 	mp->mnt_kern_flag |= MNTK_LOOKUP_SHARED | MNTK_EXTENDED_SHARED |
1034 	    MNTK_NO_IOPF | MNTK_UNMAPPED_BUFS | MNTK_USES_BCACHE;
1035 	MNT_IUNLOCK(mp);
1036 #ifdef UFS_EXTATTR
1037 #ifdef UFS_EXTATTR_AUTOSTART
1038 	/*
1039 	 *
1040 	 * Auto-starting does the following:
1041 	 *	- check for /.attribute in the fs, and extattr_start if so
1042 	 *	- for each file in .attribute, enable that file with
1043 	 * 	  an attribute of the same name.
1044 	 * Not clear how to report errors -- probably eat them.
1045 	 * This would all happen while the filesystem was busy/not
1046 	 * available, so would effectively be "atomic".
1047 	 */
1048 	(void) ufs_extattr_autostart(mp, td);
1049 #endif /* !UFS_EXTATTR_AUTOSTART */
1050 #endif /* !UFS_EXTATTR */
1051 	return (0);
1052 out:
1053 	if (fs != NULL) {
1054 		free(fs->fs_csp, M_UFSMNT);
1055 		free(fs, M_UFSMNT);
1056 	}
1057 	if (cp != NULL) {
1058 		g_topology_lock();
1059 		g_vfs_close(cp);
1060 		g_topology_unlock();
1061 	}
1062 	if (ump) {
1063 		mtx_destroy(UFS_MTX(ump));
1064 		if (mp->mnt_gjprovider != NULL) {
1065 			free(mp->mnt_gjprovider, M_UFSMNT);
1066 			mp->mnt_gjprovider = NULL;
1067 		}
1068 		free(ump, M_UFSMNT);
1069 		mp->mnt_data = NULL;
1070 	}
1071 	atomic_store_rel_ptr((uintptr_t *)&dev->si_mountpt, 0);
1072 	dev_rel(dev);
1073 	return (error);
1074 }
1075 
1076 /*
1077  * A read function for use by filesystem-layer routines.
1078  */
1079 static int
1080 ffs_use_bread(void *devfd, off_t loc, void **bufp, int size)
1081 {
1082 	struct buf *bp;
1083 	int error;
1084 
1085 	KASSERT(*bufp == NULL, ("ffs_use_bread: non-NULL *bufp %p\n", *bufp));
1086 	*bufp = malloc(size, M_UFSMNT, M_WAITOK);
1087 	if ((error = bread((struct vnode *)devfd, btodb(loc), size, NOCRED,
1088 	    &bp)) != 0)
1089 		return (error);
1090 	bcopy(bp->b_data, *bufp, size);
1091 	bp->b_flags |= B_INVAL | B_NOCACHE;
1092 	brelse(bp);
1093 	return (0);
1094 }
1095 
1096 #include <sys/sysctl.h>
1097 static int bigcgs = 0;
1098 SYSCTL_INT(_debug, OID_AUTO, bigcgs, CTLFLAG_RW, &bigcgs, 0, "");
1099 
1100 /*
1101  * Sanity checks for loading old filesystem superblocks.
1102  * See ffs_oldfscompat_write below for unwound actions.
1103  *
1104  * XXX - Parts get retired eventually.
1105  * Unfortunately new bits get added.
1106  */
1107 static void
1108 ffs_oldfscompat_read(fs, ump, sblockloc)
1109 	struct fs *fs;
1110 	struct ufsmount *ump;
1111 	ufs2_daddr_t sblockloc;
1112 {
1113 	off_t maxfilesize;
1114 
1115 	/*
1116 	 * If not yet done, update fs_flags location and value of fs_sblockloc.
1117 	 */
1118 	if ((fs->fs_old_flags & FS_FLAGS_UPDATED) == 0) {
1119 		fs->fs_flags = fs->fs_old_flags;
1120 		fs->fs_old_flags |= FS_FLAGS_UPDATED;
1121 		fs->fs_sblockloc = sblockloc;
1122 	}
1123 	/*
1124 	 * If not yet done, update UFS1 superblock with new wider fields.
1125 	 */
1126 	if (fs->fs_magic == FS_UFS1_MAGIC && fs->fs_maxbsize != fs->fs_bsize) {
1127 		fs->fs_maxbsize = fs->fs_bsize;
1128 		fs->fs_time = fs->fs_old_time;
1129 		fs->fs_size = fs->fs_old_size;
1130 		fs->fs_dsize = fs->fs_old_dsize;
1131 		fs->fs_csaddr = fs->fs_old_csaddr;
1132 		fs->fs_cstotal.cs_ndir = fs->fs_old_cstotal.cs_ndir;
1133 		fs->fs_cstotal.cs_nbfree = fs->fs_old_cstotal.cs_nbfree;
1134 		fs->fs_cstotal.cs_nifree = fs->fs_old_cstotal.cs_nifree;
1135 		fs->fs_cstotal.cs_nffree = fs->fs_old_cstotal.cs_nffree;
1136 	}
1137 	if (fs->fs_magic == FS_UFS1_MAGIC &&
1138 	    fs->fs_old_inodefmt < FS_44INODEFMT) {
1139 		fs->fs_maxfilesize = ((uint64_t)1 << 31) - 1;
1140 		fs->fs_qbmask = ~fs->fs_bmask;
1141 		fs->fs_qfmask = ~fs->fs_fmask;
1142 	}
1143 	if (fs->fs_magic == FS_UFS1_MAGIC) {
1144 		ump->um_savedmaxfilesize = fs->fs_maxfilesize;
1145 		maxfilesize = (uint64_t)0x80000000 * fs->fs_bsize - 1;
1146 		if (fs->fs_maxfilesize > maxfilesize)
1147 			fs->fs_maxfilesize = maxfilesize;
1148 	}
1149 	/* Compatibility for old filesystems */
1150 	if (fs->fs_avgfilesize <= 0)
1151 		fs->fs_avgfilesize = AVFILESIZ;
1152 	if (fs->fs_avgfpdir <= 0)
1153 		fs->fs_avgfpdir = AFPDIR;
1154 	if (bigcgs) {
1155 		fs->fs_save_cgsize = fs->fs_cgsize;
1156 		fs->fs_cgsize = fs->fs_bsize;
1157 	}
1158 }
1159 
1160 /*
1161  * Unwinding superblock updates for old filesystems.
1162  * See ffs_oldfscompat_read above for details.
1163  *
1164  * XXX - Parts get retired eventually.
1165  * Unfortunately new bits get added.
1166  */
1167 void
1168 ffs_oldfscompat_write(fs, ump)
1169 	struct fs *fs;
1170 	struct ufsmount *ump;
1171 {
1172 
1173 	/*
1174 	 * Copy back UFS2 updated fields that UFS1 inspects.
1175 	 */
1176 	if (fs->fs_magic == FS_UFS1_MAGIC) {
1177 		fs->fs_old_time = fs->fs_time;
1178 		fs->fs_old_cstotal.cs_ndir = fs->fs_cstotal.cs_ndir;
1179 		fs->fs_old_cstotal.cs_nbfree = fs->fs_cstotal.cs_nbfree;
1180 		fs->fs_old_cstotal.cs_nifree = fs->fs_cstotal.cs_nifree;
1181 		fs->fs_old_cstotal.cs_nffree = fs->fs_cstotal.cs_nffree;
1182 		fs->fs_maxfilesize = ump->um_savedmaxfilesize;
1183 	}
1184 	if (bigcgs) {
1185 		fs->fs_cgsize = fs->fs_save_cgsize;
1186 		fs->fs_save_cgsize = 0;
1187 	}
1188 }
1189 
1190 /*
1191  * unmount system call
1192  */
1193 static int
1194 ffs_unmount(mp, mntflags)
1195 	struct mount *mp;
1196 	int mntflags;
1197 {
1198 	struct thread *td;
1199 	struct ufsmount *ump = VFSTOUFS(mp);
1200 	struct fs *fs;
1201 	int error, flags, susp;
1202 #ifdef UFS_EXTATTR
1203 	int e_restart;
1204 #endif
1205 
1206 	flags = 0;
1207 	td = curthread;
1208 	fs = ump->um_fs;
1209 	susp = 0;
1210 	if (mntflags & MNT_FORCE) {
1211 		flags |= FORCECLOSE;
1212 		susp = fs->fs_ronly == 0;
1213 	}
1214 #ifdef UFS_EXTATTR
1215 	if ((error = ufs_extattr_stop(mp, td))) {
1216 		if (error != EOPNOTSUPP)
1217 			printf("WARNING: unmount %s: ufs_extattr_stop "
1218 			    "returned errno %d\n", mp->mnt_stat.f_mntonname,
1219 			    error);
1220 		e_restart = 0;
1221 	} else {
1222 		ufs_extattr_uepm_destroy(&ump->um_extattr);
1223 		e_restart = 1;
1224 	}
1225 #endif
1226 	if (susp) {
1227 		error = vfs_write_suspend_umnt(mp);
1228 		if (error != 0)
1229 			goto fail1;
1230 	}
1231 	if (MOUNTEDSOFTDEP(mp))
1232 		error = softdep_flushfiles(mp, flags, td);
1233 	else
1234 		error = ffs_flushfiles(mp, flags, td);
1235 	if (error != 0 && error != ENXIO)
1236 		goto fail;
1237 
1238 	UFS_LOCK(ump);
1239 	if (fs->fs_pendingblocks != 0 || fs->fs_pendinginodes != 0) {
1240 		printf("WARNING: unmount %s: pending error: blocks %jd "
1241 		    "files %d\n", fs->fs_fsmnt, (intmax_t)fs->fs_pendingblocks,
1242 		    fs->fs_pendinginodes);
1243 		fs->fs_pendingblocks = 0;
1244 		fs->fs_pendinginodes = 0;
1245 	}
1246 	UFS_UNLOCK(ump);
1247 	if (MOUNTEDSOFTDEP(mp))
1248 		softdep_unmount(mp);
1249 	if (fs->fs_ronly == 0 || ump->um_fsckpid > 0) {
1250 		fs->fs_clean = fs->fs_flags & (FS_UNCLEAN|FS_NEEDSFSCK) ? 0 : 1;
1251 		error = ffs_sbupdate(ump, MNT_WAIT, 0);
1252 		if (error && error != ENXIO) {
1253 			fs->fs_clean = 0;
1254 			goto fail;
1255 		}
1256 	}
1257 	if (susp)
1258 		vfs_write_resume(mp, VR_START_WRITE);
1259 	if (ump->um_trim_tq != NULL) {
1260 		while (ump->um_trim_inflight != 0)
1261 			pause("ufsutr", hz);
1262 		taskqueue_drain_all(ump->um_trim_tq);
1263 		taskqueue_free(ump->um_trim_tq);
1264 		free (ump->um_trimhash, M_TRIM);
1265 	}
1266 	g_topology_lock();
1267 	if (ump->um_fsckpid > 0) {
1268 		/*
1269 		 * Return to normal read-only mode.
1270 		 */
1271 		error = g_access(ump->um_cp, 0, -1, 0);
1272 		ump->um_fsckpid = 0;
1273 	}
1274 	g_vfs_close(ump->um_cp);
1275 	g_topology_unlock();
1276 	atomic_store_rel_ptr((uintptr_t *)&ump->um_dev->si_mountpt, 0);
1277 	vrele(ump->um_devvp);
1278 	dev_rel(ump->um_dev);
1279 	mtx_destroy(UFS_MTX(ump));
1280 	if (mp->mnt_gjprovider != NULL) {
1281 		free(mp->mnt_gjprovider, M_UFSMNT);
1282 		mp->mnt_gjprovider = NULL;
1283 	}
1284 	free(fs->fs_csp, M_UFSMNT);
1285 	free(fs, M_UFSMNT);
1286 	free(ump, M_UFSMNT);
1287 	mp->mnt_data = NULL;
1288 	MNT_ILOCK(mp);
1289 	mp->mnt_flag &= ~MNT_LOCAL;
1290 	MNT_IUNLOCK(mp);
1291 	if (td->td_su == mp) {
1292 		td->td_su = NULL;
1293 		vfs_rel(mp);
1294 	}
1295 	return (error);
1296 
1297 fail:
1298 	if (susp)
1299 		vfs_write_resume(mp, VR_START_WRITE);
1300 fail1:
1301 #ifdef UFS_EXTATTR
1302 	if (e_restart) {
1303 		ufs_extattr_uepm_init(&ump->um_extattr);
1304 #ifdef UFS_EXTATTR_AUTOSTART
1305 		(void) ufs_extattr_autostart(mp, td);
1306 #endif
1307 	}
1308 #endif
1309 
1310 	return (error);
1311 }
1312 
1313 /*
1314  * Flush out all the files in a filesystem.
1315  */
1316 int
1317 ffs_flushfiles(mp, flags, td)
1318 	struct mount *mp;
1319 	int flags;
1320 	struct thread *td;
1321 {
1322 	struct ufsmount *ump;
1323 	int qerror, error;
1324 
1325 	ump = VFSTOUFS(mp);
1326 	qerror = 0;
1327 #ifdef QUOTA
1328 	if (mp->mnt_flag & MNT_QUOTA) {
1329 		int i;
1330 		error = vflush(mp, 0, SKIPSYSTEM|flags, td);
1331 		if (error)
1332 			return (error);
1333 		for (i = 0; i < MAXQUOTAS; i++) {
1334 			error = quotaoff(td, mp, i);
1335 			if (error != 0) {
1336 				if ((flags & EARLYFLUSH) == 0)
1337 					return (error);
1338 				else
1339 					qerror = error;
1340 			}
1341 		}
1342 
1343 		/*
1344 		 * Here we fall through to vflush again to ensure that
1345 		 * we have gotten rid of all the system vnodes, unless
1346 		 * quotas must not be closed.
1347 		 */
1348 	}
1349 #endif
1350 	ASSERT_VOP_LOCKED(ump->um_devvp, "ffs_flushfiles");
1351 	if (ump->um_devvp->v_vflag & VV_COPYONWRITE) {
1352 		if ((error = vflush(mp, 0, SKIPSYSTEM | flags, td)) != 0)
1353 			return (error);
1354 		ffs_snapshot_unmount(mp);
1355 		flags |= FORCECLOSE;
1356 		/*
1357 		 * Here we fall through to vflush again to ensure
1358 		 * that we have gotten rid of all the system vnodes.
1359 		 */
1360 	}
1361 
1362 	/*
1363 	 * Do not close system files if quotas were not closed, to be
1364 	 * able to sync the remaining dquots.  The freeblks softupdate
1365 	 * workitems might hold a reference on a dquot, preventing
1366 	 * quotaoff() from completing.  Next round of
1367 	 * softdep_flushworklist() iteration should process the
1368 	 * blockers, allowing the next run of quotaoff() to finally
1369 	 * flush held dquots.
1370 	 *
1371 	 * Otherwise, flush all the files.
1372 	 */
1373 	if (qerror == 0 && (error = vflush(mp, 0, flags, td)) != 0)
1374 		return (error);
1375 
1376 	/*
1377 	 * Flush filesystem metadata.
1378 	 */
1379 	vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY);
1380 	error = VOP_FSYNC(ump->um_devvp, MNT_WAIT, td);
1381 	VOP_UNLOCK(ump->um_devvp, 0);
1382 	return (error);
1383 }
1384 
1385 /*
1386  * Get filesystem statistics.
1387  */
1388 static int
1389 ffs_statfs(mp, sbp)
1390 	struct mount *mp;
1391 	struct statfs *sbp;
1392 {
1393 	struct ufsmount *ump;
1394 	struct fs *fs;
1395 
1396 	ump = VFSTOUFS(mp);
1397 	fs = ump->um_fs;
1398 	if (fs->fs_magic != FS_UFS1_MAGIC && fs->fs_magic != FS_UFS2_MAGIC)
1399 		panic("ffs_statfs");
1400 	sbp->f_version = STATFS_VERSION;
1401 	sbp->f_bsize = fs->fs_fsize;
1402 	sbp->f_iosize = fs->fs_bsize;
1403 	sbp->f_blocks = fs->fs_dsize;
1404 	UFS_LOCK(ump);
1405 	sbp->f_bfree = fs->fs_cstotal.cs_nbfree * fs->fs_frag +
1406 	    fs->fs_cstotal.cs_nffree + dbtofsb(fs, fs->fs_pendingblocks);
1407 	sbp->f_bavail = freespace(fs, fs->fs_minfree) +
1408 	    dbtofsb(fs, fs->fs_pendingblocks);
1409 	sbp->f_files =  fs->fs_ncg * fs->fs_ipg - UFS_ROOTINO;
1410 	sbp->f_ffree = fs->fs_cstotal.cs_nifree + fs->fs_pendinginodes;
1411 	UFS_UNLOCK(ump);
1412 	sbp->f_namemax = UFS_MAXNAMLEN;
1413 	return (0);
1414 }
1415 
1416 static bool
1417 sync_doupdate(struct inode *ip)
1418 {
1419 
1420 	return ((ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_MODIFIED |
1421 	    IN_UPDATE)) != 0);
1422 }
1423 
1424 /*
1425  * For a lazy sync, we only care about access times, quotas and the
1426  * superblock.  Other filesystem changes are already converted to
1427  * cylinder group blocks or inode blocks updates and are written to
1428  * disk by syncer.
1429  */
1430 static int
1431 ffs_sync_lazy(mp)
1432      struct mount *mp;
1433 {
1434 	struct vnode *mvp, *vp;
1435 	struct inode *ip;
1436 	struct thread *td;
1437 	int allerror, error;
1438 
1439 	allerror = 0;
1440 	td = curthread;
1441 	if ((mp->mnt_flag & MNT_NOATIME) != 0)
1442 		goto qupdate;
1443 	MNT_VNODE_FOREACH_ACTIVE(vp, mp, mvp) {
1444 		if (vp->v_type == VNON) {
1445 			VI_UNLOCK(vp);
1446 			continue;
1447 		}
1448 		ip = VTOI(vp);
1449 
1450 		/*
1451 		 * The IN_ACCESS flag is converted to IN_MODIFIED by
1452 		 * ufs_close() and ufs_getattr() by the calls to
1453 		 * ufs_itimes_locked(), without subsequent UFS_UPDATE().
1454 		 * Test also all the other timestamp flags too, to pick up
1455 		 * any other cases that could be missed.
1456 		 */
1457 		if (!sync_doupdate(ip) && (vp->v_iflag & VI_OWEINACT) == 0) {
1458 			VI_UNLOCK(vp);
1459 			continue;
1460 		}
1461 		if ((error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK,
1462 		    td)) != 0)
1463 			continue;
1464 		if (sync_doupdate(ip))
1465 			error = ffs_update(vp, 0);
1466 		if (error != 0)
1467 			allerror = error;
1468 		vput(vp);
1469 	}
1470 
1471 qupdate:
1472 #ifdef QUOTA
1473 	qsync(mp);
1474 #endif
1475 
1476 	if (VFSTOUFS(mp)->um_fs->fs_fmod != 0 &&
1477 	    (error = ffs_sbupdate(VFSTOUFS(mp), MNT_LAZY, 0)) != 0)
1478 		allerror = error;
1479 	return (allerror);
1480 }
1481 
1482 /*
1483  * Go through the disk queues to initiate sandbagged IO;
1484  * go through the inodes to write those that have been modified;
1485  * initiate the writing of the super block if it has been modified.
1486  *
1487  * Note: we are always called with the filesystem marked busy using
1488  * vfs_busy().
1489  */
1490 static int
1491 ffs_sync(mp, waitfor)
1492 	struct mount *mp;
1493 	int waitfor;
1494 {
1495 	struct vnode *mvp, *vp, *devvp;
1496 	struct thread *td;
1497 	struct inode *ip;
1498 	struct ufsmount *ump = VFSTOUFS(mp);
1499 	struct fs *fs;
1500 	int error, count, lockreq, allerror = 0;
1501 	int suspend;
1502 	int suspended;
1503 	int secondary_writes;
1504 	int secondary_accwrites;
1505 	int softdep_deps;
1506 	int softdep_accdeps;
1507 	struct bufobj *bo;
1508 
1509 	suspend = 0;
1510 	suspended = 0;
1511 	td = curthread;
1512 	fs = ump->um_fs;
1513 	if (fs->fs_fmod != 0 && fs->fs_ronly != 0 && ump->um_fsckpid == 0)
1514 		panic("%s: ffs_sync: modification on read-only filesystem",
1515 		    fs->fs_fsmnt);
1516 	if (waitfor == MNT_LAZY) {
1517 		if (!rebooting)
1518 			return (ffs_sync_lazy(mp));
1519 		waitfor = MNT_NOWAIT;
1520 	}
1521 
1522 	/*
1523 	 * Write back each (modified) inode.
1524 	 */
1525 	lockreq = LK_EXCLUSIVE | LK_NOWAIT;
1526 	if (waitfor == MNT_SUSPEND) {
1527 		suspend = 1;
1528 		waitfor = MNT_WAIT;
1529 	}
1530 	if (waitfor == MNT_WAIT)
1531 		lockreq = LK_EXCLUSIVE;
1532 	lockreq |= LK_INTERLOCK | LK_SLEEPFAIL;
1533 loop:
1534 	/* Grab snapshot of secondary write counts */
1535 	MNT_ILOCK(mp);
1536 	secondary_writes = mp->mnt_secondary_writes;
1537 	secondary_accwrites = mp->mnt_secondary_accwrites;
1538 	MNT_IUNLOCK(mp);
1539 
1540 	/* Grab snapshot of softdep dependency counts */
1541 	softdep_get_depcounts(mp, &softdep_deps, &softdep_accdeps);
1542 
1543 	MNT_VNODE_FOREACH_ALL(vp, mp, mvp) {
1544 		/*
1545 		 * Depend on the vnode interlock to keep things stable enough
1546 		 * for a quick test.  Since there might be hundreds of
1547 		 * thousands of vnodes, we cannot afford even a subroutine
1548 		 * call unless there's a good chance that we have work to do.
1549 		 */
1550 		if (vp->v_type == VNON) {
1551 			VI_UNLOCK(vp);
1552 			continue;
1553 		}
1554 		ip = VTOI(vp);
1555 		if ((ip->i_flag &
1556 		    (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE)) == 0 &&
1557 		    vp->v_bufobj.bo_dirty.bv_cnt == 0) {
1558 			VI_UNLOCK(vp);
1559 			continue;
1560 		}
1561 		if ((error = vget(vp, lockreq, td)) != 0) {
1562 			if (error == ENOENT || error == ENOLCK) {
1563 				MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
1564 				goto loop;
1565 			}
1566 			continue;
1567 		}
1568 		if ((error = ffs_syncvnode(vp, waitfor, 0)) != 0)
1569 			allerror = error;
1570 		vput(vp);
1571 	}
1572 	/*
1573 	 * Force stale filesystem control information to be flushed.
1574 	 */
1575 	if (waitfor == MNT_WAIT || rebooting) {
1576 		if ((error = softdep_flushworklist(ump->um_mountp, &count, td)))
1577 			allerror = error;
1578 		/* Flushed work items may create new vnodes to clean */
1579 		if (allerror == 0 && count)
1580 			goto loop;
1581 	}
1582 #ifdef QUOTA
1583 	qsync(mp);
1584 #endif
1585 
1586 	devvp = ump->um_devvp;
1587 	bo = &devvp->v_bufobj;
1588 	BO_LOCK(bo);
1589 	if (bo->bo_numoutput > 0 || bo->bo_dirty.bv_cnt > 0) {
1590 		BO_UNLOCK(bo);
1591 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
1592 		error = VOP_FSYNC(devvp, waitfor, td);
1593 		VOP_UNLOCK(devvp, 0);
1594 		if (MOUNTEDSOFTDEP(mp) && (error == 0 || error == EAGAIN))
1595 			error = ffs_sbupdate(ump, waitfor, 0);
1596 		if (error != 0)
1597 			allerror = error;
1598 		if (allerror == 0 && waitfor == MNT_WAIT)
1599 			goto loop;
1600 	} else if (suspend != 0) {
1601 		if (softdep_check_suspend(mp,
1602 					  devvp,
1603 					  softdep_deps,
1604 					  softdep_accdeps,
1605 					  secondary_writes,
1606 					  secondary_accwrites) != 0) {
1607 			MNT_IUNLOCK(mp);
1608 			goto loop;	/* More work needed */
1609 		}
1610 		mtx_assert(MNT_MTX(mp), MA_OWNED);
1611 		mp->mnt_kern_flag |= MNTK_SUSPEND2 | MNTK_SUSPENDED;
1612 		MNT_IUNLOCK(mp);
1613 		suspended = 1;
1614 	} else
1615 		BO_UNLOCK(bo);
1616 	/*
1617 	 * Write back modified superblock.
1618 	 */
1619 	if (fs->fs_fmod != 0 &&
1620 	    (error = ffs_sbupdate(ump, waitfor, suspended)) != 0)
1621 		allerror = error;
1622 	return (allerror);
1623 }
1624 
1625 int
1626 ffs_vget(mp, ino, flags, vpp)
1627 	struct mount *mp;
1628 	ino_t ino;
1629 	int flags;
1630 	struct vnode **vpp;
1631 {
1632 	return (ffs_vgetf(mp, ino, flags, vpp, 0));
1633 }
1634 
1635 int
1636 ffs_vgetf(mp, ino, flags, vpp, ffs_flags)
1637 	struct mount *mp;
1638 	ino_t ino;
1639 	int flags;
1640 	struct vnode **vpp;
1641 	int ffs_flags;
1642 {
1643 	struct fs *fs;
1644 	struct inode *ip;
1645 	struct ufsmount *ump;
1646 	struct buf *bp;
1647 	struct vnode *vp;
1648 	int error;
1649 
1650 	error = vfs_hash_get(mp, ino, flags, curthread, vpp, NULL, NULL);
1651 	if (error || *vpp != NULL)
1652 		return (error);
1653 
1654 	/*
1655 	 * We must promote to an exclusive lock for vnode creation.  This
1656 	 * can happen if lookup is passed LOCKSHARED.
1657 	 */
1658 	if ((flags & LK_TYPE_MASK) == LK_SHARED) {
1659 		flags &= ~LK_TYPE_MASK;
1660 		flags |= LK_EXCLUSIVE;
1661 	}
1662 
1663 	/*
1664 	 * We do not lock vnode creation as it is believed to be too
1665 	 * expensive for such rare case as simultaneous creation of vnode
1666 	 * for same ino by different processes. We just allow them to race
1667 	 * and check later to decide who wins. Let the race begin!
1668 	 */
1669 
1670 	ump = VFSTOUFS(mp);
1671 	fs = ump->um_fs;
1672 	ip = uma_zalloc(uma_inode, M_WAITOK | M_ZERO);
1673 
1674 	/* Allocate a new vnode/inode. */
1675 	error = getnewvnode("ufs", mp, fs->fs_magic == FS_UFS1_MAGIC ?
1676 	    &ffs_vnodeops1 : &ffs_vnodeops2, &vp);
1677 	if (error) {
1678 		*vpp = NULL;
1679 		uma_zfree(uma_inode, ip);
1680 		return (error);
1681 	}
1682 	/*
1683 	 * FFS supports recursive locking.
1684 	 */
1685 	lockmgr(vp->v_vnlock, LK_EXCLUSIVE, NULL);
1686 	VN_LOCK_AREC(vp);
1687 	vp->v_data = ip;
1688 	vp->v_bufobj.bo_bsize = fs->fs_bsize;
1689 	ip->i_vnode = vp;
1690 	ip->i_ump = ump;
1691 	ip->i_number = ino;
1692 	ip->i_ea_refs = 0;
1693 	ip->i_nextclustercg = -1;
1694 	ip->i_flag = fs->fs_magic == FS_UFS1_MAGIC ? 0 : IN_UFS2;
1695 	ip->i_mode = 0; /* ensure error cases below throw away vnode */
1696 #ifdef QUOTA
1697 	{
1698 		int i;
1699 		for (i = 0; i < MAXQUOTAS; i++)
1700 			ip->i_dquot[i] = NODQUOT;
1701 	}
1702 #endif
1703 
1704 	if (ffs_flags & FFSV_FORCEINSMQ)
1705 		vp->v_vflag |= VV_FORCEINSMQ;
1706 	error = insmntque(vp, mp);
1707 	if (error != 0) {
1708 		uma_zfree(uma_inode, ip);
1709 		*vpp = NULL;
1710 		return (error);
1711 	}
1712 	vp->v_vflag &= ~VV_FORCEINSMQ;
1713 	error = vfs_hash_insert(vp, ino, flags, curthread, vpp, NULL, NULL);
1714 	if (error || *vpp != NULL)
1715 		return (error);
1716 
1717 	/* Read in the disk contents for the inode, copy into the inode. */
1718 	error = bread(ump->um_devvp, fsbtodb(fs, ino_to_fsba(fs, ino)),
1719 	    (int)fs->fs_bsize, NOCRED, &bp);
1720 	if (error) {
1721 		/*
1722 		 * The inode does not contain anything useful, so it would
1723 		 * be misleading to leave it on its hash chain. With mode
1724 		 * still zero, it will be unlinked and returned to the free
1725 		 * list by vput().
1726 		 */
1727 		brelse(bp);
1728 		vput(vp);
1729 		*vpp = NULL;
1730 		return (error);
1731 	}
1732 	if (I_IS_UFS1(ip))
1733 		ip->i_din1 = uma_zalloc(uma_ufs1, M_WAITOK);
1734 	else
1735 		ip->i_din2 = uma_zalloc(uma_ufs2, M_WAITOK);
1736 	if ((error = ffs_load_inode(bp, ip, fs, ino)) != 0) {
1737 		bqrelse(bp);
1738 		vput(vp);
1739 		*vpp = NULL;
1740 		return (error);
1741 	}
1742 	if (DOINGSOFTDEP(vp))
1743 		softdep_load_inodeblock(ip);
1744 	else
1745 		ip->i_effnlink = ip->i_nlink;
1746 	bqrelse(bp);
1747 
1748 	/*
1749 	 * Initialize the vnode from the inode, check for aliases.
1750 	 * Note that the underlying vnode may have changed.
1751 	 */
1752 	error = ufs_vinit(mp, I_IS_UFS1(ip) ? &ffs_fifoops1 : &ffs_fifoops2,
1753 	    &vp);
1754 	if (error) {
1755 		vput(vp);
1756 		*vpp = NULL;
1757 		return (error);
1758 	}
1759 
1760 	/*
1761 	 * Finish inode initialization.
1762 	 */
1763 	if (vp->v_type != VFIFO) {
1764 		/* FFS supports shared locking for all files except fifos. */
1765 		VN_LOCK_ASHARE(vp);
1766 	}
1767 
1768 	/*
1769 	 * Set up a generation number for this inode if it does not
1770 	 * already have one. This should only happen on old filesystems.
1771 	 */
1772 	if (ip->i_gen == 0) {
1773 		while (ip->i_gen == 0)
1774 			ip->i_gen = arc4random();
1775 		if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
1776 			ip->i_flag |= IN_MODIFIED;
1777 			DIP_SET(ip, i_gen, ip->i_gen);
1778 		}
1779 	}
1780 #ifdef MAC
1781 	if ((mp->mnt_flag & MNT_MULTILABEL) && ip->i_mode) {
1782 		/*
1783 		 * If this vnode is already allocated, and we're running
1784 		 * multi-label, attempt to perform a label association
1785 		 * from the extended attributes on the inode.
1786 		 */
1787 		error = mac_vnode_associate_extattr(mp, vp);
1788 		if (error) {
1789 			/* ufs_inactive will release ip->i_devvp ref. */
1790 			vput(vp);
1791 			*vpp = NULL;
1792 			return (error);
1793 		}
1794 	}
1795 #endif
1796 
1797 	*vpp = vp;
1798 	return (0);
1799 }
1800 
1801 /*
1802  * File handle to vnode
1803  *
1804  * Have to be really careful about stale file handles:
1805  * - check that the inode number is valid
1806  * - for UFS2 check that the inode number is initialized
1807  * - call ffs_vget() to get the locked inode
1808  * - check for an unallocated inode (i_mode == 0)
1809  * - check that the given client host has export rights and return
1810  *   those rights via. exflagsp and credanonp
1811  */
1812 static int
1813 ffs_fhtovp(mp, fhp, flags, vpp)
1814 	struct mount *mp;
1815 	struct fid *fhp;
1816 	int flags;
1817 	struct vnode **vpp;
1818 {
1819 	struct ufid *ufhp;
1820 	struct ufsmount *ump;
1821 	struct fs *fs;
1822 	struct cg *cgp;
1823 	struct buf *bp;
1824 	ino_t ino;
1825 	u_int cg;
1826 	int error;
1827 
1828 	ufhp = (struct ufid *)fhp;
1829 	ino = ufhp->ufid_ino;
1830 	ump = VFSTOUFS(mp);
1831 	fs = ump->um_fs;
1832 	if (ino < UFS_ROOTINO || ino >= fs->fs_ncg * fs->fs_ipg)
1833 		return (ESTALE);
1834 	/*
1835 	 * Need to check if inode is initialized because UFS2 does lazy
1836 	 * initialization and nfs_fhtovp can offer arbitrary inode numbers.
1837 	 */
1838 	if (fs->fs_magic != FS_UFS2_MAGIC)
1839 		return (ufs_fhtovp(mp, ufhp, flags, vpp));
1840 	cg = ino_to_cg(fs, ino);
1841 	if ((error = ffs_getcg(fs, ump->um_devvp, cg, &bp, &cgp)) != 0)
1842 		return (error);
1843 	if (ino >= cg * fs->fs_ipg + cgp->cg_initediblk) {
1844 		brelse(bp);
1845 		return (ESTALE);
1846 	}
1847 	brelse(bp);
1848 	return (ufs_fhtovp(mp, ufhp, flags, vpp));
1849 }
1850 
1851 /*
1852  * Initialize the filesystem.
1853  */
1854 static int
1855 ffs_init(vfsp)
1856 	struct vfsconf *vfsp;
1857 {
1858 
1859 	ffs_susp_initialize();
1860 	softdep_initialize();
1861 	return (ufs_init(vfsp));
1862 }
1863 
1864 /*
1865  * Undo the work of ffs_init().
1866  */
1867 static int
1868 ffs_uninit(vfsp)
1869 	struct vfsconf *vfsp;
1870 {
1871 	int ret;
1872 
1873 	ret = ufs_uninit(vfsp);
1874 	softdep_uninitialize();
1875 	ffs_susp_uninitialize();
1876 	return (ret);
1877 }
1878 
1879 /*
1880  * Structure used to pass information from ffs_sbupdate to its
1881  * helper routine ffs_use_bwrite.
1882  */
1883 struct devfd {
1884 	struct ufsmount	*ump;
1885 	struct buf	*sbbp;
1886 	int		 waitfor;
1887 	int		 suspended;
1888 	int		 error;
1889 };
1890 
1891 /*
1892  * Write a superblock and associated information back to disk.
1893  */
1894 int
1895 ffs_sbupdate(ump, waitfor, suspended)
1896 	struct ufsmount *ump;
1897 	int waitfor;
1898 	int suspended;
1899 {
1900 	struct fs *fs;
1901 	struct buf *sbbp;
1902 	struct devfd devfd;
1903 
1904 	fs = ump->um_fs;
1905 	if (fs->fs_ronly == 1 &&
1906 	    (ump->um_mountp->mnt_flag & (MNT_RDONLY | MNT_UPDATE)) !=
1907 	    (MNT_RDONLY | MNT_UPDATE) && ump->um_fsckpid == 0)
1908 		panic("ffs_sbupdate: write read-only filesystem");
1909 	/*
1910 	 * We use the superblock's buf to serialize calls to ffs_sbupdate().
1911 	 */
1912 	sbbp = getblk(ump->um_devvp, btodb(fs->fs_sblockloc),
1913 	    (int)fs->fs_sbsize, 0, 0, 0);
1914 	/*
1915 	 * Initialize info needed for write function.
1916 	 */
1917 	devfd.ump = ump;
1918 	devfd.sbbp = sbbp;
1919 	devfd.waitfor = waitfor;
1920 	devfd.suspended = suspended;
1921 	devfd.error = 0;
1922 	return (ffs_sbput(&devfd, fs, fs->fs_sblockloc, ffs_use_bwrite));
1923 }
1924 
1925 /*
1926  * Write function for use by filesystem-layer routines.
1927  */
1928 static int
1929 ffs_use_bwrite(void *devfd, off_t loc, void *buf, int size)
1930 {
1931 	struct devfd *devfdp;
1932 	struct ufsmount *ump;
1933 	struct buf *bp;
1934 	struct fs *fs;
1935 	int error;
1936 
1937 	devfdp = devfd;
1938 	ump = devfdp->ump;
1939 	fs = ump->um_fs;
1940 	/*
1941 	 * Writing the superblock summary information.
1942 	 */
1943 	if (loc != fs->fs_sblockloc) {
1944 		bp = getblk(ump->um_devvp, btodb(loc), size, 0, 0, 0);
1945 		bcopy(buf, bp->b_data, (u_int)size);
1946 		if (devfdp->suspended)
1947 			bp->b_flags |= B_VALIDSUSPWRT;
1948 		if (devfdp->waitfor != MNT_WAIT)
1949 			bawrite(bp);
1950 		else if ((error = bwrite(bp)) != 0)
1951 			devfdp->error = error;
1952 		return (0);
1953 	}
1954 	/*
1955 	 * Writing the superblock itself. We need to do special checks for it.
1956 	 */
1957 	bp = devfdp->sbbp;
1958 	if (devfdp->error != 0) {
1959 		brelse(bp);
1960 		return (devfdp->error);
1961 	}
1962 	if (fs->fs_magic == FS_UFS1_MAGIC && fs->fs_sblockloc != SBLOCK_UFS1 &&
1963 	    (fs->fs_old_flags & FS_FLAGS_UPDATED) == 0) {
1964 		printf("WARNING: %s: correcting fs_sblockloc from %jd to %d\n",
1965 		    fs->fs_fsmnt, fs->fs_sblockloc, SBLOCK_UFS1);
1966 		fs->fs_sblockloc = SBLOCK_UFS1;
1967 	}
1968 	if (fs->fs_magic == FS_UFS2_MAGIC && fs->fs_sblockloc != SBLOCK_UFS2 &&
1969 	    (fs->fs_old_flags & FS_FLAGS_UPDATED) == 0) {
1970 		printf("WARNING: %s: correcting fs_sblockloc from %jd to %d\n",
1971 		    fs->fs_fsmnt, fs->fs_sblockloc, SBLOCK_UFS2);
1972 		fs->fs_sblockloc = SBLOCK_UFS2;
1973 	}
1974 	if (MOUNTEDSOFTDEP(ump->um_mountp))
1975 		softdep_setup_sbupdate(ump, (struct fs *)bp->b_data, bp);
1976 	bcopy((caddr_t)fs, bp->b_data, (u_int)fs->fs_sbsize);
1977 	ffs_oldfscompat_write((struct fs *)bp->b_data, ump);
1978 	if (devfdp->suspended)
1979 		bp->b_flags |= B_VALIDSUSPWRT;
1980 	if (devfdp->waitfor != MNT_WAIT)
1981 		bawrite(bp);
1982 	else if ((error = bwrite(bp)) != 0)
1983 		devfdp->error = error;
1984 	return (devfdp->error);
1985 }
1986 
1987 static int
1988 ffs_extattrctl(struct mount *mp, int cmd, struct vnode *filename_vp,
1989 	int attrnamespace, const char *attrname)
1990 {
1991 
1992 #ifdef UFS_EXTATTR
1993 	return (ufs_extattrctl(mp, cmd, filename_vp, attrnamespace,
1994 	    attrname));
1995 #else
1996 	return (vfs_stdextattrctl(mp, cmd, filename_vp, attrnamespace,
1997 	    attrname));
1998 #endif
1999 }
2000 
2001 static void
2002 ffs_ifree(struct ufsmount *ump, struct inode *ip)
2003 {
2004 
2005 	if (ump->um_fstype == UFS1 && ip->i_din1 != NULL)
2006 		uma_zfree(uma_ufs1, ip->i_din1);
2007 	else if (ip->i_din2 != NULL)
2008 		uma_zfree(uma_ufs2, ip->i_din2);
2009 	uma_zfree(uma_inode, ip);
2010 }
2011 
2012 static int dobkgrdwrite = 1;
2013 SYSCTL_INT(_debug, OID_AUTO, dobkgrdwrite, CTLFLAG_RW, &dobkgrdwrite, 0,
2014     "Do background writes (honoring the BV_BKGRDWRITE flag)?");
2015 
2016 /*
2017  * Complete a background write started from bwrite.
2018  */
2019 static void
2020 ffs_backgroundwritedone(struct buf *bp)
2021 {
2022 	struct bufobj *bufobj;
2023 	struct buf *origbp;
2024 
2025 	/*
2026 	 * Find the original buffer that we are writing.
2027 	 */
2028 	bufobj = bp->b_bufobj;
2029 	BO_LOCK(bufobj);
2030 	if ((origbp = gbincore(bp->b_bufobj, bp->b_lblkno)) == NULL)
2031 		panic("backgroundwritedone: lost buffer");
2032 
2033 	/*
2034 	 * We should mark the cylinder group buffer origbp as
2035 	 * dirty, to not loose the failed write.
2036 	 */
2037 	if ((bp->b_ioflags & BIO_ERROR) != 0)
2038 		origbp->b_vflags |= BV_BKGRDERR;
2039 	BO_UNLOCK(bufobj);
2040 	/*
2041 	 * Process dependencies then return any unfinished ones.
2042 	 */
2043 	if (!LIST_EMPTY(&bp->b_dep) && (bp->b_ioflags & BIO_ERROR) == 0)
2044 		buf_complete(bp);
2045 #ifdef SOFTUPDATES
2046 	if (!LIST_EMPTY(&bp->b_dep))
2047 		softdep_move_dependencies(bp, origbp);
2048 #endif
2049 	/*
2050 	 * This buffer is marked B_NOCACHE so when it is released
2051 	 * by biodone it will be tossed.
2052 	 */
2053 	bp->b_flags |= B_NOCACHE;
2054 	bp->b_flags &= ~B_CACHE;
2055 	pbrelvp(bp);
2056 
2057 	/*
2058 	 * Prevent brelse() from trying to keep and re-dirtying bp on
2059 	 * errors. It causes b_bufobj dereference in
2060 	 * bdirty()/reassignbuf(), and b_bufobj was cleared in
2061 	 * pbrelvp() above.
2062 	 */
2063 	if ((bp->b_ioflags & BIO_ERROR) != 0)
2064 		bp->b_flags |= B_INVAL;
2065 	bufdone(bp);
2066 	BO_LOCK(bufobj);
2067 	/*
2068 	 * Clear the BV_BKGRDINPROG flag in the original buffer
2069 	 * and awaken it if it is waiting for the write to complete.
2070 	 * If BV_BKGRDINPROG is not set in the original buffer it must
2071 	 * have been released and re-instantiated - which is not legal.
2072 	 */
2073 	KASSERT((origbp->b_vflags & BV_BKGRDINPROG),
2074 	    ("backgroundwritedone: lost buffer2"));
2075 	origbp->b_vflags &= ~BV_BKGRDINPROG;
2076 	if (origbp->b_vflags & BV_BKGRDWAIT) {
2077 		origbp->b_vflags &= ~BV_BKGRDWAIT;
2078 		wakeup(&origbp->b_xflags);
2079 	}
2080 	BO_UNLOCK(bufobj);
2081 }
2082 
2083 
2084 /*
2085  * Write, release buffer on completion.  (Done by iodone
2086  * if async).  Do not bother writing anything if the buffer
2087  * is invalid.
2088  *
2089  * Note that we set B_CACHE here, indicating that buffer is
2090  * fully valid and thus cacheable.  This is true even of NFS
2091  * now so we set it generally.  This could be set either here
2092  * or in biodone() since the I/O is synchronous.  We put it
2093  * here.
2094  */
2095 static int
2096 ffs_bufwrite(struct buf *bp)
2097 {
2098 	struct buf *newbp;
2099 	struct cg *cgp;
2100 
2101 	CTR3(KTR_BUF, "bufwrite(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags);
2102 	if (bp->b_flags & B_INVAL) {
2103 		brelse(bp);
2104 		return (0);
2105 	}
2106 
2107 	if (!BUF_ISLOCKED(bp))
2108 		panic("bufwrite: buffer is not busy???");
2109 	/*
2110 	 * If a background write is already in progress, delay
2111 	 * writing this block if it is asynchronous. Otherwise
2112 	 * wait for the background write to complete.
2113 	 */
2114 	BO_LOCK(bp->b_bufobj);
2115 	if (bp->b_vflags & BV_BKGRDINPROG) {
2116 		if (bp->b_flags & B_ASYNC) {
2117 			BO_UNLOCK(bp->b_bufobj);
2118 			bdwrite(bp);
2119 			return (0);
2120 		}
2121 		bp->b_vflags |= BV_BKGRDWAIT;
2122 		msleep(&bp->b_xflags, BO_LOCKPTR(bp->b_bufobj), PRIBIO,
2123 		    "bwrbg", 0);
2124 		if (bp->b_vflags & BV_BKGRDINPROG)
2125 			panic("bufwrite: still writing");
2126 	}
2127 	bp->b_vflags &= ~BV_BKGRDERR;
2128 	BO_UNLOCK(bp->b_bufobj);
2129 
2130 	/*
2131 	 * If this buffer is marked for background writing and we
2132 	 * do not have to wait for it, make a copy and write the
2133 	 * copy so as to leave this buffer ready for further use.
2134 	 *
2135 	 * This optimization eats a lot of memory.  If we have a page
2136 	 * or buffer shortfall we can't do it.
2137 	 */
2138 	if (dobkgrdwrite && (bp->b_xflags & BX_BKGRDWRITE) &&
2139 	    (bp->b_flags & B_ASYNC) &&
2140 	    !vm_page_count_severe() &&
2141 	    !buf_dirty_count_severe()) {
2142 		KASSERT(bp->b_iodone == NULL,
2143 		    ("bufwrite: needs chained iodone (%p)", bp->b_iodone));
2144 
2145 		/* get a new block */
2146 		newbp = geteblk(bp->b_bufsize, GB_NOWAIT_BD);
2147 		if (newbp == NULL)
2148 			goto normal_write;
2149 
2150 		KASSERT(buf_mapped(bp), ("Unmapped cg"));
2151 		memcpy(newbp->b_data, bp->b_data, bp->b_bufsize);
2152 		BO_LOCK(bp->b_bufobj);
2153 		bp->b_vflags |= BV_BKGRDINPROG;
2154 		BO_UNLOCK(bp->b_bufobj);
2155 		newbp->b_xflags |=
2156 		    (bp->b_xflags & BX_FSPRIV) | BX_BKGRDMARKER;
2157 		newbp->b_lblkno = bp->b_lblkno;
2158 		newbp->b_blkno = bp->b_blkno;
2159 		newbp->b_offset = bp->b_offset;
2160 		newbp->b_iodone = ffs_backgroundwritedone;
2161 		newbp->b_flags |= B_ASYNC;
2162 		newbp->b_flags &= ~B_INVAL;
2163 		pbgetvp(bp->b_vp, newbp);
2164 
2165 #ifdef SOFTUPDATES
2166 		/*
2167 		 * Move over the dependencies.  If there are rollbacks,
2168 		 * leave the parent buffer dirtied as it will need to
2169 		 * be written again.
2170 		 */
2171 		if (LIST_EMPTY(&bp->b_dep) ||
2172 		    softdep_move_dependencies(bp, newbp) == 0)
2173 			bundirty(bp);
2174 #else
2175 		bundirty(bp);
2176 #endif
2177 
2178 		/*
2179 		 * Initiate write on the copy, release the original.  The
2180 		 * BKGRDINPROG flag prevents it from going away until
2181 		 * the background write completes. We have to recalculate
2182 		 * its check hash in case the buffer gets freed and then
2183 		 * reconstituted from the buffer cache during a later read.
2184 		 */
2185 		if ((bp->b_xflags & BX_CYLGRP) != 0) {
2186 			cgp = (struct cg *)bp->b_data;
2187 			cgp->cg_ckhash = 0;
2188 			cgp->cg_ckhash =
2189 			    calculate_crc32c(~0L, bp->b_data, bp->b_bcount);
2190 		}
2191 		bqrelse(bp);
2192 		bp = newbp;
2193 	} else
2194 		/* Mark the buffer clean */
2195 		bundirty(bp);
2196 
2197 
2198 	/* Let the normal bufwrite do the rest for us */
2199 normal_write:
2200 	/*
2201 	 * If we are writing a cylinder group, update its time.
2202 	 */
2203 	if ((bp->b_xflags & BX_CYLGRP) != 0) {
2204 		cgp = (struct cg *)bp->b_data;
2205 		cgp->cg_old_time = cgp->cg_time = time_second;
2206 	}
2207 	return (bufwrite(bp));
2208 }
2209 
2210 
2211 static void
2212 ffs_geom_strategy(struct bufobj *bo, struct buf *bp)
2213 {
2214 	struct vnode *vp;
2215 	struct buf *tbp;
2216 	int error, nocopy;
2217 
2218 	vp = bo2vnode(bo);
2219 	if (bp->b_iocmd == BIO_WRITE) {
2220 		if ((bp->b_flags & B_VALIDSUSPWRT) == 0 &&
2221 		    bp->b_vp != NULL && bp->b_vp->v_mount != NULL &&
2222 		    (bp->b_vp->v_mount->mnt_kern_flag & MNTK_SUSPENDED) != 0)
2223 			panic("ffs_geom_strategy: bad I/O");
2224 		nocopy = bp->b_flags & B_NOCOPY;
2225 		bp->b_flags &= ~(B_VALIDSUSPWRT | B_NOCOPY);
2226 		if ((vp->v_vflag & VV_COPYONWRITE) && nocopy == 0 &&
2227 		    vp->v_rdev->si_snapdata != NULL) {
2228 			if ((bp->b_flags & B_CLUSTER) != 0) {
2229 				runningbufwakeup(bp);
2230 				TAILQ_FOREACH(tbp, &bp->b_cluster.cluster_head,
2231 					      b_cluster.cluster_entry) {
2232 					error = ffs_copyonwrite(vp, tbp);
2233 					if (error != 0 &&
2234 					    error != EOPNOTSUPP) {
2235 						bp->b_error = error;
2236 						bp->b_ioflags |= BIO_ERROR;
2237 						bufdone(bp);
2238 						return;
2239 					}
2240 				}
2241 				bp->b_runningbufspace = bp->b_bufsize;
2242 				atomic_add_long(&runningbufspace,
2243 					       bp->b_runningbufspace);
2244 			} else {
2245 				error = ffs_copyonwrite(vp, bp);
2246 				if (error != 0 && error != EOPNOTSUPP) {
2247 					bp->b_error = error;
2248 					bp->b_ioflags |= BIO_ERROR;
2249 					bufdone(bp);
2250 					return;
2251 				}
2252 			}
2253 		}
2254 #ifdef SOFTUPDATES
2255 		if ((bp->b_flags & B_CLUSTER) != 0) {
2256 			TAILQ_FOREACH(tbp, &bp->b_cluster.cluster_head,
2257 				      b_cluster.cluster_entry) {
2258 				if (!LIST_EMPTY(&tbp->b_dep))
2259 					buf_start(tbp);
2260 			}
2261 		} else {
2262 			if (!LIST_EMPTY(&bp->b_dep))
2263 				buf_start(bp);
2264 		}
2265 
2266 #endif
2267 		/*
2268 		 * Check for metadata that needs check-hashes and update them.
2269 		 */
2270 		switch (bp->b_xflags & BX_FSPRIV) {
2271 		case BX_CYLGRP:
2272 			((struct cg *)bp->b_data)->cg_ckhash = 0;
2273 			((struct cg *)bp->b_data)->cg_ckhash =
2274 			    calculate_crc32c(~0L, bp->b_data, bp->b_bcount);
2275 			break;
2276 
2277 		case BX_SUPERBLOCK:
2278 		case BX_INODE:
2279 		case BX_INDIR:
2280 		case BX_DIR:
2281 			printf("Check-hash write is unimplemented!!!\n");
2282 			break;
2283 
2284 		case 0:
2285 			break;
2286 
2287 		default:
2288 			printf("multiple buffer types 0x%b\n",
2289 			    (u_int)(bp->b_xflags & BX_FSPRIV),
2290 			    PRINT_UFS_BUF_XFLAGS);
2291 			break;
2292 		}
2293 	}
2294 	g_vfs_strategy(bo, bp);
2295 }
2296 
2297 int
2298 ffs_own_mount(const struct mount *mp)
2299 {
2300 
2301 	if (mp->mnt_op == &ufs_vfsops)
2302 		return (1);
2303 	return (0);
2304 }
2305 
2306 #ifdef	DDB
2307 #ifdef SOFTUPDATES
2308 
2309 /* defined in ffs_softdep.c */
2310 extern void db_print_ffs(struct ufsmount *ump);
2311 
2312 DB_SHOW_COMMAND(ffs, db_show_ffs)
2313 {
2314 	struct mount *mp;
2315 	struct ufsmount *ump;
2316 
2317 	if (have_addr) {
2318 		ump = VFSTOUFS((struct mount *)addr);
2319 		db_print_ffs(ump);
2320 		return;
2321 	}
2322 
2323 	TAILQ_FOREACH(mp, &mountlist, mnt_list) {
2324 		if (!strcmp(mp->mnt_stat.f_fstypename, ufs_vfsconf.vfc_name))
2325 			db_print_ffs(VFSTOUFS(mp));
2326 	}
2327 }
2328 
2329 #endif	/* SOFTUPDATES */
2330 #endif	/* DDB */
2331