The Linux Kernel/get blk

__getblk edit

SYNOPSIS edit

#include <linux/buffer_head.h>

struct buffer_head * __getblk(struct block_device * bdev, sector_t block, unsigned size);
  • bdev: the block device for which to get the buffer head.
  • block: the block number of the block to get the buffer head for.
  • size: the size of the block (cluster?) in bytes.

SHORT DESCRIPTION edit

This function returns a valid buffer head for the given (device|block|size) tuple.

FULL DESCRIPTION edit

This function always returns a valid buffer head for the given (device|block|size) tuple. If the buffer head for that block already existed, it's just returned. If not, it will be created. Passing an illegal block number causes a valid block head for this invalid block to be created. Subsequent actions on that buffer head will then produce appropriate errors.

The buffer heads reference count will have been incremented after this call. Also, it will be added to the least recently used list of the current cpu and hence having its usage count incremented twice not once. However, the second increment is only done to make sure, that the buffer heads in the lru list don't get grabbed. The other lru functions make sure, that the one increment will be undone at an appropriate time. The other increment must be undone by the caller by a call to __brelse(bh).

RETURN edit

The buffer head for the given (device|block|size) tuple.

ERRATA edit

If __getblk() will lock up the machine if grow_dev_page's try_to_free_buffers() attempt is failing.