Retooled kernelResponse.
parent
448c910c13
commit
612735d590
46
ops.go
46
ops.go
|
@ -24,13 +24,45 @@ import (
|
||||||
"github.com/jacobsa/fuse/internal/fusekernel"
|
"github.com/jacobsa/fuse/internal/fusekernel"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Given an op, return the response that should be sent to the kernel. If the
|
// Return the response that should be sent to the kernel. If the op requires no
|
||||||
// op requires no response, return a nil response. If the op is unknown, return
|
// response, return a nil response.
|
||||||
// an error that should be sent to the kernel.
|
|
||||||
func kernelResponse(
|
func kernelResponse(
|
||||||
untyped fuseops.Op,
|
fuseID uint64,
|
||||||
protocol fusekernel.Protocol) (b buffer.OutMessage, err error) {
|
op fuseops.Op,
|
||||||
switch o := untyped.(type) {
|
opErr error,
|
||||||
|
protocol fusekernel.Protocol) (msg []byte) {
|
||||||
|
// If the user replied with an error, create room enough just for the result
|
||||||
|
// header and fill it in with an error. Otherwise create an appropriate
|
||||||
|
// response.
|
||||||
|
var b *buffer.OutMessage
|
||||||
|
if opErr != nil {
|
||||||
|
b = buffer.NewOutMessage(0)
|
||||||
|
if errno, ok := opErr.(syscall.Errno); ok {
|
||||||
|
b.OutHeader().Error = -int32(errno)
|
||||||
|
} else {
|
||||||
|
b.OutHeader().Error = -int32(syscall.EIO)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
b = kernelResponseForOp(op, protocol)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg = b.Bytes()
|
||||||
|
|
||||||
|
// Fill in the rest of the header.
|
||||||
|
h := b.OutHeader()
|
||||||
|
h.Unique = fuseID
|
||||||
|
h.Len = uint32(len(msg))
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Like kernelResponse, but assumes the user replied with a nil error to the
|
||||||
|
// op.
|
||||||
|
func kernelResponseForOp(
|
||||||
|
op fuseops.Op,
|
||||||
|
protocol fusekernel.Protocol) (b *buffer.OutMessage) {
|
||||||
|
// Create the appropriate output message
|
||||||
|
switch o := op.(type) {
|
||||||
case *fuseops.LookUpInodeOp:
|
case *fuseops.LookUpInodeOp:
|
||||||
size := fusekernel.EntryOutSize(protocol)
|
size := fusekernel.EntryOutSize(protocol)
|
||||||
b = buffer.NewOutMessage(size)
|
b = buffer.NewOutMessage(size)
|
||||||
|
@ -142,7 +174,7 @@ func kernelResponse(
|
||||||
out.MaxWrite = o.MaxWrite
|
out.MaxWrite = o.MaxWrite
|
||||||
|
|
||||||
default:
|
default:
|
||||||
err = syscall.ENOSYS
|
panic(fmt.Sprintf("Unknown op: %#v", op))
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue