Add support for MacFuse >= 4.0 (#103)

Older `osxfuse` is unavailable for ARM-based MacOS

Co-authored-by: Vitaliy Filippov <vitalif@yourcmc.ru>
geesefs-0-30-9
Vitaliy Filippov 2021-08-18 09:55:49 +03:00 committed by GitHub
parent 7782064498
commit 10d864429b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 5 deletions

View File

@ -37,16 +37,29 @@ type osxfuseInstallation struct {
// Environment variable used to pass the path to the executable calling the // Environment variable used to pass the path to the executable calling the
// mount helper. // mount helper.
DaemonVar string DaemonVar string
// Environment variable used to pass the "called by library" flag.
LibVar string
} }
var ( var (
osxfuseInstallations = []osxfuseInstallation{ osxfuseInstallations = []osxfuseInstallation{
// v4
{
DevicePrefix: "/dev/macfuse",
Load: "/Library/Filesystems/macfuse.fs/Contents/Resources/load_macfuse",
Mount: "/Library/Filesystems/macfuse.fs/Contents/Resources/mount_macfuse",
DaemonVar: "_FUSE_DAEMON_PATH",
LibVar: "_FUSE_CALL_BY_LIB",
},
// v3 // v3
{ {
DevicePrefix: "/dev/osxfuse", DevicePrefix: "/dev/osxfuse",
Load: "/Library/Filesystems/osxfuse.fs/Contents/Resources/load_osxfuse", Load: "/Library/Filesystems/osxfuse.fs/Contents/Resources/load_osxfuse",
Mount: "/Library/Filesystems/osxfuse.fs/Contents/Resources/mount_osxfuse", Mount: "/Library/Filesystems/osxfuse.fs/Contents/Resources/mount_osxfuse",
DaemonVar: "MOUNT_OSXFUSE_DAEMON_PATH", DaemonVar: "MOUNT_OSXFUSE_DAEMON_PATH",
LibVar: "MOUNT_OSXFUSE_CALL_BY_LIB",
}, },
// v2 // v2
@ -55,6 +68,7 @@ var (
Load: "/Library/Filesystems/osxfusefs.fs/Support/load_osxfusefs", Load: "/Library/Filesystems/osxfusefs.fs/Support/load_osxfusefs",
Mount: "/Library/Filesystems/osxfusefs.fs/Support/mount_osxfusefs", Mount: "/Library/Filesystems/osxfusefs.fs/Support/mount_osxfusefs",
DaemonVar: "MOUNT_FUSEFS_DAEMON_PATH", DaemonVar: "MOUNT_FUSEFS_DAEMON_PATH",
LibVar: "MOUNT_FUSEFS_CALL_BY_LIB",
}, },
} }
) )
@ -95,6 +109,7 @@ func openOSXFUSEDev(devPrefix string) (dev *os.File, err error) {
func callMount( func callMount(
bin string, bin string,
daemonVar string, daemonVar string,
libVar string,
dir string, dir string,
cfg *MountConfig, cfg *MountConfig,
dev *os.File, dev *os.File,
@ -127,10 +142,7 @@ func callMount(
) )
cmd.ExtraFiles = []*os.File{dev} cmd.ExtraFiles = []*os.File{dev}
cmd.Env = os.Environ() cmd.Env = os.Environ()
// OSXFUSE <3.3.0 cmd.Env = append(cmd.Env, libVar+"=")
cmd.Env = append(cmd.Env, "MOUNT_FUSEFS_CALL_BY_LIB=")
// OSXFUSE >=3.3.0
cmd.Env = append(cmd.Env, "MOUNT_OSXFUSE_CALL_BY_LIB=")
daemon := os.Args[0] daemon := os.Args[0]
if daemonVar != "" { if daemonVar != "" {
@ -197,7 +209,7 @@ func mount(
} }
// Call the mount binary with the device. // Call the mount binary with the device.
if err := callMount(loc.Mount, loc.DaemonVar, dir, cfg, dev, ready); err != nil { if err := callMount(loc.Mount, loc.DaemonVar, loc.LibVar, dir, cfg, dev, ready); err != nil {
dev.Close() dev.Close()
return nil, fmt.Errorf("callMount: %v", err) return nil, fmt.Errorf("callMount: %v", err)
} }