+#include "../h/trace.h"
+
+/*
+ * The following several routines allocate and free
+ * buffers with various side effects. In general the
+ * arguments to an allocate routine are a device and
+ * a block number, and the value is a pointer to
+ * to the buffer header; the buffer is marked "busy"
+ * so that no one else can touch it. If the block was
+ * already in core, no I/O need be done; if it is
+ * already busy, the process waits until it becomes free.
+ * The following routines allocate a buffer:
+ * getblk
+ * bread
+ * breada
+ * baddr (if it is incore)
+ * Eventually the buffer must be released, possibly with the
+ * side effect of writing it out, by using one of
+ * bwrite
+ * bdwrite
+ * bawrite
+ * brelse
+ */
+
+struct buf bfreelist[BQUEUES];
+struct buf bswlist, *bclnlist;
+
+#define BUFHSZ 63
+struct bufhd bufhash[BUFHSZ];
+#define BUFHASH(dev, dblkno) \
+ ((struct buf *)&bufhash[((int)(dev)+(int)(dblkno)) % BUFHSZ])
+
+/*
+ * Initialize hash links for buffers.
+ */
+bhinit()
+{
+ register int i;
+ register struct bufhd *bp;
+
+ for (bp = bufhash, i = 0; i < BUFHSZ; i++, bp++)
+ bp->b_forw = bp->b_back = (struct buf *)bp;
+}