| 1 | // Mount/unmount helpers for the /ipfs FUSE mount. go-fuse only builds on linux, darwin, and freebsd. |
| 2 | //go:build (linux || darwin || freebsd) && !nofuse |
| 3 | |
| 4 | package readonly |
| 5 | |
| 6 | import ( |
| 7 | "os" |
| 8 | |
| 9 | "github.com/hanwen/go-fuse/v2/fs" |
| 10 | "github.com/hanwen/go-fuse/v2/fuse" |
| 11 | "github.com/ipfs/kubo/config" |
| 12 | core "github.com/ipfs/kubo/core" |
| 13 | fusemnt "github.com/ipfs/kubo/fuse/mount" |
| 14 | ) |
| 15 | |
| 16 | // Mount mounts IPFS at a given location, and returns a mount.Mount instance. |
| 17 | func Mount(ipfs *core.IpfsNode, mountpoint string) (fusemnt.Mount, error) { |
| 18 | cfg, err := ipfs.Repo.Config() |
| 19 | if err != nil { |
| 20 | return nil, err |
| 21 | } |
| 22 | root := NewRoot(ipfs) |
| 23 | opts := &fs.Options{ |
| 24 | NullPermissions: true, |
| 25 | UID: uint32(os.Getuid()), |
| 26 | GID: uint32(os.Getgid()), |
| 27 | AttrTimeout: &immutableAttrCacheTime, |
| 28 | EntryTimeout: &immutableAttrCacheTime, |
| 29 | MountOptions: fuse.MountOptions{ |
| 30 | AllowOther: cfg.Mounts.FuseAllowOther.WithDefault(config.DefaultFuseAllowOther), |
| 31 | FsName: "ipfs", |
| 32 | MaxReadAhead: fusemnt.MaxReadAhead, |
| 33 | Debug: os.Getenv("IPFS_FUSE_DEBUG") != "", |
| 34 | }, |
| 35 | } |
| 36 | return fusemnt.NewMount(root, mountpoint, opts) |
| 37 | } |