root is mounted read-only by default; replace bflush with vflushbuf
[unix-history] / usr / src / sys / ufs / lfs / lfs_vfsops.c
index 76d5597..5bb12cb 100644 (file)
@@ -14,7 +14,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)lfs_vfsops.c        7.23 (Berkeley) %G%
+ *     @(#)lfs_vfsops.c        7.31 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -49,6 +49,7 @@ int ufs_statfs();
 int ufs_sync();
 int ufs_fhtovp();
 int ufs_vptofh();
 int ufs_sync();
 int ufs_fhtovp();
 int ufs_vptofh();
+int ufs_init();
 
 struct vfsops ufs_vfsops = {
        ufs_mount,
 
 struct vfsops ufs_vfsops = {
        ufs_mount,
@@ -58,7 +59,8 @@ struct vfsops ufs_vfsops = {
        ufs_statfs,
        ufs_sync,
        ufs_fhtovp,
        ufs_statfs,
        ufs_sync,
        ufs_fhtovp,
-       ufs_vptofh
+       ufs_vptofh,
+       ufs_init
 };
 
 /*
 };
 
 /*
@@ -85,8 +87,9 @@ ufs_mountroot()
        mp = (struct mount *)malloc((u_long)sizeof(struct mount),
                M_MOUNT, M_WAITOK);
        mp->m_op = &ufs_vfsops;
        mp = (struct mount *)malloc((u_long)sizeof(struct mount),
                M_MOUNT, M_WAITOK);
        mp->m_op = &ufs_vfsops;
-       mp->m_flag = 0;
+       mp->m_flag = M_RDONLY;
        mp->m_exroot = 0;
        mp->m_exroot = 0;
+       mp->m_mounth = (struct vnode *)0;
        error = mountfs(rootvp, mp);
        if (error) {
                free((caddr_t)mp, M_MOUNT);
        error = mountfs(rootvp, mp);
        if (error) {
                free((caddr_t)mp, M_MOUNT);
@@ -215,6 +218,8 @@ mountfs(devvp, mp)
            M_WAITOK);
        bcopy((caddr_t)bp->b_un.b_addr, (caddr_t)ump->um_fs,
           (u_int)fs->fs_sbsize);
            M_WAITOK);
        bcopy((caddr_t)bp->b_un.b_addr, (caddr_t)ump->um_fs,
           (u_int)fs->fs_sbsize);
+       if (fs->fs_sbsize < SBSIZE)
+               bp->b_flags |= B_INVAL;
        brelse(bp);
        bp = NULL;
        fs = ump->um_fs;
        brelse(bp);
        bp = NULL;
        fs = ump->um_fs;
@@ -284,7 +289,7 @@ mountfs(devvp, mp)
        ump->um_dev = dev;
        ump->um_devvp = devvp;
        ump->um_qinod = NULL;
        ump->um_dev = dev;
        ump->um_devvp = devvp;
        ump->um_qinod = NULL;
-       devvp->v_mount = mp;
+       devvp->v_mounton = mp;
 
        /* Sanity checks for old file systems.                     XXX */
        fs->fs_npsect = MAX(fs->fs_npsect, fs->fs_nsect);       /* XXX */
 
        /* Sanity checks for old file systems.                     XXX */
        fs->fs_npsect = MAX(fs->fs_npsect, fs->fs_nsect);       /* XXX */
@@ -309,6 +314,7 @@ out:
  * Make a filesystem operational.
  * Nothing to do at the moment.
  */
  * Make a filesystem operational.
  * Nothing to do at the moment.
  */
+/* ARGSUSED */
 ufs_start(mp, flags)
        struct mount *mp;
        int flags;
 ufs_start(mp, flags)
        struct mount *mp;
        int flags;
@@ -326,26 +332,23 @@ ufs_unmount(mp, flags)
 {
        register struct ufsmount *ump;
        register struct fs *fs;
 {
        register struct ufsmount *ump;
        register struct fs *fs;
-       dev_t dev;
        int error, ronly;
 
        if (flags & MNT_FORCE)
                return (EINVAL);
        int error, ronly;
 
        if (flags & MNT_FORCE)
                return (EINVAL);
+       mntflushbuf(mp, 0);
+       if (mntinvalbuf(mp))
+               return (EBUSY);
        ump = VFSTOUFS(mp);
        ump = VFSTOUFS(mp);
-       dev = ump->um_dev;
-#ifdef QUOTA
-       if ((error = iflush(dev, mp->m_qinod)) && !forcibly)
-#else
-       if ((error = iflush(dev)) && !forcibly)
-#endif
+       if (error = vflush(mp, ITOV(ump->um_qinod), flags))
                return (error);
 #ifdef QUOTA
                return (error);
 #ifdef QUOTA
-       (void)closedq(ump);
+       (void) closedq(ump);
        /*
        /*
-        * Here we have to iflush again to get rid of the quota inode.
         * A drag, but it would be ugly to cheat, & this doesn't happen often.
         */
         * A drag, but it would be ugly to cheat, & this doesn't happen often.
         */
-       (void)iflush(dev, (struct inode *)NULL);
+       if (vflush(mp, (struct vnode *)NULL, MNT_NOFORCE))
+               panic("ufs_unmount: quota");
 #endif
        fs = ump->um_fs;
        ronly = !fs->fs_ronly;
 #endif
        fs = ump->um_fs;
        ronly = !fs->fs_ronly;
@@ -362,15 +365,19 @@ ufs_root(mp, vpp)
        struct mount *mp;
        struct vnode **vpp;
 {
        struct mount *mp;
        struct vnode **vpp;
 {
-       struct inode tip, *ip;
+       register struct inode *ip;
+       struct inode *nip;
+       struct vnode tvp;
        int error;
 
        int error;
 
-       tip.i_dev = VFSTOUFS(mp)->um_dev;
-       tip.i_vnode.v_mount = mp;
-       error = iget(&tip, (ino_t)ROOTINO, &ip);
+       tvp.v_mount = mp;
+       ip = VTOI(&tvp);
+       ip->i_vnode = &tvp;
+       ip->i_dev = VFSTOUFS(mp)->um_dev;
+       error = iget(ip, (ino_t)ROOTINO, &nip);
        if (error)
                return (error);
        if (error)
                return (error);
-       *vpp = ITOV(ip);
+       *vpp = ITOV(nip);
        return (0);
 }
 
        return (0);
 }
 
@@ -389,7 +396,6 @@ ufs_statfs(mp, sbp)
        if (fs->fs_magic != FS_MAGIC)
                panic("ufs_statfs");
        sbp->f_type = MOUNT_UFS;
        if (fs->fs_magic != FS_MAGIC)
                panic("ufs_statfs");
        sbp->f_type = MOUNT_UFS;
-       sbp->f_flags = mp->m_flag &~ (M_MLOCK|M_MWAIT);
        sbp->f_fsize = fs->fs_fsize;
        sbp->f_bsize = fs->fs_bsize;
        sbp->f_blocks = fs->fs_dsize;
        sbp->f_fsize = fs->fs_fsize;
        sbp->f_bsize = fs->fs_bsize;
        sbp->f_blocks = fs->fs_dsize;
@@ -399,7 +405,6 @@ ufs_statfs(mp, sbp)
                (fs->fs_dsize - sbp->f_bfree);
        sbp->f_files =  fs->fs_ncg * fs->fs_ipg - ROOTINO;
        sbp->f_ffree = fs->fs_cstotal.cs_nifree;
                (fs->fs_dsize - sbp->f_bfree);
        sbp->f_files =  fs->fs_ncg * fs->fs_ipg - ROOTINO;
        sbp->f_ffree = fs->fs_cstotal.cs_nifree;
-       sbp->f_fsid = mp->m_fsid;
        bcopy((caddr_t)fs->fs_fsmnt, (caddr_t)&sbp->f_mntonname[0], MNAMELEN);
        bcopy((caddr_t)ump->um_mntname, (caddr_t)&sbp->f_mntfromname[0],
                MNAMELEN);
        bcopy((caddr_t)fs->fs_fsmnt, (caddr_t)&sbp->f_mntonname[0], MNAMELEN);
        bcopy((caddr_t)ump->um_mntname, (caddr_t)&sbp->f_mntfromname[0],
                MNAMELEN);
@@ -417,10 +422,11 @@ ufs_sync(mp, waitfor)
        struct mount *mp;
        int waitfor;
 {
        struct mount *mp;
        int waitfor;
 {
+       register struct vnode *vp;
        register struct inode *ip;
        register struct ufsmount *ump = VFSTOUFS(mp);
        register struct fs *fs;
        register struct inode *ip;
        register struct ufsmount *ump = VFSTOUFS(mp);
        register struct fs *fs;
-       int error = 0;
+       int error, allerror = 0;
        static int updlock = 0;
 
        if (syncprt)
        static int updlock = 0;
 
        if (syncprt)
@@ -448,22 +454,23 @@ ufs_sync(mp, waitfor)
        /*
         * Write back each (modified) inode.
         */
        /*
         * Write back each (modified) inode.
         */
-       for (ip = inode; ip < inodeNINODE; ip++) {
-               if (ip->i_devvp != ump->um_devvp ||
-                   (ip->i_flag & ILOCKED) != 0 || ITOV(ip)->v_count == 0 ||
+       for (vp = mp->m_mounth; vp; vp = vp->v_mountf) {
+               ip = VTOI(vp);
+               if ((ip->i_flag & ILOCKED) != 0 || vp->v_count == 0 ||
                    (ip->i_flag & (IMOD|IACC|IUPD|ICHG)) == 0)
                        continue;
                    (ip->i_flag & (IMOD|IACC|IUPD|ICHG)) == 0)
                        continue;
-               ILOCK(ip);
-               VREF(ITOV(ip));
-               error = iupdat(ip, &time, &time, waitfor == MNT_WAIT);
-               iput(ip);
+               VREF(vp);
+               VOP_LOCK(vp);
+               if (error = VOP_FSYNC(vp, 0, NOCRED, MNT_NOWAIT))
+                       allerror = error;
+               vput(vp);
        }
        updlock = 0;
        /*
        }
        updlock = 0;
        /*
-        * Force stale buffer cache information to be flushed.
+        * Force stale file system control information to be flushed.
         */
         */
-       bflush(ump->um_devvp->v_mount);
-       return (error);
+       vflushbuf(ump->um_devvp, waitfor == MNT_WAIT ? B_SYNC : 0);
+       return (allerror);
 }
 
 /*
 }
 
 /*
@@ -568,7 +575,9 @@ ufs_fhtovp(mp, fhp, vpp)
 {
        register struct ufid *ufhp;
        register struct fs *fs;
 {
        register struct ufid *ufhp;
        register struct fs *fs;
-       struct inode tip, *ip;
+       register struct inode *ip;
+       struct inode *nip;
+       struct vnode tvp;
        int error;
 
        ufhp = (struct ufid *)fhp;
        int error;
 
        ufhp = (struct ufid *)fhp;
@@ -578,12 +587,15 @@ ufs_fhtovp(mp, fhp, vpp)
                *vpp = (struct vnode *)0;
                return (EINVAL);
        }
                *vpp = (struct vnode *)0;
                return (EINVAL);
        }
-       tip.i_dev = VFSTOUFS(mp)->um_dev;
-       tip.i_vnode.v_mount = mp;
-       if (error = iget(&tip, ufhp->ufid_ino, &ip)) {
+       tvp.v_mount = mp;
+       ip = VTOI(&tvp);
+       ip->i_vnode = &tvp;
+       ip->i_dev = VFSTOUFS(mp)->um_dev;
+       if (error = iget(ip, ufhp->ufid_ino, &nip)) {
                *vpp = (struct vnode *)0;
                return (error);
        }
                *vpp = (struct vnode *)0;
                return (error);
        }
+       ip = nip;
        if (ip->i_mode == 0) {
                iput(ip);
                *vpp = (struct vnode *)0;
        if (ip->i_mode == 0) {
                iput(ip);
                *vpp = (struct vnode *)0;
@@ -642,8 +654,10 @@ getmdev(devvpp, fname, ndp)
                vput(vp);
                return (ENOTBLK);
        }
                vput(vp);
                return (ENOTBLK);
        }
-       if (major(vp->v_rdev) >= nblkdev)
+       if (major(vp->v_rdev) >= nblkdev) {
+               vput(vp);
                return (ENXIO);
                return (ENXIO);
+       }
        iunlock(VTOI(vp));
        *devvpp = vp;
        return (0);
        iunlock(VTOI(vp));
        *devvpp = vp;
        return (0);