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

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

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