From db43bfc4c03b37b8b91bef413f4a75e8d769dc15 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sat, 28 Dec 2019 20:44:12 +0100 Subject: main: detect fusermount3 and don't add `nonempty` fusermount3 (i.e. fusermount from libfuse 3.x) has dropped the `nonempty` option. Detect fusermount3 and don't add `nonempty` in this case. Fixes https://github.com/rfjakob/gocryptfs/pull/440 --- mount.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/mount.go b/mount.go index 446708e..61e2673 100644 --- a/mount.go +++ b/mount.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "encoding/json" "fmt" "log" @@ -362,7 +363,9 @@ func initGoFuse(fs pathfs.FileSystem, args *argContainer) *fuse.Server { tlog.Info.Printf(tlog.ColorYellow + "THE OPTION \"-forcedecode\" IS ACTIVE. GOCRYPTFS WILL RETURN CORRUPT DATA!" + tlog.ColorReset) } - if args.nonempty { + // fusermount from libfuse 3.x removed the "nonempty" option and exits + // with an error if it sees it. Only add it to the options on libfuse 2.x. + if args.nonempty && haveFusermount2() { mOpts.Options = append(mOpts.Options, "nonempty") } // Set values shown in "df -T" and friends @@ -436,6 +439,25 @@ func initGoFuse(fs pathfs.FileSystem, args *argContainer) *fuse.Server { return srv } +// haveFusermount2 finds out if the "fusermount" binary is from libfuse 2.x. +func haveFusermount2() bool { + cmd := exec.Command("/bin/fusermount", "-V") + var out bytes.Buffer + cmd.Stdout = &out + err := cmd.Run() + if err != nil { + tlog.Warn.Printf("warning: haveFusermount2: %v", err) + return false + } + // libfuse 2: fusermount version: 2.9.9 + // libfuse 3: fusermount3 version: 3.9.0 + v := out.String() + if strings.HasPrefix(v, "fusermount version") { + return true + } + return false +} + func handleSigint(srv *fuse.Server, mountpoint string) { ch := make(chan os.Signal, 1) signal.Notify(ch, os.Interrupt) -- cgit v1.2.3