2 * modified for EXT2FS support in Lites 1.1
4 * Aug 1995, Godmar Back (gback@cs.utah.edu)
5 * University of Utah, Department of Computer Science
8 * SPDX-License-Identifier: BSD-3-Clause
10 * Copyright (c) 1989, 1991, 1993, 1994
11 * The Regents of the University of California. All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * @(#)ffs_vfsops.c 8.8 (Berkeley) 4/18/94
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/namei.h>
46 #include <sys/kernel.h>
47 #include <sys/vnode.h>
48 #include <sys/mount.h>
52 #include <sys/endian.h>
53 #include <sys/fcntl.h>
54 #include <sys/malloc.h>
57 #include <sys/mutex.h>
59 #include <geom/geom.h>
60 #include <geom/geom_vfs.h>
62 #include <fs/ext2fs/fs.h>
63 #include <fs/ext2fs/ext2_mount.h>
64 #include <fs/ext2fs/inode.h>
66 #include <fs/ext2fs/ext2fs.h>
67 #include <fs/ext2fs/ext2_dinode.h>
68 #include <fs/ext2fs/ext2_extern.h>
69 #include <fs/ext2fs/ext2_extents.h>
71 SDT_PROVIDER_DECLARE(ext2fs);
74 * arg0: verbosity. Higher numbers give more verbose messages
75 * arg1: Textual message
77 SDT_PROBE_DEFINE2(ext2fs, , vfsops, trace, "int", "char*");
78 SDT_PROBE_DEFINE2(ext2fs, , vfsops, ext2_cg_validate_error, "char*", "int");
79 SDT_PROBE_DEFINE1(ext2fs, , vfsops, ext2_compute_sb_data_error, "char*");
82 static int ext2_flushfiles(struct mount *mp, int flags, struct thread *td);
83 static int ext2_mountfs(struct vnode *, struct mount *);
84 static int ext2_reload(struct mount *mp, struct thread *td);
85 static int ext2_sbupdate(struct ext2mount *, int);
86 static int ext2_cgupdate(struct ext2mount *, int);
87 static vfs_unmount_t ext2_unmount;
88 static vfs_root_t ext2_root;
89 static vfs_statfs_t ext2_statfs;
90 static vfs_sync_t ext2_sync;
91 static vfs_vget_t ext2_vget;
92 static vfs_fhtovp_t ext2_fhtovp;
93 static vfs_mount_t ext2_mount;
95 MALLOC_DEFINE(M_EXT2NODE, "ext2_node", "EXT2 vnode private part");
96 static MALLOC_DEFINE(M_EXT2MNT, "ext2_mount", "EXT2 mount structure");
98 static struct vfsops ext2fs_vfsops = {
99 .vfs_fhtovp = ext2_fhtovp,
100 .vfs_mount = ext2_mount,
101 .vfs_root = ext2_root, /* root inode via vget */
102 .vfs_statfs = ext2_statfs,
103 .vfs_sync = ext2_sync,
104 .vfs_unmount = ext2_unmount,
105 .vfs_vget = ext2_vget,
108 VFS_SET(ext2fs_vfsops, ext2fs, 0);
110 static int ext2_check_sb_compat(struct ext2fs *es, struct cdev *dev,
112 static int ext2_compute_sb_data(struct vnode * devvp,
113 struct ext2fs * es, struct m_ext2fs * fs);
115 static const char *ext2_opts[] = { "acls", "async", "noatime", "noclusterr",
116 "noclusterw", "noexec", "export", "force", "from", "multilabel",
117 "suiddir", "nosymfollow", "sync", "union", NULL };
125 ext2_mount(struct mount *mp)
127 struct vfsoptlist *opts;
130 struct ext2mount *ump = NULL;
132 struct nameidata nd, *ndp = &nd;
135 int error, flags, len;
138 opts = mp->mnt_optnew;
140 if (vfs_filteropt(opts, ext2_opts))
143 vfs_getopt(opts, "fspath", (void **)&path, NULL);
144 /* Double-check the length of path.. */
145 if (strlen(path) >= MAXMNTLEN)
146 return (ENAMETOOLONG);
149 error = vfs_getopt(opts, "from", (void **)&fspec, &len);
150 if (!error && fspec[len - 1] != '\0')
154 * If updating, check whether changing from read-only to
155 * read/write; if there is no device name, that's all we do.
157 if (mp->mnt_flag & MNT_UPDATE) {
161 if (fs->e2fs_ronly == 0 &&
162 vfs_flagopt(opts, "ro", NULL, 0)) {
163 error = VFS_SYNC(mp, MNT_WAIT);
167 if (mp->mnt_flag & MNT_FORCE)
169 error = ext2_flushfiles(mp, flags, td);
170 if (error == 0 && fs->e2fs_wasvalid &&
171 ext2_cgupdate(ump, MNT_WAIT) == 0) {
172 fs->e2fs->e2fs_state =
173 htole16((le16toh(fs->e2fs->e2fs_state) |
175 ext2_sbupdate(ump, MNT_WAIT);
178 vfs_flagopt(opts, "ro", &mp->mnt_flag, MNT_RDONLY);
180 g_access(ump->um_cp, 0, -1, 0);
183 if (!error && (mp->mnt_flag & MNT_RELOAD))
184 error = ext2_reload(mp, td);
187 devvp = ump->um_devvp;
188 if (fs->e2fs_ronly && !vfs_flagopt(opts, "ro", NULL, 0)) {
189 if (ext2_check_sb_compat(fs->e2fs, devvp->v_rdev, 0))
193 * If upgrade to read-write by non-root, then verify
194 * that user has necessary permissions on the device.
196 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
197 error = VOP_ACCESS(devvp, VREAD | VWRITE,
200 error = priv_check(td, PRIV_VFS_MOUNT_PERM);
207 error = g_access(ump->um_cp, 0, 1, 0);
212 if ((le16toh(fs->e2fs->e2fs_state) & E2FS_ISCLEAN) == 0 ||
213 (le16toh(fs->e2fs->e2fs_state) & E2FS_ERRORS)) {
214 if (mp->mnt_flag & MNT_FORCE) {
216 "WARNING: %s was not properly dismounted\n", fs->e2fs_fsmnt);
219 "WARNING: R/W mount of %s denied. Filesystem is not clean - run fsck\n",
224 fs->e2fs->e2fs_state =
225 htole16(le16toh(fs->e2fs->e2fs_state) & ~E2FS_ISCLEAN);
226 (void)ext2_cgupdate(ump, MNT_WAIT);
229 mp->mnt_flag &= ~MNT_RDONLY;
232 if (vfs_flagopt(opts, "export", NULL, 0)) {
233 /* Process export requests in vfs_mount.c. */
239 * Not an update, or updating the name: look up the name
240 * and verify that it refers to a sensible disk device.
244 NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, fspec, td);
245 if ((error = namei(ndp)) != 0)
247 NDFREE(ndp, NDF_ONLY_PNBUF);
250 if (!vn_isdisk_error(devvp, &error)) {
256 * If mount by non-root, then verify that user has necessary
257 * permissions on the device.
259 * XXXRW: VOP_ACCESS() enough?
262 if ((mp->mnt_flag & MNT_RDONLY) == 0)
264 error = VOP_ACCESS(devvp, accmode, td->td_ucred, td);
266 error = priv_check(td, PRIV_VFS_MOUNT_PERM);
272 if ((mp->mnt_flag & MNT_UPDATE) == 0) {
273 error = ext2_mountfs(devvp, mp);
275 if (devvp != ump->um_devvp) {
277 return (EINVAL); /* needs translation */
289 * Note that this strncpy() is ok because of a check at the start
292 strncpy(fs->e2fs_fsmnt, path, MAXMNTLEN);
293 fs->e2fs_fsmnt[MAXMNTLEN - 1] = '\0';
294 vfs_mountedfrom(mp, fspec);
299 ext2_check_sb_compat(struct ext2fs *es, struct cdev *dev, int ronly)
303 if (le16toh(es->e2fs_magic) != E2FS_MAGIC) {
304 printf("ext2fs: %s: wrong magic number %#x (expected %#x)\n",
305 devtoname(dev), le16toh(es->e2fs_magic), E2FS_MAGIC);
308 if (le32toh(es->e2fs_rev) > E2FS_REV0) {
309 mask = le32toh(es->e2fs_features_incompat) & ~(EXT2F_INCOMPAT_SUPP);
311 printf("WARNING: mount of %s denied due to "
312 "unsupported optional features:\n", devtoname(dev));
314 i < sizeof(incompat)/sizeof(struct ext2_feature);
316 if (mask & incompat[i].mask)
317 printf("%s ", incompat[i].name);
321 mask = le32toh(es->e2fs_features_rocompat) & ~EXT2F_ROCOMPAT_SUPP;
322 if (!ronly && mask) {
323 printf("WARNING: R/W mount of %s denied due to "
324 "unsupported optional features:\n", devtoname(dev));
326 i < sizeof(ro_compat)/sizeof(struct ext2_feature);
328 if (mask & ro_compat[i].mask)
329 printf("%s ", ro_compat[i].name);
338 ext2_cg_location(struct m_ext2fs *fs, int number)
340 int cg, descpb, logical_sb, has_super = 0;
343 * Adjust logical superblock block number.
344 * Godmar thinks: if the blocksize is greater than 1024, then
345 * the superblock is logically part of block zero.
347 logical_sb = fs->e2fs_bsize > SBSIZE ? 0 : 1;
349 if (!EXT2_HAS_INCOMPAT_FEATURE(fs, EXT2F_INCOMPAT_META_BG) ||
350 number < le32toh(fs->e2fs->e3fs_first_meta_bg))
351 return (logical_sb + number + 1);
353 if (EXT2_HAS_INCOMPAT_FEATURE(fs, EXT2F_INCOMPAT_64BIT))
354 descpb = fs->e2fs_bsize / sizeof(struct ext2_gd);
356 descpb = fs->e2fs_bsize / E2FS_REV0_GD_SIZE;
358 cg = descpb * number;
360 if (ext2_cg_has_sb(fs, cg))
363 return (has_super + cg * (e4fs_daddr_t)EXT2_BLOCKS_PER_GROUP(fs) +
364 le32toh(fs->e2fs->e2fs_first_dblock));
368 ext2_cg_validate(struct m_ext2fs *fs)
373 uint64_t first_block, last_block, last_cg_block;
375 unsigned int i, cg_count;
377 first_block = le32toh(fs->e2fs->e2fs_first_dblock);
378 last_cg_block = ext2_cg_number_gdb(fs, 0);
379 cg_count = fs->e2fs_gcount;
381 for (i = 0; i < fs->e2fs_gcount; i++) {
382 gd = &fs->e2fs_gd[i];
384 if (EXT2_HAS_INCOMPAT_FEATURE(fs, EXT2F_INCOMPAT_FLEX_BG) ||
385 i == fs->e2fs_gcount - 1) {
386 last_block = fs->e2fs_bcount - 1;
388 last_block = first_block +
389 (EXT2_BLOCKS_PER_GROUP(fs) - 1);
392 if ((cg_count == fs->e2fs_gcount) &&
393 !(le16toh(gd->ext4bgd_flags) & EXT2_BG_INODE_ZEROED))
396 b_bitmap = e2fs_gd_get_b_bitmap(gd);
398 SDT_PROBE2(ext2fs, , vfsops, ext2_cg_validate_error,
399 "block bitmap is zero", i);
403 if (b_bitmap <= last_cg_block) {
404 SDT_PROBE2(ext2fs, , vfsops, ext2_cg_validate_error,
405 "block bitmap overlaps gds", i);
408 if (b_bitmap < first_block || b_bitmap > last_block) {
409 SDT_PROBE2(ext2fs, , vfsops, ext2_cg_validate_error,
410 "block bitmap not in group", i);
414 i_bitmap = e2fs_gd_get_i_bitmap(gd);
416 SDT_PROBE2(ext2fs, , vfsops, ext2_cg_validate_error,
417 "inode bitmap is zero", i);
420 if (i_bitmap <= last_cg_block) {
421 SDT_PROBE2(ext2fs, , vfsops, ext2_cg_validate_error,
422 "inode bitmap overlaps gds", i);
425 if (i_bitmap < first_block || i_bitmap > last_block) {
426 SDT_PROBE2(ext2fs, , vfsops, ext2_cg_validate_error,
427 "inode bitmap not in group blk", i);
431 i_tables = e2fs_gd_get_i_tables(gd);
433 SDT_PROBE2(ext2fs, , vfsops, ext2_cg_validate_error,
434 "inode table is zero", i);
437 if (i_tables <= last_cg_block) {
438 SDT_PROBE2(ext2fs, , vfsops, ext2_cg_validate_error,
439 "inode talbes overlaps gds", i);
442 if (i_tables < first_block ||
443 i_tables + fs->e2fs_itpg - 1 > last_block) {
444 SDT_PROBE2(ext2fs, , vfsops, ext2_cg_validate_error,
445 "inode tables not in group blk", i);
449 if (!EXT2_HAS_INCOMPAT_FEATURE(fs, EXT2F_INCOMPAT_FLEX_BG))
450 first_block += EXT2_BLOCKS_PER_GROUP(fs);
457 * This computes the fields of the m_ext2fs structure from the
458 * data in the ext2fs structure read in.
461 ext2_compute_sb_data(struct vnode *devvp, struct ext2fs *es,
465 uint32_t e2fs_descpb, e2fs_gdbcount_alloc;
470 /* Check checksum features */
471 if (EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_GDT_CSUM) &&
472 EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_METADATA_CKSUM)) {
473 SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
474 "incorrect checksum features combination");
478 /* Precompute checksum seed for all metadata */
479 ext2_sb_csum_set_seed(fs);
481 /* Verify sb csum if possible */
482 if (EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_METADATA_CKSUM)) {
483 error = ext2_sb_csum_verify(fs);
489 /* Check for block size = 1K|2K|4K */
490 if (le32toh(es->e2fs_log_bsize) > 2) {
491 SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
496 fs->e2fs_bshift = EXT2_MIN_BLOCK_LOG_SIZE + le32toh(es->e2fs_log_bsize);
497 fs->e2fs_bsize = 1U << fs->e2fs_bshift;
498 fs->e2fs_fsbtodb = le32toh(es->e2fs_log_bsize) + 1;
499 fs->e2fs_qbmask = fs->e2fs_bsize - 1;
501 /* Check for fragment size */
502 if (le32toh(es->e2fs_log_fsize) >
503 (EXT2_MAX_FRAG_LOG_SIZE - EXT2_MIN_BLOCK_LOG_SIZE)) {
504 SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
505 "invalid log cluster size");
509 fs->e2fs_fsize = EXT2_MIN_FRAG_SIZE << le32toh(es->e2fs_log_fsize);
510 if (fs->e2fs_fsize != fs->e2fs_bsize) {
511 SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
512 "fragment size != block size");
516 fs->e2fs_fpb = fs->e2fs_bsize / fs->e2fs_fsize;
518 /* Check reserved gdt blocks for future filesystem expansion */
519 if (le16toh(es->e2fs_reserved_ngdb) > (fs->e2fs_bsize / 4)) {
520 SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
521 "number of reserved GDT blocks too large");
525 if (le32toh(es->e2fs_rev) == E2FS_REV0) {
526 fs->e2fs_isize = E2FS_REV0_INODE_SIZE;
528 fs->e2fs_isize = le16toh(es->e2fs_inode_size);
533 if (le32toh(es->e2fs_first_ino) < EXT2_FIRSTINO) {
534 SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
535 "invalid first ino");
540 * Simple sanity check for superblock inode size value.
542 if (EXT2_INODE_SIZE(fs) < E2FS_REV0_INODE_SIZE ||
543 EXT2_INODE_SIZE(fs) > fs->e2fs_bsize ||
544 (fs->e2fs_isize & (fs->e2fs_isize - 1)) != 0) {
545 SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
546 "invalid inode size");
551 /* Check group descriptors */
552 if (EXT2_HAS_INCOMPAT_FEATURE(fs, EXT2F_INCOMPAT_64BIT) &&
553 le16toh(es->e3fs_desc_size) != E2FS_64BIT_GD_SIZE) {
554 SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
555 "unsupported 64bit descriptor size");
559 fs->e2fs_bpg = le32toh(es->e2fs_bpg);
560 fs->e2fs_fpg = le32toh(es->e2fs_fpg);
561 if (fs->e2fs_bpg == 0 || fs->e2fs_fpg == 0) {
562 SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
563 "zero blocks/fragments per group");
565 } else if (fs->e2fs_bpg != fs->e2fs_fpg) {
566 SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
567 "blocks per group not equal fragments per group");
571 if (fs->e2fs_bpg != fs->e2fs_bsize * 8) {
572 SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
573 "non-standard group size unsupported");
577 fs->e2fs_ipb = fs->e2fs_bsize / EXT2_INODE_SIZE(fs);
578 if (fs->e2fs_ipb == 0 ||
579 fs->e2fs_ipb > fs->e2fs_bsize / E2FS_REV0_INODE_SIZE) {
580 SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
581 "bad inodes per block size");
585 fs->e2fs_ipg = le32toh(es->e2fs_ipg);
586 if (fs->e2fs_ipg < fs->e2fs_ipb || fs->e2fs_ipg > fs->e2fs_bsize * 8) {
587 SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
588 "invalid inodes per group");
592 fs->e2fs_itpg = fs->e2fs_ipg / fs->e2fs_ipb;
594 fs->e2fs_bcount = le32toh(es->e2fs_bcount);
595 fs->e2fs_rbcount = le32toh(es->e2fs_rbcount);
596 fs->e2fs_fbcount = le32toh(es->e2fs_fbcount);
597 if (EXT2_HAS_INCOMPAT_FEATURE(fs, EXT2F_INCOMPAT_64BIT)) {
598 fs->e2fs_bcount |= (uint64_t)(le32toh(es->e4fs_bcount_hi)) << 32;
599 fs->e2fs_rbcount |= (uint64_t)(le32toh(es->e4fs_rbcount_hi)) << 32;
600 fs->e2fs_fbcount |= (uint64_t)(le32toh(es->e4fs_fbcount_hi)) << 32;
602 if (fs->e2fs_rbcount > fs->e2fs_bcount ||
603 fs->e2fs_fbcount > fs->e2fs_bcount) {
604 SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
605 "invalid block count");
609 fs->e2fs_ficount = le32toh(es->e2fs_ficount);
610 if (fs->e2fs_ficount > le32toh(es->e2fs_icount)) {
611 SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
612 "invalid number of free inodes");
616 if (le32toh(es->e2fs_first_dblock) >= fs->e2fs_bcount) {
617 SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
618 "first data block out of range");
622 fs->e2fs_gcount = howmany(fs->e2fs_bcount -
623 le32toh(es->e2fs_first_dblock), EXT2_BLOCKS_PER_GROUP(fs));
624 if (fs->e2fs_gcount > ((uint64_t)1 << 32) - EXT2_DESCS_PER_BLOCK(fs)) {
625 SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
626 "groups count too large");
630 /* Check for extra isize in big inodes. */
631 if (EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_EXTRA_ISIZE) &&
632 EXT2_INODE_SIZE(fs) < sizeof(struct ext2fs_dinode)) {
633 SDT_PROBE1(ext2fs, , vfsops, ext2_compute_sb_data_error,
634 "no space for extra inode timestamps");
638 /* s_resuid / s_resgid ? */
640 if (EXT2_HAS_INCOMPAT_FEATURE(fs, EXT2F_INCOMPAT_64BIT)) {
641 e2fs_descpb = fs->e2fs_bsize / E2FS_64BIT_GD_SIZE;
642 e2fs_gdbcount_alloc = howmany(fs->e2fs_gcount, e2fs_descpb);
644 e2fs_descpb = fs->e2fs_bsize / E2FS_REV0_GD_SIZE;
645 e2fs_gdbcount_alloc = howmany(fs->e2fs_gcount,
646 fs->e2fs_bsize / sizeof(struct ext2_gd));
648 fs->e2fs_gdbcount = howmany(fs->e2fs_gcount, e2fs_descpb);
649 fs->e2fs_gd = malloc(e2fs_gdbcount_alloc * fs->e2fs_bsize,
650 M_EXT2MNT, M_WAITOK | M_ZERO);
651 fs->e2fs_contigdirs = malloc(fs->e2fs_gcount *
652 sizeof(*fs->e2fs_contigdirs), M_EXT2MNT, M_WAITOK | M_ZERO);
654 for (i = 0; i < fs->e2fs_gdbcount; i++) {
656 fsbtodb(fs, ext2_cg_location(fs, i)),
657 fs->e2fs_bsize, NOCRED, &bp);
660 * fs->e2fs_gd and fs->e2fs_contigdirs
661 * will be freed later by the caller,
662 * because this function could be called from
667 if (EXT2_HAS_INCOMPAT_FEATURE(fs, EXT2F_INCOMPAT_64BIT)) {
669 i * fs->e2fs_bsize / sizeof(struct ext2_gd)],
670 bp->b_data, fs->e2fs_bsize);
672 for (j = 0; j < e2fs_descpb &&
673 g_count < fs->e2fs_gcount; j++, g_count++)
674 memcpy(&fs->e2fs_gd[g_count],
675 bp->b_data + j * E2FS_REV0_GD_SIZE,
682 /* Validate cgs consistency */
683 error = ext2_cg_validate(fs);
688 if (EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_GDT_CSUM) ||
689 EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_METADATA_CKSUM)) {
690 error = ext2_gd_csum_verify(fs, devvp->v_rdev);
694 /* Initialization for the ext2 Orlov allocator variant. */
695 fs->e2fs_total_dir = 0;
696 for (i = 0; i < fs->e2fs_gcount; i++)
697 fs->e2fs_total_dir += e2fs_gd_get_ndirs(&fs->e2fs_gd[i]);
699 if (le32toh(es->e2fs_rev) == E2FS_REV0 ||
700 !EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_LARGEFILE))
701 fs->e2fs_maxfilesize = 0x7fffffff;
703 fs->e2fs_maxfilesize = 0xffffffffffff;
704 if (EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_HUGE_FILE))
705 fs->e2fs_maxfilesize = 0x7fffffffffffffff;
707 if (le32toh(es->e4fs_flags) & E2FS_UNSIGNED_HASH) {
709 } else if ((le32toh(es->e4fs_flags) & E2FS_SIGNED_HASH) == 0) {
710 #ifdef __CHAR_UNSIGNED__
711 es->e4fs_flags = htole32(le32toh(es->e4fs_flags) | E2FS_UNSIGNED_HASH);
714 es->e4fs_flags = htole32(le32toh(es->e4fs_flags) | E2FS_SIGNED_HASH);
717 if (EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_METADATA_CKSUM))
718 error = ext2_sb_csum_verify(fs);
724 * Reload all incore data for a filesystem (used after running fsck on
725 * the root filesystem and finding things to fix). The filesystem must
726 * be mounted read-only.
728 * Things to do to update the mount:
729 * 1) invalidate all cached meta-data.
730 * 2) re-read superblock from disk.
731 * 3) invalidate all cluster summary information.
732 * 4) invalidate all inactive vnodes.
733 * 5) invalidate all cached file data.
734 * 6) re-read inode data for all active vnodes.
735 * XXX we are missing some steps, in particular # 3, this has to be reviewed.
738 ext2_reload(struct mount *mp, struct thread *td)
740 struct vnode *vp, *mvp, *devvp;
749 if ((mp->mnt_flag & MNT_RDONLY) == 0)
752 * Step 1: invalidate all cached meta-data.
754 devvp = VFSTOEXT2(mp)->um_devvp;
755 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
756 if (vinvalbuf(devvp, 0, 0, 0) != 0)
757 panic("ext2_reload: dirty1");
761 * Step 2: re-read superblock from disk.
762 * constants have been adjusted for ext2
764 if ((error = bread(devvp, SBLOCK, SBSIZE, NOCRED, &bp)) != 0)
766 es = (struct ext2fs *)bp->b_data;
767 if (ext2_check_sb_compat(es, devvp->v_rdev, 0) != 0) {
769 return (EIO); /* XXX needs translation */
771 fs = VFSTOEXT2(mp)->um_e2fs;
772 bcopy(bp->b_data, fs->e2fs, sizeof(struct ext2fs));
774 if ((error = ext2_compute_sb_data(devvp, es, fs)) != 0) {
779 if (fs->fs_sbsize < SBSIZE)
780 bp->b_flags |= B_INVAL;
785 * Step 3: invalidate all cluster summary information.
787 if (fs->e2fs_contigsumsize > 0) {
788 lp = fs->e2fs_maxcluster;
789 sump = fs->e2fs_clustersum;
790 for (i = 0; i < fs->e2fs_gcount; i++, sump++) {
791 *lp++ = fs->e2fs_contigsumsize;
793 bzero(sump->cs_sum, fs->e2fs_contigsumsize + 1);
798 MNT_VNODE_FOREACH_ALL(vp, mp, mvp) {
800 * Step 4: invalidate all cached file data.
802 if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK)) {
803 MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
806 if (vinvalbuf(vp, 0, 0, 0))
807 panic("ext2_reload: dirty2");
810 * Step 5: re-read inode data for all active vnodes.
813 error = bread(devvp, fsbtodb(fs, ino_to_fsba(fs, ip->i_number)),
814 (int)fs->e2fs_bsize, NOCRED, &bp);
818 MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
822 error = ext2_ei2i((struct ext2fs_dinode *)((char *)bp->b_data +
823 EXT2_INODE_SIZE(fs) * ino_to_fsbo(fs, ip->i_number)), ip);
830 MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
838 * Common code for mount and mountroot.
841 ext2_mountfs(struct vnode *devvp, struct mount *mp)
843 struct ext2mount *ump;
847 struct cdev *dev = devvp->v_rdev;
848 struct g_consumer *cp;
856 int32_t e2fs_maxcontig;
858 ronly = vfs_flagopt(mp->mnt_optnew, "ro", NULL, 0);
859 /* XXX: use VOP_ACESS to check FS perms */
861 error = g_vfs_open(devvp, &cp, "ext2fs", ronly ? 0 : 1);
867 /* XXX: should we check for some sectorsize or 512 instead? */
868 if (((SBSIZE % cp->provider->sectorsize) != 0) ||
869 (SBSIZE < cp->provider->sectorsize)) {
876 bo = &devvp->v_bufobj;
878 bo->bo_ops = g_vfs_bufops;
879 if (devvp->v_rdev->si_iosize_max != 0)
880 mp->mnt_iosize_max = devvp->v_rdev->si_iosize_max;
881 if (mp->mnt_iosize_max > MAXPHYS)
882 mp->mnt_iosize_max = MAXPHYS;
886 if ((error = bread(devvp, SBLOCK, SBSIZE, NOCRED, &bp)) != 0)
888 es = (struct ext2fs *)bp->b_data;
889 if (ext2_check_sb_compat(es, dev, ronly) != 0) {
890 error = EINVAL; /* XXX needs translation */
893 if ((le16toh(es->e2fs_state) & E2FS_ISCLEAN) == 0 ||
894 (le16toh(es->e2fs_state) & E2FS_ERRORS)) {
895 if (ronly || (mp->mnt_flag & MNT_FORCE)) {
897 "WARNING: Filesystem was not properly dismounted\n");
900 "WARNING: R/W mount denied. Filesystem is not clean - run fsck\n");
905 ump = malloc(sizeof(*ump), M_EXT2MNT, M_WAITOK | M_ZERO);
908 * I don't know whether this is the right strategy. Note that
909 * we dynamically allocate both an m_ext2fs and an ext2fs
910 * while Linux keeps the super block in a locked buffer.
912 ump->um_e2fs = malloc(sizeof(struct m_ext2fs),
913 M_EXT2MNT, M_WAITOK | M_ZERO);
914 ump->um_e2fs->e2fs = malloc(sizeof(struct ext2fs),
915 M_EXT2MNT, M_WAITOK);
916 mtx_init(EXT2_MTX(ump), "EXT2FS", "EXT2FS Lock", MTX_DEF);
917 bcopy(es, ump->um_e2fs->e2fs, (u_int)sizeof(struct ext2fs));
918 if ((error = ext2_compute_sb_data(devvp, ump->um_e2fs->e2fs, ump->um_e2fs)))
922 * Calculate the maximum contiguous blocks and size of cluster summary
923 * array. In FFS this is done by newfs; however, the superblock
924 * in ext2fs doesn't have these variables, so we can calculate
927 e2fs_maxcontig = MAX(1, MAXPHYS / ump->um_e2fs->e2fs_bsize);
928 ump->um_e2fs->e2fs_contigsumsize = MIN(e2fs_maxcontig, EXT2_MAXCONTIG);
929 if (ump->um_e2fs->e2fs_contigsumsize > 0) {
930 size = ump->um_e2fs->e2fs_gcount * sizeof(int32_t);
931 ump->um_e2fs->e2fs_maxcluster = malloc(size, M_EXT2MNT, M_WAITOK);
932 size = ump->um_e2fs->e2fs_gcount * sizeof(struct csum);
933 ump->um_e2fs->e2fs_clustersum = malloc(size, M_EXT2MNT, M_WAITOK);
934 lp = ump->um_e2fs->e2fs_maxcluster;
935 sump = ump->um_e2fs->e2fs_clustersum;
936 for (i = 0; i < ump->um_e2fs->e2fs_gcount; i++, sump++) {
937 *lp++ = ump->um_e2fs->e2fs_contigsumsize;
939 sump->cs_sum = malloc((ump->um_e2fs->e2fs_contigsumsize + 1) *
940 sizeof(int32_t), M_EXT2MNT, M_WAITOK | M_ZERO);
947 fs->e2fs_ronly = ronly; /* ronly is set according to mnt_flags */
950 * If the fs is not mounted read-only, make sure the super block is
951 * always written back on a sync().
953 fs->e2fs_wasvalid = le16toh(fs->e2fs->e2fs_state) & E2FS_ISCLEAN ? 1 : 0;
955 fs->e2fs_fmod = 1; /* mark it modified and set fs invalid */
956 fs->e2fs->e2fs_state =
957 htole16(le16toh(fs->e2fs->e2fs_state) & ~E2FS_ISCLEAN);
960 mp->mnt_stat.f_fsid.val[0] = dev2udev(dev);
961 mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
962 mp->mnt_maxsymlinklen = EXT2_MAXSYMLINKLEN;
964 mp->mnt_flag |= MNT_LOCAL;
968 ump->um_devvp = devvp;
969 ump->um_bo = &devvp->v_bufobj;
973 * Setting those two parameters allowed us to use
974 * ufs_bmap w/o changse!
976 ump->um_nindir = EXT2_ADDR_PER_BLOCK(fs);
977 ump->um_bptrtodb = le32toh(fs->e2fs->e2fs_log_bsize) + 1;
978 ump->um_seqinc = EXT2_FRAGS_PER_BLOCK(fs);
980 ext2_sbupdate(ump, MNT_WAIT);
982 * Initialize filesystem stat information in mount struct.
985 mp->mnt_kern_flag |= MNTK_LOOKUP_SHARED | MNTK_EXTENDED_SHARED |
998 mtx_destroy(EXT2_MTX(ump));
999 free(ump->um_e2fs->e2fs_gd, M_EXT2MNT);
1000 free(ump->um_e2fs->e2fs_contigdirs, M_EXT2MNT);
1001 free(ump->um_e2fs->e2fs, M_EXT2MNT);
1002 free(ump->um_e2fs, M_EXT2MNT);
1003 free(ump, M_EXT2MNT);
1004 mp->mnt_data = NULL;
1010 * Unmount system call.
1013 ext2_unmount(struct mount *mp, int mntflags)
1015 struct ext2mount *ump;
1016 struct m_ext2fs *fs;
1018 int error, flags, i, ronly;
1021 if (mntflags & MNT_FORCE) {
1022 if (mp->mnt_flag & MNT_ROOTFS)
1024 flags |= FORCECLOSE;
1026 if ((error = ext2_flushfiles(mp, flags, curthread)) != 0)
1028 ump = VFSTOEXT2(mp);
1030 ronly = fs->e2fs_ronly;
1031 if (ronly == 0 && ext2_cgupdate(ump, MNT_WAIT) == 0) {
1032 if (fs->e2fs_wasvalid)
1033 fs->e2fs->e2fs_state =
1034 htole16(le16toh(fs->e2fs->e2fs_state) | E2FS_ISCLEAN);
1035 ext2_sbupdate(ump, MNT_WAIT);
1039 g_vfs_close(ump->um_cp);
1040 g_topology_unlock();
1041 vrele(ump->um_devvp);
1042 sump = fs->e2fs_clustersum;
1043 for (i = 0; i < fs->e2fs_gcount; i++, sump++)
1044 free(sump->cs_sum, M_EXT2MNT);
1045 free(fs->e2fs_clustersum, M_EXT2MNT);
1046 free(fs->e2fs_maxcluster, M_EXT2MNT);
1047 free(fs->e2fs_gd, M_EXT2MNT);
1048 free(fs->e2fs_contigdirs, M_EXT2MNT);
1049 free(fs->e2fs, M_EXT2MNT);
1050 free(fs, M_EXT2MNT);
1051 free(ump, M_EXT2MNT);
1052 mp->mnt_data = NULL;
1054 mp->mnt_flag &= ~MNT_LOCAL;
1060 * Flush out all the files in a filesystem.
1063 ext2_flushfiles(struct mount *mp, int flags, struct thread *td)
1067 error = vflush(mp, 0, flags, td);
1072 * Get filesystem statistics.
1075 ext2_statfs(struct mount *mp, struct statfs *sbp)
1077 struct ext2mount *ump;
1078 struct m_ext2fs *fs;
1079 uint32_t overhead, overhead_per_group, ngdb;
1082 ump = VFSTOEXT2(mp);
1084 if (le16toh(fs->e2fs->e2fs_magic) != E2FS_MAGIC)
1085 panic("ext2_statfs");
1088 * Compute the overhead (FS structures)
1090 overhead_per_group =
1091 1 /* block bitmap */ +
1092 1 /* inode bitmap */ +
1094 overhead = le32toh(fs->e2fs->e2fs_first_dblock) +
1095 fs->e2fs_gcount * overhead_per_group;
1096 if (le32toh(fs->e2fs->e2fs_rev) > E2FS_REV0 &&
1097 le32toh(fs->e2fs->e2fs_features_rocompat) & EXT2F_ROCOMPAT_SPARSESUPER) {
1098 for (i = 0, ngroups = 0; i < fs->e2fs_gcount; i++) {
1099 if (ext2_cg_has_sb(fs, i))
1103 ngroups = fs->e2fs_gcount;
1105 ngdb = fs->e2fs_gdbcount;
1106 if (le32toh(fs->e2fs->e2fs_rev) > E2FS_REV0 &&
1107 le32toh(fs->e2fs->e2fs_features_compat) & EXT2F_COMPAT_RESIZE)
1108 ngdb += le16toh(fs->e2fs->e2fs_reserved_ngdb);
1109 overhead += ngroups * (1 /* superblock */ + ngdb);
1111 sbp->f_bsize = EXT2_FRAG_SIZE(fs);
1112 sbp->f_iosize = EXT2_BLOCK_SIZE(fs);
1113 sbp->f_blocks = fs->e2fs_bcount - overhead;
1114 sbp->f_bfree = fs->e2fs_fbcount;
1115 sbp->f_bavail = sbp->f_bfree - fs->e2fs_rbcount;
1116 sbp->f_files = le32toh(fs->e2fs->e2fs_icount);
1117 sbp->f_ffree = fs->e2fs_ficount;
1122 * Go through the disk queues to initiate sandbagged IO;
1123 * go through the inodes to write those that have been modified;
1124 * initiate the writing of the super block if it has been modified.
1126 * Note: we are always called with the filesystem marked `MPBUSY'.
1129 ext2_sync(struct mount *mp, int waitfor)
1131 struct vnode *mvp, *vp;
1134 struct ext2mount *ump = VFSTOEXT2(mp);
1135 struct m_ext2fs *fs;
1136 int error, allerror = 0;
1140 if (fs->e2fs_fmod != 0 && fs->e2fs_ronly != 0) { /* XXX */
1141 panic("ext2_sync: rofs mod fs=%s", fs->e2fs_fsmnt);
1145 * Write back each (modified) inode.
1148 MNT_VNODE_FOREACH_ALL(vp, mp, mvp) {
1149 if (vp->v_type == VNON) {
1155 (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE)) == 0 &&
1156 (vp->v_bufobj.bo_dirty.bv_cnt == 0 ||
1157 waitfor == MNT_LAZY)) {
1161 error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK);
1163 if (error == ENOENT) {
1164 MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
1169 if ((error = VOP_FSYNC(vp, waitfor, td)) != 0)
1176 * Force stale filesystem control information to be flushed.
1178 if (waitfor != MNT_LAZY) {
1179 vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY);
1180 if ((error = VOP_FSYNC(ump->um_devvp, waitfor, td)) != 0)
1182 VOP_UNLOCK(ump->um_devvp);
1186 * Write back modified superblock.
1188 if (fs->e2fs_fmod != 0) {
1190 fs->e2fs->e2fs_wtime = htole32(time_second);
1191 if ((error = ext2_cgupdate(ump, waitfor)) != 0)
1198 * Look up an EXT2FS dinode number to find its incore vnode, otherwise read it
1199 * in from disk. If it is in core, wait for the lock bit to clear, then
1200 * return the inode locked. Detection and handling of mount points must be
1201 * done by the calling routine.
1204 ext2_vget(struct mount *mp, ino_t ino, int flags, struct vnode **vpp)
1206 struct m_ext2fs *fs;
1208 struct ext2mount *ump;
1212 unsigned int i, used_blocks;
1216 error = vfs_hash_get(mp, ino, flags, td, vpp, NULL, NULL);
1217 if (error || *vpp != NULL)
1220 ump = VFSTOEXT2(mp);
1221 ip = malloc(sizeof(struct inode), M_EXT2NODE, M_WAITOK | M_ZERO);
1223 /* Allocate a new vnode/inode. */
1224 if ((error = getnewvnode("ext2fs", mp, &ext2_vnodeops, &vp)) != 0) {
1226 free(ip, M_EXT2NODE);
1231 ip->i_e2fs = fs = ump->um_e2fs;
1235 lockmgr(vp->v_vnlock, LK_EXCLUSIVE, NULL);
1236 error = insmntque(vp, mp);
1238 free(ip, M_EXT2NODE);
1242 error = vfs_hash_insert(vp, ino, flags, td, vpp, NULL, NULL);
1243 if (error || *vpp != NULL)
1246 /* Read in the disk contents for the inode, copy into the inode. */
1247 if ((error = bread(ump->um_devvp, fsbtodb(fs, ino_to_fsba(fs, ino)),
1248 (int)fs->e2fs_bsize, NOCRED, &bp)) != 0) {
1250 * The inode does not contain anything useful, so it would
1251 * be misleading to leave it on its hash chain. With mode
1252 * still zero, it will be unlinked and returned to the free
1260 /* convert ext2 inode to dinode */
1261 error = ext2_ei2i((struct ext2fs_dinode *)((char *)bp->b_data +
1262 EXT2_INODE_SIZE(fs) * ino_to_fsbo(fs, ino)), ip);
1269 ip->i_block_group = ino_to_cg(fs, ino);
1270 ip->i_next_alloc_block = 0;
1271 ip->i_next_alloc_goal = 0;
1274 * Now we want to make sure that block pointers for unused
1275 * blocks are zeroed out - ext2_balloc depends on this
1276 * although for regular files and directories only
1278 * If IN_E4EXTENTS is enabled, unused blocks are not zeroed
1279 * out because we could corrupt the extent tree.
1281 if (!(ip->i_flag & IN_E4EXTENTS) &&
1282 (S_ISDIR(ip->i_mode) || S_ISREG(ip->i_mode))) {
1283 used_blocks = howmany(ip->i_size, fs->e2fs_bsize);
1284 for (i = used_blocks; i < EXT2_NDIR_BLOCKS; i++)
1287 #ifdef EXT2FS_PRINT_EXTENTS
1288 ext2_print_inode(ip);
1289 ext4_ext_print_extent_tree_status(ip);
1294 * Initialize the vnode from the inode, check for aliases.
1295 * Note that the underlying vnode may have changed.
1297 if ((error = ext2_vinit(mp, &ext2_fifoops, &vp)) != 0) {
1304 * Finish inode initialization.
1312 * File handle to vnode
1314 * Have to be really careful about stale file handles:
1315 * - check that the inode number is valid
1316 * - call ext2_vget() to get the locked inode
1317 * - check for an unallocated inode (i_mode == 0)
1318 * - check that the given client host has export rights and return
1319 * those rights via. exflagsp and credanonp
1322 ext2_fhtovp(struct mount *mp, struct fid *fhp, int flags, struct vnode **vpp)
1327 struct m_ext2fs *fs;
1330 ufhp = (struct ufid *)fhp;
1331 fs = VFSTOEXT2(mp)->um_e2fs;
1332 if (ufhp->ufid_ino < EXT2_ROOTINO ||
1333 ufhp->ufid_ino > fs->e2fs_gcount * fs->e2fs_ipg)
1336 error = VFS_VGET(mp, ufhp->ufid_ino, LK_EXCLUSIVE, &nvp);
1342 if (ip->i_mode == 0 ||
1343 ip->i_gen != ufhp->ufid_gen || ip->i_nlink <= 0) {
1349 vnode_create_vobject(*vpp, 0, curthread);
1354 * Write a superblock and associated information back to disk.
1357 ext2_sbupdate(struct ext2mount *mp, int waitfor)
1359 struct m_ext2fs *fs = mp->um_e2fs;
1360 struct ext2fs *es = fs->e2fs;
1364 es->e2fs_bcount = htole32(fs->e2fs_bcount & 0xffffffff);
1365 es->e2fs_rbcount = htole32(fs->e2fs_rbcount & 0xffffffff);
1366 es->e2fs_fbcount = htole32(fs->e2fs_fbcount & 0xffffffff);
1367 if (EXT2_HAS_INCOMPAT_FEATURE(fs, EXT2F_INCOMPAT_64BIT)) {
1368 es->e4fs_bcount_hi = htole32(fs->e2fs_bcount >> 32);
1369 es->e4fs_rbcount_hi = htole32(fs->e2fs_rbcount >> 32);
1370 es->e4fs_fbcount_hi = htole32(fs->e2fs_fbcount >> 32);
1373 es->e2fs_ficount = htole32(fs->e2fs_ficount);
1375 if (EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_METADATA_CKSUM))
1376 ext2_sb_csum_set(fs);
1378 bp = getblk(mp->um_devvp, SBLOCK, SBSIZE, 0, 0, 0);
1379 bcopy((caddr_t)es, bp->b_data, (u_int)sizeof(struct ext2fs));
1380 if (waitfor == MNT_WAIT)
1386 * The buffers for group descriptors, inode bitmaps and block bitmaps
1387 * are not busy at this point and are (hopefully) written by the
1388 * usual sync mechanism. No need to write them here.
1393 ext2_cgupdate(struct ext2mount *mp, int waitfor)
1395 struct m_ext2fs *fs = mp->um_e2fs;
1397 int i, j, g_count = 0, error = 0, allerror = 0;
1399 allerror = ext2_sbupdate(mp, waitfor);
1401 /* Update gd csums */
1402 if (EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_GDT_CSUM) ||
1403 EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_METADATA_CKSUM))
1404 ext2_gd_csum_set(fs);
1406 for (i = 0; i < fs->e2fs_gdbcount; i++) {
1407 bp = getblk(mp->um_devvp, fsbtodb(fs,
1408 ext2_cg_location(fs, i)),
1409 fs->e2fs_bsize, 0, 0, 0);
1410 if (EXT2_HAS_INCOMPAT_FEATURE(fs, EXT2F_INCOMPAT_64BIT)) {
1411 memcpy(bp->b_data, &fs->e2fs_gd[
1412 i * fs->e2fs_bsize / sizeof(struct ext2_gd)],
1415 for (j = 0; j < fs->e2fs_bsize / E2FS_REV0_GD_SIZE &&
1416 g_count < fs->e2fs_gcount; j++, g_count++)
1417 memcpy(bp->b_data + j * E2FS_REV0_GD_SIZE,
1418 &fs->e2fs_gd[g_count], E2FS_REV0_GD_SIZE);
1420 if (waitfor == MNT_WAIT)
1426 if (!allerror && error)
1432 * Return the root of a filesystem.
1435 ext2_root(struct mount *mp, int flags, struct vnode **vpp)
1440 error = VFS_VGET(mp, EXT2_ROOTINO, LK_EXCLUSIVE, &nvp);