diff --git a/file_system.go b/file_system.go index 7bcbabb..0cdeea9 100644 --- a/file_system.go +++ b/file_system.go @@ -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 diff --git a/fuseutil/not_implemented_file_system.go b/fuseutil/not_implemented_file_system.go index 1fb12f4..5d549ed 100644 --- a/fuseutil/not_implemented_file_system.go +++ b/fuseutil/not_implemented_file_system.go @@ -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) { diff --git a/samples/hello_fs.go b/samples/hello_fs.go index 28a7724..1354801 100644 --- a/samples/hello_fs.go +++ b/samples/hello_fs.go @@ -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{ diff --git a/server.go b/server.go index 0415643..6ba8932 100644 --- a/server.go +++ b/server.go @@ -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: