Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenBSD support #104

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions error_freebsd.go → error_bsd.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build openbsd freebsd

package fuse

import "syscall"
Expand Down
Binary file added examples/hellofs/hellofs
Binary file not shown.
7 changes: 7 additions & 0 deletions fs/fstestutil/mountinfo_openbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package fstestutil

import "errors"

func getMountInfo(mnt string) (*MountInfo, error) {
return nil, errors.New("OpenBSD has no useful mount information")
}
2 changes: 1 addition & 1 deletion fuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions fuse_kernel_freebsd.go → fuse_kernel_bsd.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build openbsd freebsd

package fuse

import "time"
Expand Down
32 changes: 32 additions & 0 deletions mount_openbsd.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions options_freebsd.go → options_bsd.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build openbsd freebsd

package fuse

func localVolume(conf *mountConfig) error {
Expand Down
8 changes: 8 additions & 0 deletions syscallx/asm.s
Original file line number Diff line number Diff line change
@@ -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
13 changes: 11 additions & 2 deletions syscallx/generate
Original file line number Diff line number Diff line change
@@ -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",' \
Expand All @@ -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")"
Expand All @@ -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
16 changes: 16 additions & 0 deletions syscallx/mount_openbsd.go
Original file line number Diff line number Diff line change
@@ -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)
}
30 changes: 30 additions & 0 deletions syscallx/mount_openbsd_386.go
Original file line number Diff line number Diff line change
@@ -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
}
30 changes: 30 additions & 0 deletions syscallx/mount_openbsd_amd64.go
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions syscallx/syscall.go
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 19 additions & 0 deletions syscallx/syscallx_openbsd.go
Original file line number Diff line number Diff line change
@@ -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")
}
2 changes: 1 addition & 1 deletion syscallx/syscallx_std.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !darwin
// +build !darwin,!openbsd

package syscallx

Expand Down
7 changes: 7 additions & 0 deletions syscallx/xattr_darwin_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions syscallx/xattr_darwin_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions syscallx/ztypes_openbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package syscallx

type Fusefs_args struct {
Name string
FD int
MaxRead int
}