From fdce6dd4667c670e5a229a64eb6ff4738bea5114 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 1 Sep 2020 13:49:56 +0100 Subject: [PATCH] cmount: make work under OpenBSD - fixes #1727 --- cmd/cmount/fs.go | 9 ++++++++- cmd/cmount/mount.go | 18 ++++++++++-------- cmd/cmount/mount_test.go | 2 +- cmd/cmount/mount_unsupported.go | 2 +- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/cmd/cmount/fs.go b/cmd/cmount/fs.go index 0dcde3289..47d23df41 100644 --- a/cmd/cmount/fs.go +++ b/cmd/cmount/fs.go @@ -1,4 +1,4 @@ -//go:build cmount && ((linux && cgo) || (darwin && cgo) || (freebsd && cgo) || windows) +//go:build cmount && ((linux && cgo) || (darwin && cgo) || (freebsd && cgo) || (openbsd && cgo) || windows) package cmount @@ -6,6 +6,7 @@ import ( "io" "os" "path" + "runtime" "strings" "sync" "sync/atomic" @@ -210,6 +211,12 @@ func (fsys *FS) Readdir(dirPath string, // We can't seek in directories and FUSE should know that so // return an error if ofst is ever set. if ofst > 0 { + // However openbsd doesn't seem to know this - perhaps a bug in its + // FUSE implementation or a bug in cgofuse? + // See: https://github.com/billziss-gh/cgofuse/issues/49 + if runtime.GOOS == "openbsd" { + return 0 + } return -fuse.ESPIPE } diff --git a/cmd/cmount/mount.go b/cmd/cmount/mount.go index 9bb1ab490..5b23a829e 100644 --- a/cmd/cmount/mount.go +++ b/cmd/cmount/mount.go @@ -1,4 +1,4 @@ -//go:build cmount && ((linux && cgo) || (darwin && cgo) || (freebsd && cgo) || windows) +//go:build cmount && ((linux && cgo) || (darwin && cgo) || (freebsd && cgo) || (openbsd && cgo) || windows) // Package cmount implements a FUSE mounting system for rclone remotes. // @@ -8,9 +8,9 @@ package cmount import ( "errors" "fmt" - "strings" "os" "runtime" + "strings" "time" "github.com/rclone/rclone/cmd/mountlib" @@ -59,12 +59,14 @@ func mountOptions(VFS *vfs.VFS, device string, mountpoint string, opt *mountlib. } else { options = append(options, "-o", "fsname="+device) options = append(options, "-o", "subtype=rclone") - options = append(options, "-o", fmt.Sprintf("max_readahead=%d", opt.MaxReadAhead)) - // This causes FUSE to supply O_TRUNC with the Open - // call which is more efficient for cmount. However - // it does not work with cgofuse on Windows with - // WinFSP so cmount must work with or without it. - options = append(options, "-o", "atomic_o_trunc") + if runtime.GOOS != "openbsd" { + options = append(options, "-o", fmt.Sprintf("max_readahead=%d", opt.MaxReadAhead)) + // This causes FUSE to supply O_TRUNC with the Open + // call which is more efficient for cmount. However + // it does not work with cgofuse on Windows with + // WinFSP so cmount must work with or without it. + options = append(options, "-o", "atomic_o_trunc") + } if opt.DaemonTimeout != 0 { options = append(options, "-o", fmt.Sprintf("daemon_timeout=%d", int(time.Duration(opt.DaemonTimeout).Seconds()))) } diff --git a/cmd/cmount/mount_test.go b/cmd/cmount/mount_test.go index e0cc1c4ca..65fb1a97c 100644 --- a/cmd/cmount/mount_test.go +++ b/cmd/cmount/mount_test.go @@ -1,4 +1,4 @@ -//go:build cmount && ((linux && cgo) || (darwin && cgo) || (freebsd && cgo) || windows) && (!race || !windows) +//go:build cmount && ((linux && cgo) || (darwin && cgo) || (freebsd && cgo) || (openbsd && cgo) || windows) && (!race || !windows) // Package cmount implements a FUSE mounting system for rclone remotes. // diff --git a/cmd/cmount/mount_unsupported.go b/cmd/cmount/mount_unsupported.go index 6677132d7..816900f3f 100644 --- a/cmd/cmount/mount_unsupported.go +++ b/cmd/cmount/mount_unsupported.go @@ -1,4 +1,4 @@ -//go:build !((linux && cgo && cmount) || (darwin && cgo && cmount) || (freebsd && cgo && cmount) || (windows && cmount)) +//go:build !((linux && cgo && cmount) || (darwin && cgo && cmount) || (freebsd && cgo && cmount) || (openbsd && cgo && cmount) || (windows && cmount)) // Package cmount implements a FUSE mounting system for rclone remotes. //