-
Notifications
You must be signed in to change notification settings - Fork 7
Description
#38 implements this only for qcow2, which is good enough for lima use case, but users of the library that that want read sparse raw file (or backing file) efficiently need a real implementation.
This can be implemented with SEEK_DATA and SEEK_HOLE seek flags:
https://github.com/qemu/qemu/blob/92ec7805190313c9e628f8fc4eb4f932c15247bd/block/file-posix.c#L3190
Can be done using unix.Seek:
https://pkg.go.dev/golang.org/x/sys/unix#Seek
https://cs.opensource.google/go/x/sys/+/refs/tags/v0.26.0:unix/zerrors_linux.go;l=3007
https://cs.opensource.google/go/x/sys/+/refs/tags/v0.26.0:unix/zerrors_darwin_arm64.go;l=1280
If the flags are not available or the Seek fails, the implementation can fallback to report an allocated cluster, which is less efficient but correct.
Possible use of this functionality is Go implementation of blkhash:
https://gitlab.com/nirs/blkhash/-/issues/103