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.go 1.7 kB

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

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