+ register struct ufsmount *ump;
+ register struct fs *fs;
+
+ ump = VFSTOUFS(mp);
+ fs = ump->um_fs;
+ 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_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);
+ if (sbp->f_bavail < 0)
+ sbp->f_bavail = 0;
+ sbp->f_files = fs->fs_ncg * fs->fs_ipg;
+ 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);
+ return (0);
+}
+
+int syncprt = 0;
+
+/*
+ * Go through the disk queues to initiate sandbagged IO;
+ * go through the inodes to write those that have been modified;
+ * initiate the writing of the super block if it has been modified.
+ */
+ufs_sync(mp, waitfor)
+ struct mount *mp;
+ int waitfor;
+{
+ register struct inode *ip;
+ register struct ufsmount *ump = VFSTOUFS(mp);
+ register struct fs *fs;
+ int error = 0;
+ static int updlock = 0;
+
+ if (syncprt)
+ bufstats();
+ if (updlock)
+ return (EBUSY);
+ fs = ump->um_fs;
+ if (fs == (struct fs *)1)
+ return (0);
+ updlock++;
+ /*
+ * Write back modified superblock.
+ * Consistency check that the superblock
+ * is still in the buffer cache.
+ */
+ if (fs->fs_fmod != 0) {
+ if (fs->fs_ronly != 0) { /* XXX */
+ printf("fs = %s\n", fs->fs_fsmnt);
+ panic("update: rofs mod");
+ }
+ fs->fs_fmod = 0;
+ fs->fs_time = time.tv_sec;
+ error = sbupdate(ump, waitfor);
+ }
+ /*
+ * 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 ||
+ (ip->i_flag & (IMOD|IACC|IUPD|ICHG)) == 0)
+ continue;
+ ILOCK(ip);
+ VREF(ITOV(ip));
+ error = iupdat(ip, &time, &time, waitfor == MNT_WAIT);
+ iput(ip);
+ }
+ updlock = 0;
+ /*
+ * Force stale buffer cache information to be flushed.
+ */
+ bflush(ump->um_devvp->v_rdev);
+ return (error);
+}
+
+/*
+ * Write a superblock and associated information back to disk.
+ */
+sbupdate(mp, waitfor)
+ struct ufsmount *mp;
+ int waitfor;
+{
+ register struct fs *fs = mp->um_fs;