Fixed permissions for the root.

geesefs-0-30-9
Aaron Jacobs 2015-03-03 11:03:03 +11:00
parent 44901edc6b
commit c81ae6d4b3
2 changed files with 38 additions and 9 deletions

View File

@ -57,9 +57,10 @@ func NewMemFS(
inodes: make([]*inode, fuse.RootInodeID+1),
}
// Set up the root inode.
// Set up the root inode. Its ownership information will later be modified in
// Init.
rootAttrs := fuse.InodeAttributes{
Mode: 0777 | os.ModeDir,
Mode: 0700 | os.ModeDir,
}
fs.inodes[fuse.RootInodeID] = newInode(rootAttrs)
@ -70,6 +71,10 @@ func NewMemFS(
return fs
}
////////////////////////////////////////////////////////////////////////
// Helpers
////////////////////////////////////////////////////////////////////////
func (fs *memFS) checkInvariants() {
// Check reserved inodes.
for i := 0; i < fuse.RootInodeID; i++ {
@ -109,13 +114,6 @@ func (fs *memFS) checkInvariants() {
}
}
func (fs *memFS) Init(
ctx context.Context,
req *fuse.InitRequest) (resp *fuse.InitResponse, err error) {
resp = &fuse.InitResponse{}
return
}
// Find the given inode and return it with its lock held. Panic if it doesn't
// exist.
//
@ -171,6 +169,29 @@ func (fs *memFS) allocateInode(
return
}
////////////////////////////////////////////////////////////////////////
// FileSystem methods
////////////////////////////////////////////////////////////////////////
func (fs *memFS) Init(
ctx context.Context,
req *fuse.InitRequest) (resp *fuse.InitResponse, err error) {
resp = &fuse.InitResponse{}
fs.mu.RLock()
defer fs.mu.RUnlock()
// Update the root inode's ownership information to match the credentials of
// the mounting process.
root := fs.getInodeForModifyingOrDie(fuse.RootInodeID)
defer root.mu.Unlock()
root.attributes.Uid = req.Header.Uid
root.attributes.Gid = req.Header.Gid
return
}
func (fs *memFS) LookUpInode(
ctx context.Context,
req *fuse.LookUpInodeRequest) (resp *fuse.LookUpInodeResponse, err error) {

View File

@ -59,6 +59,10 @@ type inode struct {
contents []byte // GUARDED_BY(mu)
}
////////////////////////////////////////////////////////////////////////
// Helpers
////////////////////////////////////////////////////////////////////////
func newInode(attrs fuse.InodeAttributes) (in *inode) {
in = &inode{
dir: (attrs.Mode&os.ModeDir != 0),
@ -112,6 +116,10 @@ func (inode *inode) checkInvariants() {
}
}
////////////////////////////////////////////////////////////////////////
// Public methods
////////////////////////////////////////////////////////////////////////
// Find an entry for the given child name and return its inode ID.
//
// REQUIRES: inode.dir