> Paul Eggert <egg...@cs.ucla.edu> wrote: > >> POSIX does not require that st_nblocks remain constant across any system >> call. It doesn't even require that it remain constant if you merely call >> stat twice on the same file, without doing anything else in between.
The real question is then: What is the most efficient (preferably portable) way for an archiving program (such as tar) to determine whether it should archive a particular file as sparse or non-sparse? Historically, we’ve compared st_nblocks to st_size to quickly determine if a file is sparse in order to avoid the SEEK_HOLE scan in most cases. Some programs even consider st_nblocks == 0 as an indication that a file is entirely sparse. Based on the claims I’ve read here, it sounds like st_nblocks can no longer be trusted for these purposes. So is there some other way to quickly identify sparse files so we can avoid the SEEK_HOLE scan for non-sparse files? Cheers, Tim