libblock: limit the number of retries if we fail to write a block to disk.
The original behaviour is to continously retry to write a block until the
operation succeeds, this will cause the system to enter an infinite loop
if the underlying device is unable to satisfy the request.
This patch introduces an upper limit to the number of retries and discards
the block if the limit is reached.
It also fixes a bug in the block_get() function that allows the user to
try to read a block beyond the end of the device.