1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
// Copyright 2019 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package fs
import (
"bytes"
"context"
"os"
"reflect"
"syscall"
"testing"
"unsafe"
"github.com/hanwen/go-fuse/v2/internal/ioctl"
)
type ioctlNode struct {
Inode
}
var _ = (NodeIoctler)((*ioctlNode)(nil))
func (n *ioctlNode) Ioctl(ctx context.Context, f FileHandle, cmd uint32, arg uint64, input []byte, output []byte) (result int32, errno syscall.Errno) {
for i := range output {
output[i] = input[i] + 1
}
return 1515, 0
}
func TestIoctl(t *testing.T) {
root := &ioctlNode{}
mntDir, _ := testMount(t, root, nil)
f, err := os.Open(mntDir)
if err != nil {
t.Fatalf("Create: %v", err)
}
defer f.Close()
n := 42
arg := bytes.Repeat([]byte{'x'}, n)
cmd := ioctl.New(ioctl.READ|ioctl.WRITE,
1, 1, uintptr(n))
a, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(f.Fd()), uintptr(cmd), uintptr(unsafe.Pointer(&arg[0])))
if errno != 0 {
t.Fatal(errno)
}
if a != 1515 {
t.Logf("got %d, want 1515", a)
}
if want := bytes.Repeat([]byte{'y'}, n); !reflect.DeepEqual(arg, want) {
t.Logf("got %v, want %v", arg, want)
}
}
|