From 13b15b780d9013988b1fb0e79e30b2528a877638 Mon Sep 17 00:00:00 2001 From: Alexandru Matei Date: Mon, 6 Nov 2023 13:13:51 +0000 Subject: [PATCH] unix: add IoctlLoopConfigure on linux LOOP_CONFIGURE ioctl is used to setup and configure all loop device parameters in a single step. Add to the unix package a new function that exposes LOOP_CONFIGURE. Fixes golang/go#63962 Change-Id: Ia169d268b52b1384febc6bff9c707b721ab2bb24 GitHub-Last-Rev: f9cc4c94cb654afd596df6e28a0d0a1bf60d15eb GitHub-Pull-Request: golang/sys#181 Reviewed-on: https://go-review.googlesource.com/c/sys/+/540075 LUCI-TryBot-Result: Go LUCI Reviewed-by: David Chase Reviewed-by: Tobias Klauser Auto-Submit: Tobias Klauser Reviewed-by: Matthew Dempsky Run-TryBot: Tobias Klauser TryBot-Result: Gopher Robot --- unix/ioctl_linux.go | 5 +++++ unix/linux/types.go | 1 + unix/mkerrors.sh | 1 + unix/zerrors_linux.go | 1 + unix/ztypes_linux.go | 6 ++++++ 5 files changed, 14 insertions(+) diff --git a/unix/ioctl_linux.go b/unix/ioctl_linux.go index 0d12c0851..dbe680eab 100644 --- a/unix/ioctl_linux.go +++ b/unix/ioctl_linux.go @@ -231,3 +231,8 @@ func IoctlLoopGetStatus64(fd int) (*LoopInfo64, error) { func IoctlLoopSetStatus64(fd int, value *LoopInfo64) error { return ioctlPtr(fd, LOOP_SET_STATUS64, unsafe.Pointer(value)) } + +// IoctlLoopConfigure configures all loop device parameters in a single step +func IoctlLoopConfigure(fd int, value *LoopConfig) error { + return ioctlPtr(fd, LOOP_CONFIGURE, unsafe.Pointer(value)) +} diff --git a/unix/linux/types.go b/unix/linux/types.go index 47c06ee76..9297fcfaa 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -3027,6 +3027,7 @@ const ( type LoopInfo C.struct_loop_info type LoopInfo64 C.struct_loop_info64 +type LoopConfig C.struct_loop_config // AF_TIPC diff --git a/unix/mkerrors.sh b/unix/mkerrors.sh index 5dda44503..6202638ba 100755 --- a/unix/mkerrors.sh +++ b/unix/mkerrors.sh @@ -519,6 +519,7 @@ ccflags="$@" $2 ~ /^LOCK_(SH|EX|NB|UN)$/ || $2 ~ /^LO_(KEY|NAME)_SIZE$/ || $2 ~ /^LOOP_(CLR|CTL|GET|SET)_/ || + $2 == "LOOP_CONFIGURE" || $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|TCP|MCAST|EVFILT|NOTE|SHUT|PROT|MAP|MREMAP|MFD|T?PACKET|MSG|SCM|MCL|DT|MADV|PR|LOCAL|TCPOPT|UDP)_/ || $2 ~ /^NFC_(GENL|PROTO|COMM|RF|SE|DIRECTION|LLCP|SOCKPROTO)_/ || $2 ~ /^NFC_.*_(MAX)?SIZE$/ || diff --git a/unix/zerrors_linux.go b/unix/zerrors_linux.go index 1781cfca3..c73cfe2f1 100644 --- a/unix/zerrors_linux.go +++ b/unix/zerrors_linux.go @@ -1801,6 +1801,7 @@ const ( LOCK_SH = 0x1 LOCK_UN = 0x8 LOOP_CLR_FD = 0x4c01 + LOOP_CONFIGURE = 0x4c0a LOOP_CTL_ADD = 0x4c80 LOOP_CTL_GET_FREE = 0x4c82 LOOP_CTL_REMOVE = 0x4c81 diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index b07276a1b..bbf8399ff 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -3005,6 +3005,12 @@ type LoopInfo64 struct { Encrypt_key [32]uint8 Init [2]uint64 } +type LoopConfig struct { + Fd uint32 + Size uint32 + Info LoopInfo64 + _ [8]uint64 +} type TIPCSocketAddr struct { Ref uint32