diff options
author | Jakob Unterwurzacher | 2018-07-01 19:13:28 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2018-07-01 20:56:22 +0200 |
commit | e951043084937c42421debf457e33b3db3b5bac4 (patch) | |
tree | 6eda615fd17806ad2859e67cae26aed1ac3f35a4 /internal/fusefrontend | |
parent | a2af1fb5da90ec12d05e1c3ece9c44507a5b44c8 (diff) |
fusefrontend: add File.SeekData() function
This function will enable "gocryptfs -fsck" to handle
sparse files efficiently.
Diffstat (limited to 'internal/fusefrontend')
-rw-r--r-- | internal/fusefrontend/file_holes.go | 15 |
1 files changed, 15 insertions, 0 deletions
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) +} |