# 2.11BSD#431 - /usr/src/sys/sys/ufs_subr.c

##### Functions

    badblock          X
    getfs             X
    getfsx            X
    sync              X
    syncip            X

       1: /*
       2:  * Copyright (c) 1986 Regents of the University of California.
       3:  * All rights reserved.  The Berkeley software License Agreement
       4:  * specifies the terms and conditions for redistribution.
       5:  *
       6:  *	@(#)ufs_subr.c	1.5 (2.11BSD GTE) 1996/9/13
       7:  */
       8:
       9: #include "param.h"
      10: #include "../machine/seg.h"
      11:
      12: #include "user.h"
      13: #include "proc.h"
      14: #include "fs.h"
      15: #include "inode.h"
      16: #include "buf.h"
      17: #include "mount.h"
      18: #include "kernel.h"
      19: #include "systm.h"
      20:
      21: /*
      22:  * Go through the mount table looking for filesystems which have been modified.
      23:  * For each "dirty" filesystem call 'ufs_sync' to flush changed inodes, data
      24:  * blocks and the superblock to disc.
      25:  */
      26: sync()
      27: {
      28:     register struct mount *mp;
      29:     register struct fs *fs;
      30:     int async;
      31:
      32:     if  (updlock)
      33:         return;
      34:     updlock++;
      35:     for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++)
      36:         {
      37:         if  (mp->m_inodp == NULL || mp->m_dev == NODEV)
      38:             continue;
      39:         fs = &mp->m_filsys;
      40:         if  (fs->fs_fmod == 0 || fs->fs_ilock || fs->fs_flock)
      41:             continue;
      42:         async = mp->m_flags & MNT_ASYNC;
      43:         mp->m_flags &= ~MNT_ASYNC;
      44:         ufs_sync(mp);
      45:         mp->m_flags |= async;
      46:         }
      47:     updlock = 0;
      48:     }
      49:
      50: /*
      51:  * Flush all the blocks associated with an inode.
      52:  * There are two strategies based on the size of the file;
      53:  * large files are those with more than (nbuf / 2) blocks.
      54:  * Large files
      55:  * 	Walk through the buffer pool and push any dirty pages
      56:  *	associated with the device on which the file resides.
      57:  * Small files
      58:  *	Look up each block in the file to see if it is in the
      59:  *	buffer pool writing any that are found to disk.
      60:  *	Note that we make a more stringent check of
      61:  *	writing out any block in the buffer pool that may
      62:  *	overlap the inode. This brings the inode up to
      63:  *	date with recent mods to the cooked device.
      64:  */
      65: syncip(ip)
      66:     struct inode *ip;
      67: {
      68:     register struct buf *bp;
      69:     register struct buf *lastbufp;
      70:     long lbn, lastlbn;
      71:     register int s;
      72:     daddr_t blkno;
      73:
      74:     lastlbn = howmany(ip->i_size, DEV_BSIZE);
      75:     if (lastlbn < nbuf / 2) {
      76:         for (lbn = 0; lbn < lastlbn; lbn++) {
      77:             blkno = fsbtodb(bmap(ip, lbn, B_READ, 0));
      78:             blkflush(ip->i_dev, blkno);
      79:         }
      80:     } else {
      81:         lastbufp = &buf[nbuf];
      82:         for (bp = buf; bp < lastbufp; bp++) {
      83:             if (bp->b_dev != ip->i_dev ||
      84:                 (bp->b_flags & B_DELWRI) == 0)
      85:                 continue;
      86:             s = splbio();
      87:             if (bp->b_flags & B_BUSY) {
      88:                 bp->b_flags |= B_WANTED;
      89:                 sleep((caddr_t)bp, PRIBIO+1);
      90:                 splx(s);
      91:                 bp--;
      92:                 continue;
      93:             }
      94:             splx(s);
      95:             notavail(bp);
      96:             bwrite(bp);
      97:         }
      98:     }
      99:     ip->i_flag |= ICHG;
     100:     iupdat(ip, &time, &time, 1);
     101: }
     102:
     103: /*
     104:  * Check that a specified block number is in range.
     105:  */
     106: badblock(fp, bn)
     107:     register struct fs *fp;
     108:     daddr_t bn;
     109: {
     110:
     111:     if (bn < fp->fs_isize || bn >= fp->fs_fsize) {
     112:         printf("bad block %D, ",bn);
     113:         fserr(fp, "bad block");
     114:         return (1);
     115:     }
     116:     return (0);
     117: }
     118:
     119: /*
     120:  * Getfs maps a device number into a pointer to the incore super block.
     121:  *
     122:  * The algorithm is a linear search through the mount table. A
     123:  * consistency check of the super block magic number is performed.
     124:  *
     125:  * panic: no fs -- the device is not mounted.
     126:  *	this "cannot happen"
     127:  */
     128: struct fs *
     129: getfs(dev)
     130:     dev_t dev;
     131: {
     132:     register struct mount *mp;
     133:     register struct fs *fs;
     134:
     135:     for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) {
     136:         if (mp->m_inodp == NULL || mp->m_dev != dev)
     137:             continue;
     138:         fs = &mp->m_filsys;
     139:         if (fs->fs_nfree > NICFREE || fs->fs_ninode > NICINOD) {
     140:             fserr(fs, "bad count");
     141:             fs->fs_nfree = fs->fs_ninode = 0;
     142:         }
     143:         return(fs);
     144:     }
     145:     printf("no fs on dev %u/%u\n",major(dev), minor(dev));
     146:     return((struct fs *) NULL);
     147: }
     148:
     149: #ifdef QUOTA
     150: /*
     151:  * Getfsx returns the index in the file system
     152:  * table of the specified device.  The swap device
     153:  * is also assigned a pseudo-index.  The index may
     154:  * be used as a compressed indication of the location
     155:  * of a block, recording
     156:  *	<getfsx(dev),blkno>
     157:  * rather than
     158:  *	<dev, blkno>
     159:  * provided the information need remain valid only
     160:  * as long as the file system is mounted.
     161:  */
     162: getfsx(dev)
     163:     dev_t dev;
     164: {
     165:     register struct mount *mp;
     166:
     167:     if (dev == swapdev)
     168:         return (0377);
     169:     for(mp = &mount[0]; mp < &mount[NMOUNT]; mp++)
     170:         if (mp->m_dev == dev)
     171:             return (mp - &mount[0]);
     172:     return (-1);
     173: }
     174: #endif

#### Defined functions

badblock defined in line 106; used 2 times

- in /usr/src/sys/sys/ufs_alloc.c line 58, 250

getfs defined in line 128; used 7 times

- in /usr/src/sys/h/fs.h line 132
- in /usr/src/sys/pdp/machdep2.c line 388
- in /usr/src/sys/sys/quota_subr.c line 88, 107
- in /usr/src/sys/sys/quota_ufs.c line 226, 236, 244

getfsx defined in line 162; used 4 times

- in /usr/src/sys/sys/quota_subr.c line 35
- in /usr/src/sys/sys/quota_sys.c line 171
- in /usr/src/sys/sys/quota_ufs.c line 68, 191

sync defined in line 26; used 3 times

- in /usr/src/sys/pdp/machdep2.c line 398
- in /usr/src/sys/sys/init_sysent.c line 51, 146

syncip defined in line 65; used 1 times

- in /usr/src/sys/sys/ufs_syscalls2.c line 257

Last modified: 1996-09-17 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 851 |