mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-01-18 06:30:07 +08:00
FUSE: use the mount directory permissions
This commit is contained in:
parent
95ffed87c0
commit
d77e3c96e9
@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/chrislusf/seaweedfs/weed/filesys/meta_cache"
|
"github.com/chrislusf/seaweedfs/weed/filesys/meta_cache"
|
||||||
"os"
|
"os"
|
||||||
|
"os/user"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -92,6 +93,29 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
|
|||||||
}
|
}
|
||||||
fileInfo, err := os.Stat(dir)
|
fileInfo, err := os.Stat(dir)
|
||||||
|
|
||||||
|
uid, gid := uint32(0), uint32(0)
|
||||||
|
mountMode := os.ModeDir | 0777
|
||||||
|
if err == nil {
|
||||||
|
mountMode = os.ModeDir | fileInfo.Mode()
|
||||||
|
uid, gid = util.GetFileUidGid(fileInfo)
|
||||||
|
fmt.Printf("mount point owner uid=%d gid=%d mode=%s\n", uid, gid, fileInfo.Mode())
|
||||||
|
} else {
|
||||||
|
fmt.Printf("can not stat %s\n", dir)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if uid == 0 {
|
||||||
|
if u, err := user.Current(); err == nil {
|
||||||
|
if parsedId, pe := strconv.ParseUint(u.Uid, 10, 32); pe == nil {
|
||||||
|
uid = uint32(parsedId)
|
||||||
|
}
|
||||||
|
if parsedId, pe := strconv.ParseUint(u.Gid, 10, 32); pe == nil {
|
||||||
|
gid = uint32(parsedId)
|
||||||
|
}
|
||||||
|
fmt.Printf("current uid=%d gid=%d\n", uid, gid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// mapping uid, gid
|
// mapping uid, gid
|
||||||
uidGidMapper, err := meta_cache.NewUidGidMapper(*option.uidMap, *option.gidMap)
|
uidGidMapper, err := meta_cache.NewUidGidMapper(*option.uidMap, *option.gidMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -150,6 +174,9 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
|
|||||||
CacheSizeMB: *option.cacheSizeMB,
|
CacheSizeMB: *option.cacheSizeMB,
|
||||||
DataCenter: *option.dataCenter,
|
DataCenter: *option.dataCenter,
|
||||||
EntryCacheTtl: 3 * time.Second,
|
EntryCacheTtl: 3 * time.Second,
|
||||||
|
MountUid: uid,
|
||||||
|
MountGid: gid,
|
||||||
|
MountMode: mountMode,
|
||||||
MountCtime: fileInfo.ModTime(),
|
MountCtime: fileInfo.ModTime(),
|
||||||
MountMtime: time.Now(),
|
MountMtime: time.Now(),
|
||||||
Umask: umask,
|
Umask: umask,
|
||||||
|
@ -82,9 +82,9 @@ func (dir *Dir) Getxattr(ctx context.Context, req *fuse.GetxattrRequest, resp *f
|
|||||||
func (dir *Dir) setRootDirAttributes(attr *fuse.Attr) {
|
func (dir *Dir) setRootDirAttributes(attr *fuse.Attr) {
|
||||||
attr.Inode = 1 // filer2.FullPath(dir.Path).AsInode()
|
attr.Inode = 1 // filer2.FullPath(dir.Path).AsInode()
|
||||||
attr.Valid = time.Hour
|
attr.Valid = time.Hour
|
||||||
attr.Uid = dir.entry.Attributes.Uid
|
attr.Uid = dir.wfs.option.MountUid
|
||||||
attr.Gid = dir.entry.Attributes.Gid
|
attr.Gid = dir.wfs.option.MountGid
|
||||||
attr.Mode = os.FileMode(dir.entry.Attributes.FileMode)
|
attr.Mode = dir.wfs.option.MountMode
|
||||||
attr.Crtime = dir.wfs.option.MountCtime
|
attr.Crtime = dir.wfs.option.MountCtime
|
||||||
attr.Ctime = dir.wfs.option.MountCtime
|
attr.Ctime = dir.wfs.option.MountCtime
|
||||||
attr.Mtime = dir.wfs.option.MountMtime
|
attr.Mtime = dir.wfs.option.MountMtime
|
||||||
|
@ -37,6 +37,9 @@ type Option struct {
|
|||||||
EntryCacheTtl time.Duration
|
EntryCacheTtl time.Duration
|
||||||
Umask os.FileMode
|
Umask os.FileMode
|
||||||
|
|
||||||
|
MountUid uint32
|
||||||
|
MountGid uint32
|
||||||
|
MountMode os.FileMode
|
||||||
MountCtime time.Time
|
MountCtime time.Time
|
||||||
MountMtime time.Time
|
MountMtime time.Time
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user