SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
implement read directory and read directory plus
chrislu72faae91e175
diff --git a/weed/mount/weedfs.go b/weed/mount/weedfs.goindex 68f8dd9852..fa5c7d4f9b 100644--- a/weed/mount/weedfs.go+++ b/weed/mount/weedfs.go@@ -94,9 +94,10 @@ func (wfs *WFS) String() string {return "seaweedfs"}-func (wfs *WFS) maybeReadEntry(inode uint64) (*filer_pb.Entry, fuse.Status) {- path := wfs.inodeToPath.GetPath(inode)- return wfs.maybeLoadEntry(path)+func (wfs *WFS) maybeReadEntry(inode uint64) (path util.FullPath, entry *filer_pb.Entry, status fuse.Status) {+ path = wfs.inodeToPath.GetPath(inode)+ entry, status = wfs.maybeLoadEntry(path)+ return}func (wfs *WFS) maybeLoadEntry(fullpath util.FullPath) (*filer_pb.Entry, fuse.Status) {diff --git a/weed/mount/weedfs_attr.go b/weed/mount/weedfs_attr.goindex 7e53ad5064..311d5331a9 100644--- a/weed/mount/weedfs_attr.go+++ b/weed/mount/weedfs_attr.go@@ -16,11 +16,12 @@ func (wfs *WFS) GetAttr(cancel <-chan struct{}, input *fuse.GetAttrIn, out *fusereturn fuse.OK}- entry, status := wfs.maybeReadEntry(input.NodeId)+ _, entry, status := wfs.maybeReadEntry(input.NodeId)if status != fuse.OK {return status}- wfs.setOutAttr(out, input.NodeId, entry)+ out.AttrValid = 1+ wfs.setAttrByPbEntry(&out.Attr, input.NodeId, entry)return fuse.OK}@@ -54,16 +55,15 @@ func (wfs *WFS) setRootAttr(out *fuse.AttrOut) {out.Mtime = nowout.Ctime = nowout.Atime = now- out.Mode = osToSystemMode(os.ModeDir) | uint32(wfs.option.MountMode)+ out.Mode = toSystemType(os.ModeDir) | uint32(wfs.option.MountMode)out.Nlink = 1}-func (wfs *WFS) setOutAttr(out *fuse.AttrOut, inode uint64, entry *filer_pb.Entry) {- out.AttrValid = 1+func (wfs *WFS) setAttrByPbEntry(out *fuse.Attr, inode uint64, entry *filer_pb.Entry) {out.Ino = inodeout.Uid = entry.Attributes.Uidout.Gid = entry.Attributes.Gid- out.Mode = modeToSystemMode(entry.Attributes.FileMode)+ out.Mode = toSystemMode(os.FileMode(entry.Attributes.FileMode))out.Mtime = uint64(entry.Attributes.Mtime)out.Ctime = uint64(entry.Attributes.Mtime)out.Atime = uint64(entry.Attributes.Mtime)@@ -72,15 +72,32 @@ func (wfs *WFS) setOutAttr(out *fuse.AttrOut, inode uint64, entry *filer_pb.Entr}out.Size = filer.FileSize(entry)out.Blocks = out.Size/blockSize + 1- setBlksize(&out.Attr, blockSize)+ setBlksize(out, blockSize)+ out.Nlink = 1+}++func (wfs *WFS) setAttrByFilerEntry(out *fuse.Attr, inode uint64, entry *filer.Entry) {+ out.Ino = inode+ out.Uid = entry.Attr.Uid+ out.Gid = entry.Attr.Gid+ out.Mode = toSystemMode(entry.Attr.Mode)+ out.Mtime = uint64(entry.Attr.Mtime.Unix())+ out.Ctime = uint64(entry.Attr.Mtime.Unix())+ out.Atime = uint64(entry.Attr.Mtime.Unix())+ if entry.HardLinkCounter > 0 {+ out.Nlink = uint32(entry.HardLinkCounter)+ }+ out.Size = entry.FileSize+ out.Blocks = out.Size/blockSize + 1+ setBlksize(out, blockSize)out.Nlink = 1}-func modeToSystemMode(mode uint32) uint32 {- return osToSystemMode(os.FileMode(mode)) | mode+func toSystemMode(mode os.FileMode) uint32 {+ return toSystemType(mode) | uint32(mode)}-func osToSystemMode(mode os.FileMode) uint32 {+func toSystemType(mode os.FileMode) uint32 {switch mode & os.ModeType {case os.ModeDir:return syscall.S_IFDIRdiff --git a/weed/mount/weedfs_dir.go b/weed/mount/weedfs_dir.gonew file mode 100644index 0000000000..43eb17bf29--- /dev/null+++ b/weed/mount/weedfs_dir.go@@ -0,0 +1,71 @@+package mount++import (+ "context"+ "github.com/chrislusf/seaweedfs/weed/filer"+ "github.com/chrislusf/seaweedfs/weed/filesys/meta_cache"+ "github.com/chrislusf/seaweedfs/weed/glog"+ "github.com/hanwen/go-fuse/v2/fuse"+ "math"+)++// Directory handling++func (wfs *WFS) OpenDir(cancel <-chan struct{}, input *fuse.OpenIn, out *fuse.OpenOut) (code fuse.Status) {+ return fuse.OK+}+func (wfs *WFS) ReleaseDir(input *fuse.ReleaseIn) {+}+func (wfs *WFS) FsyncDir(cancel <-chan struct{}, input *fuse.FsyncIn) (code fuse.Status) {+ return fuse.OK+}++func (wfs *WFS) ReadDir(cancel <-chan struct{}, input *fuse.ReadIn, out *fuse.DirEntryList) (code fuse.Status) {+ return wfs.doReadDirectory(input, out, false)+}++func (wfs *WFS) ReadDirPlus(cancel <-chan struct{}, input *fuse.ReadIn, out *fuse.DirEntryList) (code fuse.Status) {+ return wfs.doReadDirectory(input, out, true)+}++func (wfs *WFS) doReadDirectory(input *fuse.ReadIn, out *fuse.DirEntryList, isPlusMode bool) fuse.Status {+ dirPath := wfs.inodeToPath.GetPath(input.NodeId)++ var dirEntry fuse.DirEntry+ processEachEntryFn := func(entry *filer.Entry, isLast bool) bool {+ dirEntry.Name = entry.Name()+ inode := wfs.inodeToPath.GetInode(dirPath.Child(dirEntry.Name))+ dirEntry.Ino = inode+ dirEntry.Mode = toSystemMode(entry.Mode)+ if !isPlusMode {+ if !out.AddDirEntry(dirEntry) {+ return false+ }++ } else {+ entryOut := out.AddDirLookupEntry(dirEntry)+ if entryOut == nil {+ return false+ }+ entryOut.Generation = 1+ entryOut.EntryValid = 1+ entryOut.AttrValid = 1+ wfs.setAttrByFilerEntry(&entryOut.Attr, inode, entry)+ }+ return true+ }++ // TODO remove this with checking whether directory is not forgotten+ if err := meta_cache.EnsureVisited(wfs.metaCache, wfs, dirPath); err != nil {+ glog.Errorf("dir ReadDirAll %s: %v", dirPath, err)+ return fuse.EIO+ }+ listErr := wfs.metaCache.ListDirectoryEntries(context.Background(), dirPath, "", false, int64(math.MaxInt32), func(entry *filer.Entry) bool {+ return processEachEntryFn(entry, false)+ })+ if listErr != nil {+ glog.Errorf("list meta cache: %v", listErr)+ return fuse.EIO+ }+ return fuse.OK+}