Block IO operations

The bread( ) function reads a single block from a block device and stores it in a buffer. It receives as parameters the device identifier, the block number, and the block size, and returns a pointer to the buffer head of the buffer containing the block.

The function performs the following operations:

1. Invokes the getblk( ) function to search for the block in a software cache called the buffer cache (see Section 14.2.4). If the block is not included in the cache, getblk( ) allocates a new buffer for it.

2. Invokes mark_page_accessed( ) on the buffer page containing the data (see Section 16.7.2).

3. If the buffer already contains valid data, it terminates.

4. Invokes ll_rw_block( ) to start the read operation (see Section 13.4.6 earlier in this chapter).

5. Waits until the data transfer completes. This is done by invoking a function named wait_on_buffer( ), which inserts the current process in the b_wait wait queue and suspends the process until the buffer is unlocked.

6. Checks whether the buffer contains valid data. If so, it returns the address of the buffer head; otherwise, it returns a null pointer.

No function exists to directly write a block to disk. Declaring a buffer dirty is sufficient to force its flushing to disk at some later time. In fact, write operations are not considered critical for system performance, so they are deferred whenever possible (see Section 14.2.4).

Was this article helpful?

0 0

Post a comment