What does the -W parameter of tar actually do?
This took some digging to figure out. In the file src/compare.c
in the Git repo for tar, we find a function named verify_volume
(on line 527 at the time of writing), which contains the following comment
Verifying an archive is meant to check if the physical media got it correctly, so try to defeat clever in-memory buffering pertaining to this particular media. On Linux, for example, the floppy drive would not even be accessed for the whole verification.
That explains what it tries to do, but as to how it does it, we need to look at the code for the function. It starts off by comparing the headers to make sure they match, and if they do, it runs the function diff_archive
(line 461 at the time of writing), which goes item by item inside the archive, and when it encounters a file*, it will run the function diff_file
(line 187). It starts by checking a few easy things, such as file type and size (and others). If all of those are correct, it (for a normal file) goes and verifies each block of the file (in the read_and_process
function, line 120). For sparse files, it calls the sparse_diff_file
(line 698) in src/sparse.c
, which checks each region of the file** using the check_sparse_region
function (line 607), also in src/sparse.c
.
*It does other things for other types of archived data, such as directories
**It checks each region in a similar way that it checks an entire normal (non-sparse) file