| // Copyright 2018 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| // +build fuchsia |
| |
| package fdio |
| |
| import ( |
| "syscall/zx" |
| "syscall/zx/io" |
| ) |
| |
| // Node is a wrapper around a NodeInterface which implements FDIO. |
| type Node struct { |
| Object |
| } |
| |
| // NodeInterface returns the underlying Node FIDL interface. |
| func (n *Node) NodeInterface() (*io.NodeInterface) { |
| return (*io.NodeInterface)(n.Object.ObjectInterface) |
| } |
| |
| // Sync performs a sync operation on a Node. |
| func (n *Node) Sync() error { |
| if status, err := n.NodeInterface().Sync(); err != nil { |
| return err |
| } else if status != zx.ErrOk { |
| return zx.Error{Status: status, Text: "io.node"} |
| } |
| return nil |
| } |
| |
| // GetAttr returns the attributes for the Node. |
| func (n *Node) GetAttr() (io.NodeAttributes, error) { |
| status, attrs, err := n.NodeInterface().GetAttr() |
| if err != nil { |
| return io.NodeAttributes{}, err |
| } else if status != zx.ErrOk { |
| return io.NodeAttributes{}, zx.Error{Status: status, Text: "io.node"} |
| } |
| return attrs, nil |
| } |
| |
| // SetAttr sets the attributes for Node as defined by flags. |
| func (n *Node) SetAttr(flags uint32, attr io.NodeAttributes) error { |
| if status, err := n.NodeInterface().SetAttr(flags, attr); err != nil { |
| return err |
| } else if status != zx.ErrOk { |
| return zx.Error{Status: status, Text: "io.node"} |
| } |
| return nil |
| } |
| |
| // Ioctl calls an ioctl on Node. |
| func (n *Node) Ioctl(op uint32, max uint64, in []byte, handles []zx.Handle) ([]byte, []zx.Handle, error) { |
| status, h, b, err := n.NodeInterface().Ioctl(op, max, handles, in) |
| if err != nil { |
| return nil, nil, err |
| } else if status != zx.ErrOk { |
| return nil, nil, zx.Error{Status: status, Text: "io.node"} |
| } |
| return b, h, nil |
| } |