Created
April 14, 2016 12:59
-
-
Save amarao/91fc4467eb80aef7efbe8394583b41ba to your computer and use it in GitHub Desktop.
Dump all holes in sparse file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import os | |
import sys | |
if len(sys.argv) < 2: | |
print ("Usage: sparse_dump filename") | |
sys.exit(-1) | |
fd = os.open(sys.argv[1], os.O_RDONLY) | |
end = os.lseek(fd, 0, os.SEEK_END) | |
offset = 0 | |
try: | |
while True: | |
offset = os.lseek(fd, offset, os.SEEK_HOLE) | |
if offset >= end: | |
break | |
print ("Hole start at %s" % offset) | |
offset = os.lseek(fd,offset, os.SEEK_DATA) | |
if offset > end: | |
break | |
print ("Hole end at %s" % offset) | |
except: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment