aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2022-02-12 22:21:30 -0800
committerchrislu <chris.lu@gmail.com>2022-02-12 22:21:30 -0800
commitb0a5193e326962c8a411f872f45ddb6a16962fd9 (patch)
tree33a390b8e73035f30dc65856843720ce0e2af562
parent661a34e23da36b58f164bafb935a5d0cfdd8af2a (diff)
downloadseaweedfs-b0a5193e326962c8a411f872f45ddb6a16962fd9.tar.xz
seaweedfs-b0a5193e326962c8a411f872f45ddb6a16962fd9.zip
working
-rw-r--r--weed/mount/inode_to_path.go10
-rw-r--r--weed/mount/weedfs_attr.go15
-rw-r--r--weed/mount/weedfs_dir_read.go7
3 files changed, 25 insertions, 7 deletions
diff --git a/weed/mount/inode_to_path.go b/weed/mount/inode_to_path.go
index 04366ab0d..e3fabb422 100644
--- a/weed/mount/inode_to_path.go
+++ b/weed/mount/inode_to_path.go
@@ -59,3 +59,13 @@ func (i *InodeToPath) HasPath(path util.FullPath) bool {
_, found := i.path2inode[path]
return found
}
+
+func (i *InodeToPath) HasInode(inode uint64) bool {
+ if inode == 1 {
+ return true
+ }
+ i.RLock()
+ defer i.RUnlock()
+ _, found := i.inode2path[inode]
+ return found
+}
diff --git a/weed/mount/weedfs_attr.go b/weed/mount/weedfs_attr.go
index 788badb77..fddba289d 100644
--- a/weed/mount/weedfs_attr.go
+++ b/weed/mount/weedfs_attr.go
@@ -46,7 +46,7 @@ func (wfs *WFS) RemoveXAttr(cancel <-chan struct{}, header *fuse.InHeader, attr
}
func (wfs *WFS) setRootAttr(out *fuse.AttrOut) {
- now := uint64(time.Now().Second())
+ now := uint64(time.Now().Unix())
out.AttrValid = 119
out.Ino = 1
setBlksize(&out.Attr, blockSize)
@@ -69,17 +69,18 @@ func (wfs *WFS) setAttrByPbEntry(out *fuse.Attr, inode uint64, entry *filer_pb.E
out.Atime = uint64(entry.Attributes.Mtime)
if entry.HardLinkCounter > 0 {
out.Nlink = uint32(entry.HardLinkCounter)
+ } else {
+ out.Nlink = 1
}
out.Size = filer.FileSize(entry)
- out.Blocks = out.Size/blockSize + 1
+ out.Blocks = (out.Size + blockSize - 1) / blockSize
setBlksize(out, blockSize)
- out.Nlink = 1
}
func (wfs *WFS) setAttrByFilerEntry(out *fuse.Attr, inode uint64, entry *filer.Entry) {
out.Ino = inode
out.Size = entry.FileSize
- out.Blocks = out.Size/blockSize + 1
+ out.Blocks = (out.Size + blockSize - 1) / blockSize
setBlksize(out, blockSize)
out.Atime = uint64(entry.Attr.Mtime.Unix())
out.Mtime = uint64(entry.Attr.Mtime.Unix())
@@ -88,14 +89,16 @@ func (wfs *WFS) setAttrByFilerEntry(out *fuse.Attr, inode uint64, entry *filer.E
out.Mode = toSystemMode(entry.Attr.Mode)
if entry.HardLinkCounter > 0 {
out.Nlink = uint32(entry.HardLinkCounter)
+ } else {
+ out.Nlink = 1
}
- out.Nlink = 1
out.Uid = entry.Attr.Uid
out.Gid = entry.Attr.Gid
}
func (wfs *WFS) outputEntry(out *fuse.EntryOut, inode uint64, entry *filer.Entry) {
- // out.Generation = 1
+ out.NodeId = inode
+ out.Generation = 1
out.EntryValid = 1
out.AttrValid = 1
wfs.setAttrByFilerEntry(&out.Attr, inode, entry)
diff --git a/weed/mount/weedfs_dir_read.go b/weed/mount/weedfs_dir_read.go
index a696953a1..bae6a18a2 100644
--- a/weed/mount/weedfs_dir_read.go
+++ b/weed/mount/weedfs_dir_read.go
@@ -14,6 +14,9 @@ import (
// Directory handling
func (wfs *WFS) OpenDir(cancel <-chan struct{}, input *fuse.OpenIn, out *fuse.OpenOut) (code fuse.Status) {
+ if !wfs.inodeToPath.HasInode(input.NodeId) {
+ return fuse.ENOENT
+ }
return fuse.OK
}
func (wfs *WFS) ReleaseDir(input *fuse.ReleaseIn) {
@@ -35,13 +38,16 @@ func (wfs *WFS) doReadDirectory(input *fuse.ReadIn, out *fuse.DirEntryList, isPl
println("input size", input.Size, "offset", input.Offset, "pid", input.Caller.Pid)
+ var counter uint64
var dirEntry fuse.DirEntry
if input.Offset == 0 {
+ counter++
dirEntry.Ino = input.NodeId
dirEntry.Name = "."
dirEntry.Mode = toSystemMode(os.ModeDir)
out.AddDirEntry(dirEntry)
+ counter++
parentDir, _ := dirPath.DirAndName()
parentInode := wfs.inodeToPath.GetInode(util.FullPath(parentDir))
dirEntry.Ino = parentInode
@@ -51,7 +57,6 @@ func (wfs *WFS) doReadDirectory(input *fuse.ReadIn, out *fuse.DirEntryList, isPl
}
- var counter uint64
processEachEntryFn := func(entry *filer.Entry, isLast bool) bool {
counter++
if counter <= input.Offset {