From 2c41d759774ae702fee0c31d367864d0e943b680 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 24 Aug 2022 13:40:16 +0200 Subject: [PATCH] unix: add IoctlLoop{Get,Set}Status64 on linux These ioctls are used to get/set the status of a loop device. See https://man7.org/linux/man-pages/man4/loop.4.html for details. Change-Id: Ia66db639e6d9326af79954eea5c8f7515aa171d1 Reviewed-on: https://go-review.googlesource.com/c/sys/+/425296 TryBot-Result: Gopher Robot Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Run-TryBot: Tobias Klauser Reviewed-by: Heschi Kreinick --- unix/ioctl_linux.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/unix/ioctl_linux.go b/unix/ioctl_linux.go index 884430b8..0d12c085 100644 --- a/unix/ioctl_linux.go +++ b/unix/ioctl_linux.go @@ -4,9 +4,7 @@ package unix -import ( - "unsafe" -) +import "unsafe" // IoctlRetInt performs an ioctl operation specified by req on a device // associated with opened file descriptor fd, and returns a non-negative @@ -217,3 +215,19 @@ func IoctlKCMAttach(fd int, info KCMAttach) error { func IoctlKCMUnattach(fd int, info KCMUnattach) error { return ioctlPtr(fd, SIOCKCMUNATTACH, unsafe.Pointer(&info)) } + +// IoctlLoopGetStatus64 gets the status of the loop device associated with the +// file descriptor fd using the LOOP_GET_STATUS64 operation. +func IoctlLoopGetStatus64(fd int) (*LoopInfo64, error) { + var value LoopInfo64 + if err := ioctlPtr(fd, LOOP_GET_STATUS64, unsafe.Pointer(&value)); err != nil { + return nil, err + } + return &value, nil +} + +// IoctlLoopSetStatus64 sets the status of the loop device associated with the +// file descriptor fd using the LOOP_SET_STATUS64 operation. +func IoctlLoopSetStatus64(fd int, value *LoopInfo64) error { + return ioctlPtr(fd, LOOP_SET_STATUS64, unsafe.Pointer(value)) +}