Messages in this thread Patch in this message | | | Date | Mon, 31 Jan 2000 09:56:53 +0000 (GMT) | From | Tim Waugh <> | Subject | Re: [patch] 2.3.41pre4: lp ioctl for controlling parport timeout |
| |
Here's that patch again, this time reworked to use struct timeval.
Tim. */
Index: linux/drivers/char/lp.c diff -u linux/drivers/char/lp.c:1.1.1.4 linux/drivers/char/lp.c:1.6 --- linux/drivers/char/lp.c:1.1.1.4 Thu Jan 6 11:44:23 2000 +++ linux/drivers/char/lp.c Mon Jan 31 09:41:59 2000 @@ -106,6 +106,8 @@ * month ago... * * 14 Dec 1998, Andrea Arcangeli + * + * Copyright (C) 2000 by Tim Waugh (added LPSETTIMEOUT ioctl) */ #include <linux/module.h> @@ -133,6 +135,9 @@ /* if you have more than 3 printers, remember to increase LP_NO */ #define LP_NO 3 +/* ROUND_UP macro from fs/select.c */ +#define ROUND_UP(x,y) (((x)+(y)-1)/(y)) + struct lp_struct lp_table[LP_NO]; static unsigned int lp_count = 0; @@ -321,6 +326,7 @@ ssize_t retv = 0; ssize_t written; size_t copy_size = count; + long old_to; #ifdef LP_STATS if (jiffies-lp_table[minor].lastcall > LP_TIME(minor)) @@ -346,6 +352,9 @@ /* Go to compatibility mode. */ parport_negotiate (port, IEEE1284_MODE_COMPAT); + old_to = parport_set_timeout (lp_table[minor].dev, + lp_table[minor].timeout); + do { /* Write the data. */ written = parport_write (port, kbuf, copy_size); @@ -390,6 +399,9 @@ } } while (count > 0); + /* Not really necessary, but polite. */ + parport_set_timeout (lp_table[minor].dev, old_to); + lp_parport_release (minor); up (&lp_table[minor].port_mutex); @@ -527,6 +539,9 @@ if ((LP_F(minor) & LP_EXIST) == 0) return -ENODEV; switch ( cmd ) { + struct timeval par_timeout; + long to_jiffies; + case LPTIME: LP_TIME(minor) = arg * HZ/100; break; @@ -588,6 +603,26 @@ if (copy_to_user((int *) arg, &status, sizeof(int))) return -EFAULT; break; + + case LPSETTIMEOUT: + if (copy_from_user (&par_timeout, + (struct timeval *) arg, + sizeof (struct timeval))) { + return -EFAULT; + } + /* Convert to jiffies, place in lp_table */ + if ((par_timeout.tv_sec < 0) || + (par_timeout.tv_usec < 0)) { + return -EINVAL; + } + to_jiffies = ROUND_UP(par_timeout.tv_Usec, 1000000/HZ); + to_jiffies += par_timeout.tv_sec * (long) HZ; + if (to_jiffies <= 0) { + return -EINVAL; + } + lp_table[minor].timeout = to_jiffies; + break; + default: retval = -EINVAL; } @@ -854,6 +889,7 @@ init_waitqueue_head (&lp_table[i].waitq); init_waitqueue_head (&lp_table[i].dataq); init_MUTEX (&lp_table[i].port_mutex); + lp_table[i].timeout = 10 * HZ; } if (register_chrdev (LP_MAJOR, "lp", &lp_fops)) { Index: linux/include/linux/lp.h diff -u linux/include/linux/lp.h:1.1.1.2 linux/include/linux/lp.h:1.2 --- linux/include/linux/lp.h:1.1.1.2 Thu Oct 14 21:43:13 1999 +++ linux/include/linux/lp.h Fri Jan 28 17:25:36 2000 @@ -89,6 +89,7 @@ #define LPGETSTATS 0x060d /* get statistics (struct lp_stats) */ #endif #define LPGETFLAGS 0x060e /* get status flags */ +#define LPSETTIMEOUT 0x060f /* set parport timeout */ /* timeout for printk'ing a timeout, in jiffies (100ths of a second). This is also used for re-checking error conditions if LP_ABORT is @@ -145,6 +146,7 @@ unsigned int last_error; struct semaphore port_mutex; wait_queue_head_t dataq; + long timeout; }; /*
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |