diff --git a/error_freebsd.go b/error_bsd.go similarity index 85% rename from error_freebsd.go rename to error_bsd.go index c6ea6d6e..cb402971 100644 --- a/error_freebsd.go +++ b/error_bsd.go @@ -1,3 +1,5 @@ +// +build openbsd freebsd + package fuse import "syscall" diff --git a/examples/hellofs/hellofs b/examples/hellofs/hellofs new file mode 100755 index 00000000..04f71be9 Binary files /dev/null and b/examples/hellofs/hellofs differ diff --git a/fs/fstestutil/mountinfo_openbsd.go b/fs/fstestutil/mountinfo_openbsd.go new file mode 100644 index 00000000..ff498c04 --- /dev/null +++ b/fs/fstestutil/mountinfo_openbsd.go @@ -0,0 +1,7 @@ +package fstestutil + +import "errors" + +func getMountInfo(mnt string) (*MountInfo, error) { + return nil, errors.New("OpenBSD has no useful mount information") +} diff --git a/fuse.go b/fuse.go index 424b2dce..6fcda829 100644 --- a/fuse.go +++ b/fuse.go @@ -194,7 +194,7 @@ func initMount(c *Conn, conf *mountConfig) error { min := Protocol{protoVersionMinMajor, protoVersionMinMinor} if r.Kernel.LT(min) { - req.RespondError(Errno(syscall.EPROTO)) + req.RespondError(Errno(syscall.EIO)) c.Close() return &OldVersionError{ Kernel: r.Kernel, diff --git a/fuse_kernel_freebsd.go b/fuse_kernel_bsd.go similarity index 97% rename from fuse_kernel_freebsd.go rename to fuse_kernel_bsd.go index b1141e41..df0617ea 100644 --- a/fuse_kernel_freebsd.go +++ b/fuse_kernel_bsd.go @@ -1,3 +1,5 @@ +// +build openbsd freebsd + package fuse import "time" diff --git a/mount_openbsd.go b/mount_openbsd.go new file mode 100644 index 00000000..ef5d2678 --- /dev/null +++ b/mount_openbsd.go @@ -0,0 +1,32 @@ +package fuse + +import ( + "fmt" + "os" + "unsafe" + + "bazil.org/fuse/syscallx" +) + +const fuseBufMaxSize = (1024 * 4096) + +func mount(dir string, conf *mountConfig, ready chan<- struct{}, errp *error) (*os.File, error) { + defer close(ready) + + fmt.Printf("mount(%v, %v)\n", dir, conf) + f, err := os.OpenFile("/dev/fuse0", os.O_RDWR, 0000) + if err != nil { + *errp = err + return nil, err + } + + fuse_args := syscallx.Fusefs_args{ + FD: int(f.Fd()), + MaxRead: fuseBufMaxSize, + } + + fmt.Printf("fusefs_args(%p): %#v\n", &fusefs_args, fusefs_args) + + err = syscallx.Mount("fuse", dir, 0, uintptr(unsafe.Pointer(&fuse_args))) + return f, err +} diff --git a/options_freebsd.go b/options_bsd.go similarity index 83% rename from options_freebsd.go rename to options_bsd.go index 5a0b8480..a10deac9 100644 --- a/options_freebsd.go +++ b/options_bsd.go @@ -1,3 +1,5 @@ +// +build openbsd freebsd + package fuse func localVolume(conf *mountConfig) error { diff --git a/syscallx/asm.s b/syscallx/asm.s new file mode 100644 index 00000000..d4ca868f --- /dev/null +++ b/syscallx/asm.s @@ -0,0 +1,8 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "textflag.h" + +TEXT ·use(SB),NOSPLIT,$0 + RET diff --git a/syscallx/generate b/syscallx/generate index 476a282b..9fd19976 100755 --- a/syscallx/generate +++ b/syscallx/generate @@ -1,7 +1,7 @@ #!/bin/sh set -e -mksys="$(go env GOROOT)/src/pkg/syscall/mksyscall.pl" +mksys="$(go env GOROOT)/src/syscall/mksyscall.pl" fix() { sed 's,^package syscall$,&x\nimport "syscall",' \ @@ -12,7 +12,8 @@ fix() { | gofmt -r='SYS_LISTXATTR -> syscall.SYS_LISTXATTR' \ | gofmt -r='SYS_SETXATTR -> syscall.SYS_SETXATTR' \ | gofmt -r='SYS_REMOVEXATTR -> syscall.SYS_REMOVEXATTR' \ - | gofmt -r='SYS_MSYNC -> syscall.SYS_MSYNC' + | gofmt -r='SYS_MSYNC -> syscall.SYS_MSYNC' \ + | gofmt -r='SYS_MOUNT -> syscall.SYS_MOUNT' } cd "$(dirname "$0")" @@ -32,3 +33,11 @@ $mksys msync.go \ $mksys -l32 msync.go \ | fix \ >msync_386.go + +$mksys mount_openbsd.go \ + | fix \ + > mount_openbsd_amd64.go + +$mksys -l32 mount_openbsd.go \ + | fix \ + > mount_openbsd_386.go diff --git a/syscallx/mount_openbsd.go b/syscallx/mount_openbsd.go new file mode 100644 index 00000000..ff375c64 --- /dev/null +++ b/syscallx/mount_openbsd.go @@ -0,0 +1,16 @@ +package syscallx + +import "fmt" + +/* This is the source file for syscallx_darwin_*.go, to regenerate run + + ./generate + +*/ + +//sys mount(tpe string, dir string, flags int, data uintptr) (err error) + +func Mount(tpe string, dir string, flags int, data uintptr) (err error) { + fmt.Printf("mount(%v, %v, %v, %v)\n", tpe, dir, flags, data) + return mount(tpe, dir, flags, data) +} diff --git a/syscallx/mount_openbsd_386.go b/syscallx/mount_openbsd_386.go new file mode 100644 index 00000000..cc5af7e8 --- /dev/null +++ b/syscallx/mount_openbsd_386.go @@ -0,0 +1,30 @@ +// mksyscall.pl -l32 mount_openbsd.go +// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT + +package syscallx + +import "syscall" + +import "unsafe" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mount(tpe string, dir string, flags int, data uintptr) (err error) { + var _p0 *byte + _p0, err = syscall.BytePtrFromString(tpe) + if err != nil { + return + } + var _p1 *byte + _p1, err = syscall.BytePtrFromString(dir) + if err != nil { + return + } + _, _, e1 := syscall.Syscall6(syscall.SYS_MOUNT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(flags), uintptr(data), 0, 0) + use(unsafe.Pointer(_p0)) + use(unsafe.Pointer(_p1)) + if e1 != 0 { + err = e1 + } + return +} diff --git a/syscallx/mount_openbsd_amd64.go b/syscallx/mount_openbsd_amd64.go new file mode 100644 index 00000000..4a558b24 --- /dev/null +++ b/syscallx/mount_openbsd_amd64.go @@ -0,0 +1,30 @@ +// mksyscall.pl mount_openbsd.go +// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT + +package syscallx + +import "syscall" + +import "unsafe" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mount(tpe string, dir string, flags int, data uintptr) (err error) { + var _p0 *byte + _p0, err = syscall.BytePtrFromString(tpe) + if err != nil { + return + } + var _p1 *byte + _p1, err = syscall.BytePtrFromString(dir) + if err != nil { + return + } + _, _, e1 := syscall.Syscall6(syscall.SYS_MOUNT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(flags), uintptr(data), 0, 0) + use(unsafe.Pointer(_p0)) + use(unsafe.Pointer(_p1)) + if e1 != 0 { + err = e1 + } + return +} diff --git a/syscallx/syscall.go b/syscallx/syscall.go new file mode 100644 index 00000000..40ca4ef4 --- /dev/null +++ b/syscallx/syscall.go @@ -0,0 +1,8 @@ +package syscallx + +import "unsafe" + +// use is a no-op, but the compiler cannot see that it is. +// Calling use(p) ensures that p is kept live until that point. +//go:noescape +func use(p unsafe.Pointer) diff --git a/syscallx/syscallx_openbsd.go b/syscallx/syscallx_openbsd.go new file mode 100644 index 00000000..8595e3a6 --- /dev/null +++ b/syscallx/syscallx_openbsd.go @@ -0,0 +1,19 @@ +package syscallx + +import "errors" + +func Getxattr(path string, attr string, dest []byte) (sz int, err error) { + return 0, errors.New("not implemented") +} + +func Listxattr(path string, dest []byte) (sz int, err error) { + return 0, errors.New("not implemented") +} + +func Setxattr(path string, attr string, data []byte, flags int) (err error) { + return errors.New("not implemented") +} + +func Removexattr(path string, attr string) (err error) { + return errors.New("not implemented") +} diff --git a/syscallx/syscallx_std.go b/syscallx/syscallx_std.go index c0187a6b..8e18d1a5 100644 --- a/syscallx/syscallx_std.go +++ b/syscallx/syscallx_std.go @@ -1,4 +1,4 @@ -// +build !darwin +// +build !darwin,!openbsd package syscallx diff --git a/syscallx/xattr_darwin_386.go b/syscallx/xattr_darwin_386.go index ffc357ae..1da7fcfd 100644 --- a/syscallx/xattr_darwin_386.go +++ b/syscallx/xattr_darwin_386.go @@ -21,6 +21,8 @@ func getxattr(path string, attr string, dest *byte, size int, position uint32, o return } r0, _, e1 := syscall.Syscall6(syscall.SYS_GETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(unsafe.Pointer(dest)), uintptr(size), uintptr(position), uintptr(options)) + use(unsafe.Pointer(_p0)) + use(unsafe.Pointer(_p1)) sz = int(r0) if e1 != 0 { err = e1 @@ -43,6 +45,7 @@ func listxattr(path string, dest []byte, options int) (sz int, err error) { _p1 = unsafe.Pointer(&_zero) } r0, _, e1 := syscall.Syscall6(syscall.SYS_LISTXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(dest)), uintptr(options), 0, 0) + use(unsafe.Pointer(_p0)) sz = int(r0) if e1 != 0 { err = e1 @@ -70,6 +73,8 @@ func setxattr(path string, attr string, data []byte, position uint32, flags int) _p2 = unsafe.Pointer(&_zero) } _, _, e1 := syscall.Syscall6(syscall.SYS_SETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(data)), uintptr(position), uintptr(flags)) + use(unsafe.Pointer(_p0)) + use(unsafe.Pointer(_p1)) if e1 != 0 { err = e1 } @@ -90,6 +95,8 @@ func removexattr(path string, attr string, options int) (err error) { return } _, _, e1 := syscall.Syscall(syscall.SYS_REMOVEXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(options)) + use(unsafe.Pointer(_p0)) + use(unsafe.Pointer(_p1)) if e1 != 0 { err = e1 } diff --git a/syscallx/xattr_darwin_amd64.go b/syscallx/xattr_darwin_amd64.go index 864c4c1d..6d9c33fa 100644 --- a/syscallx/xattr_darwin_amd64.go +++ b/syscallx/xattr_darwin_amd64.go @@ -21,6 +21,8 @@ func getxattr(path string, attr string, dest *byte, size int, position uint32, o return } r0, _, e1 := syscall.Syscall6(syscall.SYS_GETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(unsafe.Pointer(dest)), uintptr(size), uintptr(position), uintptr(options)) + use(unsafe.Pointer(_p0)) + use(unsafe.Pointer(_p1)) sz = int(r0) if e1 != 0 { err = e1 @@ -43,6 +45,7 @@ func listxattr(path string, dest []byte, options int) (sz int, err error) { _p1 = unsafe.Pointer(&_zero) } r0, _, e1 := syscall.Syscall6(syscall.SYS_LISTXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(dest)), uintptr(options), 0, 0) + use(unsafe.Pointer(_p0)) sz = int(r0) if e1 != 0 { err = e1 @@ -70,6 +73,8 @@ func setxattr(path string, attr string, data []byte, position uint32, flags int) _p2 = unsafe.Pointer(&_zero) } _, _, e1 := syscall.Syscall6(syscall.SYS_SETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(data)), uintptr(position), uintptr(flags)) + use(unsafe.Pointer(_p0)) + use(unsafe.Pointer(_p1)) if e1 != 0 { err = e1 } @@ -90,6 +95,8 @@ func removexattr(path string, attr string, options int) (err error) { return } _, _, e1 := syscall.Syscall(syscall.SYS_REMOVEXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(options)) + use(unsafe.Pointer(_p0)) + use(unsafe.Pointer(_p1)) if e1 != 0 { err = e1 } diff --git a/syscallx/ztypes_openbsd.go b/syscallx/ztypes_openbsd.go new file mode 100644 index 00000000..07b4ec99 --- /dev/null +++ b/syscallx/ztypes_openbsd.go @@ -0,0 +1,7 @@ +package syscallx + +type Fusefs_args struct { + Name string + FD int + MaxRead int +}