Added an Init method.

geesefs-0-30-9
Aaron Jacobs 2015-02-27 14:40:09 +11:00
parent 99dca8b42c
commit 63b70540e3
4 changed files with 38 additions and 5 deletions

View File

@ -21,6 +21,12 @@ import (
//
// Must be safe for concurrent access via all methods.
type FileSystem interface {
// This method is called once when mounting the file system. It must succeed
// in order for the mount to succeed.
Init(
ctx context.Context,
req *InitRequest) (*InitResponse, error)
// Look up a child by name within a parent directory. The kernel calls this
// when resolving user paths to dentry structs, which are then cached.
LookUpInode(
@ -129,6 +135,15 @@ type DirOffset uint64
// Requests and responses
////////////////////////////////////////////////////////////////////////
type InitRequest struct {
// User and group IDs for the process that is mounting the file system.
Uid uint32
Gid uint32
}
type InitResponse struct {
}
type LookUpInodeRequest struct {
// The ID of the directory inode to which the child belongs.
Parent InodeID

View File

@ -15,6 +15,12 @@ type NotImplementedFileSystem struct {
var _ fuse.FileSystem = &NotImplementedFileSystem{}
func (fs *NotImplementedFileSystem) Init(
ctx context.Context,
req *fuse.InitRequest) (*fuse.InitResponse, error) {
return nil, fuse.ENOSYS
}
func (fs *NotImplementedFileSystem) LookUpInode(
ctx context.Context,
req *fuse.LookUpInodeRequest) (*fuse.LookUpInodeResponse, error) {

View File

@ -50,7 +50,7 @@ var gInodeInfo = map[fuse.InodeID]inodeInfo{
attributes: fuse.InodeAttributes{
// TODO(jacobsa): Why do we get premission denied errors when this is
// 0500?
Mode: 0555 | os.ModeDir,
Mode: 0500 | os.ModeDir,
},
dir: true,
children: []fuseutil.Dirent{

View File

@ -71,11 +71,23 @@ func (s *server) handleFuseRequest(fuseReq bazilfuse.Request) {
// Attempt to handle it.
switch typed := fuseReq.(type) {
case *bazilfuse.InitRequest:
// Responding to this is required to make mounting work, at least on OS X.
// We don't currently expose the capability for the file system to
// intercept this.
// Convert the request.
req := &InitRequest{
Uid: typed.Header.Uid,
Gid: typed.Header.Gid,
}
// Call the file system.
_, err := s.fs.Init(ctx, req)
if err != nil {
s.logger.Print("Responding:", err)
typed.RespondError(err)
return
}
// Convert the response.
fuseResp := &bazilfuse.InitResponse{}
s.logger.Println("Responding:", fuseResp)
s.logger.Print("Responding:", fuseResp)
typed.Respond(fuseResp)
case *bazilfuse.StatfsRequest: