ioctl.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // +build linux,cgo
  2. package loopback
  3. import (
  4. "unsafe"
  5. "golang.org/x/sys/unix"
  6. )
  7. func ioctlLoopCtlGetFree(fd uintptr) (int, error) {
  8. index, err := unix.IoctlGetInt(int(fd), LoopCtlGetFree)
  9. if err != nil {
  10. return 0, err
  11. }
  12. return index, nil
  13. }
  14. func ioctlLoopSetFd(loopFd, sparseFd uintptr) error {
  15. return unix.IoctlSetInt(int(loopFd), LoopSetFd, int(sparseFd))
  16. }
  17. func ioctlLoopSetStatus64(loopFd uintptr, loopInfo *loopInfo64) error {
  18. if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, LoopSetStatus64, uintptr(unsafe.Pointer(loopInfo))); err != 0 {
  19. return err
  20. }
  21. return nil
  22. }
  23. func ioctlLoopClrFd(loopFd uintptr) error {
  24. if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, LoopClrFd, 0); err != 0 {
  25. return err
  26. }
  27. return nil
  28. }
  29. func ioctlLoopGetStatus64(loopFd uintptr) (*loopInfo64, error) {
  30. loopInfo := &loopInfo64{}
  31. if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, LoopGetStatus64, uintptr(unsafe.Pointer(loopInfo))); err != 0 {
  32. return nil, err
  33. }
  34. return loopInfo, nil
  35. }
  36. func ioctlLoopSetCapacity(loopFd uintptr, value int) error {
  37. return unix.IoctlSetInt(int(loopFd), LoopSetCapacity, value)
  38. }