Skip to content

Instantly share code, notes, and snippets.

@Se7soz
Created December 30, 2011 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Se7soz/1541091 to your computer and use it in GitHub Desktop.
Save Se7soz/1541091 to your computer and use it in GitHub Desktop.
servers/apfs/buffer.c: fixed put_block call to find_block instead of get_block that creates the block if it doesn't exist.
commit 4d7f4a5e3b9561f37ee5f61727e7b48c3065c446
Author: Hussein El-Sayed <hussein.009@gmail.com>
Date: Fri Dec 30 23:28:15 2011 +0000
servers/apfs/buffer.c: fixed put_block call to find_block instead of get_blo
that creates the block if it doesn't exist.
diff --git a/servers/apfs/buffer.c b/servers/apfs/buffer.c
index a5c77b4..de18e8c 100644
--- a/servers/apfs/buffer.c
+++ b/servers/apfs/buffer.c
@@ -18,22 +18,32 @@ PUBLIC void buf_pool(void)
rear = NULL;
}
-
-
/*===========================================================================*
- * get_block *
+ * find_block *
*===========================================================================*/
-PUBLIC struct buf *get_block(dev_t dev, ino_t inum)
+PRIVATE struct buf *find_block(dev_t dev, ino_t inum)
{
struct buf *bp = front;
while(bp != NULL) {
- if (bp->b_dev == dev && bp->b_num == inum) {
+ if (bp->b_dev == dev && bp->b_num == inum) {
bp->b_count++;
return(bp);
}
bp = bp->b_next;
}
+ /* Buffer not found */
+ return (NULL);
+}
+
+/*===========================================================================*
+ * get_block *
+ *===========================================================================*/
+PUBLIC struct buf *get_block(dev_t dev, ino_t inum)
+{
+ struct buf *bp = find_block(dev, inum);
+
+ if(bp != NULL) return bp;
/* Buffer was not found. Try to allocate a new one */
return new_block(dev, inum);
@@ -81,7 +91,7 @@ PUBLIC void put_block(dev_t dev, ino_t inum)
{
struct buf *bp;
- bp = get_block(dev, inum);
+ bp = find_block(dev, inum);
if (bp == NULL) return; /* We didn't find the block. Nothing to put. */
bp->b_count--; /* Compensate for above 'get_block'. */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment