From 91f0481f4efde4133029009f15788b0f73dabcde Mon Sep 17 00:00:00 2001 From: chrislu Date: Thu, 24 Feb 2022 01:31:04 -0800 Subject: [PATCH] mount2: SetAttr set mode correctly --- weed/mount/weedfs_attr.go | 25 +++++++++++++++---------- weed/mount/weedfs_dir_read.go | 2 +- weed/mount/weedfs_file_mkrm.go | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/weed/mount/weedfs_attr.go b/weed/mount/weedfs_attr.go index 9f995608c..531c722d0 100644 --- a/weed/mount/weedfs_attr.go +++ b/weed/mount/weedfs_attr.go @@ -66,7 +66,8 @@ func (wfs *WFS) SetAttr(cancel <-chan struct{}, input *fuse.SetAttrIn, out *fuse } if mode, ok := input.GetMode(); ok { - entry.Attributes.FileMode = mode & 07777 + glog.V(4).Infof("setAttr mode %o", mode) + entry.Attributes.FileMode = chmod(entry.Attributes.FileMode, mode) } if uid, ok := input.GetUID(); ok { @@ -108,7 +109,7 @@ func (wfs *WFS) setRootAttr(out *fuse.AttrOut) { out.Mtime = now out.Ctime = now out.Atime = now - out.Mode = toSystemType(os.ModeDir) | uint32(wfs.option.MountMode) + out.Mode = toSyscallType(os.ModeDir) | uint32(wfs.option.MountMode) out.Nlink = 1 } @@ -120,7 +121,7 @@ func (wfs *WFS) setAttrByPbEntry(out *fuse.Attr, inode uint64, entry *filer_pb.E out.Mtime = uint64(entry.Attributes.Mtime) out.Ctime = uint64(entry.Attributes.Mtime) out.Atime = uint64(entry.Attributes.Mtime) - out.Mode = toSystemMode(os.FileMode(entry.Attributes.FileMode)) + out.Mode = toSyscallMode(os.FileMode(entry.Attributes.FileMode)) if entry.HardLinkCounter > 0 { out.Nlink = uint32(entry.HardLinkCounter) } else { @@ -138,7 +139,7 @@ func (wfs *WFS) setAttrByFilerEntry(out *fuse.Attr, inode uint64, entry *filer.E out.Atime = uint64(entry.Attr.Mtime.Unix()) out.Mtime = uint64(entry.Attr.Mtime.Unix()) out.Ctime = uint64(entry.Attr.Mtime.Unix()) - out.Mode = toSystemMode(entry.Attr.Mode) + out.Mode = toSyscallMode(entry.Attr.Mode) if entry.HardLinkCounter > 0 { out.Nlink = uint32(entry.HardLinkCounter) } else { @@ -164,11 +165,15 @@ func (wfs *WFS) outputFilerEntry(out *fuse.EntryOut, inode uint64, entry *filer. wfs.setAttrByFilerEntry(&out.Attr, inode, entry) } -func toSystemMode(mode os.FileMode) uint32 { - return toSystemType(mode) | uint32(mode) +func chmod(existing uint32, mode uint32) uint32 { + return existing&^07777 | mode&07777 } -func toSystemType(mode os.FileMode) uint32 { +func toSyscallMode(mode os.FileMode) uint32 { + return toSyscallType(mode) | uint32(mode) +} + +func toSyscallType(mode os.FileMode) uint32 { switch mode & os.ModeType { case os.ModeDir: return syscall.S_IFDIR @@ -187,7 +192,7 @@ func toSystemType(mode os.FileMode) uint32 { } } -func toFileType(mode uint32) os.FileMode { +func toOsFileType(mode uint32) os.FileMode { switch mode & (syscall.S_IFMT & 0xffff) { case syscall.S_IFDIR: return os.ModeDir @@ -206,6 +211,6 @@ func toFileType(mode uint32) os.FileMode { } } -func toFileMode(mode uint32) os.FileMode { - return toFileType(mode) | os.FileMode(mode&07777) +func toOsFileMode(mode uint32) os.FileMode { + return toOsFileType(mode) | os.FileMode(mode&07777) } diff --git a/weed/mount/weedfs_dir_read.go b/weed/mount/weedfs_dir_read.go index 913d0ebeb..a9d442856 100644 --- a/weed/mount/weedfs_dir_read.go +++ b/weed/mount/weedfs_dir_read.go @@ -160,7 +160,7 @@ func (wfs *WFS) doReadDirectory(input *fuse.ReadIn, out *fuse.DirEntryList, isPl processEachEntryFn := func(entry *filer.Entry, isLast bool) bool { dirEntry.Name = entry.Name() - dirEntry.Mode = toSystemMode(entry.Mode) + dirEntry.Mode = toSyscallMode(entry.Mode) if !isPlusMode { inode := wfs.inodeToPath.Lookup(dirPath.Child(dirEntry.Name), entry.IsDirectory(), false) dirEntry.Ino = inode diff --git a/weed/mount/weedfs_file_mkrm.go b/weed/mount/weedfs_file_mkrm.go index 243696dba..55aa2789c 100644 --- a/weed/mount/weedfs_file_mkrm.go +++ b/weed/mount/weedfs_file_mkrm.go @@ -45,7 +45,7 @@ func (wfs *WFS) Mknod(cancel <-chan struct{}, in *fuse.MknodIn, name string, out Attributes: &filer_pb.FuseAttributes{ Mtime: time.Now().Unix(), Crtime: time.Now().Unix(), - FileMode: uint32(toFileMode(in.Mode)), + FileMode: uint32(toOsFileMode(in.Mode)), Uid: in.Uid, Gid: in.Gid, Collection: wfs.option.Collection,