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.

file_node.go 3.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //go:build linux || (darwin && amd64)
  2. package fuse
  3. import (
  4. "context"
  5. "syscall"
  6. fusefs "github.com/hanwen/go-fuse/v2/fs"
  7. "github.com/hanwen/go-fuse/v2/fuse"
  8. "gitlink.org.cn/cloudream/common/pkgs/logger"
  9. )
  10. type FileNode struct {
  11. NodeBase
  12. file FsFile
  13. }
  14. func newFileNode(fs *Fuse, file FsFile) *FileNode {
  15. return &FileNode{
  16. NodeBase: NodeBase{fs: fs},
  17. file: file,
  18. }
  19. }
  20. func (n *FileNode) Getattr(ctx context.Context, f fusefs.FileHandle, out *fuse.AttrOut) syscall.Errno {
  21. logger.Tracef("FileNode.Getattr: %v", n.file.Name())
  22. n.fs.fillAttrOut(n.file, out)
  23. return 0
  24. }
  25. func (n *FileNode) Setattr(ctx context.Context, f fusefs.FileHandle, in *fuse.SetAttrIn, out *fuse.AttrOut) (errno syscall.Errno) {
  26. logger.Tracef("FileNode.Setattr: %v", n.file.Name())
  27. n.fs.fillAttrOut(n.file, out)
  28. size, ok := in.GetSize()
  29. if ok {
  30. err := n.file.Truncate(size)
  31. if err != nil {
  32. return translateError(err)
  33. }
  34. out.Size = size
  35. }
  36. modTime, ok := in.GetMTime()
  37. if ok {
  38. err := n.file.SetModTime(modTime)
  39. if err != nil {
  40. return translateError(err)
  41. }
  42. out.Mtime = uint64(modTime.Unix())
  43. out.Mtimensec = uint32(modTime.Nanosecond())
  44. }
  45. return 0
  46. }
  47. var _ = (fusefs.NodeSetattrer)((*FileNode)(nil))
  48. func (n *FileNode) Open(ctx context.Context, flags uint32) (fh fusefs.FileHandle, fuseFlags uint32, errno syscall.Errno) {
  49. logger.Tracef("FileNode.Open: %v, %#o", n.file.Name(), flags)
  50. // 只支持以下标志:
  51. // os.O_RDONLY
  52. // os.O_WRONLY
  53. // os.O_RDWR
  54. // os.O_APPEND
  55. // os.O_TRUNC
  56. // os.O_SYNC
  57. // 忽略其他标志位
  58. hd, err := n.file.Open(flags)
  59. if err != nil {
  60. return nil, 0, translateError(err)
  61. }
  62. return newFileHandle(hd), 0, 0
  63. }
  64. var _ = (fusefs.NodeOpener)((*FileNode)(nil))
  65. func (n *FileNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (inode *fusefs.Inode, errno syscall.Errno) {
  66. return nil, syscall.ENOTDIR
  67. }
  68. var _ = (fusefs.NodeLookuper)((*FileNode)(nil))
  69. func (n *FileNode) Opendir(ctx context.Context) syscall.Errno {
  70. return syscall.ENOTDIR
  71. }
  72. var _ = (fusefs.NodeOpendirer)((*FileNode)(nil))
  73. func (n *FileNode) Readdir(ctx context.Context) (ds fusefs.DirStream, errno syscall.Errno) {
  74. return nil, syscall.ENOTDIR
  75. }
  76. var _ = (fusefs.NodeReaddirer)((*FileNode)(nil))
  77. func (n *FileNode) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.EntryOut) (inode *fusefs.Inode, errno syscall.Errno) {
  78. return nil, syscall.ENOTDIR
  79. }
  80. var _ = (fusefs.NodeMkdirer)((*FileNode)(nil))
  81. func (n *FileNode) Create(ctx context.Context, name string, flags uint32, mode uint32, out *fuse.EntryOut) (node *fusefs.Inode, fh fusefs.FileHandle, fuseFlags uint32, errno syscall.Errno) {
  82. return nil, nil, 0, syscall.ENOTDIR
  83. }
  84. var _ = (fusefs.NodeCreater)((*FileNode)(nil))
  85. func (n *FileNode) Unlink(ctx context.Context, name string) (errno syscall.Errno) {
  86. return syscall.ENOTDIR
  87. }
  88. var _ = (fusefs.NodeUnlinker)((*FileNode)(nil))
  89. func (n *FileNode) Rmdir(ctx context.Context, name string) (errno syscall.Errno) {
  90. return syscall.ENOTDIR
  91. }
  92. var _ = (fusefs.NodeRmdirer)((*FileNode)(nil))
  93. func (n *FileNode) Rename(ctx context.Context, oldName string, newParent fusefs.InodeEmbedder, newName string, flags uint32) (errno syscall.Errno) {
  94. return syscall.ENOTDIR
  95. }
  96. var _ = (fusefs.NodeRenamer)((*FileNode)(nil))

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