aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2020-08-16 19:58:47 +0200
committerJakob Unterwurzacher2020-08-16 19:58:47 +0200
commitd212b246c5e24e6151bef45ad5a8185fdd12a28f (patch)
treed1d2eecd9fb289b674c426d0ba2bddc6c21b60ff
parent58a2726977a1b1f92063a1e51c0769af71833e72 (diff)
v2api/reverse: implement Lseek
-rw-r--r--internal/fusefrontend/file_holes.go2
-rw-r--r--internal/fusefrontend_reverse/file.go11
-rw-r--r--internal/fusefrontend_reverse/file_api_check.go23
-rw-r--r--tests/defaults/main_test.go1
-rw-r--r--tests/reverse/correctness_test.go38
5 files changed, 61 insertions, 14 deletions
diff --git a/internal/fusefrontend/file_holes.go b/internal/fusefrontend/file_holes.go
index 85792f9..0d28004 100644
--- a/internal/fusefrontend/file_holes.go
+++ b/internal/fusefrontend/file_holes.go
@@ -61,7 +61,7 @@ func (f *File) Lseek(ctx context.Context, off uint64, whence uint32) (uint64, sy
cipherOff := f.rootNode.contentEnc.PlainSizeToCipherSize(off)
newCipherOff, err := syscall.Seek(f.intFd(), int64(cipherOff), int(whence))
if err != nil {
- return uint64(newCipherOff), fs.ToErrno(err)
+ return 0, fs.ToErrno(err)
}
newOff := f.contentEnc.CipherSizeToPlainSize(uint64(newCipherOff))
return newOff, 0
diff --git a/internal/fusefrontend_reverse/file.go b/internal/fusefrontend_reverse/file.go
index 55f5f80..294872f 100644
--- a/internal/fusefrontend_reverse/file.go
+++ b/internal/fusefrontend_reverse/file.go
@@ -68,3 +68,14 @@ func (f *File) Read(ctx context.Context, buf []byte, ioff int64) (resultData fus
func (f *File) Release(context.Context) syscall.Errno {
return fs.ToErrno(f.fd.Close())
}
+
+// Lseek - FUSE call.
+func (f *File) Lseek(ctx context.Context, off uint64, whence uint32) (uint64, syscall.Errno) {
+ plainOff := f.contentEnc.CipherSizeToPlainSize(off)
+ newPlainOff, err := syscall.Seek(int(f.fd.Fd()), int64(plainOff), int(whence))
+ if err != nil {
+ return 0, fs.ToErrno(err)
+ }
+ newOff := f.contentEnc.PlainSizeToCipherSize(uint64(newPlainOff))
+ return newOff, 0
+}
diff --git a/internal/fusefrontend_reverse/file_api_check.go b/internal/fusefrontend_reverse/file_api_check.go
index 201f1ea..b7e59d4 100644
--- a/internal/fusefrontend_reverse/file_api_check.go
+++ b/internal/fusefrontend_reverse/file_api_check.go
@@ -7,22 +7,19 @@ import (
// Check that we have implemented the fs.File* interfaces
var _ = (fs.FileReader)((*File)(nil))
var _ = (fs.FileReleaser)((*File)(nil))
-
-/* TODO
-var _ = (fs.FileLseeker)((*File2)(nil))
-*/
+var _ = (fs.FileLseeker)((*File)(nil))
/* Not needed
-var _ = (fs.FileGetattrer)((*File2)(nil))
-var _ = (fs.FileGetlker)((*File2)(nil))
-var _ = (fs.FileSetlker)((*File2)(nil))
-var _ = (fs.FileSetlkwer)((*File2)(nil))
+var _ = (fs.FileGetattrer)((*File)(nil))
+var _ = (fs.FileGetlker)((*File)(nil))
+var _ = (fs.FileSetlker)((*File)(nil))
+var _ = (fs.FileSetlkwer)((*File)(nil))
*/
/* Will not implement these - reverse mode is read-only!
-var _ = (fs.FileSetattrer)((*File2)(nil))
-var _ = (fs.FileWriter)((*File2)(nil))
-var _ = (fs.FileFsyncer)((*File2)(nil))
-var _ = (fs.FileFlusher)((*File2)(nil))
-var _ = (fs.FileAllocater)((*File2)(nil))
+var _ = (fs.FileSetattrer)((*File)(nil))
+var _ = (fs.FileWriter)((*File)(nil))
+var _ = (fs.FileFsyncer)((*File)(nil))
+var _ = (fs.FileFlusher)((*File)(nil))
+var _ = (fs.FileAllocater)((*File)(nil))
*/
diff --git a/tests/defaults/main_test.go b/tests/defaults/main_test.go
index 1982c90..8873f8f 100644
--- a/tests/defaults/main_test.go
+++ b/tests/defaults/main_test.go
@@ -263,6 +263,7 @@ func TestCpWarnings(t *testing.T) {
}
}
+// TestSeekData tests that fs.FileLseeker is implemented
func TestSeekData(t *testing.T) {
fn := filepath.Join(test_helpers.DefaultPlainDir, t.Name())
f, err := os.Create(fn)
diff --git a/tests/reverse/correctness_test.go b/tests/reverse/correctness_test.go
index 78c9c4b..9d7a1c8 100644
--- a/tests/reverse/correctness_test.go
+++ b/tests/reverse/correctness_test.go
@@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"os"
+ "path/filepath"
"syscall"
"testing"
@@ -257,3 +258,40 @@ func TestStatfs(t *testing.T) {
t.Errorf("statfs reports size zero: %#v", st)
}
}
+
+// TestSeekData tests that fs.FileLseeker is implemented
+func TestSeekData(t *testing.T) {
+ if !plaintextnames {
+ t.Skip()
+ }
+
+ fn := filepath.Join(dirA, t.Name())
+ f, err := os.Create(fn)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var oneTiB int64 = 1024 * 1024 * 1024 * 1024
+ if _, err = f.Seek(oneTiB, 0); err != nil {
+ t.Fatal(err)
+ }
+ if _, err = f.Write([]byte("foo")); err != nil {
+ t.Fatal(err)
+ }
+ f.Close()
+
+ const SEEK_DATA = 3
+
+ fn2 := filepath.Join(dirB, t.Name())
+ f, err = os.Open(fn2)
+ if err != nil {
+ t.Fatal(err)
+ }
+ off, err := f.Seek(1024*1024, SEEK_DATA)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if off < oneTiB-1024*1024 {
+ t.Errorf("off=%d, expected=%d\n", off, oneTiB)
+ }
+ f.Close()
+}