๐ filefrag for python
Spent last night making this, added some turd polish today and added it to pypi.
๐คท what?
I wanted to get file fragmentation info so I can punch holes in files, aligned
with memory pages. But I really didnโt want to parse filefragโs outputs, so I
wrote a python version with a friendly API and a command line that can produce
json.
It only works on Linux as it depends on the FIE interface, but pull requests welcome.
โ๏ธ how?
See the video for a demo including installing from source, but you can install with pip:
pip install filefrag
Then run pyfilefrag on the command line. See --help for details. It has
--verbose, and --json outputs for your parsing pleasure.
To use the library, just call filefrag.FileMap('/path/whatever') to build a
map of the extents in the file using ioctlโs interface. Then you can poke about
in the guts of a file:
- โ๏ธโ๐ฅ inspect fragmentation
- ๐ find out where data is on your physical drive
- ๐ฐ compare extents between paths
- ๐ use them as dict keys
- ๐ณ๏ธ check files for holes, like before and after hole punching
- โ verify your XFS deduplication strategy, write your own stats tool
- ๐ฉ dump file layouts to json (
print(f"{filemap:j}") - โ ๏ธ break your disk because you believed the outputs of this 0.0.1 release!
Comes with a Device class to do comparisons, so it ought to work with fragments in files on different mountpoints, bind mounts and so on (unfortunately not snapโs FUSE mounts; theyโre far too abstract and piped in via a socket)