v2api/reverse: implement Lseek

This commit is contained in:
Jakob Unterwurzacher 2020-08-16 19:58:47 +02:00
parent 58a2726977
commit d212b246c5
5 changed files with 61 additions and 14 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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))
*/

View File

@ -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)

View File

@ -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()
}