pax_global_header00006660000000000000000000000064133631376110014516gustar00rootroot0000000000000052 comment=01780425206817ff049d3eef4327d3f28e04450f golang-github-dennwc-ioctl-1.0.0+git20181021.0178042/000077500000000000000000000000001336313761100210515ustar00rootroot00000000000000golang-github-dennwc-ioctl-1.0.0+git20181021.0178042/LICENSE000066400000000000000000000020561336313761100220610ustar00rootroot00000000000000MIT License Copyright (c) 2018 Denys Smirnov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. golang-github-dennwc-ioctl-1.0.0+git20181021.0178042/ioctl.go000066400000000000000000000026011336313761100225110ustar00rootroot00000000000000package ioctl import ( "fmt" "os" "reflect" "syscall" ) const ( nrBits = 8 typeBits = 8 sizeBits = 14 dirBits = 2 ) const ( nrMask = (1 << nrBits) - 1 typeMask = (1 << typeBits) - 1 sizeMask = (1 << sizeBits) - 1 dirMask = (1 << dirBits) - 1 ) const ( nrShift = 0 typeShift = nrShift + nrBits sizeShift = typeShift + typeBits dirShift = sizeShift + sizeBits ) const ( None = 0 Write = 1 Read = 2 ) func IOC(dir, typ, nr, size uintptr) uintptr { return (dir << dirShift) | (typ << typeShift) | (nr << nrShift) | (size << sizeShift) } func IO(typ, nr uintptr) uintptr { return IOC(None, typ, nr, 0) } func IOR(typ, nr, size uintptr) uintptr { return IOC(Read, typ, nr, size) } func IOW(typ, nr, size uintptr) uintptr { return IOC(Write, typ, nr, size) } func IOWR(typ, nr, size uintptr) uintptr { return IOC(Read|Write, typ, nr, size) } func Ioctl(f *os.File, ioc uintptr, addr uintptr) error { _, _, e := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), ioc, addr) if e != 0 { return e } return nil } func Do(f *os.File, ioc uintptr, arg interface{}) error { var addr uintptr if arg != nil { v := reflect.ValueOf(arg) switch v.Kind() { case reflect.Ptr: addr = v.Elem().UnsafeAddr() case reflect.Slice: addr = v.Index(0).UnsafeAddr() default: return fmt.Errorf("expected ptr or slice, got %T", arg) } } return Ioctl(f, ioc, addr) } golang-github-dennwc-ioctl-1.0.0+git20181021.0178042/ioctl_test.go000066400000000000000000000005251336313761100235530ustar00rootroot00000000000000package ioctl import ( "testing" ) var casesIOC = []struct { got uintptr expect uintptr }{ {got: IOC(1, 2, 3, 4), expect: 0x40040203}, } func TestIOC(t *testing.T) { for i, c := range casesIOC { if c.got != c.expect { t.Errorf("unexpected ioc (case %d): %x(%b) vs %x(%b)", i+1, c.got, c.got, c.expect, c.expect) } } }