statfs.f_bsize => statfs.f_iosize; statfs.f_fsize => statfs.f_bsize (for SunOS)
[unix-history] / usr / src / sys / ufs / lfs / lfs_vfsops.c
index 67e04ab..7076647 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)lfs_vfsops.c        7.63 (Berkeley) %G%
+ *     @(#)lfs_vfsops.c        7.67 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -39,12 +39,12 @@ struct vfsops lfs_vfsops = {
        lfs_mount,
        ufs_start,
        lfs_unmount,
        lfs_mount,
        ufs_start,
        lfs_unmount,
-       ufs_root,
+       lfs_root,
        ufs_quotactl,
        lfs_statfs,
        lfs_sync,
        ufs_quotactl,
        lfs_statfs,
        lfs_sync,
-       ufs_fhtovp,
-       ufs_vptofh,
+       lfs_fhtovp,
+       lfs_vptofh,
        lfs_init,
 };
 
        lfs_init,
 };
 
@@ -226,7 +226,7 @@ lfs_mountfs(devvp, mp, p)
 
        /* Set up the I/O information */
        fs->lfs_iocount = 0;
 
        /* Set up the I/O information */
        fs->lfs_iocount = 0;
-       fs->lfs_seglist = NULL;
+       /* XXX NOTUSED: fs->lfs_seglist = NULL; */
 
        /* Set the file system readonly/modify bits. */
        fs = ump->um_lfs;
 
        /* Set the file system readonly/modify bits. */
        fs = ump->um_lfs;
@@ -246,25 +246,13 @@ lfs_mountfs(devvp, mp, p)
        for (i = 0; i < MAXQUOTAS; i++)
                ump->um_quotas[i] = NULLVP;
 
        for (i = 0; i < MAXQUOTAS; i++)
                ump->um_quotas[i] = NULLVP;
 
-       /* Initialize UFS glue. */
-       ump->um_blkatoff = lfs_blkatoff;
-       ump->um_write = lfs_write;
-       ump->um_iget = lfs_iget;
-       ump->um_ialloc = lfs_ialloc;
-       ump->um_ifree = lfs_ifree;
-       ump->um_itrunc = lfs_itrunc;
-       ump->um_iupdat = lfs_iupdat;
-       ump->um_bwrite = lfs_bwrite;
-       ump->um_bmap = lfs_bmap;
-
        /* Read the ifile disk inode and store it in a vnode. */
        /* Read the ifile disk inode and store it in a vnode. */
-       error = bread(devvp, fs->lfs_idaddr, fs->lfs_bsize, NOCRED, &bp);
-       if (error)
+       if (error = bread(devvp, fs->lfs_idaddr, fs->lfs_bsize, NOCRED, &bp))
                goto out;
                goto out;
-       error = lfs_vcreate(mp, LFS_IFILE_INUM, &vp);
-       if (error)
+       if (error = lfs_vcreate(mp, LFS_IFILE_INUM, &vp))
                goto out;
        ip = VTOI(vp);
                goto out;
        ip = VTOI(vp);
+       VREF(ip->i_devvp);
 
        /* The ifile inode is stored in the superblock. */
        fs->lfs_ivnode = vp;
 
        /* The ifile inode is stored in the superblock. */
        fs->lfs_ivnode = vp;
@@ -276,22 +264,6 @@ lfs_mountfs(devvp, mp, p)
        /* Initialize the associated vnode */
        vp->v_type = IFTOVT(ip->i_mode);
 
        /* Initialize the associated vnode */
        vp->v_type = IFTOVT(ip->i_mode);
 
-       /*
-        * Read in the segusage table.
-        * 
-        * Since we always explicitly write the segusage table at a checkpoint,
-        * we're assuming that it is continguous on disk.
-        */
-       seg_addr = ip->i_din.di_db[0];
-       size = fs->lfs_segtabsz << fs->lfs_bshift;
-       fs->lfs_segtab = malloc(size, M_SUPERBLK, M_WAITOK);
-       error = bread(devvp, seg_addr, size, NOCRED, &bp);
-       if (error) {
-               free(fs->lfs_segtab, M_SUPERBLK);
-               goto out;
-       }
-       bcopy((caddr_t)bp->b_un.b_addr, fs->lfs_segtab, size);
-       brelse(bp);
        devvp->v_specflags |= SI_MOUNTEDON;
        VREF(ip->i_devvp);
 
        devvp->v_specflags |= SI_MOUNTEDON;
        VREF(ip->i_devvp);
 
@@ -322,7 +294,9 @@ lfs_unmount(mp, mntflags, p)
        int i, error, ronly, flags = 0;
        int ndirty;                                             /* LFS */
 
        int i, error, ronly, flags = 0;
        int ndirty;                                             /* LFS */
 
-printf("lfs_unmount\n");
+#ifdef VERBOSE
+       printf("lfs_unmount\n");
+#endif
        if (mntflags & MNT_FORCE) {
                if (!doforce || mp == rootfs)
                        return (EINVAL);
        if (mntflags & MNT_FORCE) {
                if (!doforce || mp == rootfs)
                        return (EINVAL);
@@ -373,34 +347,18 @@ lfs_statfs(mp, sbp, p)
        register struct ufsmount *ump;
 
        ump = VFSTOUFS(mp);
        register struct ufsmount *ump;
 
        ump = VFSTOUFS(mp);
-#ifdef NOTLFS                                                  /* LFS */
-       fs = ump->um_fs;
-       if (fs->fs_magic != FS_MAGIC)
-               panic("ufs_statfs");
-       sbp->f_type = MOUNT_UFS;
-       sbp->f_fsize = fs->fs_fsize;
-       sbp->f_bsize = fs->fs_bsize;
-       sbp->f_blocks = fs->fs_dsize;
-       sbp->f_bfree = fs->fs_cstotal.cs_nbfree * fs->fs_frag +
-               fs->fs_cstotal.cs_nffree;
-       sbp->f_bavail = (fs->fs_dsize * (100 - fs->fs_minfree) / 100) -
-               (fs->fs_dsize - sbp->f_bfree);
-       sbp->f_files =  fs->fs_ncg * fs->fs_ipg - ROOTINO;
-       sbp->f_ffree = fs->fs_cstotal.cs_nifree;
-#else
        fs = ump->um_lfs;
        if (fs->lfs_magic != LFS_MAGIC)
                panic("lfs_statfs: magic");
        sbp->f_type = MOUNT_LFS;
        fs = ump->um_lfs;
        if (fs->lfs_magic != LFS_MAGIC)
                panic("lfs_statfs: magic");
        sbp->f_type = MOUNT_LFS;
-       sbp->f_fsize = fs->lfs_bsize;
        sbp->f_bsize = fs->lfs_bsize;
        sbp->f_bsize = fs->lfs_bsize;
+       sbp->f_iosize = fs->lfs_bsize;
        sbp->f_blocks = fs->lfs_dsize;
        sbp->f_bfree = fs->lfs_bfree;
        sbp->f_bavail = (fs->lfs_dsize * (100 - fs->lfs_minfree) / 100) -
                (fs->lfs_dsize - sbp->f_bfree);
        sbp->f_files = fs->lfs_nfiles;
        sbp->f_ffree = fs->lfs_bfree * INOPB(fs);
        sbp->f_blocks = fs->lfs_dsize;
        sbp->f_bfree = fs->lfs_bfree;
        sbp->f_bavail = (fs->lfs_dsize * (100 - fs->lfs_minfree) / 100) -
                (fs->lfs_dsize - sbp->f_bfree);
        sbp->f_files = fs->lfs_nfiles;
        sbp->f_ffree = fs->lfs_bfree * INOPB(fs);
-#endif
        if (sbp != &mp->mnt_stat) {
                bcopy((caddr_t)mp->mnt_stat.f_mntonname,
                        (caddr_t)&sbp->f_mntonname[0], MNAMELEN);
        if (sbp != &mp->mnt_stat) {
                bcopy((caddr_t)mp->mnt_stat.f_mntonname,
                        (caddr_t)&sbp->f_mntonname[0], MNAMELEN);
@@ -421,12 +379,18 @@ lfs_sync(mp, waitfor)
        struct mount *mp;
        int waitfor;
 {
        struct mount *mp;
        int waitfor;
 {
-       extern int syncprt;
+       extern int crashandburn, syncprt;
        static int sync_lock, sync_want;
        int error;
 
        static int sync_lock, sync_want;
        int error;
 
-printf("lfs_sync\n");
+#ifdef VERBOSE
+       printf("lfs_sync\n");
+#endif
 
 
+#ifdef DIAGNOSTIC
+       if (crashandburn)
+               return (0);
+#endif
        /*
         * Meta data blocks are only marked dirty, not busy, so LFS syncs
         * must be single threaded.
        /*
         * Meta data blocks are only marked dirty, not busy, so LFS syncs
         * must be single threaded.
@@ -453,3 +417,69 @@ printf("lfs_sync\n");
        }
        return (error);
 }
        }
        return (error);
 }
+
+/*
+ * File handle to vnode
+ *
+ * Have to be really careful about stale file handles:
+ * - check that the inode number is valid
+ * - call lfs_vget() to get the locked inode
+ * - check for an unallocated inode (i_mode == 0)
+ * - check that the generation number matches
+ *
+ * XXX
+ * use ifile to see if inode is allocated instead of reading off disk
+ * what is the relationship between my generational number and the NFS
+ * generational number.
+ */
+int
+lfs_fhtovp(mp, fhp, vpp)
+       register struct mount *mp;
+       struct fid *fhp;
+       struct vnode **vpp;
+{
+       register struct inode *ip;
+       register struct ufid *ufhp;
+       struct vnode *nvp;
+       int error;
+
+       ufhp = (struct ufid *)fhp;
+       if (ufhp->ufid_ino < ROOTINO)
+               return (EINVAL);
+       if (error = lfs_vget(mp, ufhp->ufid_ino, &nvp)) {
+               *vpp = NULLVP;
+               return (error);
+       }
+       ip = VTOI(nvp);
+       if (ip->i_mode == 0) {
+               ufs_iput(ip);
+               *vpp = NULLVP;
+               return (EINVAL);
+       }
+       if (ip->i_gen != ufhp->ufid_gen) {
+               ufs_iput(ip);
+               *vpp = NULLVP;
+               return (EINVAL);
+       }
+       *vpp = nvp;
+       return (0);
+}
+
+/*
+ * Vnode pointer to File handle
+ */
+/* ARGSUSED */
+lfs_vptofh(vp, fhp)
+       struct vnode *vp;
+       struct fid *fhp;
+{
+       register struct inode *ip;
+       register struct ufid *ufhp;
+
+       ip = VTOI(vp);
+       ufhp = (struct ufid *)fhp;
+       ufhp->ufid_len = sizeof(struct ufid);
+       ufhp->ufid_ino = ip->i_number;
+       ufhp->ufid_gen = ip->i_gen;
+       return (0);
+}