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.

71 lines
2.1 KiB

  1. package mount
  2. import (
  3. "context"
  4. "github.com/chrislusf/seaweedfs/weed/filer"
  5. "github.com/chrislusf/seaweedfs/weed/filesys/meta_cache"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. "github.com/hanwen/go-fuse/v2/fuse"
  8. "math"
  9. )
  10. // Directory handling
  11. func (wfs *WFS) OpenDir(cancel <-chan struct{}, input *fuse.OpenIn, out *fuse.OpenOut) (code fuse.Status) {
  12. return fuse.OK
  13. }
  14. func (wfs *WFS) ReleaseDir(input *fuse.ReleaseIn) {
  15. }
  16. func (wfs *WFS) FsyncDir(cancel <-chan struct{}, input *fuse.FsyncIn) (code fuse.Status) {
  17. return fuse.OK
  18. }
  19. func (wfs *WFS) ReadDir(cancel <-chan struct{}, input *fuse.ReadIn, out *fuse.DirEntryList) (code fuse.Status) {
  20. return wfs.doReadDirectory(input, out, false)
  21. }
  22. func (wfs *WFS) ReadDirPlus(cancel <-chan struct{}, input *fuse.ReadIn, out *fuse.DirEntryList) (code fuse.Status) {
  23. return wfs.doReadDirectory(input, out, true)
  24. }
  25. func (wfs *WFS) doReadDirectory(input *fuse.ReadIn, out *fuse.DirEntryList, isPlusMode bool) fuse.Status {
  26. dirPath := wfs.inodeToPath.GetPath(input.NodeId)
  27. var dirEntry fuse.DirEntry
  28. processEachEntryFn := func(entry *filer.Entry, isLast bool) bool {
  29. dirEntry.Name = entry.Name()
  30. inode := wfs.inodeToPath.GetInode(dirPath.Child(dirEntry.Name))
  31. dirEntry.Ino = inode
  32. dirEntry.Mode = toSystemMode(entry.Mode)
  33. if !isPlusMode {
  34. if !out.AddDirEntry(dirEntry) {
  35. return false
  36. }
  37. } else {
  38. entryOut := out.AddDirLookupEntry(dirEntry)
  39. if entryOut == nil {
  40. return false
  41. }
  42. entryOut.Generation = 1
  43. entryOut.EntryValid = 1
  44. entryOut.AttrValid = 1
  45. wfs.setAttrByFilerEntry(&entryOut.Attr, inode, entry)
  46. }
  47. return true
  48. }
  49. // TODO remove this with checking whether directory is not forgotten
  50. if err := meta_cache.EnsureVisited(wfs.metaCache, wfs, dirPath); err != nil {
  51. glog.Errorf("dir ReadDirAll %s: %v", dirPath, err)
  52. return fuse.EIO
  53. }
  54. listErr := wfs.metaCache.ListDirectoryEntries(context.Background(), dirPath, "", false, int64(math.MaxInt32), func(entry *filer.Entry) bool {
  55. return processEachEntryFn(entry, false)
  56. })
  57. if listErr != nil {
  58. glog.Errorf("list meta cache: %v", listErr)
  59. return fuse.EIO
  60. }
  61. return fuse.OK
  62. }