Browse Source

add mkdir

pull/2668/head
chrislu 3 years ago
parent
commit
e85ca10a1a
  1. 10
      weed/mount/weedfs_attr.go
  2. 6
      weed/mount/weedfs_dir_lookup.go
  3. 72
      weed/mount/weedfs_dir_mkrm.go
  4. 2
      weed/mount/weedfs_dir_read.go
  5. 8
      weed/mount/wfs_save.go

10
weed/mount/weedfs_attr.go

@ -109,7 +109,15 @@ func (wfs *WFS) setAttrByFilerEntry(out *fuse.Attr, inode uint64, entry *filer.E
out.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 = inode
out.Generation = 1
out.EntryValid = 1

6
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 strin
inode := wfs.inodeToPath.GetInode(fullFilePath)
wfs.outputEntry(out, inode, localEntry)
wfs.outputFilerEntry(out, inode, localEntry)
return fuse.OK

72
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
}

2
weed/mount/weedfs_dir_read.go

@ -73,7 +73,7 @@ func (wfs *WFS) doReadDirectory(input *fuse.ReadIn, out *fuse.DirEntryList, isPl
if entryOut == nil {
return false
}
wfs.outputEntry(entryOut, inode, entry)
wfs.outputFilerEntry(entryOut, inode, entry)
}
return true
}

8
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
}
Loading…
Cancel
Save