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.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. )
  9. type FileNode struct {
  10. NodeBase
  11. file FsFile
  12. }
  13. func newFileNode(fs *Fuse, file FsFile) *FileNode {
  14. return &FileNode{
  15. NodeBase: NodeBase{fs: fs},
  16. file: file,
  17. }
  18. }
  19. func (n *FileNode) Getattr(ctx context.Context, f fusefs.FileHandle, out *fuse.AttrOut) syscall.Errno {
  20. n.fs.fillAttrOut(n.file, out)
  21. return 0
  22. }
  23. func (n *FileNode) Setattr(ctx context.Context, f fusefs.FileHandle, in *fuse.SetAttrIn, out *fuse.AttrOut) (errno syscall.Errno) {
  24. n.fs.fillAttrOut(n.file, out)
  25. size, ok := in.GetSize()
  26. if ok {
  27. err := n.file.Truncate(size)
  28. if err != nil {
  29. return translateError(err)
  30. }
  31. out.Size = size
  32. }
  33. modTime, ok := in.GetMTime()
  34. if ok {
  35. err := n.file.SetModTime(modTime)
  36. if err != nil {
  37. return translateError(err)
  38. }
  39. out.Mtime = uint64(modTime.Unix())
  40. out.Mtimensec = uint32(modTime.Nanosecond())
  41. }
  42. return 0
  43. }
  44. var _ = (fusefs.NodeSetattrer)((*FileNode)(nil))
  45. func (n *FileNode) Open(ctx context.Context, flags uint32) (fh fusefs.FileHandle, fuseFlags uint32, errno syscall.Errno) {
  46. // 只支持以下标志:
  47. // os.O_RDONLY
  48. // os.O_WRONLY
  49. // os.O_RDWR
  50. // os.O_APPEND
  51. // os.O_TRUNC
  52. // os.O_SYNC
  53. // 忽略其他标志位
  54. hd, err := n.file.Open(flags)
  55. if err != nil {
  56. return nil, 0, translateError(err)
  57. }
  58. return newFileHandle(hd), 0, 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))

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