From 694b569856e3a51c9668fc42406ef0710785361e Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Sun, 21 Oct 2018 21:02:44 +0300 Subject: [PATCH] switch to dennwc/ioctl library --- btrfs.go | 2 +- ioctl/ioctl.go | 85 +++++++++++++++++---------------------------- ioctl/ioctl_test.go | 21 ----------- ioctl_h.go | 2 +- 4 files changed, 34 insertions(+), 76 deletions(-) delete mode 100644 ioctl/ioctl_test.go diff --git a/btrfs.go b/btrfs.go index fc2a483..e17f49b 100644 --- a/btrfs.go +++ b/btrfs.go @@ -2,7 +2,7 @@ package btrfs import ( "fmt" - "github.com/dennwc/btrfs/ioctl" + "github.com/dennwc/ioctl" "io" "os" "path/filepath" diff --git a/ioctl/ioctl.go b/ioctl/ioctl.go index 0571c5b..fe1d886 100644 --- a/ioctl/ioctl.go +++ b/ioctl/ioctl.go @@ -1,82 +1,61 @@ package ioctl import ( - "fmt" + "github.com/dennwc/ioctl" "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 + None = ioctl.None + Write = ioctl.Write + Read = ioctl.Read ) +// IOC +// +// Deprecated: use github/dennwc/ioctl func IOC(dir, typ, nr, size uintptr) uintptr { - return (dir << dirShift) | - (typ << typeShift) | - (nr << nrShift) | - (size << sizeShift) + return ioctl.IOC(dir, typ, nr, size) } +// IO +// +// Deprecated: use github/dennwc/ioctl func IO(typ, nr uintptr) uintptr { - return IOC(None, typ, nr, 0) + return ioctl.IO(typ, nr) } +// IOC +// +// Deprecated: use github/dennwc/ioctl func IOR(typ, nr, size uintptr) uintptr { - return IOC(Read, typ, nr, size) + return ioctl.IOR(typ, nr, size) } +// IOW +// +// Deprecated: use github/dennwc/ioctl func IOW(typ, nr, size uintptr) uintptr { - return IOC(Write, typ, nr, size) + return ioctl.IOW(typ, nr, size) } +// IOWR +// +// Deprecated: use github/dennwc/ioctl func IOWR(typ, nr, size uintptr) uintptr { - return IOC(Read|Write, typ, nr, size) + return ioctl.IOWR(typ, nr, size) } +// Ioctl +// +// Deprecated: use github/dennwc/ioctl 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 + return ioctl.Ioctl(f, ioc, addr) } +// Do +// +// Deprecated: use github/dennwc/ioctl 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") - } - } - return Ioctl(f, ioc, addr) + return ioctl.Do(f, ioc, arg) } diff --git a/ioctl/ioctl_test.go b/ioctl/ioctl_test.go deleted file mode 100644 index 565fc83..0000000 --- a/ioctl/ioctl_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package 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) - } - } -} diff --git a/ioctl_h.go b/ioctl_h.go index a35a123..769689b 100644 --- a/ioctl_h.go +++ b/ioctl_h.go @@ -3,7 +3,7 @@ package btrfs import ( "encoding/binary" "encoding/hex" - "github.com/dennwc/btrfs/ioctl" + "github.com/dennwc/ioctl" "os" "strconv" "strings"