fusefrontend: add File.SeekData() function

This function will enable "gocryptfs -fsck" to handle
sparse files efficiently.
This commit is contained in:
Jakob Unterwurzacher 2018-07-01 19:13:28 +02:00
parent a2af1fb5da
commit e951043084

View File

@ -3,6 +3,9 @@ package fusefrontend
// Helper functions for sparse files (files with holes)
import (
"runtime"
"syscall"
"github.com/hanwen/go-fuse/fuse"
"github.com/rfjakob/gocryptfs/internal/tlog"
@ -53,3 +56,15 @@ func (f *File) zeroPad(plainSize uint64) fuse.Status {
_, status := f.doWrite(pad, int64(plainSize))
return status
}
// SeekData calls the lseek syscall with SEEK_DATA. It returns the offset of the
// next data bytes, skipping over file holes.
func (f *File) SeekData(oldOffset int64) (int64, error) {
if runtime.GOOS != "linux" {
// Does MacOS support something like this?
return 0, syscall.EOPNOTSUPP
}
const SEEK_DATA = 3
fd := f.intFd()
return syscall.Seek(fd, oldOffset, SEEK_DATA)
}