Hi,
On linux, reads to a block device that fail on a sector return a
failure for the *entire* read, as if no bytes were read, and the location
of the exact sector that failed is not provided. [You can test this out,
and it's also apparent from reading the kernel source code.]
However, when doing a direct read, the good sectors up until the read error
are actually transferred to the userspace buffer, even though read()
returns -1.
Perhaps you could implement a 'paranoid' mode that prewrites known data to
the read buffer before each read. On an I/O error, it can see how many
'sectors' no longer match the original data and assume that those sectors
were correctly read, and mark the following sector as a 'bad sector'. It
would be possible to write a routine to check for the correctness/validity
of this method vs. a specific drive one a known bad sector is found.
Thanks,
Eli Saks