Commit 41672d15 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

nodefs: by default return input offset for Lseek

parent 1ee3533f
...@@ -21,3 +21,9 @@ func ToErrno(err error) syscall.Errno { ...@@ -21,3 +21,9 @@ func ToErrno(err error) syscall.Errno {
// RENAME_EXCHANGE is a flag argument for renameat2() // RENAME_EXCHANGE is a flag argument for renameat2()
const RENAME_EXCHANGE = 0x2 const RENAME_EXCHANGE = 0x2
// seek to the next data
const _SEEK_DATA = 3
// seek to the next hole
const _SEEK_HOLE = 4
...@@ -195,10 +195,16 @@ func (n *OperationStubs) CopyFileRange(ctx context.Context, fhIn FileHandle, ...@@ -195,10 +195,16 @@ func (n *OperationStubs) CopyFileRange(ctx context.Context, fhIn FileHandle,
return 0, syscall.EROFS return 0, syscall.EROFS
} }
// Lseek is called for seeking to and beyond holes. By default, it
// returns the input offset unchanged.
func (n *OperationStubs) Lseek(ctx context.Context, f FileHandle, off uint64, whence uint32) (uint64, syscall.Errno) { func (n *OperationStubs) Lseek(ctx context.Context, f FileHandle, off uint64, whence uint32) (uint64, syscall.Errno) {
if f != nil { if f != nil {
return f.Lseek(ctx, off, whence) return f.Lseek(ctx, off, whence)
} }
if whence == _SEEK_DATA || whence == _SEEK_HOLE {
return off, OK
}
return 0, syscall.ENOTSUP return 0, syscall.ENOTSUP
} }
......
...@@ -81,9 +81,7 @@ func TestDirectIO(t *testing.T) { ...@@ -81,9 +81,7 @@ func TestDirectIO(t *testing.T) {
t.Errorf("got %q want %q", got, want) t.Errorf("got %q want %q", got, want)
} }
const SEEK_DATA = 3 /* seek to the next data */ if n, err := syscall.Seek(int(f.Fd()), 512, _SEEK_DATA); err != nil {
if n, err := syscall.Seek(int(f.Fd()), 512, SEEK_DATA); err != nil {
t.Errorf("Seek: %v", err) t.Errorf("Seek: %v", err)
} else if n != 1024 { } else if n != 1024 {
t.Errorf("seek: got %d, want %d", n, 1024) t.Errorf("seek: got %d, want %d", n, 1024)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment