2021-09-09 12:25:25 +00:00
|
|
|
//go:build linux || freebsd
|
2021-02-03 17:46:08 +00:00
|
|
|
// +build linux freebsd
|
2016-07-17 22:03:23 +00:00
|
|
|
|
2022-08-28 11:21:57 +00:00
|
|
|
// Package mount implements a FUSE mounting system for rclone remotes.
|
2016-07-17 22:03:23 +00:00
|
|
|
package mount
|
|
|
|
|
|
|
|
import (
|
2018-07-18 15:21:35 +00:00
|
|
|
"fmt"
|
2020-07-24 14:41:31 +00:00
|
|
|
"runtime"
|
2016-09-09 07:39:19 +00:00
|
|
|
|
2016-07-17 22:03:23 +00:00
|
|
|
"bazil.org/fuse"
|
2017-05-02 21:35:07 +00:00
|
|
|
fusefs "bazil.org/fuse/fs"
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/cmd/mountlib"
|
|
|
|
"github.com/rclone/rclone/fs"
|
|
|
|
"github.com/rclone/rclone/vfs"
|
2016-07-17 22:03:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2020-07-23 12:08:38 +00:00
|
|
|
mountlib.NewMountCommand("mount", false, mount)
|
2020-04-25 05:03:07 +00:00
|
|
|
mountlib.AddRc("mount", mount)
|
2016-07-17 22:03:23 +00:00
|
|
|
}
|
|
|
|
|
2017-05-02 21:35:07 +00:00
|
|
|
// mountOptions configures the options from the command line flags
|
2020-07-23 16:17:01 +00:00
|
|
|
func mountOptions(VFS *vfs.VFS, device string, opt *mountlib.Options) (options []fuse.MountOption) {
|
2017-05-02 21:35:07 +00:00
|
|
|
options = []fuse.MountOption{
|
2020-07-23 16:17:01 +00:00
|
|
|
fuse.MaxReadahead(uint32(opt.MaxReadAhead)),
|
2017-05-02 21:35:07 +00:00
|
|
|
fuse.Subtype("rclone"),
|
2018-05-03 08:45:24 +00:00
|
|
|
fuse.FSName(device),
|
2017-05-02 21:35:07 +00:00
|
|
|
|
|
|
|
// Options from benchmarking in the fuse module
|
|
|
|
//fuse.MaxReadahead(64 * 1024 * 1024),
|
|
|
|
//fuse.WritebackCache(),
|
|
|
|
}
|
2020-07-23 16:17:01 +00:00
|
|
|
if opt.AsyncRead {
|
2020-02-04 10:21:07 +00:00
|
|
|
options = append(options, fuse.AsyncRead())
|
|
|
|
}
|
2020-07-23 16:17:01 +00:00
|
|
|
if opt.AllowOther {
|
2017-05-02 21:35:07 +00:00
|
|
|
options = append(options, fuse.AllowOther())
|
|
|
|
}
|
2020-07-23 16:17:01 +00:00
|
|
|
if opt.AllowRoot {
|
2020-02-25 14:21:03 +00:00
|
|
|
// options = append(options, fuse.AllowRoot())
|
|
|
|
fs.Errorf(nil, "Ignoring --allow-root. Support has been removed upstream - see https://github.com/bazil/fuse/issues/144 for more info")
|
2017-05-02 21:35:07 +00:00
|
|
|
}
|
2020-07-23 16:17:01 +00:00
|
|
|
if opt.DefaultPermissions {
|
2017-05-02 21:35:07 +00:00
|
|
|
options = append(options, fuse.DefaultPermissions())
|
|
|
|
}
|
2020-07-22 16:58:49 +00:00
|
|
|
if VFS.Opt.ReadOnly {
|
2017-05-02 21:35:07 +00:00
|
|
|
options = append(options, fuse.ReadOnly())
|
|
|
|
}
|
2020-07-23 16:17:01 +00:00
|
|
|
if opt.WritebackCache {
|
2017-05-02 21:35:07 +00:00
|
|
|
options = append(options, fuse.WritebackCache())
|
|
|
|
}
|
2020-07-23 16:17:01 +00:00
|
|
|
if opt.DaemonTimeout != 0 {
|
|
|
|
options = append(options, fuse.DaemonTimeout(fmt.Sprint(int(opt.DaemonTimeout.Seconds()))))
|
2018-07-18 15:21:35 +00:00
|
|
|
}
|
2020-07-23 16:17:01 +00:00
|
|
|
if len(opt.ExtraOptions) > 0 {
|
2017-06-19 12:44:49 +00:00
|
|
|
fs.Errorf(nil, "-o/--option not supported with this FUSE backend")
|
|
|
|
}
|
2020-07-23 16:17:01 +00:00
|
|
|
if len(opt.ExtraFlags) > 0 {
|
2017-06-19 12:44:49 +00:00
|
|
|
fs.Errorf(nil, "--fuse-flag not supported with this FUSE backend")
|
|
|
|
}
|
2017-05-02 21:35:07 +00:00
|
|
|
return options
|
|
|
|
}
|
|
|
|
|
|
|
|
// mount the file system
|
|
|
|
//
|
|
|
|
// The mount point will be ready when this returns.
|
|
|
|
//
|
|
|
|
// returns an error, and an error channel for the serve process to
|
|
|
|
// report an error when fusermount is called.
|
2020-07-23 16:17:01 +00:00
|
|
|
func mount(VFS *vfs.VFS, mountpoint string, opt *mountlib.Options) (<-chan error, func() error, error) {
|
2022-06-11 14:18:48 +00:00
|
|
|
f := VFS.Fs()
|
2020-07-24 14:41:31 +00:00
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
fs.Logf(nil, "macOS users: please try \"rclone cmount\" as it will be the default in v1.54")
|
|
|
|
}
|
2022-06-11 14:18:48 +00:00
|
|
|
if err := mountlib.CheckOverlap(f, mountpoint); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
if err := mountlib.CheckAllowNonEmpty(mountpoint, opt); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
fs.Debugf(f, "Mounting on %q", mountpoint)
|
2020-07-24 14:41:31 +00:00
|
|
|
|
2020-07-23 16:17:01 +00:00
|
|
|
if opt.DebugFUSE {
|
2020-07-23 12:08:38 +00:00
|
|
|
fuse.Debug = func(msg interface{}) {
|
|
|
|
fs.Debugf("fuse", "%v", msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-09 11:56:43 +00:00
|
|
|
c, err := fuse.Mount(mountpoint, mountOptions(VFS, opt.DeviceName, opt)...)
|
2017-05-02 21:35:07 +00:00
|
|
|
if err != nil {
|
2020-07-22 16:58:49 +00:00
|
|
|
return nil, nil, err
|
2017-05-02 21:35:07 +00:00
|
|
|
}
|
|
|
|
|
2020-07-23 16:17:01 +00:00
|
|
|
filesys := NewFS(VFS, opt)
|
2021-03-16 13:23:36 +00:00
|
|
|
filesys.server = fusefs.New(c, nil)
|
2017-05-02 21:35:07 +00:00
|
|
|
|
|
|
|
// Serve the mount point in the background returning error to errChan
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
go func() {
|
2021-03-16 13:23:36 +00:00
|
|
|
err := filesys.server.Serve(filesys)
|
2017-05-02 21:35:07 +00:00
|
|
|
closeErr := c.Close()
|
|
|
|
if err == nil {
|
|
|
|
err = closeErr
|
|
|
|
}
|
|
|
|
errChan <- err
|
|
|
|
}()
|
|
|
|
|
|
|
|
unmount := func() error {
|
2017-11-07 18:03:23 +00:00
|
|
|
// Shutdown the VFS
|
|
|
|
filesys.VFS.Shutdown()
|
2017-05-02 21:35:07 +00:00
|
|
|
return fuse.Unmount(mountpoint)
|
|
|
|
}
|
|
|
|
|
2020-07-22 16:58:49 +00:00
|
|
|
return errChan, unmount, nil
|
2017-05-02 21:35:07 +00:00
|
|
|
}
|