Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can ext4 detect corrupted file contents?

Tags:

unix

ext4

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.

like image 698
Lukas Boersma Avatar asked Jul 10 '15 15:07

Lukas Boersma


2 Answers

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.

like image 164
jlliagre Avatar answered Oct 29 '22 17:10

jlliagre


"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.

like image 31
jobeard Avatar answered Oct 29 '22 17:10

jobeard