diff --git a/connection.go b/connection.go index e1d03da..d81fff8 100644 --- a/connection.go +++ b/connection.go @@ -15,6 +15,7 @@ package fuse import ( + "errors" "fmt" "log" "path" @@ -24,6 +25,7 @@ import ( "golang.org/x/net/context" "github.com/jacobsa/fuse/fuseops" + "github.com/jacobsa/fuse/internal/buffer" "github.com/jacobsa/fuse/internal/fusekernel" "github.com/jacobsa/fuse/internal/fuseshim" ) @@ -202,6 +204,21 @@ func (c *Connection) handleInterrupt(fuseID uint64) { cancel() } +func (c *Connection) allocateInMessage() (m *buffer.InMessage) { + panic("TODO") +} + +func (c *Connection) destroyInMessage(m *buffer.InMessage) { + panic("TODO") +} + +// Read the next message from the kernel. The message must later be destroyed +// using destroyInMessage. +func (c *Connection) readMessage() (m *buffer.InMessage, err error) { + err = errors.New("TODO") + return +} + // Read the next op from the kernel process. Return io.EOF if the kernel has // closed the connection. // @@ -212,9 +229,9 @@ func (c *Connection) handleInterrupt(fuseID uint64) { func (c *Connection) ReadOp() (op fuseops.Op, err error) { // Keep going until we find a request we know how to convert. for { - // Read the next message from the fuseshim connection. - var m *fuseshim.Message - m, err = c.wrapped.ReadMessage() + // Read the next message from the kernel. + var m *buffer.InMessage + m, err = c.readMessage() if err != nil { return } @@ -224,7 +241,7 @@ func (c *Connection) ReadOp() (op fuseops.Op, err error) { c.nextOpID++ // Set up op dependencies. - opCtx := c.beginOp(m.Hdr.Opcode, m.Hdr.Unique) + opCtx := c.beginOp(m.Header().Opcode, m.Header().Unique) var debugLogForOp func(int, string, ...interface{}) if c.debugLogger != nil { @@ -238,12 +255,11 @@ func (c *Connection) ReadOp() (op fuseops.Op, err error) { fuseID uint64, replyMsg []byte, opErr error) (err error) { - // Make sure we destroy the message, as required by - // fuseshim.Connection.ReadMessage. - defer m.Destroy() + // Make sure we destroy the message, as required by readMessage. + defer c.destroyInMessage(m) // Clean up state for this op. - c.finishOp(m.Hdr.Opcode, m.Hdr.Unique) + c.finishOp(m.Header().Opcode, m.Header().Unique) // Debug logging if c.debugLogger != nil { diff --git a/fuseops/convert.go b/fuseops/convert.go index fb30d8e..220a91b 100644 --- a/fuseops/convert.go +++ b/fuseops/convert.go @@ -23,6 +23,7 @@ import ( "time" "unsafe" + "github.com/jacobsa/fuse/internal/buffer" "github.com/jacobsa/fuse/internal/fusekernel" "github.com/jacobsa/fuse/internal/fuseshim" "golang.org/x/net/context" @@ -39,7 +40,7 @@ import ( // responsible for arranging for the message to be destroyed. func Convert( opCtx context.Context, - m *fuseshim.Message, + m *buffer.InMessage, protocol fusekernel.Protocol, debugLogForOp func(int, string, ...interface{}), errorLogger *log.Logger, @@ -47,7 +48,7 @@ func Convert( var co *commonOp var io internalOp - switch m.Hdr.Opcode { + switch m.Header().Opcode { case fusekernel.OpLookup: buf := m.Bytes() n := len(buf) @@ -58,7 +59,7 @@ func Convert( to := &LookUpInodeOp{ protocol: protocol, - Parent: InodeID(m.Hdr.Nodeid), + Parent: InodeID(m.Header().Nodeid), Name: string(buf[:n-1]), } io = to @@ -67,7 +68,7 @@ func Convert( case fusekernel.OpGetattr: to := &GetInodeAttributesOp{ protocol: protocol, - Inode: InodeID(m.Hdr.Nodeid), + Inode: InodeID(m.Header().Nodeid), } io = to co = &to.commonOp @@ -81,7 +82,7 @@ func Convert( to := &SetInodeAttributesOp{ protocol: protocol, - Inode: InodeID(m.Hdr.Nodeid), + Inode: InodeID(m.Header().Nodeid), } valid := fusekernel.SetattrValid(in.Valid) @@ -115,7 +116,7 @@ func Convert( } to := &ForgetInodeOp{ - Inode: InodeID(m.Hdr.Nodeid), + Inode: InodeID(m.Header().Nodeid), N: in.Nlookup, } io = to @@ -138,7 +139,7 @@ func Convert( to := &MkDirOp{ protocol: protocol, - Parent: InodeID(m.Hdr.Nodeid), + Parent: InodeID(m.Header().Nodeid), Name: string(name), // On Linux, vfs_mkdir calls through to the inode with at most @@ -170,7 +171,7 @@ func Convert( to := &CreateFileOp{ protocol: protocol, - Parent: InodeID(m.Hdr.Nodeid), + Parent: InodeID(m.Header().Nodeid), Name: string(name), Mode: fuseshim.FileMode(in.Mode), } @@ -193,7 +194,7 @@ func Convert( to := &CreateSymlinkOp{ protocol: protocol, - Parent: InodeID(m.Hdr.Nodeid), + Parent: InodeID(m.Header().Nodeid), Name: string(newName), Target: string(target), } @@ -224,7 +225,7 @@ func Convert( oldName, newName := names[:i], names[i+1:len(names)-1] to := &RenameOp{ - OldParent: InodeID(m.Hdr.Nodeid), + OldParent: InodeID(m.Header().Nodeid), OldName: string(oldName), NewParent: InodeID(in.Newdir), NewName: string(newName), @@ -241,7 +242,7 @@ func Convert( } to := &UnlinkOp{ - Parent: InodeID(m.Hdr.Nodeid), + Parent: InodeID(m.Header().Nodeid), Name: string(buf[:n-1]), } io = to @@ -256,7 +257,7 @@ func Convert( } to := &RmDirOp{ - Parent: InodeID(m.Hdr.Nodeid), + Parent: InodeID(m.Header().Nodeid), Name: string(buf[:n-1]), } io = to @@ -264,14 +265,14 @@ func Convert( case fusekernel.OpOpen: to := &OpenFileOp{ - Inode: InodeID(m.Hdr.Nodeid), + Inode: InodeID(m.Header().Nodeid), } io = to co = &to.commonOp case fusekernel.OpOpendir: to := &OpenDirOp{ - Inode: InodeID(m.Hdr.Nodeid), + Inode: InodeID(m.Header().Nodeid), } io = to co = &to.commonOp @@ -284,7 +285,7 @@ func Convert( } to := &ReadFileOp{ - Inode: InodeID(m.Hdr.Nodeid), + Inode: InodeID(m.Header().Nodeid), Handle: HandleID(in.Fh), Offset: int64(in.Offset), Size: int(in.Size), @@ -300,7 +301,7 @@ func Convert( } to := &ReadDirOp{ - Inode: InodeID(m.Hdr.Nodeid), + Inode: InodeID(m.Header().Nodeid), Handle: HandleID(in.Fh), Offset: DirOffset(in.Offset), Size: int(in.Size), @@ -349,7 +350,7 @@ func Convert( } to := &WriteFileOp{ - Inode: InodeID(m.Hdr.Nodeid), + Inode: InodeID(m.Header().Nodeid), Handle: HandleID(in.Fh), Data: buf, Offset: int64(in.Offset), @@ -365,7 +366,7 @@ func Convert( } to := &SyncFileOp{ - Inode: InodeID(m.Hdr.Nodeid), + Inode: InodeID(m.Header().Nodeid), Handle: HandleID(in.Fh), } io = to @@ -379,7 +380,7 @@ func Convert( } to := &FlushFileOp{ - Inode: InodeID(m.Hdr.Nodeid), + Inode: InodeID(m.Header().Nodeid), Handle: HandleID(in.Fh), } io = to @@ -387,7 +388,7 @@ func Convert( case fusekernel.OpReadlink: to := &ReadSymlinkOp{ - Inode: InodeID(m.Hdr.Nodeid), + Inode: InodeID(m.Header().Nodeid), } io = to co = &to.commonOp @@ -412,8 +413,8 @@ func Convert( default: to := &unknownOp{ - opCode: m.Hdr.Opcode, - inode: InodeID(m.Hdr.Nodeid), + opCode: m.Header().Opcode, + inode: InodeID(m.Header().Nodeid), } io = to co = &to.commonOp @@ -422,7 +423,7 @@ func Convert( co.init( opCtx, io, - m.Hdr.Unique, + m.Header().Unique, sendReply, debugLogForOp, errorLogger)