itisravi
itisravi

Reputation: 3571

Does __bread() always return PAGE_SIZE number of bytes?

The Linux kernel API has a __bread method:

__bread(struct block_device *bdev, sector_t block, unsigned size)

which returns a buffer_head pointer whose data field contains size worth of data.However, I noticed that reading beyond size bytes still gave me valid data up to PAGE_SIZE number of bytes. This got me wondering if I can presume the buffer_head returned by a *__bread* always contains valid data worth PAGE_SIZE bytes even if the size argument passed to it is lesser.

Or maybe it was just a coincidence.

Upvotes: 0

Views: 186

Answers (1)

Matias Bjørling
Matias Bjørling

Reputation: 554

The __bread perform a read IO from given block interface, but depending on the backing store, you get different results.

For harddrives, the block device will fetch data in sector sizes. Usually this is either 512 bytes or 4K. If 512 bytes, and you ask for 256 bytes, you'll be able to access the last parts of the sector. Thus, you may fetch up to the sector size. However, it is not always true. With memory backed devices, you may only access the 256 bytes, as it is not served up by the block layer, but by the VSL.

In short, no. You should not rely on this feature, as it depends on which block device is backing the storage and may also change with block layer implementation.

Upvotes: 1

Related Questions