Browse Source

mount2: SetAttr set mode correctly

original_weed_mount
chrislu 3 years ago
parent
commit
91f0481f4e
  1. 25
      weed/mount/weedfs_attr.go
  2. 2
      weed/mount/weedfs_dir_read.go
  3. 2
      weed/mount/weedfs_file_mkrm.go

25
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)
}

2
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

2
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,

Loading…
Cancel
Save