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.

fuse.go 2.1 kB

8 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //go:build linux || (darwin && amd64)
  2. package fuse
  3. import (
  4. "os"
  5. "syscall"
  6. fusefs "github.com/hanwen/go-fuse/v2/fs"
  7. "github.com/hanwen/go-fuse/v2/fuse"
  8. "gitlink.org.cn/cloudream/storage2/client/internal/mount/config"
  9. )
  10. type Fuse struct {
  11. config *config.Config
  12. fs Fs
  13. }
  14. func NewFuse(config *config.Config, fs Fs) *Fuse {
  15. return &Fuse{
  16. config: config,
  17. fs: fs,
  18. }
  19. }
  20. func (v *Fuse) Root() fusefs.InodeEmbedder {
  21. return newDirNode(v, v.fs.Root())
  22. }
  23. func translateError(err error) syscall.Errno {
  24. switch err {
  25. case nil:
  26. return 0
  27. case ErrNotExists, os.ErrNotExist:
  28. return syscall.ENOENT
  29. case ErrExists, os.ErrExist:
  30. return syscall.EEXIST
  31. case ErrPermission, os.ErrPermission:
  32. return syscall.EACCES
  33. case ErrNotEmpty:
  34. return syscall.ENOTEMPTY
  35. case ErrIOError:
  36. return syscall.EIO
  37. case ErrNotSupported:
  38. return syscall.ENOTSUP
  39. default:
  40. return syscall.EIO
  41. }
  42. }
  43. // get the Mode from a fs Node
  44. func (v *Fuse) getMode(node FsEntry) uint32 {
  45. Mode := node.Mode().Perm()
  46. if node.IsDir() {
  47. Mode |= fuse.S_IFDIR
  48. } else {
  49. Mode |= fuse.S_IFREG
  50. }
  51. return uint32(Mode)
  52. }
  53. // fill in attr from node
  54. func (v *Fuse) fillAttr(node FsEntry, attr *fuse.Attr) {
  55. Size := uint64(node.Size())
  56. const BlockSize = 512
  57. Blocks := (Size + BlockSize - 1) / BlockSize
  58. attr.Owner.Gid = v.config.GID
  59. attr.Owner.Uid = v.config.UID
  60. attr.Mode = v.getMode(node)
  61. attr.Size = Size
  62. attr.Nlink = 1
  63. attr.Blocks = Blocks
  64. // attr.Blksize = BlockSize // not supported in freebsd/darwin, defaults to 4k if not set
  65. modTime := node.ModTime()
  66. attr.Atime = uint64(modTime.Unix())
  67. attr.Atimensec = uint32(modTime.Nanosecond())
  68. attr.Mtime = uint64(modTime.Unix())
  69. attr.Mtimensec = uint32(modTime.Nanosecond())
  70. attr.Ctime = uint64(modTime.Unix())
  71. attr.Ctimensec = uint32(modTime.Nanosecond())
  72. }
  73. func (v *Fuse) fillAttrOut(node FsEntry, out *fuse.AttrOut) {
  74. v.fillAttr(node, &out.Attr)
  75. out.SetTimeout(v.config.AttrTimeout)
  76. }
  77. func (v *Fuse) fillEntryOut(node FsEntry, out *fuse.EntryOut) {
  78. v.fillAttr(node, &out.Attr)
  79. out.SetAttrTimeout(v.config.AttrTimeout)
  80. out.SetEntryTimeout(v.config.AttrTimeout)
  81. }

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