You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mount_linux.go 1.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //go:build linux || (darwin && amd64)
  2. package mount
  3. import (
  4. fusefs "github.com/hanwen/go-fuse/v2/fs"
  5. "github.com/hanwen/go-fuse/v2/fuse"
  6. "gitlink.org.cn/cloudream/common/utils/sync2"
  7. db2 "gitlink.org.cn/cloudream/storage2/client/internal/db"
  8. "gitlink.org.cn/cloudream/storage2/client/internal/downloader"
  9. "gitlink.org.cn/cloudream/storage2/client/internal/mount/config"
  10. fuse2 "gitlink.org.cn/cloudream/storage2/client/internal/mount/fuse"
  11. "gitlink.org.cn/cloudream/storage2/client/internal/mount/vfs"
  12. "gitlink.org.cn/cloudream/storage2/client/internal/uploader"
  13. clitypes "gitlink.org.cn/cloudream/storage2/client/types"
  14. )
  15. type MountEvent interface {
  16. IsMountEvent() bool
  17. }
  18. type MountExitEvent struct {
  19. MountEvent
  20. }
  21. type MountingFailedEvent struct {
  22. MountEvent
  23. Err error
  24. }
  25. type Mount struct {
  26. cfg *config.Config
  27. vfs *vfs.Vfs
  28. fuse *fuse2.Fuse
  29. }
  30. func NewMount(cfg *config.Config, db *db2.DB, uploader *uploader.Uploader, downloader *downloader.Downloader) *Mount {
  31. vfs := vfs.NewVfs(cfg, db, uploader, downloader)
  32. fuse := fuse2.NewFuse(cfg, vfs)
  33. return &Mount{
  34. cfg: cfg,
  35. vfs: vfs,
  36. fuse: fuse,
  37. }
  38. }
  39. func (m *Mount) Start() *sync2.UnboundChannel[MountEvent] {
  40. ch := sync2.NewUnboundChannel[MountEvent]()
  41. m.vfs.Start()
  42. go func() {
  43. defer m.vfs.Stop()
  44. nodeFsOpt := &fusefs.Options{
  45. MountOptions: fuse.MountOptions{
  46. FsName: "CDS",
  47. // Debug: true,
  48. },
  49. }
  50. rawFs := fusefs.NewNodeFS(m.fuse.Root(), nodeFsOpt)
  51. svr, err := fuse.NewServer(rawFs, m.cfg.MountPoint, &nodeFsOpt.MountOptions)
  52. if err != nil {
  53. ch.Send(MountingFailedEvent{Err: err})
  54. return
  55. }
  56. svr.Serve()
  57. ch.Send(MountExitEvent{})
  58. }()
  59. return ch
  60. }
  61. func (m *Mount) NotifyObjectInvalid(obj clitypes.Object) {
  62. }
  63. func (m *Mount) NotifyPackageInvalid(pkg clitypes.Package) {
  64. }
  65. func (m *Mount) NotifyBucketInvalid(bkt clitypes.Bucket) {
  66. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。