Re: drivers/char/tty_io.c

Priyanka Grover (priya@cdac.ernet.in)
Mon, 14 Sep 1998 11:40:51 +0530


> Linux deallocates the tty structure when the last file descriptor
> associated with the tty is closed, and reallocates it in init_dev() when
> the tty is opened again. In both Linux 2.0.35 and Linux 2.1.120, there
> is a "fast_track" code path which avoids reinitializing the tty
> structure (including the tty->driver virtual function table) if the tty
> is already open.
>

The patch I applied is here ...

==================================================
--- /usr/src/linux/drivers/char/tty_io.c.orig Tue Aug 18 11:39:56 1998
+++ /usr/src/linux/drivers/char/tty_io.c Mon Sep 14 12:06:39 1998
@@ -1016,7 +1016,22 @@
tty->link->count++;
}
tty->count++;
- tty->driver = *driver; /* N.B. why do this every time?? */
+ /*
+ Commented by (priya@cdac.ernet.in,pkgrover@hotmail.com) Priyanka,INDIA
+
+ Since, a driver could change the driver corresponding to this tty at
+ any time, (through an ioctl, for e.g., we shouldn't be doing this
+ everytime we open a tty! Note that this code gets executed even during
+ fast_track tty open ... (We however require this for the very first time
+ the tty is opened, to assign it to the default driver. )
+ This code is present in the beginning of init_dev(), to be called only
+ during first open of tty.
+ */
+
+ /* N.B. why do this every time?? */
+ /*
+ tty->driver = *driver;
+ */
success:
retval = 0;
*ret_tty = tty;
=====================================================================

This code is part of the _fast track_ and thus gets executed on all the
opens for an already opened device. Shouldn't it get executed only for the
first open?

> The above code is certainly not redundant; if you remove this code,
> tty->driver will never get properly initialized, and the system will
> crash immediately upon boot.

The sytem works perfectly with the patch I applied. What I do is this:
>From bash, I load my module, which, upon some ioctl, gets the tty structure
for the current tty (using con_get_info), and modifies few routines of the
tty->driver for the current tty, to point to driver routines pertinent to my
module.
Now, if any operation involves opening the tty etc. the driver for the
current tty is set back to the original driver using the above code and
functionality of the Gist card comes to an abrupt end.
Later, using another ioctl, I come back to the bash by changing the tty->driver
to the original tty->driver.

Please comment ....

regards,

Priyanka Grover,
(priya@cdac.ernet.in)
Consultant,
CDAC ( Centre for Development of Advanced Computing ),
Pune, INDIA.

-
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/faq.html