| 1 | // Mount/unmount helpers for the /mfs FUSE mount. go-fuse only builds on linux, darwin, and freebsd. |
| 2 | //go:build (linux || darwin || freebsd) && !nofuse |
| 3 | |
| 4 | package mfs |
| 5 | |
| 6 | import ( |
| 7 | "os" |
| 8 | "time" |
| 9 | |
| 10 | "github.com/hanwen/go-fuse/v2/fs" |
| 11 | "github.com/hanwen/go-fuse/v2/fuse" |
| 12 | "github.com/ipfs/kubo/config" |
| 13 | core "github.com/ipfs/kubo/core" |
| 14 | fusemnt "github.com/ipfs/kubo/fuse/mount" |
| 15 | ) |
| 16 | |
| 17 | // How long the kernel caches Lookup and Getattr results. 1 second |
| 18 | // matches the go-fuse default and what gocryptfs/rclone use. |
| 19 | // var (not const) because fs.Options needs a *time.Duration. |
| 20 | var mutableCacheTime = time.Second |
| 21 | |
| 22 | // Mount mounts MFS at a given location, and returns a mount.Mount instance. |
| 23 | func Mount(ipfs *core.IpfsNode, mountpoint string) (fusemnt.Mount, error) { |
| 24 | cfg, err := ipfs.Repo.Config() |
| 25 | if err != nil { |
| 26 | return nil, err |
| 27 | } |
| 28 | root := NewFileSystem(ipfs, cfg.Mounts, cfg.Import) |
| 29 | opts := &fs.Options{ |
| 30 | NullPermissions: true, |
| 31 | UID: uint32(os.Getuid()), |
| 32 | GID: uint32(os.Getgid()), |
| 33 | EntryTimeout: &mutableCacheTime, |
| 34 | AttrTimeout: &mutableCacheTime, |
| 35 | MountOptions: fuse.MountOptions{ |
| 36 | AllowOther: cfg.Mounts.FuseAllowOther.WithDefault(config.DefaultFuseAllowOther), |
| 37 | FsName: "mfs", |
| 38 | MaxReadAhead: fusemnt.MaxReadAhead, |
| 39 | Debug: os.Getenv("IPFS_FUSE_DEBUG") != "", |
| 40 | ExtraCapabilities: fusemnt.WritableMountCapabilities, |
| 41 | }, |
| 42 | } |
| 43 | return fusemnt.NewMount(root, mountpoint, opts) |
| 44 | } |