Skip to content

Commit

Permalink
NetBSD port
Browse files Browse the repository at this point in the history
  • Loading branch information
billziss-gh committed Jun 27, 2018
1 parent c42dc88 commit 3bc5ead
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/passthrough/passthrough.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build darwin freebsd openbsd linux
// +build darwin freebsd netbsd openbsd linux

/*
* passthrough.go
Expand Down Expand Up @@ -58,7 +58,7 @@ func (self *Ptfs) Statfs(path string, stat *fuse.Statfs_t) (errc int) {
defer trace(path)(&errc, stat)
path = filepath.Join(self.root, path)
stgo := syscall.Statfs_t{}
errc = errno(syscall.Statfs(path, &stgo))
errc = errno(syscall_Statfs(path, &stgo))
copyFusestatfsFromGostatfs(stat, &stgo)
return
}
Expand Down
4 changes: 4 additions & 0 deletions examples/passthrough/port_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ func copyFusestatFromGostat(dst *fuse.Stat_t, src *syscall.Stat_t) {
dst.Blocks = int64(src.Blocks)
dst.Birthtim.Sec, dst.Birthtim.Nsec = src.Birthtimespec.Sec, src.Birthtimespec.Nsec
}

func syscall_Statfs(path string, stat *syscall.Statfs_t) error {
return syscall.Statfs(path, stat)
}
4 changes: 4 additions & 0 deletions examples/passthrough/port_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ func copyFusestatFromGostat(dst *fuse.Stat_t, src *syscall.Stat_t) {
dst.Blocks = int64(src.Blocks)
dst.Birthtim.Sec, dst.Birthtim.Nsec = src.Birthtimespec.Sec, src.Birthtimespec.Nsec
}

func syscall_Statfs(path string, stat *syscall.Statfs_t) error {
return syscall.Statfs(path, stat)
}
4 changes: 4 additions & 0 deletions examples/passthrough/port_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ func copyFusestatFromGostat(dst *fuse.Stat_t, src *syscall.Stat_t) {
dst.Blksize = int64(src.Blksize)
dst.Blocks = int64(src.Blocks)
}

func syscall_Statfs(path string, stat *syscall.Statfs_t) error {
return syscall.Statfs(path, stat)
}
65 changes: 65 additions & 0 deletions examples/passthrough/port_netbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// +build netbsd

/*
* port_netbsd.go
*
* Copyright 2017-2018 Bill Zissimopoulos
*/
/*
* This file is part of Cgofuse.
*
* It is licensed under the MIT license. The full license text can be found
* in the License.txt file at the root of this project.
*/

package main

import (
"syscall"

"github.com/billziss-gh/cgofuse/fuse"
)

func setuidgid() func() {
euid := syscall.Geteuid()
if 0 == euid {
uid, gid, _ := fuse.Getcontext()
egid := syscall.Getegid()
syscall.Setegid(int(gid))
syscall.Seteuid(int(uid))
return func() {
syscall.Seteuid(euid)
syscall.Setegid(egid)
}
}
return func() {
}
}

func copyFusestatfsFromGostatfs(dst *fuse.Statfs_t, src *syscall.Statfs_t) {
*dst = fuse.Statfs_t{}
dst.Namemax = 255
}

func copyFusestatFromGostat(dst *fuse.Stat_t, src *syscall.Stat_t) {
*dst = fuse.Stat_t{}
dst.Dev = uint64(src.Dev)
dst.Ino = uint64(src.Ino)
dst.Mode = uint32(src.Mode)
dst.Nlink = uint32(src.Nlink)
dst.Uid = uint32(src.Uid)
dst.Gid = uint32(src.Gid)
dst.Rdev = uint64(src.Rdev)
dst.Size = int64(src.Size)
dst.Atim.Sec, dst.Atim.Nsec = src.Atimespec.Sec, src.Atimespec.Nsec
dst.Mtim.Sec, dst.Mtim.Nsec = src.Mtimespec.Sec, src.Mtimespec.Nsec
dst.Ctim.Sec, dst.Ctim.Nsec = src.Ctimespec.Sec, src.Ctimespec.Nsec
dst.Blksize = int64(src.Blksize)
dst.Blocks = int64(src.Blocks)
dst.Birthtim.Sec, dst.Birthtim.Nsec = src.Birthtimespec.Sec, src.Birthtimespec.Nsec
}

func syscall_Statfs(path string, stat *syscall.Statfs_t) error {
*stat = syscall.Statfs_t{}
return nil
}
4 changes: 4 additions & 0 deletions examples/passthrough/port_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ func copyFusestatFromGostat(dst *fuse.Stat_t, src *syscall.Stat_t) {
dst.Blocks = int64(src.Blocks)
dst.Birthtim.Sec, dst.Birthtim.Nsec = src.X__st_birthtim.Sec, src.X__st_birthtim.Nsec
}

func syscall_Statfs(path string, stat *syscall.Statfs_t) error {
return syscall.Statfs(path, stat)
}
12 changes: 9 additions & 3 deletions fuse/fsop_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package fuse

/*
#if !(defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__) || defined(_WIN32))
#if !(defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__linux__) || defined(_WIN32))
#error platform not supported
#endif
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__linux__)
#include <errno.h>
#include <fcntl.h>
Expand Down Expand Up @@ -139,11 +139,17 @@ package fuse
#define ENOLINK ENOENT
#endif
#elif defined(__NetBSD__)
// these are not defined anywhere; convert to EINVAL
#define ENOTRECOVERABLE EINVAL
#define EOWNERDEAD EINVAL
#endif
#if defined(__APPLE__) || defined(__linux__)
#include <sys/xattr.h>
#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(_WIN32)
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(_WIN32)
#define XATTR_CREATE 1
#define XATTR_REPLACE 2
#endif
Expand Down
7 changes: 4 additions & 3 deletions fuse/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ func hostInit(conn0 *c_struct_fuse_conn_info) (user_data unsafe.Pointer) {

func hostDestroy(user_data unsafe.Pointer) {
defer recover()
if "netbsd" == runtime.GOOS {
user_data = c_fuse_get_context().private_data
}
host := hostHandleGet(user_data)
host.fsop.Destroy()
if nil != host.sigc {
Expand Down Expand Up @@ -864,14 +867,12 @@ func OptParse(args []string, format string, vals ...interface{}) (outargs []stri
defer c_fuse_opt_free_args(&fuse_args)
argc := 1 + len(args)
argp := c_calloc(c_size_t(argc+1), c_size_t(unsafe.Sizeof((*c_char)(nil))))
defer c_free(argp)
argv := (*[1 << 16]*c_char)(argp)
argv[0] = c_CString("<UNKNOWN>")
defer c_free(unsafe.Pointer(argv[0]))
for i := 0; len(args) > i; i++ {
argv[1+i] = c_CString(args[i])
defer c_free(unsafe.Pointer(argv[1+i]))
}
fuse_args.allocated = 1
fuse_args.argc = c_int(argc)
fuse_args.argv = (**c_char)(&argv[0])

Expand Down
19 changes: 11 additions & 8 deletions fuse/host_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ package fuse
#cgo freebsd CFLAGS: -DFUSE_USE_VERSION=28 -D_FILE_OFFSET_BITS=64 -I/usr/local/include/fuse
#cgo freebsd LDFLAGS: -L/usr/local/lib -lfuse
#cgo netbsd CFLAGS: -DFUSE_USE_VERSION=28 -D_FILE_OFFSET_BITS=64
#cgo netbsd LDFLAGS: -lrefuse
#cgo openbsd CFLAGS: -DFUSE_USE_VERSION=28 -D_FILE_OFFSET_BITS=64
#cgo openbsd LDFLAGS: -lfuse
Expand All @@ -31,7 +34,7 @@ package fuse
// The flag `I/usr/local/include/winfsp` only works on xgo and docker.
#cgo windows CFLAGS: -DFUSE_USE_VERSION=28 -I/usr/local/include/winfsp
#if !(defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__) || defined(_WIN32))
#if !(defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__linux__) || defined(_WIN32))
#error platform not supported
#endif
Expand All @@ -40,7 +43,7 @@ package fuse
#include <stdlib.h>
#include <string.h>
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__linux__)
#include <spawn.h>
#include <sys/mount.h>
Expand Down Expand Up @@ -200,7 +203,7 @@ static PVOID cgofuse_init_winfsp(VOID)
#endif
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__linux__)
typedef struct stat fuse_stat_t;
typedef struct stat fuse_stat_ex_t;
typedef struct statvfs fuse_statvfs_t;
Expand Down Expand Up @@ -268,7 +271,7 @@ static inline void hostAsgnCconninfo(struct fuse_conn_info *conn,
#if defined(__APPLE__)
if (capCaseInsensitive)
FUSE_ENABLE_CASE_INSENSITIVE(conn);
#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__)
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__linux__)
#elif defined(_WIN32)
#if defined(FSP_FUSE_CAP_STAT_EX)
conn->want |= conn->capable & FSP_FUSE_CAP_STAT_EX;
Expand Down Expand Up @@ -409,15 +412,15 @@ static int _hostGetxattr(char *path, char *name, char *value, size_t size,
static void hostStaticInit(void)
{
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__linux__)
#elif defined(_WIN32)
InitializeCriticalSection(&cgofuse_lock);
#endif
}
static int hostFuseInit(void)
{
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__linux__)
return 1;
#elif defined(_WIN32)
return 0 != cgofuse_init_fast(0);
Expand Down Expand Up @@ -485,10 +488,10 @@ static int hostMount(int argc, char *argv[], void *data)
static int hostUnmount(struct fuse *fuse, char *mountpoint)
{
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
if (0 == mountpoint)
return 0;
// darwin,freebsd: unmount is available to non-root
// darwin,freebsd,netbsd: unmount is available to non-root
// openbsd: kern.usermount has been removed and mount/unmount is available to root only
return 0 == unmount(mountpoint, MNT_FORCE);
#elif defined(__linux__)
Expand Down
2 changes: 1 addition & 1 deletion fuse/host_unix_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build darwin freebsd openbsd linux
// +build darwin freebsd netbsd openbsd linux

/*
* host_unix_test.go
Expand Down

0 comments on commit 3bc5ead

Please sign in to comment.