Exemplo n.º 1
0
// Fill in the response that should be sent to the kernel, or set noResponse if
// the op requires no response.
func (c *Connection) kernelResponse(
	m *buffer.OutMessage,
	fuseID uint64,
	op interface{},
	opErr error) (noResponse bool) {
	h := m.OutHeader()
	h.Unique = fuseID

	// Special case: handle the ops for which the kernel expects no response.
	// interruptOp .
	switch op.(type) {
	case *fuseops.ForgetInodeOp:
		noResponse = true
		return

	case *interruptOp:
		noResponse = true
		return
	}

	// If the user returned the error, fill in the error field of the outgoing
	// message header.
	if opErr != nil {
		m.OutHeader().Error = -int32(syscall.EIO)
		if errno, ok := opErr.(syscall.Errno); ok {
			m.OutHeader().Error = -int32(errno)
		}

		// Special case: for some types, convertInMessage grew the message in order
		// to obtain a destination buffer. Make sure that we shrink back to just
		// the header, because on OS X the kernel otherwise returns EINVAL when we
		// attempt to write an error response with a length that extends beyond the
		// header.
		m.ShrinkTo(buffer.OutMessageInitialSize)
	}

	// Otherwise, fill in the rest of the response.
	if opErr == nil {
		c.kernelResponseForOp(m, op)
	}

	h.Len = uint32(m.Len())
	return
}