mirror of
https://github.com/dennwc/btrfs
synced 2025-05-11 20:29:15 +00:00
switch to dennwc/ioctl library
This commit is contained in:
parent
75c27127c2
commit
694b569856
2
btrfs.go
2
btrfs.go
@ -2,7 +2,7 @@ package btrfs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dennwc/btrfs/ioctl"
|
"github.com/dennwc/ioctl"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -1,82 +1,61 @@
|
|||||||
package ioctl
|
package ioctl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"github.com/dennwc/ioctl"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
|
||||||
"syscall"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
nrBits = 8
|
None = ioctl.None
|
||||||
typeBits = 8
|
Write = ioctl.Write
|
||||||
sizeBits = 14
|
Read = ioctl.Read
|
||||||
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
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// IOC
|
||||||
|
//
|
||||||
|
// Deprecated: use github/dennwc/ioctl
|
||||||
func IOC(dir, typ, nr, size uintptr) uintptr {
|
func IOC(dir, typ, nr, size uintptr) uintptr {
|
||||||
return (dir << dirShift) |
|
return ioctl.IOC(dir, typ, nr, size)
|
||||||
(typ << typeShift) |
|
|
||||||
(nr << nrShift) |
|
|
||||||
(size << sizeShift)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IO
|
||||||
|
//
|
||||||
|
// Deprecated: use github/dennwc/ioctl
|
||||||
func IO(typ, nr uintptr) uintptr {
|
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 {
|
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 {
|
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 {
|
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 {
|
func Ioctl(f *os.File, ioc uintptr, addr uintptr) error {
|
||||||
_, _, e := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), ioc, addr)
|
return ioctl.Ioctl(f, ioc, addr)
|
||||||
if e != 0 {
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do
|
||||||
|
//
|
||||||
|
// Deprecated: use github/dennwc/ioctl
|
||||||
func Do(f *os.File, ioc uintptr, arg interface{}) error {
|
func Do(f *os.File, ioc uintptr, arg interface{}) error {
|
||||||
var addr uintptr
|
return ioctl.Do(f, ioc, arg)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,7 +3,7 @@ package btrfs
|
|||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"github.com/dennwc/btrfs/ioctl"
|
"github.com/dennwc/ioctl"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
Loading…
Reference in New Issue
Block a user