diff --git a/connection.go b/connection.go index ed984bf..1b6e141 100644 --- a/connection.go +++ b/connection.go @@ -112,9 +112,9 @@ func (c *Connection) Init() (err error) { return } - initOp, ok := op.(*fuseops.InitOp) + initOp, ok := op.(*fuseops.InternalInitOp) if !ok { - err = fmt.Errorf("Expected *fuseops.InitOp, got %T", op) + err = fmt.Errorf("Expected *fuseops.InternalInitOp, got %T", op) return } @@ -137,7 +137,7 @@ func (c *Connection) Init() (err error) { } if initOp.Kernel.LT(c.protocol) { - c.protocol = r.Kernel + c.protocol = initOp.Kernel } // Respond to the init op. diff --git a/fuseops/convert.go b/fuseops/convert.go index b8bee74..c9f3db5 100644 --- a/fuseops/convert.go +++ b/fuseops/convert.go @@ -418,6 +418,22 @@ func Convert( io = to co = &to.commonOp + case fusekernel.OpInit: + type input fusekernel.InitIn + in := (*input)(m.Consume(unsafe.Sizeof(input{}))) + if in == nil { + err = errors.New("Corrupt OpInit") + return + } + + to := &InternalInitOp{ + Kernel: fusekernel.Protocol{in.Major, in.Minor}, + MaxReadahead: in.MaxReadahead, + Flags: fusekernel.InitFlags(in.Flags), + } + io = to + co = &to.commonOp + default: to := &unknownOp{ opCode: m.Header().Opcode, diff --git a/fuseops/ops.go b/fuseops/ops.go index 65f951b..0eb15b8 100644 --- a/fuseops/ops.go +++ b/fuseops/ops.go @@ -945,3 +945,30 @@ type InternalInterruptOp struct { func (o *InternalInterruptOp) kernelResponse() (b buffer.OutMessage) { panic("Shouldn't get here.") } + +// Do not use this struct directly. See the TODO in fuseops/ops.go. +type InternalInitOp struct { + commonOp + + // In + Kernel fusekernel.Protocol + + // Out + Library fusekernel.Protocol + MaxReadahead uint32 + Flags fusekernel.InitFlags + MaxWrite uint32 +} + +func (o *InternalInitOp) kernelResponse() (b buffer.OutMessage) { + b = buffer.NewOutMessage(unsafe.Sizeof(fusekernel.InitOut{})) + out := (*fusekernel.InitOut)(b.Grow(unsafe.Sizeof(fusekernel.InitOut{}))) + + out.Major = o.Library.Major + out.Minor = o.Library.Minor + out.MaxReadahead = o.MaxReadahead + out.Flags = uint32(o.Flags) + out.MaxWrite = o.MaxWrite + + return +}