On Thu, Jun 26, 2008 at 4:00 PM, Cynthia Eastham <cynthia.eastham at sun.com> wrote: > It's been pointed out to me that the work which the above tool does > could be performed by comparing file size with blocksize, however the > sample program was written to demonstrate the use of SEEK_HOLE/SEEK_DATA > (which could be expanded to gather data and hole offsets of a file). :)
That is until you have compression on zfs. It breaks the traditional du + ls comparison method. Create a compressed zfs file system, copy /bin/ls to it. # zfs create local/z # zfs set compression=on local/z Notice that the sizes are different according to du. # du -k /local/z/ls /bin/ls 17 /local/z/ls 27 /bin/ls But they really are the same. $ openssl md5 /bin/ls /local/z/ls MD5(/bin/ls)= b57e173220af4b919f1d4bef9db11482 MD5(/local/z/ls)= b57e173220af4b919f1d4bef9db11482 And neither is sparse according to your code. $ ./sparse_test-1 /bin/ls ; echo $? 1 $ ./sparse_test-1 /local/z/ls ; echo $? 1 Create a couple sparse files: # dd if=/dev/random of=/var/tmp/sparse bs=1k count=1 oseek=1024k 1+0 records in 1+0 records out # dd if=/dev/random of=/local/z/sparse bs=1k count=1 oseek=1024k 1+0 records in 1+0 records out The traditional combination of du and ls suggests that they are both sparse. # du -k /var/tmp/sparse /local/z/sparse 32 /var/tmp/sparse 10 /local/z/sparse # ls -l /var/tmp/sparse /local/z/sparse -rw-r--r-- 1 root root 1073742848 Jun 26 21:37 /local/z/sparse -rw-r--r-- 1 root root 1073742848 Jun 26 21:34 /var/tmp/sparse Your code confirms it. $ ./sparse_test-1 /var/tmp/sparse ; echo $? 0 $ ./sparse_test-1 /local/z/sparse ; echo $? 0 -- Mike Gerdts http://mgerdts.blogspot.com/
