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

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

unix.superglobalmegacorp.com

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