BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / sys / buf.h
index f69bf5f..5661986 100644 (file)
@@ -1,9 +1,41 @@
-/*     buf.h   4.20    83/01/16        */
+/*
+ * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)buf.h       7.11 (Berkeley) 5/9/90
+ */
 
 /*
  * The header for buffers in the buffer pool and otherwise used
 
 /*
  * The header for buffers in the buffer pool and otherwise used
- * to describe a block i/o request is given here.  The routines
- * which manipulate these things are given in bio.c.
+ * to describe a block i/o request is given here.
  *
  * Each buffer in the pool is usually doubly linked into 2 lists:
  * hashed into a chain by <dev,blkno> so it can be located in the cache,
  *
  * Each buffer in the pool is usually doubly linked into 2 lists:
  * hashed into a chain by <dev,blkno> so it can be located in the cache,
@@ -36,6 +68,7 @@ struct buf
        long    b_flags;                /* too much goes here to describe */
        struct  buf *b_forw, *b_back;   /* hash chain (2 way street) */
        struct  buf *av_forw, *av_back; /* position on free list if not BUSY */
        long    b_flags;                /* too much goes here to describe */
        struct  buf *b_forw, *b_back;   /* hash chain (2 way street) */
        struct  buf *av_forw, *av_back; /* position on free list if not BUSY */
+       struct  buf *b_blockf, **b_blockb;/* associated vnode */
 #define        b_actf  av_forw                 /* alternate names for driver queue */
 #define        b_actl  av_back                 /*    head - isn't history wonderful */
        long    b_bcount;               /* transfer count */
 #define        b_actf  av_forw                 /* alternate names for driver queue */
 #define        b_actl  av_back                 /*    head - isn't history wonderful */
        long    b_bcount;               /* transfer count */
@@ -52,12 +85,19 @@ struct buf
            struct dinode *b_dino;      /* ilist */
            daddr_t *b_daddr;           /* indirect block */
        } b_un;
            struct dinode *b_dino;      /* ilist */
            daddr_t *b_daddr;           /* indirect block */
        } b_un;
+       daddr_t b_lblkno;               /* logical block number */
        daddr_t b_blkno;                /* block # on device */
        long    b_resid;                /* words not transferred after error */
 #define        b_errcnt b_resid                /* while i/o in progress: # retries */
        daddr_t b_blkno;                /* block # on device */
        long    b_resid;                /* words not transferred after error */
 #define        b_errcnt b_resid                /* while i/o in progress: # retries */
-#define        b_pfcent b_resid                /* garbage: don't ask */
        struct  proc *b_proc;           /* proc doing physical or swap I/O */
        int     (*b_iodone)();          /* function called by iodone */
        struct  proc *b_proc;           /* proc doing physical or swap I/O */
        int     (*b_iodone)();          /* function called by iodone */
+       struct  vnode *b_vp;            /* vnode for dev */
+       int     b_pfcent;               /* center page when swapping cluster */
+       struct  ucred *b_rcred;         /* ref to read credentials */
+       struct  ucred *b_wcred;         /* ref to write credendtials */
+       int     b_dirtyoff;             /* offset in buffer of dirty region */
+       int     b_dirtyend;             /* offset of end of dirty region */
+       caddr_t b_saveaddr;             /* original b_addr for PHYSIO */
 };
 
 #define        BQUEUES         4               /* number of free buffer queues */
 };
 
 #define        BQUEUES         4               /* number of free buffer queues */
@@ -68,10 +108,15 @@ struct buf
 #define        BQ_EMPTY        3               /* buffer headers with no memory */
 
 #ifdef KERNEL
 #define        BQ_EMPTY        3               /* buffer headers with no memory */
 
 #ifdef KERNEL
-#define        BUFHSZ  63
+#define        BUFHSZ  512
 #define RND    (MAXBSIZE/DEV_BSIZE)
 #define RND    (MAXBSIZE/DEV_BSIZE)
-#define        BUFHASH(dev, dblkno)    \
-       ((struct buf *)&bufhash[((int)(dev)+(((int)(dblkno))/RND)) % BUFHSZ])
+#if    ((BUFHSZ&(BUFHSZ-1)) == 0)
+#define        BUFHASH(dvp, dblkno)    \
+       ((struct buf *)&bufhash[((int)(dvp)+(((int)(dblkno))/RND))&(BUFHSZ-1)])
+#else
+#define        BUFHASH(dvp, dblkno)    \
+       ((struct buf *)&bufhash[((int)(dvp)+(((int)(dblkno))/RND)) % BUFHSZ])
+#endif
 
 struct buf *buf;               /* the buffer pool itself */
 char   *buffers;
 
 struct buf *buf;               /* the buffer pool itself */
 char   *buffers;
@@ -79,21 +124,14 @@ int        nbuf;                   /* number of buffer headers */
 int    bufpages;               /* number of memory pages in the buffer pool */
 struct buf *swbuf;             /* swap I/O headers */
 int    nswbuf;
 int    bufpages;               /* number of memory pages in the buffer pool */
 struct buf *swbuf;             /* swap I/O headers */
 int    nswbuf;
-short  *swsize;
-int    *swpf;
 struct bufhd bufhash[BUFHSZ];  /* heads of hash lists */
 struct buf bfreelist[BQUEUES]; /* heads of available lists */
 struct buf bswlist;            /* head of free swap header list */
 struct buf *bclnlist;          /* head of cleaned page list */
 
 struct bufhd bufhash[BUFHSZ];  /* heads of hash lists */
 struct buf bfreelist[BQUEUES]; /* heads of available lists */
 struct buf bswlist;            /* head of free swap header list */
 struct buf *bclnlist;          /* head of cleaned page list */
 
-struct buf *alloc();
-struct buf *realloccg();
-struct buf *baddr();
 struct buf *getblk();
 struct buf *geteblk();
 struct buf *getnewbuf();
 struct buf *getblk();
 struct buf *geteblk();
 struct buf *getnewbuf();
-struct buf *bread();
-struct buf *breada();
 
 unsigned minphys();
 #endif
 
 unsigned minphys();
 #endif
@@ -123,6 +161,8 @@ unsigned minphys();
 #define        B_HEAD          0x040000        /* a buffer header, not a buffer */
 #define        B_BAD           0x100000        /* bad block revectoring in progress */
 #define        B_CALL          0x200000        /* call b_iodone from iodone */
 #define        B_HEAD          0x040000        /* a buffer header, not a buffer */
 #define        B_BAD           0x100000        /* bad block revectoring in progress */
 #define        B_CALL          0x200000        /* call b_iodone from iodone */
+#define        B_RAW           0x400000        /* set by physio for raw transfers */
+#define        B_NOCACHE       0x800000        /* do not cache block after use */
 
 /*
  * Insq/Remq for the buffer hash lists.
 
 /*
  * Insq/Remq for the buffer hash lists.
@@ -158,17 +198,6 @@ unsigned minphys();
        (bp)->av_forw = (dp); \
 }
 
        (bp)->av_forw = (dp); \
 }
 
-/*
- * Take a buffer off the free list it's on and
- * mark it as being use (B_BUSY) by a device.
- */
-#define        notavail(bp) { \
-       int x = spl6(); \
-       bremfree(bp); \
-       (bp)->b_flags |= B_BUSY; \
-       splx(x); \
-}
-
 #define        iodone  biodone
 #define        iowait  biowait
 
 #define        iodone  biodone
 #define        iowait  biowait
 
@@ -176,25 +205,8 @@ unsigned minphys();
  * Zero out a buffer's data portion.
  */
 #define        clrbuf(bp) { \
  * Zero out a buffer's data portion.
  */
 #define        clrbuf(bp) { \
-       blkclr(bp->b_un.b_addr, bp->b_bcount); \
-       bp->b_resid = 0; \
+       blkclr((bp)->b_un.b_addr, (unsigned)(bp)->b_bcount); \
+       (bp)->b_resid = 0; \
 }
 }
-
-#ifdef sun
-/*
- * Declarations for buffer space rmaps
- */
-struct map *buffermap;
-#define BUFMAPSIZE     256
-
-/*
- * "Average" size of a buffer
- * nbuf*AVGBSIZE is total amount of buffer data
- */
-#define        AVGBSIZE        2048
-
-/*
- * Unit of buffer space allocation
- */
-#define        BUFALLOCSIZE    1024
-#endif
+#define B_CLRBUF       0x1     /* request allocated buffer be cleared */
+#define B_SYNC         0x2     /* do all allocations synchronously */