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.

vfs.go 1.9 kB

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

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