ext2_vfsops.c revision 128019
1/*
2 *  modified for EXT2FS support in Lites 1.1
3 *
4 *  Aug 1995, Godmar Back (gback@cs.utah.edu)
5 *  University of Utah, Department of Computer Science
6 */
7/*
8 * Copyright (c) 1989, 1991, 1993, 1994
9 *	The Regents of the University of California.  All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 * 4. Neither the name of the University nor the names of its contributors
20 *    may be used to endorse or promote products derived from this software
21 *    without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 *	@(#)ffs_vfsops.c	8.8 (Berkeley) 4/18/94
36 * $FreeBSD: head/sys/gnu/fs/ext2fs/ext2_vfsops.c 128019 2004-04-07 20:46:16Z imp $
37 */
38
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/namei.h>
42#include <sys/proc.h>
43#include <sys/kernel.h>
44#include <sys/vnode.h>
45#include <sys/mount.h>
46#include <sys/bio.h>
47#include <sys/buf.h>
48#include <sys/conf.h>
49#include <sys/fcntl.h>
50#include <sys/malloc.h>
51#include <sys/stat.h>
52#include <sys/mutex.h>
53
54#include <gnu/ext2fs/ext2_mount.h>
55#include <gnu/ext2fs/inode.h>
56
57#include <gnu/ext2fs/fs.h>
58#include <gnu/ext2fs/ext2_extern.h>
59#include <gnu/ext2fs/ext2_fs.h>
60#include <gnu/ext2fs/ext2_fs_sb.h>
61
62static int ext2_flushfiles(struct mount *mp, int flags, struct thread *td);
63static int ext2_mountfs(struct vnode *, struct mount *, struct thread *);
64static int ext2_reload(struct mount *mp, struct ucred *cred, struct thread *td);
65static int ext2_sbupdate(struct ext2mount *, int);
66
67static vfs_unmount_t		ext2_unmount;
68static vfs_root_t		ext2_root;
69static vfs_statfs_t		ext2_statfs;
70static vfs_sync_t		ext2_sync;
71static vfs_vget_t		ext2_vget;
72static vfs_fhtovp_t		ext2_fhtovp;
73static vfs_vptofh_t		ext2_vptofh;
74static vfs_init_t		ext2_init;
75static vfs_uninit_t		ext2_uninit;
76static vfs_nmount_t		ext2_mount;
77
78MALLOC_DEFINE(M_EXT2NODE, "EXT2 node", "EXT2 vnode private part");
79static MALLOC_DEFINE(M_EXT2MNT, "EXT2 mount", "EXT2 mount structure");
80
81static struct vfsops ext2fs_vfsops = {
82	.vfs_fhtovp =		ext2_fhtovp,
83	.vfs_init =		ext2_init,
84	.vfs_nmount =		ext2_mount,
85	.vfs_root =		ext2_root,	/* root inode via vget */
86	.vfs_statfs =		ext2_statfs,
87	.vfs_sync =		ext2_sync,
88	.vfs_uninit =		ext2_uninit,
89	.vfs_unmount =		ext2_unmount,
90	.vfs_vget =		ext2_vget,
91	.vfs_vptofh =		ext2_vptofh,
92};
93
94VFS_SET(ext2fs_vfsops, ext2fs, 0);
95#define bsd_malloc malloc
96#define bsd_free free
97
98static int ext2fs_inode_hash_lock;
99
100static int	ext2_check_sb_compat(struct ext2_super_block *es, dev_t dev,
101		    int ronly);
102static int	compute_sb_data(struct vnode * devvp,
103		    struct ext2_super_block * es, struct ext2_sb_info * fs);
104
105#ifdef notyet
106static int ext2_mountroot(void);
107
108/*
109 * Called by main() when ext2fs is going to be mounted as root.
110 *
111 * Name is updated by mount(8) after booting.
112 */
113#define ROOTNAME	"root_device"
114
115static int
116ext2_mountroot()
117{
118	struct ext2_sb_info *fs;
119	struct mount *mp;
120	struct thread *td = curthread;
121	struct ext2mount *ump;
122	u_int size;
123	int error;
124
125	if ((error = bdevvp(rootdev, &rootvp))) {
126		printf("ext2_mountroot: can't find rootvp\n");
127		return (error);
128	}
129	mp = bsd_malloc((u_long)sizeof(struct mount), M_MOUNT, M_WAITOK);
130	bzero((char *)mp, (u_long)sizeof(struct mount));
131	TAILQ_INIT(&mp->mnt_nvnodelist);
132	mp->mnt_op = &ext2fs_vfsops;
133	mp->mnt_flag = MNT_RDONLY;
134	if (error = ext2_mountfs(rootvp, mp, td)) {
135		bsd_free(mp, M_MOUNT);
136		return (error);
137	}
138	if (error = vfs_lock(mp)) {
139		(void)ext2_unmount(mp, 0, td);
140		bsd_free(mp, M_MOUNT);
141		return (error);
142	}
143	TAILQ_INSERT_HEAD(&mountlist, mp, mnt_list);
144	mp->mnt_flag |= MNT_ROOTFS;
145	mp->mnt_vnodecovered = NULLVP;
146	ump = VFSTOEXT2(mp);
147	fs = ump->um_e2fs;
148	bzero(fs->fs_fsmnt, sizeof(fs->fs_fsmnt));
149	fs->fs_fsmnt[0] = '/';
150	bcopy((caddr_t)fs->fs_fsmnt, (caddr_t)mp->mnt_stat.f_mntonname,
151	    MNAMELEN);
152	(void) copystr(ROOTNAME, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
153	    &size);
154	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
155	(void)ext2_statfs(mp, &mp->mnt_stat, td);
156	vfs_unlock(mp);
157	inittodr(fs->s_es->s_wtime);		/* this helps to set the time */
158	return (0);
159}
160#endif
161
162/*
163 * VFS Operations.
164 *
165 * mount system call
166 */
167static int
168ext2_mount(mp, ndp, td)
169	struct mount *mp;
170	struct nameidata *ndp;
171	struct thread *td;
172{
173	struct export_args *export;
174	struct vfsoptlist *opts;
175	struct vnode *devvp;
176	struct ext2mount *ump = 0;
177	struct ext2_sb_info *fs;
178	char *path, *fspec;
179	size_t size;
180	int error, flags, len;
181	mode_t accessmode;
182
183	opts = mp->mnt_optnew;
184
185	vfs_getopt(opts, "fspath", (void **)&path, NULL);
186	/* Double-check the length of path.. */
187	if (strlen(path) >= MAXMNTLEN - 1)
188		return (ENAMETOOLONG);
189
190	fspec = NULL;
191	error = vfs_getopt(opts, "from", (void **)&fspec, &len);
192	if (!error && fspec[len - 1] != '\0')
193		return (EINVAL);
194
195	/*
196	 * If updating, check whether changing from read-only to
197	 * read/write; if there is no device name, that's all we do.
198	 */
199	if (mp->mnt_flag & MNT_UPDATE) {
200		ump = VFSTOEXT2(mp);
201		fs = ump->um_e2fs;
202		error = 0;
203		if (fs->s_rd_only == 0 && (mp->mnt_flag & MNT_RDONLY)) {
204			flags = WRITECLOSE;
205			if (mp->mnt_flag & MNT_FORCE)
206				flags |= FORCECLOSE;
207			if (vfs_busy(mp, LK_NOWAIT, 0, td))
208				return (EBUSY);
209			error = ext2_flushfiles(mp, flags, td);
210			vfs_unbusy(mp, td);
211			if (!error && fs->s_wasvalid) {
212				fs->s_es->s_state |= EXT2_VALID_FS;
213				ext2_sbupdate(ump, MNT_WAIT);
214			}
215			fs->s_rd_only = 1;
216		}
217		if (!error && (mp->mnt_flag & MNT_RELOAD))
218			error = ext2_reload(mp, ndp->ni_cnd.cn_cred, td);
219		if (error)
220			return (error);
221		devvp = ump->um_devvp;
222		if (ext2_check_sb_compat(fs->s_es, devvp->v_rdev,
223		    (mp->mnt_kern_flag & MNTK_WANTRDWR) == 0) != 0)
224			return (EPERM);
225		if (fs->s_rd_only && (mp->mnt_kern_flag & MNTK_WANTRDWR)) {
226			/*
227			 * If upgrade to read-write by non-root, then verify
228			 * that user has necessary permissions on the device.
229			 */
230			if (suser(td)) {
231				vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
232				if ((error = VOP_ACCESS(devvp, VREAD | VWRITE,
233				    td->td_ucred, td)) != 0) {
234					VOP_UNLOCK(devvp, 0, td);
235					return (error);
236				}
237				VOP_UNLOCK(devvp, 0, td);
238			}
239
240			if ((fs->s_es->s_state & EXT2_VALID_FS) == 0 ||
241			    (fs->s_es->s_state & EXT2_ERROR_FS)) {
242				if (mp->mnt_flag & MNT_FORCE) {
243					printf(
244"WARNING: %s was not properly dismounted\n",
245					    fs->fs_fsmnt);
246				} else {
247					printf(
248"WARNING: R/W mount of %s denied.  Filesystem is not clean - run fsck\n",
249					    fs->fs_fsmnt);
250					return (EPERM);
251				}
252			}
253			fs->s_es->s_state &= ~EXT2_VALID_FS;
254			ext2_sbupdate(ump, MNT_WAIT);
255			fs->s_rd_only = 0;
256		}
257		if (fspec == NULL) {
258			error = vfs_getopt(opts, "export", (void **)&export,
259			    &len);
260			if (error || len != sizeof(struct export_args))
261				return (EINVAL);
262				/* Process export requests. */
263			return (vfs_export(mp, export));
264		}
265	}
266	/*
267	 * Not an update, or updating the name: look up the name
268	 * and verify that it refers to a sensible disk device.
269	 */
270	if (fspec == NULL)
271		return (EINVAL);
272	NDINIT(ndp, LOOKUP, FOLLOW, UIO_SYSSPACE, fspec, td);
273	if ((error = namei(ndp)) != 0)
274		return (error);
275	NDFREE(ndp, NDF_ONLY_PNBUF);
276	devvp = ndp->ni_vp;
277
278	if (!vn_isdisk(devvp, &error)) {
279		vrele(devvp);
280		return (error);
281	}
282
283	/*
284	 * If mount by non-root, then verify that user has necessary
285	 * permissions on the device.
286	 */
287	if (suser(td)) {
288		accessmode = VREAD;
289		if ((mp->mnt_flag & MNT_RDONLY) == 0)
290			accessmode |= VWRITE;
291		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
292		if ((error = VOP_ACCESS(devvp, accessmode, td->td_ucred, td)) != 0) {
293			vput(devvp);
294			return (error);
295		}
296		VOP_UNLOCK(devvp, 0, td);
297	}
298
299	if ((mp->mnt_flag & MNT_UPDATE) == 0) {
300		error = ext2_mountfs(devvp, mp, td);
301	} else {
302		if (devvp != ump->um_devvp)
303			error = EINVAL;	/* needs translation */
304		else
305			vrele(devvp);
306	}
307	if (error) {
308		vrele(devvp);
309		return (error);
310	}
311	ump = VFSTOEXT2(mp);
312	fs = ump->um_e2fs;
313	/*
314	 * Note that this strncpy() is ok because of a check at the start
315	 * of ext2_mount().
316	 */
317	strncpy(fs->fs_fsmnt, path, MAXMNTLEN);
318	fs->fs_fsmnt[MAXMNTLEN - 1] = '\0';
319	(void)copystr(fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size);
320	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
321	(void)ext2_statfs(mp, &mp->mnt_stat, td);
322	return (0);
323}
324
325/*
326 * checks that the data in the descriptor blocks make sense
327 * this is taken from ext2/super.c
328 */
329static int ext2_check_descriptors (struct ext2_sb_info * sb)
330{
331        int i;
332        int desc_block = 0;
333        unsigned long block = sb->s_es->s_first_data_block;
334        struct ext2_group_desc * gdp = NULL;
335
336        /* ext2_debug ("Checking group descriptors"); */
337
338        for (i = 0; i < sb->s_groups_count; i++)
339        {
340		/* examine next descriptor block */
341                if ((i % EXT2_DESC_PER_BLOCK(sb)) == 0)
342                        gdp = (struct ext2_group_desc *)
343				sb->s_group_desc[desc_block++]->b_data;
344                if (gdp->bg_block_bitmap < block ||
345                    gdp->bg_block_bitmap >= block + EXT2_BLOCKS_PER_GROUP(sb))
346                {
347                        printf ("ext2_check_descriptors: "
348                                    "Block bitmap for group %d"
349                                    " not in group (block %lu)!\n",
350                                    i, (unsigned long) gdp->bg_block_bitmap);
351                        return 0;
352                }
353                if (gdp->bg_inode_bitmap < block ||
354                    gdp->bg_inode_bitmap >= block + EXT2_BLOCKS_PER_GROUP(sb))
355                {
356                        printf ("ext2_check_descriptors: "
357                                    "Inode bitmap for group %d"
358                                    " not in group (block %lu)!\n",
359                                    i, (unsigned long) gdp->bg_inode_bitmap);
360                        return 0;
361                }
362                if (gdp->bg_inode_table < block ||
363                    gdp->bg_inode_table + sb->s_itb_per_group >=
364                    block + EXT2_BLOCKS_PER_GROUP(sb))
365                {
366                        printf ("ext2_check_descriptors: "
367                                    "Inode table for group %d"
368                                    " not in group (block %lu)!\n",
369                                    i, (unsigned long) gdp->bg_inode_table);
370                        return 0;
371                }
372                block += EXT2_BLOCKS_PER_GROUP(sb);
373                gdp++;
374        }
375        return 1;
376}
377
378static int
379ext2_check_sb_compat(es, dev, ronly)
380	struct ext2_super_block *es;
381	dev_t dev;
382	int ronly;
383{
384
385	if (es->s_magic != EXT2_SUPER_MAGIC) {
386		printf("ext2fs: %s: wrong magic number %#x (expected %#x)\n",
387		    devtoname(dev), es->s_magic, EXT2_SUPER_MAGIC);
388		return (1);
389	}
390	if (es->s_rev_level > EXT2_GOOD_OLD_REV) {
391		if (es->s_feature_incompat & ~EXT2_FEATURE_INCOMPAT_SUPP) {
392			printf(
393"WARNING: mount of %s denied due to unsupported optional features\n",
394			    devtoname(dev));
395			return (1);
396		}
397		if (!ronly &&
398		    (es->s_feature_ro_compat & ~EXT2_FEATURE_RO_COMPAT_SUPP)) {
399			printf(
400"WARNING: R/W mount of %s denied due to unsupported optional features\n",
401			    devtoname(dev));
402			return (1);
403		}
404	}
405	return (0);
406}
407
408/*
409 * this computes the fields of the  ext2_sb_info structure from the
410 * data in the ext2_super_block structure read in
411 */
412static int compute_sb_data(devvp, es, fs)
413	struct vnode * devvp;
414	struct ext2_super_block * es;
415	struct ext2_sb_info * fs;
416{
417    int db_count, error;
418    int i, j;
419    int logic_sb_block = 1;	/* XXX for now */
420
421#if 1
422#define V(v)
423#else
424#define V(v)  printf(#v"= %d\n", fs->v);
425#endif
426
427    fs->s_blocksize = EXT2_MIN_BLOCK_SIZE << es->s_log_block_size;
428    V(s_blocksize)
429    fs->s_bshift = EXT2_MIN_BLOCK_LOG_SIZE + es->s_log_block_size;
430    V(s_bshift)
431    fs->s_fsbtodb = es->s_log_block_size + 1;
432    V(s_fsbtodb)
433    fs->s_qbmask = fs->s_blocksize - 1;
434    V(s_bmask)
435    fs->s_blocksize_bits = EXT2_BLOCK_SIZE_BITS(es);
436    V(s_blocksize_bits)
437    fs->s_frag_size = EXT2_MIN_FRAG_SIZE << es->s_log_frag_size;
438    V(s_frag_size)
439    if (fs->s_frag_size)
440	fs->s_frags_per_block = fs->s_blocksize / fs->s_frag_size;
441    V(s_frags_per_block)
442    fs->s_blocks_per_group = es->s_blocks_per_group;
443    V(s_blocks_per_group)
444    fs->s_frags_per_group = es->s_frags_per_group;
445    V(s_frags_per_group)
446    fs->s_inodes_per_group = es->s_inodes_per_group;
447    V(s_inodes_per_group)
448    fs->s_inodes_per_block = fs->s_blocksize / EXT2_INODE_SIZE;
449    V(s_inodes_per_block)
450    fs->s_itb_per_group = fs->s_inodes_per_group /fs->s_inodes_per_block;
451    V(s_itb_per_group)
452    fs->s_desc_per_block = fs->s_blocksize / sizeof (struct ext2_group_desc);
453    V(s_desc_per_block)
454    /* s_resuid / s_resgid ? */
455    fs->s_groups_count = (es->s_blocks_count -
456			  es->s_first_data_block +
457			  EXT2_BLOCKS_PER_GROUP(fs) - 1) /
458			 EXT2_BLOCKS_PER_GROUP(fs);
459    V(s_groups_count)
460    db_count = (fs->s_groups_count + EXT2_DESC_PER_BLOCK(fs) - 1) /
461	EXT2_DESC_PER_BLOCK(fs);
462    fs->s_db_per_group = db_count;
463    V(s_db_per_group)
464
465    fs->s_group_desc = bsd_malloc(db_count * sizeof (struct buf *),
466		M_EXT2MNT, M_WAITOK);
467
468    /* adjust logic_sb_block */
469    if(fs->s_blocksize > SBSIZE)
470	/* Godmar thinks: if the blocksize is greater than 1024, then
471	   the superblock is logically part of block zero.
472	 */
473        logic_sb_block = 0;
474
475    for (i = 0; i < db_count; i++) {
476	error = bread(devvp , fsbtodb(fs, logic_sb_block + i + 1),
477		fs->s_blocksize, NOCRED, &fs->s_group_desc[i]);
478	if(error) {
479	    for (j = 0; j < i; j++)
480		brelse(fs->s_group_desc[j]);
481	    bsd_free(fs->s_group_desc, M_EXT2MNT);
482	    printf("EXT2-fs: unable to read group descriptors (%d)\n", error);
483	    return EIO;
484	}
485	LCK_BUF(fs->s_group_desc[i])
486    }
487    if(!ext2_check_descriptors(fs)) {
488	    for (j = 0; j < db_count; j++)
489		    ULCK_BUF(fs->s_group_desc[j])
490	    bsd_free(fs->s_group_desc, M_EXT2MNT);
491	    printf("EXT2-fs: (ext2_check_descriptors failure) "
492		   "unable to read group descriptors\n");
493	    return EIO;
494    }
495
496    for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++) {
497	    fs->s_inode_bitmap_number[i] = 0;
498	    fs->s_inode_bitmap[i] = NULL;
499	    fs->s_block_bitmap_number[i] = 0;
500	    fs->s_block_bitmap[i] = NULL;
501    }
502    fs->s_loaded_inode_bitmaps = 0;
503    fs->s_loaded_block_bitmaps = 0;
504    if (es->s_rev_level == EXT2_GOOD_OLD_REV || (es->s_feature_ro_compat &
505        EXT2_FEATURE_RO_COMPAT_LARGE_FILE) == 0)
506	fs->fs_maxfilesize = 0x7fffffff;
507    else
508	fs->fs_maxfilesize = 0x7fffffffffffffff;
509    return 0;
510}
511
512/*
513 * Reload all incore data for a filesystem (used after running fsck on
514 * the root filesystem and finding things to fix). The filesystem must
515 * be mounted read-only.
516 *
517 * Things to do to update the mount:
518 *	1) invalidate all cached meta-data.
519 *	2) re-read superblock from disk.
520 *	3) re-read summary information from disk.
521 *	4) invalidate all inactive vnodes.
522 *	5) invalidate all cached file data.
523 *	6) re-read inode data for all active vnodes.
524 */
525static int
526ext2_reload(mp, cred, td)
527	struct mount *mp;
528	struct ucred *cred;
529	struct thread *td;
530{
531	struct vnode *vp, *nvp, *devvp;
532	struct inode *ip;
533	struct buf *bp;
534	struct ext2_super_block * es;
535	struct ext2_sb_info *fs;
536	int error;
537
538	if ((mp->mnt_flag & MNT_RDONLY) == 0)
539		return (EINVAL);
540	/*
541	 * Step 1: invalidate all cached meta-data.
542	 */
543	devvp = VFSTOEXT2(mp)->um_devvp;
544	vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
545	if (vinvalbuf(devvp, 0, cred, td, 0, 0) != 0)
546		panic("ext2_reload: dirty1");
547	VOP_UNLOCK(devvp, 0, td);
548
549	/*
550	 * Step 2: re-read superblock from disk.
551	 * constants have been adjusted for ext2
552	 */
553	if ((error = bread(devvp, SBLOCK, SBSIZE, NOCRED, &bp)) != 0)
554		return (error);
555	es = (struct ext2_super_block *)bp->b_data;
556	if (ext2_check_sb_compat(es, devvp->v_rdev, 0) != 0) {
557		brelse(bp);
558		return (EIO);		/* XXX needs translation */
559	}
560	fs = VFSTOEXT2(mp)->um_e2fs;
561	bcopy(bp->b_data, fs->s_es, sizeof(struct ext2_super_block));
562
563	if((error = compute_sb_data(devvp, es, fs)) != 0) {
564		brelse(bp);
565		return error;
566	}
567#ifdef UNKLAR
568	if (fs->fs_sbsize < SBSIZE)
569		bp->b_flags |= B_INVAL;
570#endif
571	brelse(bp);
572
573loop:
574	MNT_ILOCK(mp);
575	for (vp = TAILQ_FIRST(&mp->mnt_nvnodelist); vp != NULL; vp = nvp) {
576		if (vp->v_mount != mp) {
577			MNT_IUNLOCK(mp);
578			goto loop;
579		}
580		nvp = TAILQ_NEXT(vp, v_nmntvnodes);
581		VI_LOCK(vp);
582		if (vp->v_iflag & VI_XLOCK) {
583			VI_UNLOCK(vp);
584			continue;
585		}
586		MNT_IUNLOCK(mp);
587		/*
588		 * Step 4: invalidate all inactive vnodes.
589		 */
590		if (vp->v_usecount == 0) {
591			vgonel(vp, td);
592			goto loop;
593		}
594		/*
595		 * Step 5: invalidate all cached file data.
596		 */
597		if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, td)) {
598			goto loop;
599		}
600		if (vinvalbuf(vp, 0, cred, td, 0, 0))
601			panic("ext2_reload: dirty2");
602		/*
603		 * Step 6: re-read inode data for all active vnodes.
604		 */
605		ip = VTOI(vp);
606		error =
607		    bread(devvp, fsbtodb(fs, ino_to_fsba(fs, ip->i_number)),
608		    (int)fs->s_blocksize, NOCRED, &bp);
609		if (error) {
610			VOP_UNLOCK(vp, 0, td);
611			vrele(vp);
612			return (error);
613		}
614		ext2_ei2i((struct ext2_inode *) ((char *)bp->b_data +
615		    EXT2_INODE_SIZE * ino_to_fsbo(fs, ip->i_number)), ip);
616		brelse(bp);
617		VOP_UNLOCK(vp, 0, td);
618		vrele(vp);
619		MNT_ILOCK(mp);
620	}
621	MNT_IUNLOCK(mp);
622	return (0);
623}
624
625/*
626 * Common code for mount and mountroot
627 */
628static int
629ext2_mountfs(devvp, mp, td)
630	struct vnode *devvp;
631	struct mount *mp;
632	struct thread *td;
633{
634	struct ext2mount *ump;
635	struct buf *bp;
636	struct ext2_sb_info *fs;
637	struct ext2_super_block * es;
638	dev_t dev = devvp->v_rdev;
639	int error;
640	int ronly;
641
642	/*
643	 * Disallow multiple mounts of the same device.
644	 * Disallow mounting of a device that is currently in use
645	 * (except for root, which might share swap device for miniroot).
646	 * Flush out any old buffers remaining from a previous use.
647	 */
648	if ((error = vfs_mountedon(devvp)) != 0)
649		return (error);
650	if (vcount(devvp) > 1 && devvp != rootvp)
651		return (EBUSY);
652	vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
653	error = vinvalbuf(devvp, V_SAVE, td->td_ucred, td, 0, 0);
654	if (error) {
655		VOP_UNLOCK(devvp, 0, td);
656		return (error);
657	}
658
659	ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
660	/*
661	 * XXX: open the device with read and write access even if only
662	 * read access is needed now.  Write access is needed if the
663	 * filesystem is ever mounted read/write, and we don't change the
664	 * access mode for remounts.
665	 */
666#ifdef notyet
667	error = VOP_OPEN(devvp, ronly ? FREAD : FREAD | FWRITE, FSCRED, td, -1);
668#else
669	error = VOP_OPEN(devvp, FREAD | FWRITE, FSCRED, td, -1);
670#endif
671	VOP_UNLOCK(devvp, 0, td);
672	if (error)
673		return (error);
674	if (devvp->v_rdev->si_iosize_max != 0)
675		mp->mnt_iosize_max = devvp->v_rdev->si_iosize_max;
676	if (mp->mnt_iosize_max > MAXPHYS)
677		mp->mnt_iosize_max = MAXPHYS;
678
679	bp = NULL;
680	ump = NULL;
681	if ((error = bread(devvp, SBLOCK, SBSIZE, NOCRED, &bp)) != 0)
682		goto out;
683	es = (struct ext2_super_block *)bp->b_data;
684	if (ext2_check_sb_compat(es, dev, ronly) != 0) {
685		error = EINVAL;		/* XXX needs translation */
686		goto out;
687	}
688	if ((es->s_state & EXT2_VALID_FS) == 0 ||
689	    (es->s_state & EXT2_ERROR_FS)) {
690		if (ronly || (mp->mnt_flag & MNT_FORCE)) {
691			printf(
692"WARNING: Filesystem was not properly dismounted\n");
693		} else {
694			printf(
695"WARNING: R/W mount denied.  Filesystem is not clean - run fsck\n");
696			error = EPERM;
697			goto out;
698		}
699	}
700	ump = bsd_malloc(sizeof *ump, M_EXT2MNT, M_WAITOK);
701	bzero((caddr_t)ump, sizeof *ump);
702	/* I don't know whether this is the right strategy. Note that
703	   we dynamically allocate both an ext2_sb_info and an ext2_super_block
704	   while Linux keeps the super block in a locked buffer
705	 */
706	ump->um_e2fs = bsd_malloc(sizeof(struct ext2_sb_info),
707		M_EXT2MNT, M_WAITOK);
708	ump->um_e2fs->s_es = bsd_malloc(sizeof(struct ext2_super_block),
709		M_EXT2MNT, M_WAITOK);
710	bcopy(es, ump->um_e2fs->s_es, (u_int)sizeof(struct ext2_super_block));
711	if ((error = compute_sb_data(devvp, ump->um_e2fs->s_es, ump->um_e2fs)))
712		goto out;
713	/*
714	 * We don't free the group descriptors allocated by compute_sb_data()
715	 * until ext2_unmount().  This is OK since the mount will succeed.
716	 */
717	brelse(bp);
718	bp = NULL;
719	fs = ump->um_e2fs;
720	fs->s_rd_only = ronly;	/* ronly is set according to mnt_flags */
721	/* if the fs is not mounted read-only, make sure the super block is
722	   always written back on a sync()
723	 */
724	fs->s_wasvalid = fs->s_es->s_state & EXT2_VALID_FS ? 1 : 0;
725	if (ronly == 0) {
726		fs->s_dirt = 1;		/* mark it modified */
727		fs->s_es->s_state &= ~EXT2_VALID_FS;	/* set fs invalid */
728	}
729	mp->mnt_data = (qaddr_t)ump;
730	mp->mnt_stat.f_fsid.val[0] = dev2udev(dev);
731	mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
732	mp->mnt_maxsymlinklen = EXT2_MAXSYMLINKLEN;
733	mp->mnt_flag |= MNT_LOCAL;
734	ump->um_mountp = mp;
735	ump->um_dev = dev;
736	ump->um_devvp = devvp;
737	/* setting those two parameters allowed us to use
738	   ufs_bmap w/o changse !
739	*/
740	ump->um_nindir = EXT2_ADDR_PER_BLOCK(fs);
741	ump->um_bptrtodb = fs->s_es->s_log_block_size + 1;
742	ump->um_seqinc = EXT2_FRAGS_PER_BLOCK(fs);
743	devvp->v_rdev->si_mountpoint = mp;
744	if (ronly == 0)
745		ext2_sbupdate(ump, MNT_WAIT);
746	return (0);
747out:
748	if (bp)
749		brelse(bp);
750	/* XXX: see comment above VOP_OPEN. */
751#ifdef notyet
752	(void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD | FWRITE, NOCRED, td);
753#else
754	(void)VOP_CLOSE(devvp, FREAD | FWRITE, NOCRED, td);
755#endif
756	if (ump) {
757		bsd_free(ump->um_e2fs->s_es, M_EXT2MNT);
758		bsd_free(ump->um_e2fs, M_EXT2MNT);
759		bsd_free(ump, M_EXT2MNT);
760		mp->mnt_data = (qaddr_t)0;
761	}
762	return (error);
763}
764
765/*
766 * unmount system call
767 */
768static int
769ext2_unmount(mp, mntflags, td)
770	struct mount *mp;
771	int mntflags;
772	struct thread *td;
773{
774	struct ext2mount *ump;
775	struct ext2_sb_info *fs;
776	int error, flags, ronly, i;
777
778	flags = 0;
779	if (mntflags & MNT_FORCE) {
780		if (mp->mnt_flag & MNT_ROOTFS)
781			return (EINVAL);
782		flags |= FORCECLOSE;
783	}
784	if ((error = ext2_flushfiles(mp, flags, td)) != 0)
785		return (error);
786	ump = VFSTOEXT2(mp);
787	fs = ump->um_e2fs;
788	ronly = fs->s_rd_only;
789	if (ronly == 0) {
790		if (fs->s_wasvalid)
791			fs->s_es->s_state |= EXT2_VALID_FS;
792		ext2_sbupdate(ump, MNT_WAIT);
793	}
794
795	/* release buffers containing group descriptors */
796	for(i = 0; i < fs->s_db_per_group; i++)
797		ULCK_BUF(fs->s_group_desc[i])
798	bsd_free(fs->s_group_desc, M_EXT2MNT);
799
800	/* release cached inode/block bitmaps */
801        for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++)
802                if (fs->s_inode_bitmap[i])
803			ULCK_BUF(fs->s_inode_bitmap[i])
804
805        for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++)
806                if (fs->s_block_bitmap[i])
807			ULCK_BUF(fs->s_block_bitmap[i])
808
809	ump->um_devvp->v_rdev->si_mountpoint = NULL;
810	/* XXX: see comment above VOP_OPEN. */
811#ifdef notyet
812	error = VOP_CLOSE(ump->um_devvp, ronly ? FREAD : FREAD | FWRITE,
813	    NOCRED, td);
814#else
815	error = VOP_CLOSE(ump->um_devvp, FREAD | FWRITE, NOCRED, td);
816#endif
817	vrele(ump->um_devvp);
818	bsd_free(fs->s_es, M_EXT2MNT);
819	bsd_free(fs, M_EXT2MNT);
820	bsd_free(ump, M_EXT2MNT);
821	mp->mnt_data = (qaddr_t)0;
822	mp->mnt_flag &= ~MNT_LOCAL;
823	return (error);
824}
825
826/*
827 * Flush out all the files in a filesystem.
828 */
829static int
830ext2_flushfiles(mp, flags, td)
831	struct mount *mp;
832	int flags;
833	struct thread *td;
834{
835	int error;
836
837	error = vflush(mp, 0, flags);
838	return (error);
839}
840
841/*
842 * Get file system statistics.
843 * taken from ext2/super.c ext2_statfs
844 */
845static int
846ext2_statfs(mp, sbp, td)
847	struct mount *mp;
848	struct statfs *sbp;
849	struct thread *td;
850{
851        unsigned long overhead;
852	struct ext2mount *ump;
853	struct ext2_sb_info *fs;
854	struct ext2_super_block *es;
855	int i, nsb;
856
857	ump = VFSTOEXT2(mp);
858	fs = ump->um_e2fs;
859	es = fs->s_es;
860
861	if (es->s_magic != EXT2_SUPER_MAGIC)
862		panic("ext2_statfs - magic number spoiled");
863
864	/*
865	 * Compute the overhead (FS structures)
866	 */
867	if (es->s_feature_ro_compat & EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) {
868		nsb = 0;
869		for (i = 0 ; i < fs->s_groups_count; i++)
870			if (ext2_group_sparse(i))
871				nsb++;
872	} else
873		nsb = fs->s_groups_count;
874	overhead = es->s_first_data_block +
875	    /* Superblocks and block group descriptors: */
876	    nsb * (1 + fs->s_db_per_group) +
877	    /* Inode bitmap, block bitmap, and inode table: */
878	    fs->s_groups_count * (1 + 1 + fs->s_itb_per_group);
879
880	sbp->f_bsize = EXT2_FRAG_SIZE(fs);
881	sbp->f_iosize = EXT2_BLOCK_SIZE(fs);
882	sbp->f_blocks = es->s_blocks_count - overhead;
883	sbp->f_bfree = es->s_free_blocks_count;
884	sbp->f_bavail = sbp->f_bfree - es->s_r_blocks_count;
885	sbp->f_files = es->s_inodes_count;
886	sbp->f_ffree = es->s_free_inodes_count;
887	if (sbp != &mp->mnt_stat) {
888		sbp->f_type = mp->mnt_vfc->vfc_typenum;
889		bcopy((caddr_t)mp->mnt_stat.f_mntonname,
890			(caddr_t)&sbp->f_mntonname[0], MNAMELEN);
891		bcopy((caddr_t)mp->mnt_stat.f_mntfromname,
892			(caddr_t)&sbp->f_mntfromname[0], MNAMELEN);
893	}
894	return (0);
895}
896
897/*
898 * Go through the disk queues to initiate sandbagged IO;
899 * go through the inodes to write those that have been modified;
900 * initiate the writing of the super block if it has been modified.
901 *
902 * Note: we are always called with the filesystem marked `MPBUSY'.
903 */
904static int
905ext2_sync(mp, waitfor, cred, td)
906	struct mount *mp;
907	int waitfor;
908	struct ucred *cred;
909	struct thread *td;
910{
911	struct vnode *nvp, *vp;
912	struct inode *ip;
913	struct ext2mount *ump = VFSTOEXT2(mp);
914	struct ext2_sb_info *fs;
915	int error, allerror = 0;
916
917	fs = ump->um_e2fs;
918	if (fs->s_dirt != 0 && fs->s_rd_only != 0) {		/* XXX */
919		printf("fs = %s\n", fs->fs_fsmnt);
920		panic("ext2_sync: rofs mod");
921	}
922	/*
923	 * Write back each (modified) inode.
924	 */
925	MNT_ILOCK(mp);
926loop:
927	for (vp = TAILQ_FIRST(&mp->mnt_nvnodelist); vp != NULL; vp = nvp) {
928		/*
929		 * If the vnode that we are about to sync is no longer
930		 * associated with this mount point, start over.
931		 */
932		if (vp->v_mount != mp)
933			goto loop;
934		nvp = TAILQ_NEXT(vp, v_nmntvnodes);
935		VI_LOCK(vp);
936		if (vp->v_iflag & VI_XLOCK) {
937			VI_UNLOCK(vp);
938			continue;
939		}
940		MNT_IUNLOCK(mp);
941		ip = VTOI(vp);
942		if (vp->v_type == VNON ||
943		    ((ip->i_flag &
944		    (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE)) == 0 &&
945		    (TAILQ_EMPTY(&vp->v_dirtyblkhd) || waitfor == MNT_LAZY))) {
946			VI_UNLOCK(vp);
947			MNT_ILOCK(mp);
948			continue;
949		}
950		error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK, td);
951		if (error) {
952			MNT_ILOCK(mp);
953			if (error == ENOENT)
954				goto loop;
955			continue;
956		}
957		if ((error = VOP_FSYNC(vp, cred, waitfor, td)) != 0)
958			allerror = error;
959		VOP_UNLOCK(vp, 0, td);
960		vrele(vp);
961		MNT_ILOCK(mp);
962	}
963	MNT_IUNLOCK(mp);
964	/*
965	 * Force stale file system control information to be flushed.
966	 */
967	if (waitfor != MNT_LAZY) {
968		vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY, td);
969		if ((error = VOP_FSYNC(ump->um_devvp, cred, waitfor, td)) != 0)
970			allerror = error;
971		VOP_UNLOCK(ump->um_devvp, 0, td);
972	}
973	/*
974	 * Write back modified superblock.
975	 */
976	if (fs->s_dirt != 0) {
977		fs->s_dirt = 0;
978		fs->s_es->s_wtime = time_second;
979		if ((error = ext2_sbupdate(ump, waitfor)) != 0)
980			allerror = error;
981	}
982	return (allerror);
983}
984
985/*
986 * Look up an EXT2FS dinode number to find its incore vnode, otherwise read it
987 * in from disk.  If it is in core, wait for the lock bit to clear, then
988 * return the inode locked.  Detection and handling of mount points must be
989 * done by the calling routine.
990 */
991static int
992ext2_vget(mp, ino, flags, vpp)
993	struct mount *mp;
994	ino_t ino;
995	int flags;
996	struct vnode **vpp;
997{
998	struct ext2_sb_info *fs;
999	struct inode *ip;
1000	struct ext2mount *ump;
1001	struct buf *bp;
1002	struct vnode *vp;
1003	dev_t dev;
1004	int i, error;
1005	int used_blocks;
1006
1007	ump = VFSTOEXT2(mp);
1008	dev = ump->um_dev;
1009restart:
1010	if ((error = ext2_ihashget(dev, ino, flags, vpp)) != 0)
1011		return (error);
1012	if (*vpp != NULL)
1013		return (0);
1014
1015	/*
1016	 * Lock out the creation of new entries in the FFS hash table in
1017	 * case getnewvnode() or MALLOC() blocks, otherwise a duplicate
1018	 * may occur!
1019	 */
1020	if (ext2fs_inode_hash_lock) {
1021		while (ext2fs_inode_hash_lock) {
1022			ext2fs_inode_hash_lock = -1;
1023			tsleep(&ext2fs_inode_hash_lock, PVM, "e2vget", 0);
1024		}
1025		goto restart;
1026	}
1027	ext2fs_inode_hash_lock = 1;
1028
1029	/*
1030	 * If this MALLOC() is performed after the getnewvnode()
1031	 * it might block, leaving a vnode with a NULL v_data to be
1032	 * found by ext2_sync() if a sync happens to fire right then,
1033	 * which will cause a panic because ext2_sync() blindly
1034	 * dereferences vp->v_data (as well it should).
1035	 */
1036	MALLOC(ip, struct inode *, sizeof(struct inode), M_EXT2NODE, M_WAITOK);
1037
1038	/* Allocate a new vnode/inode. */
1039	if ((error = getnewvnode("ext2fs", mp, ext2_vnodeop_p, &vp)) != 0) {
1040		if (ext2fs_inode_hash_lock < 0)
1041			wakeup(&ext2fs_inode_hash_lock);
1042		ext2fs_inode_hash_lock = 0;
1043		*vpp = NULL;
1044		FREE(ip, M_EXT2NODE);
1045		return (error);
1046	}
1047	bzero((caddr_t)ip, sizeof(struct inode));
1048	vp->v_data = ip;
1049	ip->i_vnode = vp;
1050	ip->i_e2fs = fs = ump->um_e2fs;
1051	ip->i_dev = dev;
1052	ip->i_number = ino;
1053	/*
1054	 * Put it onto its hash chain and lock it so that other requests for
1055	 * this inode will block if they arrive while we are sleeping waiting
1056	 * for old data structures to be purged or for the contents of the
1057	 * disk portion of this inode to be read.
1058	 */
1059	ext2_ihashins(ip);
1060
1061	if (ext2fs_inode_hash_lock < 0)
1062		wakeup(&ext2fs_inode_hash_lock);
1063	ext2fs_inode_hash_lock = 0;
1064
1065	/* Read in the disk contents for the inode, copy into the inode. */
1066#if 0
1067printf("ext2_vget(%d) dbn= %d ", ino, fsbtodb(fs, ino_to_fsba(fs, ino)));
1068#endif
1069	if ((error = bread(ump->um_devvp, fsbtodb(fs, ino_to_fsba(fs, ino)),
1070	    (int)fs->s_blocksize, NOCRED, &bp)) != 0) {
1071		/*
1072		 * The inode does not contain anything useful, so it would
1073		 * be misleading to leave it on its hash chain. With mode
1074		 * still zero, it will be unlinked and returned to the free
1075		 * list by vput().
1076		 */
1077		vput(vp);
1078		brelse(bp);
1079		*vpp = NULL;
1080		return (error);
1081	}
1082	/* convert ext2 inode to dinode */
1083	ext2_ei2i((struct ext2_inode *) ((char *)bp->b_data + EXT2_INODE_SIZE *
1084			ino_to_fsbo(fs, ino)), ip);
1085	ip->i_block_group = ino_to_cg(fs, ino);
1086	ip->i_next_alloc_block = 0;
1087	ip->i_next_alloc_goal = 0;
1088	ip->i_prealloc_count = 0;
1089	ip->i_prealloc_block = 0;
1090        /* now we want to make sure that block pointers for unused
1091           blocks are zeroed out - ext2_balloc depends on this
1092	   although for regular files and directories only
1093	*/
1094	if(S_ISDIR(ip->i_mode) || S_ISREG(ip->i_mode)) {
1095		used_blocks = (ip->i_size+fs->s_blocksize-1) / fs->s_blocksize;
1096		for(i = used_blocks; i < EXT2_NDIR_BLOCKS; i++)
1097			ip->i_db[i] = 0;
1098	}
1099/*
1100	ext2_print_inode(ip);
1101*/
1102	brelse(bp);
1103
1104	/*
1105	 * Initialize the vnode from the inode, check for aliases.
1106	 * Note that the underlying vnode may have changed.
1107	 */
1108	if ((error = ext2_vinit(mp, ext2_specop_p, ext2_fifoop_p, &vp)) != 0) {
1109		vput(vp);
1110		*vpp = NULL;
1111		return (error);
1112	}
1113	/*
1114	 * Finish inode initialization now that aliasing has been resolved.
1115	 */
1116	ip->i_devvp = ump->um_devvp;
1117	VREF(ip->i_devvp);
1118	/*
1119	 * Set up a generation number for this inode if it does not
1120	 * already have one. This should only happen on old filesystems.
1121	 */
1122	if (ip->i_gen == 0) {
1123		ip->i_gen = random() / 2 + 1;
1124		if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
1125			ip->i_flag |= IN_MODIFIED;
1126	}
1127	*vpp = vp;
1128	return (0);
1129}
1130
1131/*
1132 * File handle to vnode
1133 *
1134 * Have to be really careful about stale file handles:
1135 * - check that the inode number is valid
1136 * - call ext2_vget() to get the locked inode
1137 * - check for an unallocated inode (i_mode == 0)
1138 * - check that the given client host has export rights and return
1139 *   those rights via. exflagsp and credanonp
1140 */
1141static int
1142ext2_fhtovp(mp, fhp, vpp)
1143	struct mount *mp;
1144	struct fid *fhp;
1145	struct vnode **vpp;
1146{
1147	struct inode *ip;
1148	struct ufid *ufhp;
1149	struct vnode *nvp;
1150	struct ext2_sb_info *fs;
1151	int error;
1152
1153	ufhp = (struct ufid *)fhp;
1154	fs = VFSTOEXT2(mp)->um_e2fs;
1155	if (ufhp->ufid_ino < ROOTINO ||
1156	    ufhp->ufid_ino > fs->s_groups_count * fs->s_es->s_inodes_per_group)
1157		return (ESTALE);
1158
1159	error = VFS_VGET(mp, ufhp->ufid_ino, LK_EXCLUSIVE, &nvp);
1160	if (error) {
1161		*vpp = NULLVP;
1162		return (error);
1163	}
1164	ip = VTOI(nvp);
1165	if (ip->i_mode == 0 ||
1166	    ip->i_gen != ufhp->ufid_gen || ip->i_nlink <= 0) {
1167		vput(nvp);
1168		*vpp = NULLVP;
1169		return (ESTALE);
1170	}
1171	*vpp = nvp;
1172	return (0);
1173}
1174
1175/*
1176 * Vnode pointer to File handle
1177 */
1178/* ARGSUSED */
1179static int
1180ext2_vptofh(vp, fhp)
1181	struct vnode *vp;
1182	struct fid *fhp;
1183{
1184	struct inode *ip;
1185	struct ufid *ufhp;
1186
1187	ip = VTOI(vp);
1188	ufhp = (struct ufid *)fhp;
1189	ufhp->ufid_len = sizeof(struct ufid);
1190	ufhp->ufid_ino = ip->i_number;
1191	ufhp->ufid_gen = ip->i_gen;
1192	return (0);
1193}
1194
1195/*
1196 * Write a superblock and associated information back to disk.
1197 */
1198static int
1199ext2_sbupdate(mp, waitfor)
1200	struct ext2mount *mp;
1201	int waitfor;
1202{
1203	struct ext2_sb_info *fs = mp->um_e2fs;
1204	struct ext2_super_block *es = fs->s_es;
1205	struct buf *bp;
1206	int error = 0;
1207/*
1208printf("\nupdating superblock, waitfor=%s\n", waitfor == MNT_WAIT ? "yes":"no");
1209*/
1210	bp = getblk(mp->um_devvp, SBLOCK, SBSIZE, 0, 0, 0);
1211	bcopy((caddr_t)es, bp->b_data, (u_int)sizeof(struct ext2_super_block));
1212	if (waitfor == MNT_WAIT)
1213		error = bwrite(bp);
1214	else
1215		bawrite(bp);
1216
1217	/*
1218	 * The buffers for group descriptors, inode bitmaps and block bitmaps
1219	 * are not busy at this point and are (hopefully) written by the
1220	 * usual sync mechanism. No need to write them here
1221		 */
1222
1223	return (error);
1224}
1225
1226/*
1227 * Return the root of a filesystem.
1228 */
1229static int
1230ext2_root(mp, vpp)
1231	struct mount *mp;
1232	struct vnode **vpp;
1233{
1234	struct vnode *nvp;
1235	int error;
1236
1237	error = VFS_VGET(mp, (ino_t)ROOTINO, LK_EXCLUSIVE, &nvp);
1238	if (error)
1239		return (error);
1240	*vpp = nvp;
1241	return (0);
1242}
1243
1244static int
1245ext2_init(struct vfsconf *vfsp)
1246{
1247
1248	ext2_ihashinit();
1249	return (0);
1250}
1251
1252static int
1253ext2_uninit(struct vfsconf *vfsp)
1254{
1255
1256	ext2_ihashuninit();
1257	return (0);
1258}
1259