getblk Kernel Service

Purpose

Assigns a buffer to the specified block.

Syntax

#include <sys/types.h>
#include <sys/errno.h>
#include <sys/buf.h>

struct buf *getblk
(
dev,  blkno)
dev_t  dev;
daddr_t  blkno;
  

Parameters

Item Description
dev Specifies the device containing the block to be allocated.
blkno Specifies the block to be allocated.

Description

The getblk kernel service first checks whether the specified buffer is in the buffer cache. If the buffer resides there, but is in use, the e_sleep service is called to wait until the buffer is no longer in use. Upon waking, the getblk service tries again to access the buffer. If the buffer is in the cache and not in use, it is removed from the free list and marked as busy. Its buffer header is then returned. If the buffer is not in the buffer cache, another buffer is taken from the free list and returned.

Execution Environment

The getblk kernel service can be called from the process environment only.

Return Values

The getblk service returns a pointer to the buffer header. A nonzero value for B_ERROR in the b_flags field of the buffer header (buf structure) indicates an error. If this occurs, the caller should release the block's buffer using the brelse kernel service.

On a platform that supports storage keys, the buffer header is allocated from the storage protected by the KKEY_BLOCK_DEV kernel key.