Skip to content

Instantly share code, notes, and snippets.

@amarao
Created April 14, 2016 12:59
Show Gist options
  • Save amarao/91fc4467eb80aef7efbe8394583b41ba to your computer and use it in GitHub Desktop.
Save amarao/91fc4467eb80aef7efbe8394583b41ba to your computer and use it in GitHub Desktop.
Dump all holes in sparse file
#!/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