You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
2.3 KiB

5 years ago
5 years ago
5 years ago
  1. package filesys
  2. import (
  3. "context"
  4. "github.com/seaweedfs/fuse"
  5. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  6. "github.com/chrislusf/seaweedfs/weed/util"
  7. )
  8. func getxattr(entry *filer_pb.Entry, req *fuse.GetxattrRequest, resp *fuse.GetxattrResponse) error {
  9. if entry == nil {
  10. return fuse.ErrNoXattr
  11. }
  12. if entry.Extended == nil {
  13. return fuse.ErrNoXattr
  14. }
  15. data, found := entry.Extended[req.Name]
  16. if !found {
  17. return fuse.ErrNoXattr
  18. }
  19. if req.Position < uint32(len(data)) {
  20. size := req.Size
  21. if req.Position+size >= uint32(len(data)) {
  22. size = uint32(len(data)) - req.Position
  23. }
  24. if size == 0 {
  25. resp.Xattr = data[req.Position:]
  26. } else {
  27. resp.Xattr = data[req.Position : req.Position+size]
  28. }
  29. }
  30. return nil
  31. }
  32. func setxattr(entry *filer_pb.Entry, req *fuse.SetxattrRequest) error {
  33. if entry == nil {
  34. return fuse.EIO
  35. }
  36. if entry.Extended == nil {
  37. entry.Extended = make(map[string][]byte)
  38. }
  39. data, _ := entry.Extended[req.Name]
  40. newData := make([]byte, int(req.Position)+len(req.Xattr))
  41. copy(newData, data)
  42. copy(newData[int(req.Position):], req.Xattr)
  43. entry.Extended[req.Name] = newData
  44. return nil
  45. }
  46. func removexattr(entry *filer_pb.Entry, req *fuse.RemovexattrRequest) error {
  47. if entry == nil {
  48. return fuse.ErrNoXattr
  49. }
  50. if entry.Extended == nil {
  51. return fuse.ErrNoXattr
  52. }
  53. _, found := entry.Extended[req.Name]
  54. if !found {
  55. return fuse.ErrNoXattr
  56. }
  57. delete(entry.Extended, req.Name)
  58. return nil
  59. }
  60. func listxattr(entry *filer_pb.Entry, req *fuse.ListxattrRequest, resp *fuse.ListxattrResponse) error {
  61. if entry == nil {
  62. return fuse.EIO
  63. }
  64. for k := range entry.Extended {
  65. resp.Append(k)
  66. }
  67. size := req.Size
  68. if req.Position+size >= uint32(len(resp.Xattr)) {
  69. size = uint32(len(resp.Xattr)) - req.Position
  70. }
  71. if size == 0 {
  72. resp.Xattr = resp.Xattr[req.Position:]
  73. } else {
  74. resp.Xattr = resp.Xattr[req.Position : req.Position+size]
  75. }
  76. return nil
  77. }
  78. func (wfs *WFS) maybeLoadEntry(dir, name string) (entry *filer_pb.Entry, err error) {
  79. fullpath := util.NewFullPath(dir, name)
  80. // glog.V(3).Infof("read entry cache miss %s", fullpath)
  81. // read from async meta cache
  82. cachedEntry, cacheErr := wfs.metaCache.FindEntry(context.Background(), fullpath)
  83. if cacheErr == filer_pb.ErrNotFound {
  84. return nil, fuse.ENOENT
  85. }
  86. return cachedEntry.ToProtoEntry(), nil
  87. }