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
add mkdir
chrislue85ca10a1a42
diff --git a/weed/mount/weedfs_attr.go b/weed/mount/weedfs_attr.goindex 4354baa86e..8dbf65fe8c 100644--- a/weed/mount/weedfs_attr.go+++ b/weed/mount/weedfs_attr.go@@ -109,7 +109,15 @@ func (wfs *WFS) setAttrByFilerEntry(out *fuse.Attr, inode uint64, entry *filer.Eout.Gid = entry.Attr.Gid}-func (wfs *WFS) outputEntry(out *fuse.EntryOut, inode uint64, entry *filer.Entry) {+func (wfs *WFS) outputPbEntry(out *fuse.EntryOut, inode uint64, entry *filer_pb.Entry) {+ out.NodeId = inode+ out.Generation = 1+ out.EntryValid = 1+ out.AttrValid = 1+ wfs.setAttrByPbEntry(&out.Attr, inode, entry)+}++func (wfs *WFS) outputFilerEntry(out *fuse.EntryOut, inode uint64, entry *filer.Entry) {out.NodeId = inodeout.Generation = 1out.EntryValid = 1diff --git a/weed/mount/weedfs_dir_lookup.go b/weed/mount/weedfs_dir_lookup.goindex b74948f654..477cfad0a4 100644--- a/weed/mount/weedfs_dir_lookup.go+++ b/weed/mount/weedfs_dir_lookup.go@@ -16,6 +16,10 @@ import (func (wfs *WFS) Lookup(cancel <-chan struct{}, header *fuse.InHeader, name string, out *fuse.EntryOut) (code fuse.Status) {+ if s := checkName(name); s != fuse.OK {+ return s+ }+dirPath := wfs.inodeToPath.GetPath(header.NodeId)fullFilePath := dirPath.Child(name)@@ -48,7 +52,7 @@ func (wfs *WFS) Lookup(cancel <-chan struct{}, header *fuse.InHeader, name strininode := wfs.inodeToPath.GetInode(fullFilePath)- wfs.outputEntry(out, inode, localEntry)+ wfs.outputFilerEntry(out, inode, localEntry)return fuse.OKdiff --git a/weed/mount/weedfs_dir_mkrm.go b/weed/mount/weedfs_dir_mkrm.gonew file mode 100644index 0000000000..670275915c--- /dev/null+++ b/weed/mount/weedfs_dir_mkrm.go@@ -0,0 +1,72 @@+package mount++import (+ "context"+ "fmt"+ "github.com/chrislusf/seaweedfs/weed/filer"+ "github.com/chrislusf/seaweedfs/weed/glog"+ "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"+ "github.com/hanwen/go-fuse/v2/fuse"+ "os"+ "time"+)++func (wfs *WFS) Mkdir(cancel <-chan struct{}, in *fuse.MkdirIn, name string, out *fuse.EntryOut) (code fuse.Status) {++ if s := checkName(name); s != fuse.OK {+ return s+ }++ newEntry := &filer_pb.Entry{+ Name: name,+ IsDirectory: true,+ Attributes: &filer_pb.FuseAttributes{+ Mtime: time.Now().Unix(),+ Crtime: time.Now().Unix(),+ FileMode: uint32(os.ModeDir) | in.Mode&^uint32(wfs.option.Umask),+ Uid: in.Uid,+ Gid: in.Gid,+ },+ }++ dirFullPath := wfs.inodeToPath.GetPath(in.NodeId)++ entryFullPath := dirFullPath.Child(name)++ err := wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {++ wfs.mapPbIdFromLocalToFiler(newEntry)+ defer wfs.mapPbIdFromFilerToLocal(newEntry)++ request := &filer_pb.CreateEntryRequest{+ Directory: string(dirFullPath),+ Entry: newEntry,+ Signatures: []int32{wfs.signature},+ }++ glog.V(1).Infof("mkdir: %v", request)+ if err := filer_pb.CreateEntry(client, request); err != nil {+ glog.V(0).Infof("mkdir %s: %v", entryFullPath, err)+ return err+ }++ if err := wfs.metaCache.InsertEntry(context.Background(), filer.FromPbEntry(request.Directory, request.Entry)); err != nil {+ return fmt.Errorf("local mkdir dir %s: %v", entryFullPath, err)+ }++ return nil+ })++ glog.V(0).Infof("mkdir %s: %v", entryFullPath, err)++ if err != nil {+ return fuse.EIO+ }++ inode := wfs.inodeToPath.GetInode(entryFullPath)++ wfs.outputPbEntry(out, inode, newEntry)++ return fuse.OK++}diff --git a/weed/mount/weedfs_dir_read.go b/weed/mount/weedfs_dir_read.goindex 40e164fc9d..96fd36ffef 100644--- a/weed/mount/weedfs_dir_read.go+++ b/weed/mount/weedfs_dir_read.go@@ -73,7 +73,7 @@ func (wfs *WFS) doReadDirectory(input *fuse.ReadIn, out *fuse.DirEntryList, isPlif entryOut == nil {return false}- wfs.outputEntry(entryOut, inode, entry)+ wfs.outputFilerEntry(entryOut, inode, entry)}return true}diff --git a/weed/mount/wfs_save.go b/weed/mount/wfs_save.goindex 240c010d8e..0cac30453a 100644--- a/weed/mount/wfs_save.go+++ b/weed/mount/wfs_save.go@@ -8,6 +8,7 @@ import ("github.com/chrislusf/seaweedfs/weed/pb/filer_pb""github.com/chrislusf/seaweedfs/weed/util""github.com/hanwen/go-fuse/v2/fuse"+ "syscall")func (wfs *WFS) saveEntry(path util.FullPath, entry *filer_pb.Entry) (code fuse.Status) {@@ -57,3 +58,10 @@ func (wfs *WFS) mapPbIdFromLocalToFiler(entry *filer_pb.Entry) {}entry.Attributes.Uid, entry.Attributes.Gid = wfs.option.UidGidMapper.LocalToFiler(entry.Attributes.Uid, entry.Attributes.Gid)}++func checkName(name string) fuse.Status {+ if len(name) >= 256 {+ return fuse.Status(syscall.ENAMETOOLONG)+ }+ return fuse.OK+}