Can the ext4 filesystem detect data corruption of file contents? If yes, is it enabled by default and how can I check for corrupted data?
I have read that ext4 maintains checksums for file metadata and its journal, but I was unable to find any information on checksums for the actual file contents.
For clarity: I want to know if a file has changed since the last write operation.
No, ext4
doesn't and can't detect file content corruption.
Well known file systems implementing silent data corruption detection and therefore able to correct it when enough redundancy is available are ZFS
and btrfs
.
They do it by computing and storing a CRC
for every data block written and by checking the CRC
or each data block read. Should the CRC doesn't match the data, the latter is not provided to the caller and either RAID
allows for an alternate block to be used instead, or an I/O
error is reported.
The reading process will never receive corrupted data, either it is correct or the read fails.
"Can the ext4 filesystem detect data corruption of file contents?" Not in the sense you are expecting. It performs journaling, creating a boolean {before vs after} copy to ensure io completion.
A CRC / checksum is a test for modification from a known state and although the CRC or checksum may not compare to the original, that does not imply that the file is then "corrupt" (aka invalid) - - it only says it has been changed. Strictly speaking, one form of "corruption" would be to alter the 'magic number' at the beginning of a file, like changing %PDF to %xYz - - that would make the content unusable to any program.
"... to know if a file has changed since the last write operation". Systems that track mtime() will do so uniformly, so every write will modify mtime() making your request impossible.
The only way mtime() would not reflect last write io would be media degredation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With