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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
package fs_test
import (
"context"
"errors"
"fmt"
"os"
"syscall"
"testing"
"golang.org/x/sys/unix"
"github.com/anacrolix/fuse/fs/fstestutil"
"github.com/anacrolix/fuse/fs/fstestutil/spawntest/httpjson"
)
func platformStatfs(st *syscall.Statfs_t) *statfsResult {
return &statfsResult{
Blocks: st.Blocks,
Bfree: st.Bfree,
Bavail: st.Bavail,
Files: st.Files,
Ffree: st.Ffree,
Bsize: int64(st.Iosize),
Namelen: 0,
Frsize: 0,
}
}
func platformStat(fi os.FileInfo) *statResult {
r := &statResult{
Mode: fi.Mode(),
}
st := fi.Sys().(*syscall.Stat_t)
r.Ino = st.Ino
r.Nlink = uint64(st.Nlink)
r.UID = st.Uid
r.GID = st.Gid
r.Blksize = int64(st.Blksize)
return r
}
type exchangeData struct {
fstestutil.File
// this struct cannot be zero size or multiple instances may look identical
_ int
}
type exchangedataRequest struct {
Path1 string
Path2 string
Options int
WantErrno syscall.Errno
}
func doExchange(ctx context.Context, req exchangedataRequest) (*struct{}, error) {
if err := unix.Exchangedata(req.Path1, req.Path2, req.Options); !errors.Is(err, req.WantErrno) {
return nil, fmt.Errorf("from error from exchangedata: %v", err)
}
return &struct{}{}, nil
}
var exchangeHelper = helpers.Register("exchange", httpjson.ServePOST(doExchange))
func TestExchangeDataNotSupported(t *testing.T) {
maybeParallel(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
mnt, err := fstestutil.MountedT(t, fstestutil.SimpleFS{&fstestutil.ChildMap{
"one": &exchangeData{},
"two": &exchangeData{},
}}, nil)
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
control := exchangeHelper.Spawn(ctx, t)
defer control.Close()
req := exchangedataRequest{
Path1: mnt.Dir + "/one",
Path2: mnt.Dir + "/two",
Options: 0,
WantErrno: syscall.ENOTSUP,
}
var nothing struct{}
if err := control.JSON("/").Call(ctx, req, ¬hing); err != nil {
t.Fatalf("calling helper: %v", err)
}
}
|