| // Copyright 2016 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 provides unix-style IO, implementing Zircon's "system/ulib/fdio" |
| package fdio |
| |
| import ( |
| "syscall/zx" |
| ) |
| |
| // FDIO provides classic unix-style IO over various transports |
| type FDIO interface { |
| Read(data []byte) (int, error) |
| ReadAt(data []byte, off int64) (int, error) |
| Write(data []byte) (int, error) |
| WriteAt(data []byte, off int64) (int, error) |
| Seek(offset int64, whence int) (int64, error) |
| Close() error |
| Open(path string, flags uint32, mode uint32) (FDIO, error) |
| Clone() ([]zx.Handle, error) // TODO(smklein): Pass type back from Clone |
| Ioctl(op uint32, in, out []byte) ([]zx.Handle, error) |
| IoctlSetHandle(op uint32, in zx.Handle) error |
| Misc(op uint32, off int64, in, out []byte, handles []zx.Handle) (n int, err error) |
| // TODO(smklein): Add missing ops, like "Wait" |
| } |
| |
| const ( |
| // MaxHandles is the maximum number of handles which can be transferred in an fdio op. |
| MaxHandles = 3 |
| // ChunkSize is the largest number of bytes which can be used in a single low-level op. |
| ChunkSize = 8192 |
| // IoctlMaxInput is the largest acceptable size for an Ioctl op input. |
| IoctlMaxInput = 1024 |
| // maximum number of bytes in a path |
| PathMax = 4096 |
| ) |
| |
| type Protocol uint32 |
| |
| // All available FDIO protocols |
| const ( |
| // The SERVICE protocol allows access to a generic interface. |
| ProtocolService = Protocol(iota) |
| // The FILE protocol allows access to a regular file. |
| ProtocolFile |
| // The DIRECTORY protocol allows access to a directory, which may |
| // contain additional nodes. |
| ProtocolDirectory |
| // The PIPE protocol uses message ports as simple, no-flow-control io pipes. |
| ProtocolPipe |
| // The VMOFILE protocol accesses a file as a VMO. |
| ProtocolVMOFile |
| // The DEVICE protocol allows access to a generic device. |
| ProtocolDevice |
| // The SOCKET protocol provides socket access. |
| ProtocolSocket |
| ProtocolSocketConnected |
| ) |
| |
| // FDIO Ioctls |
| func IoctlNum(kind, family, number uint32) uint32 { |
| return ((kind & 0xF) << 20) | ((family & 0xFF) << 8) | (number & 0xFF) |
| } |
| func IoctlKind(ioctl uint32) uint32 { |
| return (ioctl >> 20) & 0xF |
| } |
| func IoctlFamily(ioctl uint32) uint32 { |
| return (ioctl >> 8) & 0xFF |
| } |
| func IoctlNumber(ioctl uint32) uint32 { |
| return ioctl & 0xFF |
| } |
| |
| const ( |
| IoctlKindDefault = 0x0 // IOCTL_KIND_DEFAULT |
| IoctlKindGetHandle = 0x1 // IOCTL_KIND_GET_HANDLE |
| IoctlKindGetTwoHandles = 0x2 // IOCTL_KIND_GET_TWO_HANDLES |
| IoctlKindSetHandle = 0x3 // IOCTL_KIND_SET_HANDLE |
| IoctlKindGetThreeHandles = 0x4 // IOCTL_KIND_GET_THREE_HANDLES |
| ) |
| |
| const ( |
| IoctlFamilyReserved = 0x00 // IOCTL_FAMILY_RESERVED |
| IoctlFamilyDevice = 0x01 // IOCTL_FAMILY_DEVICE |
| IoctlFamilyVFS = 0x02 // IOCTL_FAMILY_VFS |
| IoctlFamilyDMCTL = 0x03 // IOCTL_FAMILY_DMCTL |
| IoctlFamilyTest = 0x04 // IOCTL_FAMILY_TEST |
| ) |
| |
| const ( |
| IoctlFamilyBlock = 0x13 // IOCTL_FAMILY_BLOCK |
| IoctlFamilyNetconfig = 0x26 // IOCTL_FAMILY_NETCONFIG |
| ) |
| |
| const ( |
| IoctlFamilyPower = 0x30 // IOCTL_FAMILY_POWER |
| ) |
| |
| var IoctlDeviceBind = IoctlNum(IoctlKindDefault, IoctlFamilyDevice, 0) |
| var IoctlDeviceGetEventHandle = IoctlNum(IoctlKindGetHandle, IoctlFamilyDevice, 1) |
| var IoctlDeviceGetDriverName = IoctlNum(IoctlKindDefault, IoctlFamilyDevice, 2) |
| var IoctlDeviceGetDeviceName = IoctlNum(IoctlKindDefault, IoctlFamilyDevice, 3) |
| var IoctlDeviceGetTopoPath = IoctlNum(IoctlKindDefault, IoctlFamilyDevice, 4) |
| var IoctlDeviceSync = IoctlNum(IoctlKindDefault, IoctlFamilyDevice, 6) |
| var IoctlDeviceDebugSuspend = IoctlNum(IoctlKindDefault, IoctlFamilyDevice, 7) |
| var IoctlDeviceDebugResume = IoctlNum(IoctlKindDefault, IoctlFamilyDevice, 8) |
| |
| var IoctlVFSMountFS = IoctlNum(IoctlKindSetHandle, IoctlFamilyVFS, 0) |
| var IoctlVFSUnmountFS = IoctlNum(IoctlKindDefault, IoctlFamilyVFS, 1) |
| var IoctlVFSUnmountNode = IoctlNum(IoctlKindGetHandle, IoctlFamilyVFS, 2) |
| var IoctlVFSQueryFS = IoctlNum(IoctlKindDefault, IoctlFamilyVFS, 4) |
| var IoctlVFSGetTokenFS = IoctlNum(IoctlKindGetHandle, IoctlFamilyVFS, 5) |
| var IoctlVFSWatchDir = IoctlNum(IoctlKindSetHandle, IoctlFamilyVFS, 8) |
| var IoctlVFSGetDevicePath = IoctlNum(IoctlKindDefault, IoctlFamilyVFS, 9) |
| |
| var IoctlPowerGetInfo = IoctlNum(IoctlKindDefault, IoctlFamilyPower, 1) |
| var IoctlPowerGetBatteryInfo = IoctlNum(IoctlKindDefault, IoctlFamilyPower, 2) |
| var IoctlPowerGetStateChangeEvent = IoctlNum(IoctlKindGetHandle, IoctlFamilyPower, 3) |
| |
| type PowerInfoResult struct { |
| PowerType uint32 |
| State uint32 |
| } |
| |
| type BatteryInfoResult struct { |
| Unit uint32 |
| DesignCapacity uint32 |
| LastFullCapacity uint32 |
| DesignVoltage uint32 |
| CapacityWarning uint32 |
| CapacityLow uint32 |
| CapacityGranularityLowWarning uint32 |
| CapacityGranularityWarningFull uint32 |
| PresentRate int32 |
| RemainingCapacity uint32 |
| PresentVoltage uint32 |
| } |
| |
| const ( |
| PowerTypeAC = 0 |
| PowerTypeBattery = 1 |
| |
| PowerStateOnline = 1 << 0 |
| PowerStateDischarging = 1 << 1 |
| PowerStateCharging = 1 << 2 |
| PowerStateCritical = 1 << 3 |
| |
| BatteryUnitMW = 0 |
| BatteryUnitMA = 1 |
| ) |
| |
| type VFSWatchDirRequest struct { |
| H zx.Handle |
| Mask uint32 |
| Options uint32 |
| } |
| |
| const ( |
| VFSWatchEventDeleted = iota |
| VFSWatchEventAdded |
| VFSWatchEventRemoved |
| VFSWatchEventExisting |
| VFSWatchEventIdle |
| ) |
| |
| const ( |
| VFSWatchMaskDeleted = 1 << iota |
| VFSWatchMaskAdded |
| VFSWatchMaskRemoved |
| VFSWatchMaskExisting |
| VFSWatchMaskIdle |
| VFSWatchMaskAll = 0x1F |
| ) |
| |
| type Vnattr struct { |
| Valid uint32 |
| Mode Vtype |
| Inode uint64 |
| Size uint64 |
| Blksize uint64 |
| Blkcount uint64 |
| Nlink uint64 |
| CreateTime uint64 |
| ModifyTime uint64 |
| } |
| |
| // VnattrBlksize is the size of block used in "Blockcount", which may be distinct from Blksize. |
| const VnattrBlksize = 512 |
| |
| const ( |
| AttrCtime = 1 << iota |
| AttrMtime |
| AttrAtime |
| ) |
| |
| type Vtype uint32 |
| |
| // bit-compatible with POSIX stat |
| const ( |
| VtypeMask Vtype = 0170000 |
| VtypeSock Vtype = 0140000 |
| VtypeLink Vtype = 0120000 |
| VtypeFile Vtype = 0100000 |
| VtypeBdev Vtype = 0060000 |
| VtypeDir Vtype = 0040000 |
| VtypeCdev Vtype = 0020000 |
| VtypePipe Vtype = 0010000 |
| |
| VtypeISUID Vtype = 0004000 |
| VtypeISGID Vtype = 0002000 |
| VtypeISVTX Vtype = 0001000 |
| VtypeIRWXU Vtype = 0000700 |
| VtypeIRUSR Vtype = 0000400 |
| VtypeIWUSR Vtype = 0000200 |
| VtypeIXUSR Vtype = 0000100 |
| VtypeIRWXG Vtype = 0000070 |
| VtypeIRGRP Vtype = 0000040 |
| VtypeIWGRP Vtype = 0000020 |
| VtypeIXGRP Vtype = 0000010 |
| VtypeIRWXO Vtype = 0000007 |
| VtypeIROTH Vtype = 0000004 |
| VtypeIWOTH Vtype = 0000002 |
| VtypeIXOTH Vtype = 0000001 |
| ) |
| |
| const ( |
| HandleTypeRemote = 0x32 |
| HandleTypePipe = 0x33 |
| HandleTypeEvent = 0x34 |
| HandleTypeLogger = 0x35 |
| HandleTypeSocket = 0x36 |
| ) |