ioctl.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package devmapper
  2. import (
  3. "unsafe"
  4. )
  5. func ioctlLoopCtlGetFree(fd uintptr) (int, error) {
  6. index, _, err := sysSyscall(sysSysIoctl, fd, LoopCtlGetFree, 0)
  7. if err != 0 {
  8. return 0, err
  9. }
  10. return int(index), nil
  11. }
  12. func ioctlLoopSetFd(loopFd, sparseFd uintptr) error {
  13. if _, _, err := sysSyscall(sysSysIoctl, loopFd, LoopSetFd, sparseFd); err != 0 {
  14. return err
  15. }
  16. return nil
  17. }
  18. func ioctlLoopSetStatus64(loopFd uintptr, loopInfo *LoopInfo64) error {
  19. if _, _, err := sysSyscall(sysSysIoctl, loopFd, LoopSetStatus64, uintptr(unsafe.Pointer(loopInfo))); err != 0 {
  20. return err
  21. }
  22. return nil
  23. }
  24. func ioctlLoopClrFd(loopFd uintptr) error {
  25. if _, _, err := sysSyscall(sysSysIoctl, loopFd, LoopClrFd, 0); err != 0 {
  26. return err
  27. }
  28. return nil
  29. }
  30. func ioctlLoopGetStatus64(loopFd uintptr) (*LoopInfo64, error) {
  31. loopInfo := &LoopInfo64{}
  32. if _, _, err := sysSyscall(sysSysIoctl, loopFd, LoopGetStatus64, uintptr(unsafe.Pointer(loopInfo))); err != 0 {
  33. return nil, err
  34. }
  35. return loopInfo, nil
  36. }
  37. func ioctlLoopSetCapacity(loopFd uintptr, value int) error {
  38. if _, _, err := sysSyscall(sysSysIoctl, loopFd, LoopSetCapacity, uintptr(value)); err != 0 {
  39. return err
  40. }
  41. return nil
  42. }
  43. func ioctlBlkGetSize64(fd uintptr) (int64, error) {
  44. var size int64
  45. if _, _, err := sysSyscall(sysSysIoctl, fd, BlkGetSize64, uintptr(unsafe.Pointer(&size))); err != 0 {
  46. return 0, err
  47. }
  48. return size, nil
  49. }