nfsmount: fix mount_nfs options incompatible with OpenBSD - fixes #8578

nfsmount built its mount options for GNU/Linux syntax unconditionally:
"-o port=N", "-o mountport=N" and "-o tcp". OpenBSD's mount_nfs(8)
rejects "-o mountport" outright ("option not supported", per the
reporter's log) and has no "tcp" suboption either, since it selects
TCP with the separate "-T" flag instead of an -o suboption.

Add a runtime.GOOS == "openbsd" branch that builds the option list
OpenBSD's mount_nfs actually accepts: "-o port=N" plus "-T" for TCP,
with no mountport option since OpenBSD's mountd is located via
portmap rather than a fixed, settable port. This follows the same
GOOS-branching pattern already used in this file's unmount function
(darwin) and in cmd/cmount/mount.go for openbsd/freebsd differences.

FreeBSD's mount_nfs(8) documents "port=", "mountport=" and "tcp" as
-o suboptions identical to Linux, so the existing option set is left
unchanged for freebsd and all other platforms.

Verified by cross-compiling (go build and go vet) for GOOS=openbsd,
freebsd, linux and darwin, all of which succeed. Actually mounting
via mount_nfs on OpenBSD needs a BSD machine to confirm at runtime,
which wasn't available here.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Socialpranker
2026-07-30 19:54:16 +01:00
committed by Nick Craig-Wood
co-authored by Claude Opus 4.8
parent be6c689a68
commit 47fb3c7156
+19 -4
View File
@@ -55,10 +55,25 @@ func mount(VFS *vfs.VFS, mountpoint string, opt *mountlib.Options) (asyncerrors
}
// Options
options := []string{
"-o", fmt.Sprintf("port=%s", port),
"-o", fmt.Sprintf("mountport=%s", port),
"-o", "tcp",
//
// OpenBSD's mount_nfs(8) doesn't understand "-o mountport=" or "-o
// tcp" - the mountd port isn't settable that way and TCP is
// requested with the "-T" flag instead, so build a different set of
// options there. FreeBSD's mount_nfs(8) accepts the same "-o
// port=", "-o mountport=" and "-o tcp" options as Linux so it uses
// the common case.
var options []string
if runtime.GOOS == "openbsd" {
options = []string{
"-o", fmt.Sprintf("port=%s", port),
"-T",
}
} else {
options = []string{
"-o", fmt.Sprintf("port=%s", port),
"-o", fmt.Sprintf("mountport=%s", port),
"-o", "tcp",
}
}
for _, option := range opt.ExtraOptions {
options = append(options, "-o", option)