Context :
OS : Red hat 8.X
File systems : EXT4, XFS
Storage Types : SSD, HDD
Corruption : Meant here is an activity that result in written data cannot be retrieved as it was written. .e.g. Disk Device level corruption.
Linux read call signature is ssize_t read(int fd, void buf[.count], size_t count);
.
Say the file referred by fd
, has corrupted segments (+ NOT corrupted segments). If the read request goes through one or more corrupted segments(assume segments are A(OK)--B(corrupted)--C(OK)--D(corrupted)--E(OK) and fd
's file position is set before the beginning of A and "count" is large enough to contain all A -> E segments),
Is there a possibility of read's return value to be larger than ZERO ? (and
buf
to contain data) ?
If so,
1.1. What would be contained inbuf
? will it contain any data from corrupted segments B and D ? What could be the return value of read' ?1.2 What are probability of this happening ? What factors could increase the probability of this happening ? e.g. re-boot ?
Would the file size returned by fstat count any bytes from corrupted segments ?
Purpose : I am trying to decide(under above given OS, File system conditions), if I NEED to add a "application level calculated checksum" along with written(binary) data and when reading the same file if read returns success(i.e. return value > 0), validate the (app level written)checksum before concluding data as valid.
Also I am NOT worried about some intruder modifying the written data here. Only worried about things that can happen from system activity. e.g. machine re-boot