- printf("%s: %s\n", fs->fs_fsmnt, cp);
-}
-
-/*
- * Getfsx returns the index in the file system
- * table of the specified device. The swap device
- * is also assigned a pseudo-index. The index may
- * be used as a compressed indication of the location
- * of a block, recording
- * <getfsx(dev),blkno>
- * rather than
- * <dev, blkno>
- * provided the information need remain valid only
- * as long as the file system is mounted.
- */
-getfsx(dev)
- dev_t dev;
-{
- register struct mount *mp;
-
- if (dev == swapdev)
- return (MSWAPX);
- for(mp = &mount[0]; mp < &mount[NMOUNT]; mp++)
- if (mp->m_dev == dev)
- return (mp - &mount[0]);
- return (-1);
-}
-
-/*
- * Update is the internal name of 'sync'. It goes through the disk
- * queues to initiate sandbagged IO; goes through the inodes to write
- * modified nodes; and it goes through the mount table to initiate
- * the writing of the modified super blocks.
- */
-update(flag)
- int flag;
-{
- register struct inode *ip;
- register struct mount *mp;
- register struct buf *bp;
- struct fs *fs;
- int i, blks;
-
- if (updlock)
- return;
- updlock++;
- /*
- * Write back modified superblocks.
- * Consistency check that the superblock
- * of each file system is still in the buffer cache.
- */
- for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) {
- if (mp->m_bufp == NULL)
- continue;
- fs = mp->m_bufp->b_un.b_fs;
- if (fs->fs_fmod == 0)
- continue;
- if (fs->fs_ronly != 0)
- panic("update: rofs mod");
- bp = getblk(mp->m_dev, SBLOCK, SBSIZE);
- fs->fs_fmod = 0;
- fs->fs_time = time;
- if (bp->b_un.b_fs != fs)
- panic("update: bad b_fs");
- bwrite(bp);
- blks = howmany(fs->fs_cssize, fs->fs_bsize);
- for (i = 0; i < blks; i++) {
- bp = getblk(mp->m_dev,
- fsbtodb(fs, fs->fs_csaddr + (i * fs->fs_frag)),
- fs->fs_bsize);
- bwrite(bp);
- }
- }
- /*
- * Write back each (modified) inode.
- */
- for (ip = inode; ip < inodeNINODE; ip++) {
- if ((ip->i_flag & ILOCK) != 0 || ip->i_count == 0)
- continue;
- ip->i_flag |= ILOCK;
- ip->i_count++;
- iupdat(ip, &time, &time, 0);
- iput(ip);
- }
- updlock = 0;
- /*
- * Force stale buffer cache information to be flushed,
- * for all devices.
- */
- bflush(NODEV);
-}
-
-/*
- * block operations
- *
- * check if a block is available
- */
-isblock(fs, cp, h)
- struct fs *fs;
- unsigned char *cp;
- int h;
-{
- unsigned char mask;
-
- switch (fs->fs_frag) {
- case 8:
- return (cp[h] == 0xff);
- case 4:
- mask = 0x0f << ((h & 0x1) << 2);
- return ((cp[h >> 1] & mask) == mask);
- case 2:
- mask = 0x03 << ((h & 0x3) << 1);
- return ((cp[h >> 2] & mask) == mask);
- case 1:
- mask = 0x01 << (h & 0x7);
- return ((cp[h >> 3] & mask) == mask);
- default:
- panic("isblock");
- return (NULL);
- }
-}
-
-/*
- * take a block out of the map
- */
-clrblock(fs, cp, h)
- struct fs *fs;
- unsigned char *cp;
- int h;
-{
- switch ((fs)->fs_frag) {
- case 8:
- cp[h] = 0;
- return;
- case 4:
- cp[h >> 1] &= ~(0x0f << ((h & 0x1) << 2));
- return;
- case 2:
- cp[h >> 2] &= ~(0x03 << ((h & 0x3) << 1));
- return;
- case 1:
- cp[h >> 3] &= ~(0x01 << (h & 0x7));
- return;
- default:
- panic("clrblock");
- return;
- }
-}
-
-/*
- * put a block into the map
- */
-setblock(fs, cp, h)
- struct fs *fs;
- unsigned char *cp;
- int h;
-{
- switch (fs->fs_frag) {
- case 8:
- cp[h] = 0xff;
- return;
- case 4:
- cp[h >> 1] |= (0x0f << ((h & 0x1) << 2));
- return;
- case 2:
- cp[h >> 2] |= (0x03 << ((h & 0x3) << 1));
- return;
- case 1:
- cp[h >> 3] |= (0x01 << (h & 0x7));
- return;
- default:
- panic("setblock");
- return;
- }