github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/abi/linux/ioctl.go (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package linux 16 17 // ioctl(2) requests provided by asm-generic/ioctls.h 18 // 19 // These are ordered by request number (low byte). 20 const ( 21 TCGETS = 0x00005401 22 TCSETS = 0x00005402 23 TCSETSW = 0x00005403 24 TCSETSF = 0x00005404 25 TCSBRK = 0x00005409 26 TIOCEXCL = 0x0000540c 27 TIOCNXCL = 0x0000540d 28 TIOCSCTTY = 0x0000540e 29 TIOCGPGRP = 0x0000540f 30 TIOCSPGRP = 0x00005410 31 TIOCOUTQ = 0x00005411 32 TIOCSTI = 0x00005412 33 TIOCGWINSZ = 0x00005413 34 TIOCSWINSZ = 0x00005414 35 TIOCMGET = 0x00005415 36 TIOCMBIS = 0x00005416 37 TIOCMBIC = 0x00005417 38 TIOCMSET = 0x00005418 39 TIOCINQ = 0x0000541b 40 FIONREAD = TIOCINQ 41 FIONBIO = 0x00005421 42 TIOCSETD = 0x00005423 43 TIOCNOTTY = 0x00005422 44 TIOCGETD = 0x00005424 45 TCSBRKP = 0x00005425 46 TIOCSBRK = 0x00005427 47 TIOCCBRK = 0x00005428 48 TIOCGSID = 0x00005429 49 TIOCGPTN = 0x80045430 50 TIOCSPTLCK = 0x40045431 51 TIOCGDEV = 0x80045432 52 TIOCVHANGUP = 0x00005437 53 TCFLSH = 0x0000540b 54 TIOCCONS = 0x0000541d 55 TIOCSSERIAL = 0x0000541f 56 TIOCGEXCL = 0x80045440 57 TIOCGPTPEER = 0x80045441 58 TIOCGICOUNT = 0x0000545d 59 FIONCLEX = 0x00005450 60 FIOCLEX = 0x00005451 61 FIOASYNC = 0x00005452 62 FIOSETOWN = 0x00008901 63 SIOCSPGRP = 0x00008902 64 FIOGETOWN = 0x00008903 65 SIOCGPGRP = 0x00008904 66 ) 67 68 // ioctl(2) requests provided by uapi/linux/sockios.h 69 const ( 70 SIOCGIFNAME = 0x8910 71 SIOCGIFCONF = 0x8912 72 SIOCGIFFLAGS = 0x8913 73 SIOCGIFADDR = 0x8915 74 SIOCGIFDSTADDR = 0x8917 75 SIOCGIFBRDADDR = 0x8919 76 SIOCGIFNETMASK = 0x891b 77 SIOCGIFMETRIC = 0x891d 78 SIOCGIFMTU = 0x8921 79 SIOCGIFMEM = 0x891f 80 SIOCGIFHWADDR = 0x8927 81 SIOCGIFINDEX = 0x8933 82 SIOCGIFPFLAGS = 0x8935 83 SIOCGIFTXQLEN = 0x8942 84 SIOCETHTOOL = 0x8946 85 SIOCGMIIPHY = 0x8947 86 SIOCGMIIREG = 0x8948 87 SIOCGIFMAP = 0x8970 88 ) 89 90 // ioctl(2) requests provided by uapi/asm-generic/sockios.h 91 const ( 92 SIOCGSTAMP = 0x8906 93 ) 94 95 // ioctl(2) directions. Used to calculate requests number. 96 // Constants from asm-generic/ioctl.h. 97 const ( 98 _IOC_NONE = 0 99 _IOC_WRITE = 1 100 _IOC_READ = 2 101 ) 102 103 // Constants from asm-generic/ioctl.h. 104 const ( 105 _IOC_NRBITS = 8 106 _IOC_TYPEBITS = 8 107 _IOC_SIZEBITS = 14 108 _IOC_DIRBITS = 2 109 110 _IOC_NRSHIFT = 0 111 _IOC_TYPESHIFT = _IOC_NRSHIFT + _IOC_NRBITS 112 _IOC_SIZESHIFT = _IOC_TYPESHIFT + _IOC_TYPEBITS 113 _IOC_DIRSHIFT = _IOC_SIZESHIFT + _IOC_SIZEBITS 114 ) 115 116 // Constants from uapi/linux/fs.h. 117 const ( 118 FS_IOC_GETFLAGS = 2148034049 119 FS_VERITY_FL = 1048576 120 ) 121 122 // Constants from uapi/linux/fsverity.h. 123 const ( 124 FS_VERITY_HASH_ALG_SHA256 = 1 125 FS_VERITY_HASH_ALG_SHA512 = 2 126 127 FS_IOC_ENABLE_VERITY = 1082156677 128 FS_IOC_MEASURE_VERITY = 3221513862 129 ) 130 131 // DigestMetadata is a helper struct for VerityDigest. 132 // 133 // +marshal 134 type DigestMetadata struct { 135 DigestAlgorithm uint16 136 DigestSize uint16 137 } 138 139 // SizeOfDigestMetadata is the size of struct DigestMetadata. 140 const SizeOfDigestMetadata = 4 141 142 // VerityDigest is struct from uapi/linux/fsverity.h. 143 type VerityDigest struct { 144 Metadata DigestMetadata 145 Digest []byte 146 } 147 148 // IOC outputs the result of _IOC macro in asm-generic/ioctl.h. 149 func IOC(dir, typ, nr, size uint32) uint32 { 150 return uint32(dir)<<_IOC_DIRSHIFT | typ<<_IOC_TYPESHIFT | nr<<_IOC_NRSHIFT | size<<_IOC_SIZESHIFT 151 } 152 153 // Kcov ioctls from kernel/kcov.h. 154 var ( 155 KCOV_INIT_TRACE = IOC(_IOC_READ, 'c', 1, 8) 156 KCOV_ENABLE = IOC(_IOC_NONE, 'c', 100, 0) 157 KCOV_DISABLE = IOC(_IOC_NONE, 'c', 101, 0) 158 ) 159 160 // Kcov trace types from kernel/kcov.h. 161 const ( 162 KCOV_TRACE_PC = 0 163 KCOV_TRACE_CMP = 1 164 ) 165 166 // Kcov state constants from kernel/kcov.h. 167 const ( 168 KCOV_MODE_DISABLED = 0 169 KCOV_MODE_INIT = 1 170 KCOV_MODE_TRACE_PC = 2 171 KCOV_MODE_TRACE_CMP = 3 172 )