From f6757f270073d026979807e47062dedbffec50bc Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Sun, 4 Oct 2020 12:34:18 -0400 Subject: [PATCH] unix: add Linux watchdog structures and missing constants This CL also adds the type-safe wrappers IoctlGetWatchdogInfo and IoctlWatchdogKeepalive around the raw ioctl interface. Change-Id: I98e3970807b28832e49524700b17b6b6f75d91ed Reviewed-on: https://go-review.googlesource.com/c/sys/+/259497 Run-TryBot: Matt Layher Run-TryBot: Ian Lance Taylor TryBot-Result: Go Bot Reviewed-by: Terin Stock Reviewed-by: Florian Lehner Reviewed-by: Ian Lance Taylor Reviewed-by: Tobias Klauser Trust: Tobias Klauser --- unix/linux/types.go | 5 +++++ unix/mkerrors.sh | 2 +- unix/syscall_linux.go | 16 ++++++++++++++++ unix/zerrors_linux.go | 17 +++++++++++++++++ unix/ztypes_linux.go | 6 ++++++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/unix/linux/types.go b/unix/linux/types.go index 1888a498..9778b0af 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -120,6 +120,7 @@ struct termios2 { #include #include #include +#include #include // abi/abi.h generated by mkall.go. @@ -2510,3 +2511,7 @@ const ( CAN_RAW_FD_FRAMES = C.CAN_RAW_FD_FRAMES CAN_RAW_JOIN_FILTERS = C.CAN_RAW_JOIN_FILTERS ) + +// Watchdog API + +type WatchdogInfo C.struct_watchdog_info diff --git a/unix/mkerrors.sh b/unix/mkerrors.sh index 1bef7148..9bd8cd8f 100755 --- a/unix/mkerrors.sh +++ b/unix/mkerrors.sh @@ -546,7 +546,7 @@ ccflags="$@" $2 ~ /^XATTR_(CREATE|REPLACE|NO(DEFAULT|FOLLOW|SECURITY)|SHOWCOMPRESSION)/ || $2 ~ /^ATTR_(BIT_MAP_COUNT|(CMN|VOL|FILE)_)/ || $2 ~ /^FSOPT_/ || - $2 ~ /^WDIOC_/ || + $2 ~ /^WDIO[CFS]_/ || $2 ~ /^NFN/ || $2 ~ /^XDP_/ || $2 ~ /^RWF_/ || diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index 94dafa4e..122e7eb0 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -106,6 +106,15 @@ func IoctlGetRTCTime(fd int) (*RTCTime, error) { return &value, err } +// IoctlGetWatchdogInfo fetches information about a watchdog device from the +// Linux watchdog API. For more information, see: +// https://www.kernel.org/doc/html/latest/watchdog/watchdog-api.html. +func IoctlGetWatchdogInfo(fd int) (*WatchdogInfo, error) { + var value WatchdogInfo + err := ioctl(fd, WDIOC_GETSUPPORT, uintptr(unsafe.Pointer(&value))) + return &value, err +} + func IoctlGetRTCWkAlrm(fd int) (*RTCWkAlrm, error) { var value RTCWkAlrm err := ioctl(fd, RTC_WKALM_RD, uintptr(unsafe.Pointer(&value))) @@ -137,6 +146,13 @@ func IoctlFileDedupeRange(destFd int, value *FileDedupeRange) error { return err } +// IoctlWatchdogKeepalive issues a keepalive ioctl to a watchdog device. For +// more information, see: +// https://www.kernel.org/doc/html/latest/watchdog/watchdog-api.html. +func IoctlWatchdogKeepalive(fd int) error { + return ioctl(fd, WDIOC_KEEPALIVE, 0) +} + //sys Linkat(olddirfd int, oldpath string, newdirfd int, newpath string, flags int) (err error) func Link(oldpath string, newpath string) (err error) { diff --git a/unix/zerrors_linux.go b/unix/zerrors_linux.go index 79e032f4..780d689f 100644 --- a/unix/zerrors_linux.go +++ b/unix/zerrors_linux.go @@ -2357,6 +2357,23 @@ const ( WCONTINUED = 0x8 WDIOC_SETPRETIMEOUT = 0xc0045708 WDIOC_SETTIMEOUT = 0xc0045706 + WDIOF_ALARMONLY = 0x400 + WDIOF_CARDRESET = 0x20 + WDIOF_EXTERN1 = 0x4 + WDIOF_EXTERN2 = 0x8 + WDIOF_FANFAULT = 0x2 + WDIOF_KEEPALIVEPING = 0x8000 + WDIOF_MAGICCLOSE = 0x100 + WDIOF_OVERHEAT = 0x1 + WDIOF_POWEROVER = 0x40 + WDIOF_POWERUNDER = 0x10 + WDIOF_PRETIMEOUT = 0x200 + WDIOF_SETTIMEOUT = 0x80 + WDIOF_UNKNOWN = -0x1 + WDIOS_DISABLECARD = 0x1 + WDIOS_ENABLECARD = 0x2 + WDIOS_TEMPPANIC = 0x4 + WDIOS_UNKNOWN = -0x1 WEXITED = 0x4 WIN_ACKMEDIACHANGE = 0xdb WIN_CHECKPOWERMODE1 = 0xe5 diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index a92a5019..2309ffca 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -2567,3 +2567,9 @@ const ( CAN_RAW_FD_FRAMES = 0x5 CAN_RAW_JOIN_FILTERS = 0x6 ) + +type WatchdogInfo struct { + Options uint32 + Version uint32 + Identity [32]uint8 +}