10 /*===========================================================================*
12 *===========================================================================*/
13 PUBLIC
void buf_pool(void)
15 /* Initialize the buffer pool. */
23 /*===========================================================================*
25 *===========================================================================*/
26 PUBLIC
struct buf
*get_block(dev
, inum
)
33 while(bp
!= NIL_BUF
) {
34 if (bp
->b_dev
== dev
&& bp
->b_num
== inum
) {
41 /* Buffer was not found. Try to allocate a new one */
42 return new_block(dev
, inum
);
46 /*===========================================================================*
48 *===========================================================================*/
49 PUBLIC
struct buf
*new_block(dev
, inum
)
53 /* Allocate a new buffer and add it to the double linked buffer list */
56 bp
= malloc(sizeof(struct buf
));
65 memset(bp
->b_data
, 0 , PIPE_BUF
);
67 /* Add at the end of the buffer */
68 if (front
== NIL_BUF
) { /* Empty list? */
82 /*===========================================================================*
84 *===========================================================================*/
85 PUBLIC
void put_block(dev
, inum
)
91 bp
= get_block(dev
, inum
);
92 if (bp
== NIL_BUF
) return; /* We didn't find the block. Nothing to put. */
94 bp
->b_count
--; /* Compensate for above 'get_block'. */
95 if (--bp
->b_count
> 0) return;
97 /* Cut bp out of the loop */
98 if (bp
->b_prev
== NIL_BUF
)
101 bp
->b_prev
->b_next
= bp
->b_next
;
103 if (bp
->b_next
== NIL_BUF
)
106 bp
->b_next
->b_prev
= bp
->b_prev
;
108 /* Buffer administration is done. Now it's safe to free up bp. */