From e951043084937c42421debf457e33b3db3b5bac4 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 1 Jul 2018 19:13:28 +0200 Subject: fusefrontend: add File.SeekData() function This function will enable "gocryptfs -fsck" to handle sparse files efficiently. --- internal/fusefrontend/file_holes.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'internal/fusefrontend') diff --git a/internal/fusefrontend/file_holes.go b/internal/fusefrontend/file_holes.go index 2b95c5c..04a00ec 100644 --- a/internal/fusefrontend/file_holes.go +++ b/internal/fusefrontend/file_holes.go @@ -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) +} -- cgit v1.2.3