Skip to content

Implement block status interface for raw image #44

Description

@nirs

#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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions