patch-2.1.15 linux/drivers/char/softdog.c

Next file: linux/drivers/char/tpqic02.c
Previous file: linux/drivers/char/serial.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.14/linux/drivers/char/softdog.c linux/drivers/char/softdog.c
@@ -1,18 +1,19 @@
 /*
- *	SoftDog	0.04:	A Software Watchdog Device
+ *	SoftDog	0.05:	A Software Watchdog Device
  *
- *	(c) Copyright 1995    Alan Cox <alan@lxorguk.ukuu.org.uk>
- *
- *	Email us for quotes on Linux software and driver development. 
- *
- *			-----------------------
+ *	(c) Copyright 1996 Alan Cox <alan@cymru.net>, All Rights Reserved.
+ *				http://www.cymru.net
  *
  *	This program is free software; you can redistribute it and/or
  *	modify it under the terms of the GNU General Public License
  *	as published by the Free Software Foundation; either version
  *	2 of the License, or (at your option) any later version.
+ *	
+ *	Neither Alan Cox nor CymruNet Ltd. admit liability nor provide 
+ *	warranty for any of this software. This material is provided 
+ *	"AS-IS" and at no charge.	
  *
- *			-----------------------
+ *	(c) Copyright 1995    Alan Cox <alan@lxorguk.ukuu.org.uk>
  *
  *	Software only watchdog driver. Unlike its big brother the WDT501P
  *	driver this won't always recover a failed machine.
@@ -31,6 +32,8 @@
 #include <linux/fs.h>
 #include <linux/mm.h>
 #include <linux/miscdevice.h>
+#include <linux/watchdog.h>
+#include <asm/uaccess.h>
 
 #define WATCHDOG_MINOR	130
 #define TIMER_MARGIN	60		/* (secs) Default is 1 minute */
@@ -93,7 +96,7 @@
 #endif	
 }
 
-static int softdog_write(struct inode *inode, struct file *file, const char *data, int len)
+static void softdog_ping(void)
 {
 	/*
 	 *	Refresh the timer.
@@ -101,7 +104,49 @@
 	del_timer(&watchdog_ticktock);
 	watchdog_ticktock.expires=jiffies + (soft_margin * HZ);
 	add_timer(&watchdog_ticktock);
-	return 1;
+	return;
+}
+
+static long softdog_write(struct inode *inode, struct file *file, const char *data, unsigned long len)
+{
+	/*
+	 *	Refresh the timer.
+	 */
+	if(len)
+	{
+		softdog_ping();
+		return 1;
+	}
+	return 0;
+}
+
+static int softdog_ioctl(struct inode *inode, struct file *file,
+	unsigned int cmd, unsigned long arg)
+{
+	int i;
+	static struct watchdog_info ident=
+	{
+		0,
+		0,
+		"Software Watchdog"
+	};
+	switch(cmd)
+	{
+		default:
+			return -ENOIOCTLCMD;
+		case WDIOC_GETSUPPORT:
+			i = verify_area(VERIFY_WRITE, (void*) arg, sizeof(struct watchdog_info));
+			if (i)
+				return i;
+			else
+				return copy_to_user((struct watchdog_info *)arg, &ident, sizeof(ident));
+		case WDIOC_GETSTATUS:
+		case WDIOC_GETBOOTSTATUS:
+			return put_user(0,(int *)arg);
+		case WDIOC_KEEPALIVE:
+			softdog_ping();
+			return 0;
+	}
 }
 
 static struct file_operations softdog_fops=
@@ -111,7 +156,7 @@
 	softdog_write,	/* Write */
 	NULL,		/* Readdir */
 	NULL,		/* Select */
-	NULL,		/* Ioctl */
+	softdog_ioctl,	/* Ioctl */
 	NULL,		/* MMap */
 	softdog_open,
 	softdog_release,
@@ -131,7 +176,7 @@
 	misc_register(&softdog_miscdev);
 	init_timer(&watchdog_ticktock);
 	watchdog_ticktock.function=watchdog_fire;
-	printk("Software Watchdog Timer: 0.04, timer margin: %d sec\n", soft_margin);
+	printk("Software Watchdog Timer: 0.05, timer margin: %d sec\n", soft_margin);
 }	
 
 #ifdef MODULE

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov