Annotation of 42BSD/sys/vax/ufs_machdep.c, revision 1.1.1.1

1.1       root        1: /*     ufs_machdep.c   6.1     83/07/29        */
                      2: 
                      3: #include "../machine/pte.h"
                      4: 
                      5: #include "../h/param.h"
                      6: #include "../h/systm.h"
                      7: #include "../h/dir.h"
                      8: #include "../h/user.h"
                      9: #include "../h/buf.h"
                     10: #include "../h/conf.h"
                     11: #include "../h/proc.h"
                     12: #include "../h/seg.h"
                     13: #include "../h/vm.h"
                     14: 
                     15: /*
                     16:  * Machine dependent handling of the buffer cache.
                     17:  */
                     18: 
                     19: /*
                     20:  * Expand or contract the actual memory allocated to a buffer.
                     21:  * If no memory is available, release buffer and take error exit
                     22:  */
                     23: allocbuf(tp, size)
                     24:        register struct buf *tp;
                     25:        int size;
                     26: {
                     27:        register struct buf *bp, *ep;
                     28:        int sizealloc, take;
                     29: 
                     30:        sizealloc = roundup(size, CLBYTES);
                     31:        /*
                     32:         * Buffer size does not change
                     33:         */
                     34:        if (sizealloc == tp->b_bufsize)
                     35:                goto out;
                     36:        /*
                     37:         * Buffer size is shrinking.
                     38:         * Place excess space in a buffer header taken from the
                     39:         * BQ_EMPTY buffer list and placed on the "most free" list.
                     40:         * If no extra buffer headers are available, leave the
                     41:         * extra space in the present buffer.
                     42:         */
                     43:        if (sizealloc < tp->b_bufsize) {
                     44:                ep = bfreelist[BQ_EMPTY].av_forw;
                     45:                if (ep == &bfreelist[BQ_EMPTY])
                     46:                        goto out;
                     47:                notavail(ep);
                     48:                pagemove(tp->b_un.b_addr + sizealloc, ep->b_un.b_addr,
                     49:                    (int)tp->b_bufsize - sizealloc);
                     50:                ep->b_bufsize = tp->b_bufsize - sizealloc;
                     51:                tp->b_bufsize = sizealloc;
                     52:                ep->b_flags |= B_INVAL;
                     53:                ep->b_bcount = 0;
                     54:                brelse(ep);
                     55:                goto out;
                     56:        }
                     57:        /*
                     58:         * More buffer space is needed. Get it out of buffers on
                     59:         * the "most free" list, placing the empty headers on the
                     60:         * BQ_EMPTY buffer header list.
                     61:         */
                     62:        while (tp->b_bufsize < sizealloc) {
                     63:                take = sizealloc - tp->b_bufsize;
                     64:                bp = getnewbuf();
                     65:                if (take >= bp->b_bufsize)
                     66:                        take = bp->b_bufsize;
                     67:                pagemove(&bp->b_un.b_addr[bp->b_bufsize - take],
                     68:                    &tp->b_un.b_addr[tp->b_bufsize], take);
                     69:                tp->b_bufsize += take;
                     70:                bp->b_bufsize = bp->b_bufsize - take;
                     71:                if (bp->b_bcount > bp->b_bufsize)
                     72:                        bp->b_bcount = bp->b_bufsize;
                     73:                if (bp->b_bufsize <= 0) {
                     74:                        bremhash(bp);
                     75:                        binshash(bp, &bfreelist[BQ_EMPTY]);
                     76:                        bp->b_dev = (dev_t)NODEV;
                     77:                        bp->b_error = 0;
                     78:                        bp->b_flags |= B_INVAL;
                     79:                }
                     80:                brelse(bp);
                     81:        }
                     82: out:
                     83:        tp->b_bcount = size;
                     84:        return (1);
                     85: }
                     86: 
                     87: /*
                     88:  * Release space associated with a buffer.
                     89:  */
                     90: bfree(bp)
                     91:        struct buf *bp;
                     92: {
                     93: 
                     94:        bp->b_bcount = 0;
                     95: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.