8 FORWARD
_PROTOTYPE( struct buf
*new_block
, (dev_t dev
, ino_t inum
) );
10 /*===========================================================================*
12 *===========================================================================*/
13 PUBLIC
void buf_pool(void)
15 /* Initialize the buffer pool. */
23 /*===========================================================================*
25 *===========================================================================*/
26 PUBLIC
struct buf
*get_block(dev_t dev
, ino_t inum
)
28 struct buf
*bp
= front
;
31 if (bp
->b_dev
== dev
&& bp
->b_num
== inum
) {
38 /* Buffer was not found. Try to allocate a new one */
39 return new_block(dev
, inum
);
43 /*===========================================================================*
45 *===========================================================================*/
46 PRIVATE
struct buf
*new_block(dev_t dev
, ino_t inum
)
48 /* Allocate a new buffer and add it to the double linked buffer list */
51 bp
= malloc(sizeof(struct buf
));
60 memset(bp
->b_data
, 0 , PIPE_BUF
);
62 /* Add at the end of the buffer */
63 if (front
== NULL
) { /* Empty list? */
77 /*===========================================================================*
79 *===========================================================================*/
80 PUBLIC
void put_block(dev_t dev
, ino_t inum
)
84 bp
= get_block(dev
, inum
);
85 if (bp
== NULL
) return; /* We didn't find the block. Nothing to put. */
87 bp
->b_count
--; /* Compensate for above 'get_block'. */
88 if (--bp
->b_count
> 0) return;
90 /* Cut bp out of the loop */
91 if (bp
->b_prev
== NULL
)
94 bp
->b_prev
->b_next
= bp
->b_next
;
96 if (bp
->b_next
== NULL
)
99 bp
->b_next
->b_prev
= bp
->b_prev
;
101 /* Buffer administration is done. Now it's safe to free up bp. */