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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. log := logger.WithField("F", "FileNode.Setattr")
  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. log.Warnf("truncate: %v", err)
  33. return translateError(err)
  34. }
  35. out.Size = size
  36. }
  37. modTime, ok := in.GetMTime()
  38. if ok {
  39. err := n.file.SetModTime(modTime)
  40. if err != nil {
  41. log.Warnf("set mod time: %v", err)
  42. return translateError(err)
  43. }
  44. out.Mtime = uint64(modTime.Unix())
  45. out.Mtimensec = uint32(modTime.Nanosecond())
  46. }
  47. return 0
  48. }
  49. var _ = (fusefs.NodeSetattrer)((*FileNode)(nil))
  50. func (n *FileNode) Open(ctx context.Context, flags uint32) (fh fusefs.FileHandle, fuseFlags uint32, errno syscall.Errno) {
  51. log := logger.WithField("F", "FileNode.Open")
  52. log.Tracef("args: %v", flags)
  53. hd, flags, err := n.file.Open(flags)
  54. if err != nil {
  55. log.Warnf("open: %v", err)
  56. return nil, 0, translateError(err)
  57. }
  58. return newFileHandle(hd), flags, 0
  59. }
  60. var _ = (fusefs.NodeOpener)((*FileNode)(nil))
  61. func (n *FileNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (inode *fusefs.Inode, errno syscall.Errno) {
  62. return nil, syscall.ENOTDIR
  63. }
  64. var _ = (fusefs.NodeLookuper)((*FileNode)(nil))
  65. func (n *FileNode) Opendir(ctx context.Context) syscall.Errno {
  66. return syscall.ENOTDIR
  67. }
  68. var _ = (fusefs.NodeOpendirer)((*FileNode)(nil))
  69. func (n *FileNode) Readdir(ctx context.Context) (ds fusefs.DirStream, errno syscall.Errno) {
  70. return nil, syscall.ENOTDIR
  71. }
  72. var _ = (fusefs.NodeReaddirer)((*FileNode)(nil))
  73. func (n *FileNode) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.EntryOut) (inode *fusefs.Inode, errno syscall.Errno) {
  74. return nil, syscall.ENOTDIR
  75. }
  76. var _ = (fusefs.NodeMkdirer)((*FileNode)(nil))
  77. 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) {
  78. return nil, nil, 0, syscall.ENOTDIR
  79. }
  80. var _ = (fusefs.NodeCreater)((*FileNode)(nil))
  81. func (n *FileNode) Unlink(ctx context.Context, name string) (errno syscall.Errno) {
  82. return syscall.ENOTDIR
  83. }
  84. var _ = (fusefs.NodeUnlinker)((*FileNode)(nil))
  85. func (n *FileNode) Rmdir(ctx context.Context, name string) (errno syscall.Errno) {
  86. return syscall.ENOTDIR
  87. }
  88. var _ = (fusefs.NodeRmdirer)((*FileNode)(nil))
  89. func (n *FileNode) Rename(ctx context.Context, oldName string, newParent fusefs.InodeEmbedder, newName string, flags uint32) (errno syscall.Errno) {
  90. return syscall.ENOTDIR
  91. }
  92. var _ = (fusefs.NodeRenamer)((*FileNode)(nil))

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