Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / vfs / gnu / ext2fs / ext2_vfsops.c
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  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *      This product includes software developed by the University of
22  *      California, Berkeley and its contributors.
23  * 4. Neither the name of the University nor the names of its contributors
24  *    may be used to endorse or promote products derived from this software
25  *    without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  *
39  *      @(#)ffs_vfsops.c        8.8 (Berkeley) 4/18/94
40  *      $FreeBSD: src/sys/gnu/ext2fs/ext2_vfsops.c,v 1.63.2.7 2002/07/01 00:18:51 iedowse Exp $
41  */
42
43 #include "opt_quota.h"
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/namei.h>
48 #include <sys/proc.h>
49 #include <sys/kernel.h>
50 #include <sys/vnode.h>
51 #include <sys/mount.h>
52 #include <sys/buf.h>
53 #include <sys/conf.h>
54 #include <sys/fcntl.h>
55 #include <sys/disklabel.h>
56 #include <sys/malloc.h>
57 #include <sys/stat.h>
58
59 #include <ufs/ufs/quota.h>
60 #include <ufs/ufs/ufsmount.h>
61 #include <ufs/ufs/inode.h>
62 #include <ufs/ufs/ufs_extern.h>
63
64 #include <vm/vm_zone.h>
65
66 #include <gnu/ext2fs/fs.h>
67 #include <gnu/ext2fs/ext2_extern.h>
68 #include <gnu/ext2fs/ext2_fs.h>
69 #include <gnu/ext2fs/ext2_fs_sb.h>
70
71 static int ext2_fhtovp __P((struct mount *, struct fid *, struct vnode **));
72 static int ext2_flushfiles __P((struct mount *mp, int flags, struct proc *p));
73 static int ext2_mount __P((struct mount *,
74             char *, caddr_t, struct nameidata *, struct proc *));
75 static int ext2_mountfs __P((struct vnode *, struct mount *, struct proc *));
76 static int ext2_reload __P((struct mount *mountp, struct ucred *cred,
77                         struct proc *p));
78 static int ext2_sbupdate __P((struct ufsmount *, int));
79 static int ext2_statfs __P((struct mount *, struct statfs *, struct proc *));
80 static int ext2_sync __P((struct mount *, int, struct ucred *, struct proc *));
81 static int ext2_unmount __P((struct mount *, int, struct proc *));
82 static int ext2_vget __P((struct mount *, ino_t, struct vnode **));
83 static int ext2_vptofh __P((struct vnode *, struct fid *));
84
85 static MALLOC_DEFINE(M_EXT2NODE, "EXT2 node", "EXT2 vnode private part");
86
87 static struct vfsops ext2fs_vfsops = {
88         ext2_mount,
89         ufs_start,              /* empty function */
90         ext2_unmount,
91         ufs_root,               /* root inode via vget */
92         ufs_quotactl,           /* does operations associated with quotas */
93         ext2_statfs,
94         ext2_sync,
95         ext2_vget,
96         ext2_fhtovp,
97         ufs_check_export,
98         ext2_vptofh,
99         ext2_init,
100         vfs_stduninit,
101         vfs_stdextattrctl,
102 };
103
104 VFS_SET(ext2fs_vfsops, ext2fs, 0);
105 #define bsd_malloc malloc
106 #define bsd_free free
107
108 static int ext2fs_inode_hash_lock;
109
110 static int      ext2_check_sb_compat __P((struct ext2_super_block *es,
111                                           dev_t dev, int ronly));
112 static int      compute_sb_data __P((struct vnode * devvp,
113                                      struct ext2_super_block * es,
114                                      struct ext2_sb_info * fs));
115
116 #ifdef notyet
117 static int ext2_mountroot __P((void));
118
119 /*
120  * Called by main() when ext2fs is going to be mounted as root.
121  *
122  * Name is updated by mount(8) after booting.
123  */
124 #define ROOTNAME        "root_device"
125
126 static int
127 ext2_mountroot()
128 {
129         register struct ext2_sb_info *fs;
130         register struct mount *mp;
131         struct proc *p = curproc;
132         struct ufsmount *ump;
133         u_int size;
134         int error;
135         
136         if ((error = bdevvp(rootdev, &rootvp))) {
137                 printf("ext2_mountroot: can't find rootvp\n");
138                 return (error);
139         }
140         mp = bsd_malloc((u_long)sizeof(struct mount), M_MOUNT, M_WAITOK);
141         bzero((char *)mp, (u_long)sizeof(struct mount));
142         TAILQ_INIT(&mp->mnt_nvnodelist);
143         TAILQ_INIT(&mp->mnt_reservedvnlist);
144         mp->mnt_op = &ext2fs_vfsops;
145         mp->mnt_flag = MNT_RDONLY;
146         if (error = ext2_mountfs(rootvp, mp, p)) {
147                 bsd_free(mp, M_MOUNT);
148                 return (error);
149         }
150         if (error = vfs_lock(mp)) {
151                 (void)ext2_unmount(mp, 0, p);
152                 bsd_free(mp, M_MOUNT);
153                 return (error);
154         }
155         TAILQ_INSERT_HEAD(&mountlist, mp, mnt_list);
156         mp->mnt_flag |= MNT_ROOTFS;
157         mp->mnt_vnodecovered = NULLVP;
158         ump = VFSTOUFS(mp);
159         fs = ump->um_e2fs;
160         bzero(fs->fs_fsmnt, sizeof(fs->fs_fsmnt));
161         fs->fs_fsmnt[0] = '/';
162         bcopy((caddr_t)fs->fs_fsmnt, (caddr_t)mp->mnt_stat.f_mntonname,
163             MNAMELEN);
164         (void) copystr(ROOTNAME, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
165             &size);
166         bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
167         (void)ext2_statfs(mp, &mp->mnt_stat, p);
168         vfs_unlock(mp);
169         inittodr(fs->s_es->s_wtime);            /* this helps to set the time */
170         return (0);
171 }
172 #endif
173
174 /*
175  * VFS Operations.
176  *
177  * mount system call
178  */
179 static int
180 ext2_mount(mp, path, data, ndp, p)
181         register struct mount *mp;      
182         char *path;
183         caddr_t data;           /* this is actually a (struct ufs_args *) */
184         struct nameidata *ndp;
185         struct proc *p;
186 {
187         struct vnode *devvp;
188         struct ufs_args args;
189         struct ufsmount *ump = 0;
190         register struct ext2_sb_info *fs;
191         size_t size;
192         int error, flags;
193         mode_t accessmode;
194
195         if ((error = copyin(data, (caddr_t)&args, sizeof (struct ufs_args))) != 0)
196                 return (error);
197         /*
198          * If updating, check whether changing from read-only to
199          * read/write; if there is no device name, that's all we do.
200          */
201         if (mp->mnt_flag & MNT_UPDATE) {
202                 ump = VFSTOUFS(mp);
203                 fs = ump->um_e2fs;
204                 error = 0;
205                 if (fs->s_rd_only == 0 && (mp->mnt_flag & MNT_RDONLY)) {
206                         flags = WRITECLOSE;
207                         if (mp->mnt_flag & MNT_FORCE)
208                                 flags |= FORCECLOSE;
209                         if (vfs_busy(mp, LK_NOWAIT, 0, p))
210                                 return (EBUSY);
211                         error = ext2_flushfiles(mp, flags, p);
212                         vfs_unbusy(mp, p);
213                         if (!error && fs->s_wasvalid) {
214                                 fs->s_es->s_state |= EXT2_VALID_FS;
215                                 ext2_sbupdate(ump, MNT_WAIT);
216                         }
217                         fs->s_rd_only = 1;
218                 }
219                 if (!error && (mp->mnt_flag & MNT_RELOAD))
220                         error = ext2_reload(mp, ndp->ni_cnd.cn_cred, p);
221                 if (error)
222                         return (error);
223                 devvp = ump->um_devvp;
224                 if (ext2_check_sb_compat(fs->s_es, devvp->v_rdev,
225                     (mp->mnt_kern_flag & MNTK_WANTRDWR) == 0) != 0)
226                         return (EPERM);
227                 if (fs->s_rd_only && (mp->mnt_kern_flag & MNTK_WANTRDWR)) {
228                         /*
229                          * If upgrade to read-write by non-root, then verify
230                          * that user has necessary permissions on the device.
231                          */
232                         if (p->p_ucred->cr_uid != 0) {
233                                 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
234                                 if ((error = VOP_ACCESS(devvp, VREAD | VWRITE,
235                                     p->p_ucred, p)) != 0) {
236                                         VOP_UNLOCK(devvp, 0, p);
237                                         return (error);
238                                 }
239                                 VOP_UNLOCK(devvp, 0, p);
240                         }
241
242                         if ((fs->s_es->s_state & EXT2_VALID_FS) == 0 ||
243                             (fs->s_es->s_state & EXT2_ERROR_FS)) {
244                                 if (mp->mnt_flag & MNT_FORCE) {
245                                         printf(
246 "WARNING: %s was not properly dismounted\n",
247                                             fs->fs_fsmnt);
248                                 } else {
249                                         printf(
250 "WARNING: R/W mount of %s denied.  Filesystem is not clean - run fsck\n",
251                                             fs->fs_fsmnt);
252                                         return (EPERM);
253                                 }
254                         }
255                         fs->s_es->s_state &= ~EXT2_VALID_FS;
256                         ext2_sbupdate(ump, MNT_WAIT);
257                         fs->s_rd_only = 0;
258                 }
259                 if (args.fspec == 0) {
260                         /*
261                          * Process export requests.
262                          */
263                         return (vfs_export(mp, &ump->um_export, &args.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 block device.
269          */
270         NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p);
271         if ((error = namei(ndp)) != 0)
272                 return (error);
273         NDFREE(ndp, NDF_ONLY_PNBUF);
274         devvp = ndp->ni_vp;
275
276         if (!vn_isdisk(devvp, &error)) {
277                 vrele(devvp);
278                 return (error);
279         }
280
281         /*
282          * If mount by non-root, then verify that user has necessary
283          * permissions on the device.
284          */
285         if (p->p_ucred->cr_uid != 0) {
286                 accessmode = VREAD;
287                 if ((mp->mnt_flag & MNT_RDONLY) == 0)
288                         accessmode |= VWRITE;
289                 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
290                 if ((error = VOP_ACCESS(devvp, accessmode, p->p_ucred, p)) != 0) {
291                         vput(devvp);
292                         return (error);
293                 }
294                 VOP_UNLOCK(devvp, 0, p);
295         }
296
297         if ((mp->mnt_flag & MNT_UPDATE) == 0) {
298                 error = ext2_mountfs(devvp, mp, p);
299         } else {
300                 if (devvp != ump->um_devvp)
301                         error = EINVAL; /* needs translation */
302                 else
303                         vrele(devvp);
304         }
305         if (error) {
306                 vrele(devvp);
307                 return (error);
308         }
309         ump = VFSTOUFS(mp);
310         fs = ump->um_e2fs;
311         (void) copyinstr(path, fs->fs_fsmnt, sizeof(fs->fs_fsmnt) - 1, &size);
312         bzero(fs->fs_fsmnt + size, sizeof(fs->fs_fsmnt) - size);
313         bcopy((caddr_t)fs->fs_fsmnt, (caddr_t)mp->mnt_stat.f_mntonname,
314             MNAMELEN);
315         (void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, 
316             &size);
317         bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
318         (void)ext2_statfs(mp, &mp->mnt_stat, p);
319         return (0);
320 }
321
322 /*
323  * checks that the data in the descriptor blocks make sense
324  * this is taken from ext2/super.c
325  */
326 static int ext2_check_descriptors (struct ext2_sb_info * sb)
327 {
328         int i;
329         int desc_block = 0;
330         unsigned long block = sb->s_es->s_first_data_block;
331         struct ext2_group_desc * gdp = NULL;
332
333         /* ext2_debug ("Checking group descriptors"); */
334
335         for (i = 0; i < sb->s_groups_count; i++)
336         {
337                 /* examine next descriptor block */
338                 if ((i % EXT2_DESC_PER_BLOCK(sb)) == 0)
339                         gdp = (struct ext2_group_desc *) 
340                                 sb->s_group_desc[desc_block++]->b_data;
341                 if (gdp->bg_block_bitmap < block ||
342                     gdp->bg_block_bitmap >= block + EXT2_BLOCKS_PER_GROUP(sb))
343                 {
344                         printf ("ext2_check_descriptors: "
345                                     "Block bitmap for group %d"
346                                     " not in group (block %lu)!\n",
347                                     i, (unsigned long) gdp->bg_block_bitmap);
348                         return 0;
349                 }
350                 if (gdp->bg_inode_bitmap < block ||
351                     gdp->bg_inode_bitmap >= block + EXT2_BLOCKS_PER_GROUP(sb))
352                 {
353                         printf ("ext2_check_descriptors: "
354                                     "Inode bitmap for group %d"
355                                     " not in group (block %lu)!\n",
356                                     i, (unsigned long) gdp->bg_inode_bitmap);
357                         return 0;
358                 }
359                 if (gdp->bg_inode_table < block ||
360                     gdp->bg_inode_table + sb->s_itb_per_group >=
361                     block + EXT2_BLOCKS_PER_GROUP(sb))
362                 {
363                         printf ("ext2_check_descriptors: "
364                                     "Inode table for group %d"
365                                     " not in group (block %lu)!\n",
366                                     i, (unsigned long) gdp->bg_inode_table);
367                         return 0;
368                 }
369                 block += EXT2_BLOCKS_PER_GROUP(sb);
370                 gdp++;
371         }
372         return 1;
373 }
374
375 static int
376 ext2_check_sb_compat(es, dev, ronly)
377         struct ext2_super_block *es;
378         dev_t dev;
379         int ronly;
380 {
381
382         if (es->s_magic != EXT2_SUPER_MAGIC) {
383                 printf("ext2fs: %s: wrong magic number %#x (expected %#x)\n",
384                     devtoname(dev), es->s_magic, EXT2_SUPER_MAGIC);
385                 return (1);
386         }
387         if (es->s_rev_level > EXT2_GOOD_OLD_REV) {
388                 if (es->s_feature_incompat & ~EXT2_FEATURE_INCOMPAT_SUPP) {
389                         printf(
390 "WARNING: mount of %s denied due to unsupported optional features\n",
391                             devtoname(dev));
392                         return (1);
393                 }
394                 if (!ronly &&
395                     (es->s_feature_ro_compat & ~EXT2_FEATURE_RO_COMPAT_SUPP)) {
396                         printf(
397 "WARNING: R/W mount of %s denied due to unsupported optional features\n",
398                             devtoname(dev));
399                         return (1);
400                 }
401         }
402         return (0);
403 }
404
405 /*
406  * this computes the fields of the  ext2_sb_info structure from the
407  * data in the ext2_super_block structure read in
408  */
409 static int compute_sb_data(devvp, es, fs)
410         struct vnode * devvp;
411         struct ext2_super_block * es;
412         struct ext2_sb_info * fs;
413 {
414     int db_count, error;
415     int i, j;
416     int logic_sb_block = 1;     /* XXX for now */
417
418 #if 1
419 #define V(v)  
420 #else
421 #define V(v)  printf(#v"= %d\n", fs->v);
422 #endif
423
424     fs->s_blocksize = EXT2_MIN_BLOCK_SIZE << es->s_log_block_size; 
425     V(s_blocksize)
426     fs->s_bshift = EXT2_MIN_BLOCK_LOG_SIZE + es->s_log_block_size;
427     V(s_bshift)
428     fs->s_fsbtodb = es->s_log_block_size + 1;
429     V(s_fsbtodb)
430     fs->s_qbmask = fs->s_blocksize - 1;
431     V(s_bmask)
432     fs->s_blocksize_bits = EXT2_BLOCK_SIZE_BITS(es);
433     V(s_blocksize_bits)
434     fs->s_frag_size = EXT2_MIN_FRAG_SIZE << es->s_log_frag_size;
435     V(s_frag_size)
436     if (fs->s_frag_size)
437         fs->s_frags_per_block = fs->s_blocksize / fs->s_frag_size;
438     V(s_frags_per_block)
439     fs->s_blocks_per_group = es->s_blocks_per_group;
440     V(s_blocks_per_group)
441     fs->s_frags_per_group = es->s_frags_per_group;
442     V(s_frags_per_group)
443     fs->s_inodes_per_group = es->s_inodes_per_group;
444     V(s_inodes_per_group)
445     fs->s_inodes_per_block = fs->s_blocksize / EXT2_INODE_SIZE;
446     V(s_inodes_per_block)
447     fs->s_itb_per_group = fs->s_inodes_per_group /fs->s_inodes_per_block;
448     V(s_itb_per_group)
449     fs->s_desc_per_block = fs->s_blocksize / sizeof (struct ext2_group_desc);
450     V(s_desc_per_block)
451     /* s_resuid / s_resgid ? */
452     fs->s_groups_count = (es->s_blocks_count -
453                           es->s_first_data_block +
454                           EXT2_BLOCKS_PER_GROUP(fs) - 1) /
455                          EXT2_BLOCKS_PER_GROUP(fs);
456     V(s_groups_count)
457     db_count = (fs->s_groups_count + EXT2_DESC_PER_BLOCK(fs) - 1) /
458         EXT2_DESC_PER_BLOCK(fs);
459     fs->s_db_per_group = db_count;
460     V(s_db_per_group)
461
462     fs->s_group_desc = bsd_malloc(db_count * sizeof (struct buf *),
463                 M_UFSMNT, M_WAITOK);
464
465     /* adjust logic_sb_block */
466     if(fs->s_blocksize > SBSIZE) 
467         /* Godmar thinks: if the blocksize is greater than 1024, then
468            the superblock is logically part of block zero. 
469          */
470         logic_sb_block = 0;
471     
472     for (i = 0; i < db_count; i++) {
473         error = bread(devvp , fsbtodb(fs, logic_sb_block + i + 1), 
474                 fs->s_blocksize, NOCRED, &fs->s_group_desc[i]);
475         if(error) {
476             for (j = 0; j < i; j++)
477                 brelse(fs->s_group_desc[j]);
478             bsd_free(fs->s_group_desc, M_UFSMNT);
479             printf("EXT2-fs: unable to read group descriptors (%d)\n", error);
480             return EIO;
481         }
482         /* Set the B_LOCKED flag on the buffer, then brelse() it */
483         LCK_BUF(fs->s_group_desc[i])
484     }
485     if(!ext2_check_descriptors(fs)) {
486             for (j = 0; j < db_count; j++)
487                     ULCK_BUF(fs->s_group_desc[j])
488             bsd_free(fs->s_group_desc, M_UFSMNT);
489             printf("EXT2-fs: (ext2_check_descriptors failure) "
490                    "unable to read group descriptors\n");
491             return EIO;
492     }
493
494     for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++) {
495             fs->s_inode_bitmap_number[i] = 0;
496             fs->s_inode_bitmap[i] = NULL;
497             fs->s_block_bitmap_number[i] = 0;
498             fs->s_block_bitmap[i] = NULL;
499     }
500     fs->s_loaded_inode_bitmaps = 0;
501     fs->s_loaded_block_bitmaps = 0;
502     return 0;
503 }
504
505 /*
506  * Reload all incore data for a filesystem (used after running fsck on
507  * the root filesystem and finding things to fix). The filesystem must
508  * be mounted read-only.
509  *
510  * Things to do to update the mount:
511  *      1) invalidate all cached meta-data.
512  *      2) re-read superblock from disk.
513  *      3) re-read summary information from disk.
514  *      4) invalidate all inactive vnodes.
515  *      5) invalidate all cached file data.
516  *      6) re-read inode data for all active vnodes.
517  */
518 static int
519 ext2_reload(mountp, cred, p)
520         register struct mount *mountp;
521         struct ucred *cred;
522         struct proc *p;
523 {
524         register struct vnode *vp, *nvp, *devvp;
525         struct inode *ip;
526         struct buf *bp;
527         struct ext2_super_block * es;
528         struct ext2_sb_info *fs;
529         int error;
530
531         if ((mountp->mnt_flag & MNT_RDONLY) == 0)
532                 return (EINVAL);
533         /*
534          * Step 1: invalidate all cached meta-data.
535          */
536         devvp = VFSTOUFS(mountp)->um_devvp;
537         if (vinvalbuf(devvp, 0, cred, p, 0, 0))
538                 panic("ext2_reload: dirty1");
539         /*
540          * Step 2: re-read superblock from disk.
541          * constants have been adjusted for ext2
542          */
543         if ((error = bread(devvp, SBLOCK, SBSIZE, NOCRED, &bp)) != 0)
544                 return (error);
545         es = (struct ext2_super_block *)bp->b_data;
546         if (ext2_check_sb_compat(es, devvp->v_rdev, 0) != 0) {
547                 brelse(bp);
548                 return (EIO);           /* XXX needs translation */
549         }
550         fs = VFSTOUFS(mountp)->um_e2fs;
551         bcopy(bp->b_data, fs->s_es, sizeof(struct ext2_super_block));
552
553         if((error = compute_sb_data(devvp, es, fs)) != 0) {
554                 brelse(bp);
555                 return error;
556         }
557 #ifdef UNKLAR
558         if (fs->fs_sbsize < SBSIZE)
559                 bp->b_flags |= B_INVAL;
560 #endif
561         brelse(bp);
562
563 loop:
564         simple_lock(&mntvnode_slock);
565         for (vp = TAILQ_FIRST(&mountp->mnt_nvnodelist); vp != NULL; vp = nvp) {
566                 if (vp->v_mount != mountp) {
567                         simple_unlock(&mntvnode_slock);
568                         goto loop;
569                 }
570                 nvp = TAILQ_NEXT(vp, v_nmntvnodes);
571                 /*
572                  * Step 4: invalidate all inactive vnodes.
573                  */
574                 if (vrecycle(vp, &mntvnode_slock, p))
575                         goto loop;
576                 /*
577                  * Step 5: invalidate all cached file data.
578                  */
579                 simple_lock(&vp->v_interlock);
580                 simple_unlock(&mntvnode_slock);
581                 if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, p)) {
582                         goto loop;
583                 }
584                 if (vinvalbuf(vp, 0, cred, p, 0, 0))
585                         panic("ext2_reload: dirty2");
586                 /*
587                  * Step 6: re-read inode data for all active vnodes.
588                  */
589                 ip = VTOI(vp);
590                 error =
591                     bread(devvp, fsbtodb(fs, ino_to_fsba(fs, ip->i_number)),
592                     (int)fs->s_blocksize, NOCRED, &bp);
593                 if (error) {
594                         vput(vp);
595                         return (error);
596                 }
597                 ext2_ei2di((struct ext2_inode *) ((char *)bp->b_data + 
598                     EXT2_INODE_SIZE * ino_to_fsbo(fs, ip->i_number)), 
599                     &ip->i_din);
600                 brelse(bp);
601                 vput(vp);
602                 simple_lock(&mntvnode_slock);
603         }
604         simple_unlock(&mntvnode_slock);
605         return (0);
606 }
607
608 /*
609  * Common code for mount and mountroot
610  */
611 static int
612 ext2_mountfs(devvp, mp, p)
613         register struct vnode *devvp;
614         struct mount *mp;
615         struct proc *p;
616 {
617         register struct ufsmount *ump;
618         struct buf *bp;
619         register struct ext2_sb_info *fs;
620         struct ext2_super_block * es;
621         dev_t dev = devvp->v_rdev;
622         struct partinfo dpart;
623         int havepart = 0;
624         int error, i, size;
625         int ronly;
626
627         /*
628          * Disallow multiple mounts of the same device.
629          * Disallow mounting of a device that is currently in use
630          * (except for root, which might share swap device for miniroot).
631          * Flush out any old buffers remaining from a previous use.
632          */
633         if ((error = vfs_mountedon(devvp)) != 0)
634                 return (error);
635         if (vcount(devvp) > 1 && devvp != rootvp)
636                 return (EBUSY);
637         if ((error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0)) != 0)
638                 return (error);
639 #ifdef READONLY
640 /* turn on this to force it to be read-only */
641         mp->mnt_flag |= MNT_RDONLY;
642 #endif
643
644         ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
645         vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
646         error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p);
647         VOP_UNLOCK(devvp, 0, p);
648         if (error)
649                 return (error);
650         if (devvp->v_rdev->si_iosize_max != 0)
651                 mp->mnt_iosize_max = devvp->v_rdev->si_iosize_max;
652         if (mp->mnt_iosize_max > MAXPHYS)
653                 mp->mnt_iosize_max = MAXPHYS;
654         if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, NOCRED, p) != 0)
655                 size = DEV_BSIZE;
656         else {
657                 havepart = 1;
658                 size = dpart.disklab->d_secsize;
659         }
660
661         bp = NULL;
662         ump = NULL;
663         if ((error = bread(devvp, SBLOCK, SBSIZE, NOCRED, &bp)) != 0)
664                 goto out;
665         es = (struct ext2_super_block *)bp->b_data;
666         if (ext2_check_sb_compat(es, dev, ronly) != 0) {
667                 error = EINVAL;         /* XXX needs translation */
668                 goto out;
669         }
670         if ((es->s_state & EXT2_VALID_FS) == 0 ||
671             (es->s_state & EXT2_ERROR_FS)) {
672                 if (ronly || (mp->mnt_flag & MNT_FORCE)) {
673                         printf(
674 "WARNING: Filesystem was not properly dismounted\n");
675                 } else {
676                         printf(
677 "WARNING: R/W mount denied.  Filesystem is not clean - run fsck\n");
678                         error = EPERM;
679                         goto out;
680                 }
681         }
682         ump = bsd_malloc(sizeof *ump, M_UFSMNT, M_WAITOK);
683         bzero((caddr_t)ump, sizeof *ump);
684         ump->um_malloctype = M_EXT2NODE;
685         ump->um_blkatoff = ext2_blkatoff;
686         ump->um_truncate = ext2_truncate;
687         ump->um_update = ext2_update;
688         ump->um_valloc = ext2_valloc;
689         ump->um_vfree = ext2_vfree;
690         /* I don't know whether this is the right strategy. Note that
691            we dynamically allocate both a ext2_sb_info and a ext2_super_block
692            while Linux keeps the super block in a locked buffer
693          */
694         ump->um_e2fs = bsd_malloc(sizeof(struct ext2_sb_info), 
695                 M_UFSMNT, M_WAITOK);
696         ump->um_e2fs->s_es = bsd_malloc(sizeof(struct ext2_super_block), 
697                 M_UFSMNT, M_WAITOK);
698         bcopy(es, ump->um_e2fs->s_es, (u_int)sizeof(struct ext2_super_block));
699         if ((error = compute_sb_data(devvp, ump->um_e2fs->s_es, ump->um_e2fs)))
700                 goto out;
701         /*
702          * We don't free the group descriptors allocated by compute_sb_data()
703          * until ext2_unmount().  This is OK since the mount will succeed.
704          */
705         brelse(bp);
706         bp = NULL;
707         fs = ump->um_e2fs;
708         fs->s_rd_only = ronly;  /* ronly is set according to mnt_flags */
709         /* if the fs is not mounted read-only, make sure the super block is 
710            always written back on a sync()
711          */
712         fs->s_wasvalid = fs->s_es->s_state & EXT2_VALID_FS ? 1 : 0;
713         if (ronly == 0) {
714                 fs->s_dirt = 1;         /* mark it modified */
715                 fs->s_es->s_state &= ~EXT2_VALID_FS;    /* set fs invalid */
716         }
717         mp->mnt_data = (qaddr_t)ump;
718         mp->mnt_stat.f_fsid.val[0] = dev2udev(dev);
719         mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
720         mp->mnt_maxsymlinklen = EXT2_MAXSYMLINKLEN;
721         mp->mnt_flag |= MNT_LOCAL;
722         ump->um_mountp = mp;
723         ump->um_dev = dev;
724         ump->um_devvp = devvp;
725         /* setting those two parameters allows us to use 
726            ufs_bmap w/o changse !
727         */
728         ump->um_nindir = EXT2_ADDR_PER_BLOCK(fs);
729         ump->um_bptrtodb = fs->s_es->s_log_block_size + 1;
730         ump->um_seqinc = EXT2_FRAGS_PER_BLOCK(fs);
731         for (i = 0; i < MAXQUOTAS; i++)
732                 ump->um_quotas[i] = NULLVP; 
733         devvp->v_specmountpoint = mp;
734         if (ronly == 0) 
735                 ext2_sbupdate(ump, MNT_WAIT);
736         return (0);
737 out:
738         if (bp)
739                 brelse(bp);
740         (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
741         if (ump) {
742                 bsd_free(ump->um_e2fs->s_es, M_UFSMNT);
743                 bsd_free(ump->um_e2fs, M_UFSMNT);
744                 bsd_free(ump, M_UFSMNT);
745                 mp->mnt_data = (qaddr_t)0;
746         }
747         return (error);
748 }
749
750 /*
751  * unmount system call
752  */
753 static int
754 ext2_unmount(mp, mntflags, p)
755         struct mount *mp;
756         int mntflags;
757         struct proc *p;
758 {
759         register struct ufsmount *ump;
760         register struct ext2_sb_info *fs;
761         int error, flags, ronly, i;
762
763         flags = 0;
764         if (mntflags & MNT_FORCE) {
765                 if (mp->mnt_flag & MNT_ROOTFS)
766                         return (EINVAL);
767                 flags |= FORCECLOSE;
768         }
769         if ((error = ext2_flushfiles(mp, flags, p)) != 0)
770                 return (error);
771         ump = VFSTOUFS(mp);
772         fs = ump->um_e2fs;
773         ronly = fs->s_rd_only;
774         if (ronly == 0) {
775                 if (fs->s_wasvalid)
776                         fs->s_es->s_state |= EXT2_VALID_FS;
777                 ext2_sbupdate(ump, MNT_WAIT);
778         }
779
780         /* release buffers containing group descriptors */
781         for(i = 0; i < fs->s_db_per_group; i++) 
782                 ULCK_BUF(fs->s_group_desc[i])
783         bsd_free(fs->s_group_desc, M_UFSMNT);
784
785         /* release cached inode/block bitmaps */
786         for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++)
787                 if (fs->s_inode_bitmap[i])
788                         ULCK_BUF(fs->s_inode_bitmap[i])
789
790         for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++)
791                 if (fs->s_block_bitmap[i])
792                         ULCK_BUF(fs->s_block_bitmap[i])
793
794         ump->um_devvp->v_specmountpoint = NULL;
795         error = VOP_CLOSE(ump->um_devvp, ronly ? FREAD : FREAD|FWRITE,
796                 NOCRED, p);
797         vrele(ump->um_devvp);
798         bsd_free(fs->s_es, M_UFSMNT);
799         bsd_free(fs, M_UFSMNT);
800         bsd_free(ump, M_UFSMNT);
801         mp->mnt_data = (qaddr_t)0;
802         mp->mnt_flag &= ~MNT_LOCAL;
803         return (error);
804 }
805
806 /*
807  * Flush out all the files in a filesystem.
808  */
809 static int
810 ext2_flushfiles(mp, flags, p)
811         register struct mount *mp;
812         int flags;
813         struct proc *p;
814 {
815         register struct ufsmount *ump;
816         int error;
817 #if QUOTA
818         int i;
819 #endif
820
821         ump = VFSTOUFS(mp);
822 #if QUOTA
823         if (mp->mnt_flag & MNT_QUOTA) {
824                 if ((error = vflush(mp, 0, SKIPSYSTEM|flags)) != 0)
825                         return (error);
826                 for (i = 0; i < MAXQUOTAS; i++) {
827                         if (ump->um_quotas[i] == NULLVP)
828                                 continue;
829                         quotaoff(p, mp, i);
830                 }
831                 /*
832                  * Here we fall through to vflush again to ensure
833                  * that we have gotten rid of all the system vnodes.
834                  */
835         }
836 #endif
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  */
845 static int
846 ext2_statfs(mp, sbp, p)
847         struct mount *mp;
848         register struct statfs *sbp;
849         struct proc *p;
850 {
851         unsigned long overhead;
852         register struct ufsmount *ump;
853         register struct ext2_sb_info *fs;
854         register struct ext2_super_block *es;
855         int i, nsb;
856
857         ump = VFSTOUFS(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  */
904 static int
905 ext2_sync(mp, waitfor, cred, p)
906         struct mount *mp;
907         int waitfor;
908         struct ucred *cred;
909         struct proc *p;
910 {
911         struct vnode *nvp, *vp;
912         struct inode *ip;
913         struct ufsmount *ump = VFSTOUFS(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         simple_lock(&mntvnode_slock);
926 loop:
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                 simple_lock(&vp->v_interlock);
935                 nvp = TAILQ_NEXT(vp, v_nmntvnodes);
936                 ip = VTOI(vp);
937                 if (vp->v_type == VNON ||
938                     ((ip->i_flag &
939                     (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE)) == 0 &&
940                     (TAILQ_EMPTY(&vp->v_dirtyblkhd) || waitfor == MNT_LAZY))) {
941                         simple_unlock(&vp->v_interlock);
942                         continue;
943                 }
944                 simple_unlock(&mntvnode_slock);
945                 error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK, p);
946                 if (error) {
947                         simple_lock(&mntvnode_slock);
948                         if (error == ENOENT)
949                                 goto loop;
950                         continue;
951                 }
952                 if ((error = VOP_FSYNC(vp, cred, waitfor, p)) != 0)
953                         allerror = error;
954                 VOP_UNLOCK(vp, 0, p);
955                 vrele(vp);
956                 simple_lock(&mntvnode_slock);
957         }
958         simple_unlock(&mntvnode_slock);
959         /*
960          * Force stale file system control information to be flushed.
961          */
962         if (waitfor != MNT_LAZY) {
963                 vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY, p);
964                 if ((error = VOP_FSYNC(ump->um_devvp, cred, waitfor, p)) != 0)
965                         allerror = error;
966                 VOP_UNLOCK(ump->um_devvp, 0, p);
967         }
968 #if QUOTA
969         qsync(mp);
970 #endif
971         /*
972          * Write back modified superblock.
973          */
974         if (fs->s_dirt != 0) {
975                 fs->s_dirt = 0;
976                 fs->s_es->s_wtime = time_second;
977                 if ((error = ext2_sbupdate(ump, waitfor)) != 0)
978                         allerror = error;
979         }
980         return (allerror);
981 }
982
983 /*
984  * Look up a EXT2FS dinode number to find its incore vnode, otherwise read it
985  * in from disk.  If it is in core, wait for the lock bit to clear, then
986  * return the inode locked.  Detection and handling of mount points must be
987  * done by the calling routine.
988  */
989 static int
990 ext2_vget(mp, ino, vpp)
991         struct mount *mp;
992         ino_t ino;
993         struct vnode **vpp;
994 {
995         register struct ext2_sb_info *fs;
996         register struct inode *ip;
997         struct ufsmount *ump;
998         struct buf *bp;
999         struct vnode *vp;
1000         dev_t dev;
1001         int i, error;
1002         int used_blocks;
1003
1004         ump = VFSTOUFS(mp);
1005         dev = ump->um_dev;
1006 restart:
1007         if ((*vpp = ufs_ihashget(dev, ino)) != NULL)
1008                 return (0);
1009
1010         /*
1011          * Lock out the creation of new entries in the FFS hash table in
1012          * case getnewvnode() or MALLOC() blocks, otherwise a duplicate
1013          * may occur!
1014          */
1015         if (ext2fs_inode_hash_lock) {
1016                 while (ext2fs_inode_hash_lock) {
1017                         ext2fs_inode_hash_lock = -1;
1018                         tsleep(&ext2fs_inode_hash_lock, PVM, "e2vget", 0);
1019                 }
1020                 goto restart;
1021         }
1022         ext2fs_inode_hash_lock = 1;
1023
1024         /*
1025          * If this MALLOC() is performed after the getnewvnode()
1026          * it might block, leaving a vnode with a NULL v_data to be
1027          * found by ext2_sync() if a sync happens to fire right then,
1028          * which will cause a panic because ext2_sync() blindly
1029          * dereferences vp->v_data (as well it should).
1030          */
1031         MALLOC(ip, struct inode *, sizeof(struct inode), M_EXT2NODE, M_WAITOK);
1032
1033         /* Allocate a new vnode/inode. */
1034         if ((error = getnewvnode(VT_UFS, mp, ext2_vnodeop_p, &vp)) != 0) {
1035                 if (ext2fs_inode_hash_lock < 0)
1036                         wakeup(&ext2fs_inode_hash_lock);
1037                 ext2fs_inode_hash_lock = 0;
1038                 *vpp = NULL;
1039                 FREE(ip, M_EXT2NODE);
1040                 return (error);
1041         }
1042         bzero((caddr_t)ip, sizeof(struct inode));
1043         lockinit(&ip->i_lock, PINOD, "ext2in", 0, 0);
1044         vp->v_data = ip;
1045         ip->i_vnode = vp;
1046         ip->i_e2fs = fs = ump->um_e2fs;
1047         ip->i_dev = dev;
1048         ip->i_number = ino;
1049 #if QUOTA
1050         for (i = 0; i < MAXQUOTAS; i++)
1051                 ip->i_dquot[i] = NODQUOT;
1052 #endif
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         ufs_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
1067 printf("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_ei2di((struct ext2_inode *) ((char *)bp->b_data + EXT2_INODE_SIZE *
1084                         ino_to_fsbo(fs, ino)), &ip->i_din);
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 = ufs_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  */
1141 static int
1142 ext2_fhtovp(mp, fhp, vpp)
1143         register struct mount *mp;
1144         struct fid *fhp;
1145         struct vnode **vpp;
1146 {
1147         register struct ufid *ufhp;
1148         struct ext2_sb_info *fs;
1149
1150         ufhp = (struct ufid *)fhp;
1151         fs = VFSTOUFS(mp)->um_e2fs;
1152         if (ufhp->ufid_ino < ROOTINO ||
1153             ufhp->ufid_ino > fs->s_groups_count * fs->s_es->s_inodes_per_group)
1154                 return (ESTALE);
1155         return (ufs_fhtovp(mp, ufhp, vpp));
1156 }
1157
1158 /*
1159  * Vnode pointer to File handle
1160  */
1161 /* ARGSUSED */
1162 static int
1163 ext2_vptofh(vp, fhp)
1164         struct vnode *vp;
1165         struct fid *fhp;
1166 {
1167         register struct inode *ip;
1168         register struct ufid *ufhp;
1169
1170         ip = VTOI(vp);
1171         ufhp = (struct ufid *)fhp;
1172         ufhp->ufid_len = sizeof(struct ufid);
1173         ufhp->ufid_ino = ip->i_number;
1174         ufhp->ufid_gen = ip->i_gen;
1175         return (0);
1176 }
1177
1178 /*
1179  * Write a superblock and associated information back to disk.
1180  */
1181 static int
1182 ext2_sbupdate(mp, waitfor)
1183         struct ufsmount *mp;
1184         int waitfor;
1185 {
1186         register struct ext2_sb_info *fs = mp->um_e2fs;
1187         register struct ext2_super_block *es = fs->s_es;
1188         register struct buf *bp;
1189         int error = 0;
1190 /*
1191 printf("\nupdating superblock, waitfor=%s\n", waitfor == MNT_WAIT ? "yes":"no");
1192 */
1193         bp = getblk(mp->um_devvp, SBLOCK, SBSIZE, 0, 0);
1194         bcopy((caddr_t)es, bp->b_data, (u_int)sizeof(struct ext2_super_block));
1195         if (waitfor == MNT_WAIT)
1196                 error = bwrite(bp);
1197         else
1198                 bawrite(bp);
1199
1200         /*
1201          * The buffers for group descriptors, inode bitmaps and block bitmaps
1202          * are not busy at this point and are (hopefully) written by the
1203          * usual sync mechanism. No need to write them here
1204                  */
1205
1206         return (error);
1207 }