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 <mdlayher@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Terin Stock <terinjokes@gmail.com>
Reviewed-by: Florian Lehner <lehner.florian86@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Tobias Klauser <tobias.klauser@gmail.com>
diff --git a/unix/linux/types.go b/unix/linux/types.go
index 1888a49..9778b0a 100644
--- a/unix/linux/types.go
+++ b/unix/linux/types.go
@@ -120,6 +120,7 @@
 #include <linux/stat.h>
 #include <linux/taskstats.h>
 #include <linux/tipc.h>
+#include <linux/watchdog.h>
 #include <linux/vm_sockets.h>
 
 // abi/abi.h generated by mkall.go.
@@ -2510,3 +2511,7 @@
 	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 1bef714..9bd8cd8 100755
--- a/unix/mkerrors.sh
+++ b/unix/mkerrors.sh
@@ -546,7 +546,7 @@
 		$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 94dafa4..122e7eb 100644
--- a/unix/syscall_linux.go
+++ b/unix/syscall_linux.go
@@ -106,6 +106,15 @@
 	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 @@
 	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 79e032f..780d689 100644
--- a/unix/zerrors_linux.go
+++ b/unix/zerrors_linux.go
@@ -2357,6 +2357,23 @@
 	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 a92a501..2309ffc 100644
--- a/unix/ztypes_linux.go
+++ b/unix/ztypes_linux.go
@@ -2567,3 +2567,9 @@
 	CAN_RAW_FD_FRAMES     = 0x5
 	CAN_RAW_JOIN_FILTERS  = 0x6
 )
+
+type WatchdogInfo struct {
+	Options  uint32
+	Version  uint32
+	Identity [32]uint8
+}