2 * linux/drivers/char/tty_io.c 4 * Copyright (C) 1991, 1992 Linus Torvalds 8 * 'tty_io.c' gives an orthogonal feeling to tty's, be they consoles 9 * or rs-channels. It also implements echoing, cooked mode etc. 11 * Kill-line thanks to John T Kohl, who also corrected VMIN = VTIME = 0. 13 * Modified by Theodore Ts'o, 9/14/92, to dynamically allocate the 14 * tty_struct and tty_queue structures. Previously there was an array 15 * of 256 tty_struct's which was statically allocated, and the 16 * tty_queue structures were allocated at boot time. Both are now 17 * dynamically allocated only when the tty is open. 19 * Also restructured routines so that there is more of a separation 20 * between the high-level tty routines (tty_io.c and tty_ioctl.c) and 21 * the low-level tty routines (serial.c, pty.c, console.c). This 22 * makes for cleaner and more compact code. -TYT, 9/17/92 24 * Modified by Fred N. van Kempen, 01/29/93, to add line disciplines 25 * which can be dynamically activated and de-activated by the line 26 * discipline handling modules (like SLIP). 28 * NOTE: pay no attention to the line discipline code (yet); its 29 * interface is still subject to change in this version... 32 * Added functionality to the OPOST tty handling. No delays, but all 33 * other bits should be there. 34 * -- Nick Holloway <alfie@dcs.warwick.ac.uk>, 27th May 1993. 36 * Rewrote canonical mode and added more termios flags. 37 * -- julian@uhunix.uhcc.hawaii.edu (J. Cowley), 13Jan94 39 * Reorganized FASYNC support so mouse code can share it. 40 * -- ctm@ardi.com, 9Sep95 42 * New TIOCLINUX variants added. 43 * -- mj@k332.feld.cvut.cz, 19-Nov-95 45 * Restrict vt switching via ioctl() 46 * -- grif@cs.ucr.edu, 5-Dec-95 49 #include <linux/config.h> 50 #include <linux/types.h> 51 #include <linux/major.h> 52 #include <linux/errno.h> 53 #include <linux/signal.h> 54 #include <linux/fcntl.h> 55 #include <linux/sched.h> 56 #include <linux/interrupt.h> 57 #include <linux/tty.h> 58 #include <linux/tty_flip.h> 59 #include <linux/timer.h> 60 #include <linux/ctype.h> 63 #include <linux/string.h> 64 #include <linux/malloc.h> 66 #include <asm/uaccess.h> 67 #include <asm/system.h> 68 #include <asm/bitops.h> 75 #include <linux/kerneld.h> 78 #define CONSOLE_DEV MKDEV(TTY_MAJOR,0) 79 #define TTY_DEV MKDEV(TTYAUX_MAJOR,0) 81 #undef TTY_DEBUG_HANGUP 83 #define TTY_PARANOIA_CHECK 84 #define CHECK_TTY_COUNT 86 externvoiddo_blank_screen(int nopowersave
); 87 externvoidset_vesa_blanking(const unsigned long arg
); 89 struct termios tty_std_termios
;/* for the benefit of tty drivers */ 90 struct tty_driver
*tty_drivers
= NULL
;/* linked list of tty drivers */ 91 struct tty_ldisc ldiscs
[NR_LDISCS
];/* line disc dispatch table */ 94 * fg_console is the current virtual console, 95 * last_console is the last used one, 96 * want_console is the console we want to switch to, 97 * kmsg_redirect is the console for kernel messages, 98 * redirect is the pseudo-tty that console output 99 * is redirected to if asked by TIOCCONS. 103 int want_console
= -1; 104 int kmsg_redirect
=0; 105 struct tty_struct
* redirect
= NULL
; 106 struct wait_queue
* keypress_wait
= NULL
; 107 char vt_dont_switch
=0; 109 static voidinitialize_tty_struct(struct tty_struct
*tty
); 111 static longtty_read(struct inode
*,struct file
*,char*,unsigned long); 112 static longtty_write(struct inode
*,struct file
*,const char*,unsigned long); 113 static inttty_select(struct inode
*,struct file
*,int, select_table
*); 114 static inttty_open(struct inode
*,struct file
*); 115 static voidtty_release(struct inode
*,struct file
*); 116 static inttty_ioctl(struct inode
* inode
,struct file
* file
, 117 unsigned int cmd
,unsigned long arg
); 118 static inttty_fasync(struct inode
* inode
,struct file
* filp
,int on
); 120 externvoidreset_palette(int currcons
) ; 121 externvoidset_palette(void) ; 124 #define MIN(a,b) ((a) < (b) ? (a) : (b)) 128 * These two routines return the name of tty. tty_name() should NOT 129 * be used in interrupt drivers, since it's not re-entrant. Use 130 * _tty_name() instead. 132 char*_tty_name(struct tty_struct
*tty
,char*buf
) 135 sprintf(buf
,"%s%d", tty
->driver
.name
, 136 MINOR(tty
->device
) - tty
->driver
.minor_start
+ 137 tty
->driver
.name_base
); 139 strcpy(buf
,"NULL tty"); 143 char*tty_name(struct tty_struct
*tty
) 147 return(_tty_name(tty
, buf
)); 150 inlineinttty_paranoia_check(struct tty_struct
*tty
, kdev_t device
, 153 #ifdef TTY_PARANOIA_CHECK 154 static const char*badmagic
= 155 "Warning: bad magic number for tty struct (%s) in %s\n"; 156 static const char*badtty
= 157 "Warning: null TTY for (%s) in %s\n"; 160 printk(badtty
,kdevname(device
), routine
); 163 if(tty
->magic
!= TTY_MAGIC
) { 164 printk(badmagic
,kdevname(device
), routine
); 171 static intcheck_tty_count(struct tty_struct
*tty
,const char*routine
) 173 #ifdef CHECK_TTY_COUNT 177 for(f
= first_file
, i
=0; i
<nr_files
; i
++, f
= f
->f_next
) { 180 if(f
->private_data
== tty
) { 184 if(tty
->driver
.type
== TTY_DRIVER_TYPE_PTY
&& 185 tty
->driver
.subtype
== PTY_TYPE_SLAVE
&& 186 tty
->link
&& tty
->link
->count
) 188 if(tty
->count
!= count
) { 189 printk("Warning: dev (%s) tty->count(%d) != #fd's(%d) in %s\n", 190 kdevname(tty
->device
), tty
->count
, count
, routine
); 197 inttty_register_ldisc(int disc
,struct tty_ldisc
*new_ldisc
) 199 if(disc
< N_TTY
|| disc
>= NR_LDISCS
) 203 ldiscs
[disc
] = *new_ldisc
; 204 ldiscs
[disc
].flags
|= LDISC_FLAG_DEFINED
; 205 ldiscs
[disc
].num
= disc
; 207 memset(&ldiscs
[disc
],0,sizeof(struct tty_ldisc
)); 212 /* Set the discipline of a tty line. */ 213 static inttty_set_ldisc(struct tty_struct
*tty
,int ldisc
) 216 struct tty_ldisc o_ldisc
; 218 if((ldisc
< N_TTY
) || (ldisc
>= NR_LDISCS
)) 220 #ifdef CONFIG_KERNELD 221 /* Eduardo Blanco <ejbs@cs.cs.com.uy> */ 222 if(!(ldiscs
[ldisc
].flags
& LDISC_FLAG_DEFINED
)) { 224 sprintf(modname
,"tty-ldisc-%d", ldisc
); 225 request_module(modname
); 228 if(!(ldiscs
[ldisc
].flags
& LDISC_FLAG_DEFINED
)) 231 if(tty
->ldisc
.num
== ldisc
) 232 return0;/* We are already in the desired discipline */ 233 o_ldisc
= tty
->ldisc
; 235 tty_wait_until_sent(tty
,0); 237 /* Shutdown the current discipline. */ 239 (tty
->ldisc
.close
)(tty
); 241 /* Now set up the new line discipline. */ 242 tty
->ldisc
= ldiscs
[ldisc
]; 243 tty
->termios
->c_line
= ldisc
; 245 retval
= (tty
->ldisc
.open
)(tty
); 247 tty
->ldisc
= o_ldisc
; 248 tty
->termios
->c_line
= tty
->ldisc
.num
; 249 if(tty
->ldisc
.open
&& (tty
->ldisc
.open(tty
) <0)) { 250 tty
->ldisc
= ldiscs
[N_TTY
]; 251 tty
->termios
->c_line
= N_TTY
; 252 if(tty
->ldisc
.open
) { 253 int r
= tty
->ldisc
.open(tty
); 256 panic("Couldn't open N_TTY ldisc for " 262 if(tty
->ldisc
.num
!= o_ldisc
.num
&& tty
->driver
.set_ldisc
) 263 tty
->driver
.set_ldisc(tty
); 268 * This routine returns a tty driver structure, given a device number 270 struct tty_driver
*get_tty_driver(kdev_t device
) 273 struct tty_driver
*p
; 275 minor
=MINOR(device
); 276 major
=MAJOR(device
); 278 for(p
= tty_drivers
; p
; p
= p
->next
) { 279 if(p
->major
!= major
) 281 if(minor
< p
->minor_start
) 283 if(minor
>= p
->minor_start
+ p
->num
) 291 * If we try to write to, or set the state of, a terminal and we're 292 * not in the foreground, send a SIGTTOU. If the signal is blocked or 293 * ignored, go ahead and perform the operation. (POSIX 7.2) 295 inttty_check_change(struct tty_struct
* tty
) 297 if(current
->tty
!= tty
) 300 printk("tty_check_change: tty->pgrp <= 0!\n"); 303 if(current
->pgrp
== tty
->pgrp
) 305 if(is_ignored(SIGTTOU
)) 307 if(is_orphaned_pgrp(current
->pgrp
)) 309 (void)kill_pg(current
->pgrp
,SIGTTOU
,1); 313 static longhung_up_tty_read(struct inode
* inode
,struct file
* file
, 314 char* buf
,unsigned long count
) 319 static longhung_up_tty_write(struct inode
* inode
, 320 struct file
* file
,const char* buf
,unsigned long count
) 325 static inthung_up_tty_select(struct inode
* inode
,struct file
* filp
, 326 int sel_type
, select_table
* wait
) 331 static inthung_up_tty_ioctl(struct inode
* inode
,struct file
* file
, 332 unsigned int cmd
,unsigned long arg
) 334 return cmd
== TIOCSPGRP
? -ENOTTY
: -EIO
; 337 static long longtty_lseek(struct inode
* inode
,struct file
* file
, 338 long long offset
,int orig
) 343 static struct file_operations tty_fops
= { 347 NULL
,/* tty_readdir */ 357 static struct file_operations hung_up_tty_fops
= { 361 NULL
,/* hung_up_tty_readdir */ 364 NULL
,/* hung_up_tty_mmap */ 365 NULL
,/* hung_up_tty_open */ 366 tty_release
,/* hung_up_tty_release */ 367 NULL
,/* hung_up_tty_fsync */ 368 NULL
/* hung_up_tty_fasync */ 371 voiddo_tty_hangup(struct tty_struct
* tty
,struct file_operations
*fops
) 375 struct task_struct
*p
; 379 check_tty_count(tty
,"do_tty_hangup"); 380 for(filp
= first_file
, i
=0; i
<nr_files
; i
++, filp
= filp
->f_next
) { 383 if(filp
->private_data
!= tty
) 387 if(filp
->f_inode
->i_rdev
== CONSOLE_DEV
) 389 if(filp
->f_op
!= &tty_fops
) 391 tty_fasync(filp
->f_inode
, filp
,0); 395 if(tty
->ldisc
.flush_buffer
) 396 tty
->ldisc
.flush_buffer(tty
); 397 if(tty
->driver
.flush_buffer
) 398 tty
->driver
.flush_buffer(tty
); 399 if((tty
->flags
& (1<< TTY_DO_WRITE_WAKEUP
)) && 400 tty
->ldisc
.write_wakeup
) 401 (tty
->ldisc
.write_wakeup
)(tty
); 402 wake_up_interruptible(&tty
->write_wait
); 403 wake_up_interruptible(&tty
->read_wait
); 406 * Shutdown the current line discipline, and reset it to 409 if(tty
->ldisc
.num
!= ldiscs
[N_TTY
].num
) { 411 (tty
->ldisc
.close
)(tty
); 412 tty
->ldisc
= ldiscs
[N_TTY
]; 413 tty
->termios
->c_line
= N_TTY
; 414 if(tty
->ldisc
.open
) { 415 i
= (tty
->ldisc
.open
)(tty
); 417 printk("do_tty_hangup: N_TTY open: error %d\n", 423 if((tty
->session
>0) && (p
->session
== tty
->session
) && 425 send_sig(SIGHUP
,p
,1); 426 send_sig(SIGCONT
,p
,1); 428 p
->tty_old_pgrp
= tty
->pgrp
; 437 if(tty
->driver
.flags
& TTY_DRIVER_RESET_TERMIOS
) 438 *tty
->termios
= tty
->driver
.init_termios
; 439 if(tty
->driver
.hangup
) 440 (tty
->driver
.hangup
)(tty
); 443 voidtty_hangup(struct tty_struct
* tty
) 445 #ifdef TTY_DEBUG_HANGUP 446 printk("%s hangup...\n",tty_name(tty
)); 448 do_tty_hangup(tty
, &hung_up_tty_fops
); 451 voidtty_vhangup(struct tty_struct
* tty
) 453 #ifdef TTY_DEBUG_HANGUP 454 printk("%s vhangup...\n",tty_name(tty
)); 456 do_tty_hangup(tty
, &hung_up_tty_fops
); 459 inttty_hung_up_p(struct file
* filp
) 461 return(filp
->f_op
== &hung_up_tty_fops
); 465 * This function is typically called only by the session leader, when 466 * it wants to disassociate itself from its controlling tty. 468 * It performs the following functions: 469 * (1) Sends a SIGHUP and SIGCONT to the foreground process group 470 * (2) Clears the tty from being controlling the session 471 * (3) Clears the controlling tty for all processes in the 474 * The argument on_exit is set to 1 if called when a process is 475 * exiting; it is 0 if called by the ioctl TIOCNOTTY. 477 voiddisassociate_ctty(int on_exit
) 479 struct tty_struct
*tty
= current
->tty
; 480 struct task_struct
*p
; 484 tty_pgrp
= tty
->pgrp
; 485 if(on_exit
&& tty
->driver
.type
!= TTY_DRIVER_TYPE_PTY
) 488 if(current
->tty_old_pgrp
) { 489 kill_pg(current
->tty_old_pgrp
, SIGHUP
, on_exit
); 490 kill_pg(current
->tty_old_pgrp
, SIGCONT
, on_exit
); 495 kill_pg(tty_pgrp
, SIGHUP
, on_exit
); 497 kill_pg(tty_pgrp
, SIGCONT
, on_exit
); 500 current
->tty_old_pgrp
=0; 505 if(p
->session
== current
->session
) 510 * Sometimes we want to wait until a particular VT has been activated. We 511 * do it in a very simple manner. Everybody waits on a single queue and 512 * get woken up at once. Those that are satisfied go on with their business, 513 * while those not ready go back to sleep. Seems overkill to add a wait 514 * to each vt just for this - usually this does nothing! 516 static struct wait_queue
*vt_activate_queue
= NULL
; 519 * Sleeps until a vt is activated, or the task is interrupted. Returns 520 * 0 if activation, -1 if interrupted. 522 intvt_waitactive(void) 524 interruptible_sleep_on(&vt_activate_queue
); 525 return(current
->signal
& ~current
->blocked
) ? -1:0; 528 #define vt_wake_waitactive() wake_up(&vt_activate_queue) 530 voidreset_vc(unsigned int new_console
) 532 vt_cons
[new_console
]->vc_mode
= KD_TEXT
; 533 kbd_table
[new_console
].kbdmode
= VC_XLATE
; 534 vt_cons
[new_console
]->vt_mode
.mode
= VT_AUTO
; 535 vt_cons
[new_console
]->vt_mode
.waitv
=0; 536 vt_cons
[new_console
]->vt_mode
.relsig
=0; 537 vt_cons
[new_console
]->vt_mode
.acqsig
=0; 538 vt_cons
[new_console
]->vt_mode
.frsig
=0; 539 vt_cons
[new_console
]->vt_pid
= -1; 540 vt_cons
[new_console
]->vt_newvt
= -1; 541 reset_palette(new_console
) ; 545 * Performs the back end of a vt switch 547 voidcomplete_change_console(unsigned int new_console
) 549 unsigned char old_vc_mode
; 551 if((new_console
== fg_console
) || (vt_dont_switch
)) 553 if(!vc_cons_allocated(new_console
)) 555 last_console
= fg_console
; 558 * If we're switching, we could be going from KD_GRAPHICS to 559 * KD_TEXT mode or vice versa, which means we need to blank or 560 * unblank the screen later. 562 old_vc_mode
= vt_cons
[fg_console
]->vc_mode
; 563 update_screen(new_console
); 566 * If this new console is under process control, send it a signal 567 * telling it that it has acquired. Also check if it has died and 568 * clean up (similar to logic employed in change_console()) 570 if(vt_cons
[new_console
]->vt_mode
.mode
== VT_PROCESS
) 573 * Send the signal as privileged - kill_proc() will 574 * tell us if the process has gone or something else 577 if(kill_proc(vt_cons
[new_console
]->vt_pid
, 578 vt_cons
[new_console
]->vt_mode
.acqsig
, 582 * The controlling process has died, so we revert back to 583 * normal operation. In this case, we'll also change back 584 * to KD_TEXT mode. I'm not sure if this is strictly correct 585 * but it saves the agony when the X server dies and the screen 586 * remains blanked due to KD_GRAPHICS! It would be nice to do 587 * this outside of VT_PROCESS but there is no single process 588 * to account for and tracking tty count may be undesirable. 590 reset_vc(new_console
); 595 * We do this here because the controlling process above may have 596 * gone, and so there is now a new vc_mode 598 if(old_vc_mode
!= vt_cons
[new_console
]->vc_mode
) 600 if(vt_cons
[new_console
]->vc_mode
== KD_TEXT
) 606 /* Set the colour palette for this VT */ 607 if(vt_cons
[new_console
]->vc_mode
== KD_TEXT
) 611 * Wake anyone waiting for their VT to activate 613 vt_wake_waitactive(); 618 * Performs the front-end of a vt switch 620 voidchange_console(unsigned int new_console
) 622 if((new_console
== fg_console
) || (vt_dont_switch
)) 624 if(!vc_cons_allocated(new_console
)) 628 * If this vt is in process mode, then we need to handshake with 629 * that process before switching. Essentially, we store where that 630 * vt wants to switch to and wait for it to tell us when it's done 631 * (via VT_RELDISP ioctl). 633 * We also check to see if the controlling process still exists. 634 * If it doesn't, we reset this vt to auto mode and continue. 635 * This is a cheap way to track process control. The worst thing 636 * that can happen is: we send a signal to a process, it dies, and 637 * the switch gets "lost" waiting for a response; hopefully, the 638 * user will try again, we'll detect the process is gone (unless 639 * the user waits just the right amount of time :-) and revert the 640 * vt to auto control. 642 if(vt_cons
[fg_console
]->vt_mode
.mode
== VT_PROCESS
) 645 * Send the signal as privileged - kill_proc() will 646 * tell us if the process has gone or something else 649 if(kill_proc(vt_cons
[fg_console
]->vt_pid
, 650 vt_cons
[fg_console
]->vt_mode
.relsig
, 654 * It worked. Mark the vt to switch to and 655 * return. The process needs to send us a 656 * VT_RELDISP ioctl to complete the switch. 658 vt_cons
[fg_console
]->vt_newvt
= new_console
; 663 * The controlling process has died, so we revert back to 664 * normal operation. In this case, we'll also change back 665 * to KD_TEXT mode. I'm not sure if this is strictly correct 666 * but it saves the agony when the X server dies and the screen 667 * remains blanked due to KD_GRAPHICS! It would be nice to do 668 * this outside of VT_PROCESS but there is no single process 669 * to account for and tracking tty count may be undesirable. 671 reset_vc(fg_console
); 674 * Fall through to normal (VT_AUTO) handling of the switch... 679 * Ignore all switches in KD_GRAPHICS+VT_AUTO mode 681 if(vt_cons
[fg_console
]->vc_mode
== KD_GRAPHICS
) 684 complete_change_console(new_console
); 687 voidwait_for_keypress(void) 689 sleep_on(&keypress_wait
); 692 voidstop_tty(struct tty_struct
*tty
) 697 if(tty
->link
&& tty
->link
->packet
) { 698 tty
->ctrl_status
&= ~TIOCPKT_START
; 699 tty
->ctrl_status
|= TIOCPKT_STOP
; 700 wake_up_interruptible(&tty
->link
->read_wait
); 703 (tty
->driver
.stop
)(tty
); 706 voidstart_tty(struct tty_struct
*tty
) 708 if(!tty
->stopped
|| tty
->flow_stopped
) 711 if(tty
->link
&& tty
->link
->packet
) { 712 tty
->ctrl_status
&= ~TIOCPKT_STOP
; 713 tty
->ctrl_status
|= TIOCPKT_START
; 714 wake_up_interruptible(&tty
->link
->read_wait
); 716 if(tty
->driver
.start
) 717 (tty
->driver
.start
)(tty
); 718 if((tty
->flags
& (1<< TTY_DO_WRITE_WAKEUP
)) && 719 tty
->ldisc
.write_wakeup
) 720 (tty
->ldisc
.write_wakeup
)(tty
); 721 wake_up_interruptible(&tty
->write_wait
); 724 static longtty_read(struct inode
* inode
,struct file
* file
, 725 char* buf
,unsigned long count
) 728 struct tty_struct
* tty
; 730 tty
= (struct tty_struct
*)file
->private_data
; 731 if(tty_paranoia_check(tty
, inode
->i_rdev
,"tty_read")) 733 if(!tty
|| (tty
->flags
& (1<< TTY_IO_ERROR
))) 736 /* This check not only needs to be done before reading, but also 737 whenever read_chan() gets woken up after sleeping, so I've 738 moved it to there. This should only be done for the N_TTY 739 line discipline, anyway. Same goes for write_chan(). -- jlc. */ 741 if((inode
->i_rdev
!= CONSOLE_DEV
) &&/* don't stop on /dev/console */ 743 (current
->tty
== tty
) && 744 (tty
->pgrp
!= current
->pgrp
)) 745 if(is_ignored(SIGTTIN
) ||is_orphaned_pgrp(current
->pgrp
)) 748 (void)kill_pg(current
->pgrp
, SIGTTIN
,1); 753 i
= (tty
->ldisc
.read
)(tty
,file
,buf
,count
); 757 inode
->i_atime
= CURRENT_TIME
; 762 * Split writes up in sane blocksizes to avoid 763 * denial-of-service type attacks 765 staticinlineintdo_tty_write( 766 int(*write
)(struct tty_struct
*,struct file
*,const unsigned char*,unsigned int), 768 struct tty_struct
*tty
, 770 const unsigned char*buf
, 773 int ret
=0, written
=0; 776 unsigned long size
= PAGE_SIZE
*2; 779 ret
=write(tty
, file
, buf
, size
); 788 if(current
->signal
& ~current
->blocked
) 794 inode
->i_mtime
= CURRENT_TIME
; 801 static longtty_write(struct inode
* inode
,struct file
* file
, 802 const char* buf
,unsigned long count
) 805 struct tty_struct
* tty
; 807 is_console
= (inode
->i_rdev
== CONSOLE_DEV
); 809 if(is_console
&& redirect
) 812 tty
= (struct tty_struct
*)file
->private_data
; 813 if(tty_paranoia_check(tty
, inode
->i_rdev
,"tty_write")) 815 if(!tty
|| !tty
->driver
.write
|| (tty
->flags
& (1<< TTY_IO_ERROR
))) 818 if(!is_console
&&L_TOSTOP(tty
) && (tty
->pgrp
>0) && 819 (current
->tty
== tty
) && (tty
->pgrp
!= current
->pgrp
)) { 820 if(is_orphaned_pgrp(current
->pgrp
)) 822 if(!is_ignored(SIGTTOU
)) { 823 (void)kill_pg(current
->pgrp
, SIGTTOU
,1); 828 if(!tty
->ldisc
.write
) 830 returndo_tty_write(tty
->ldisc
.write
, 832 (const unsigned char*)buf
, 833 (unsigned int)count
); 837 * This is so ripe with races that you should *really* not touch this 838 * unless you know exactly what you are doing. All the changes have to be 839 * made atomically, or there may be incorrect pointers all over the place. 841 static intinit_dev(kdev_t device
,struct tty_struct
**ret_tty
) 843 struct tty_struct
*tty
, **tty_loc
, *o_tty
, **o_tty_loc
; 844 struct termios
*tp
, **tp_loc
, *o_tp
, **o_tp_loc
; 845 struct termios
*ltp
, **ltp_loc
, *o_ltp
, **o_ltp_loc
; 846 struct tty_driver
*driver
; 850 driver
=get_tty_driver(device
); 854 idx
=MINOR(device
) - driver
->minor_start
; 859 o_tp_loc
= o_ltp_loc
= NULL
; 861 tty_loc
= &driver
->table
[idx
]; 862 tp_loc
= &driver
->termios
[idx
]; 863 ltp_loc
= &driver
->termios_locked
[idx
]; 867 if(driver
->type
== TTY_DRIVER_TYPE_PTY
&& 868 driver
->subtype
== PTY_TYPE_MASTER
&& 869 *tty_loc
&& (*tty_loc
)->count
) 872 if(!*tty_loc
&& !tty
) { 873 if(!(tty
= (struct tty_struct
*)get_free_page(GFP_KERNEL
))) 875 initialize_tty_struct(tty
); 876 tty
->device
= device
; 877 tty
->driver
= *driver
; 880 if(!*tp_loc
&& !tp
) { 881 tp
= (struct termios
*)kmalloc(sizeof(struct termios
), 885 *tp
= driver
->init_termios
; 888 if(!*ltp_loc
&& !ltp
) { 889 ltp
= (struct termios
*)kmalloc(sizeof(struct termios
), 893 memset(ltp
,0,sizeof(struct termios
)); 896 if(driver
->type
== TTY_DRIVER_TYPE_PTY
) { 897 o_tty_loc
= &driver
->other
->table
[idx
]; 898 o_tp_loc
= &driver
->other
->termios
[idx
]; 899 o_ltp_loc
= &driver
->other
->termios_locked
[idx
]; 901 if(!*o_tty_loc
&& !o_tty
) { 904 o_tty
= (struct tty_struct
*) 905 get_free_page(GFP_KERNEL
); 908 o_device
=MKDEV(driver
->other
->major
, 909 driver
->other
->minor_start
+ idx
); 910 initialize_tty_struct(o_tty
); 911 o_tty
->device
= o_device
; 912 o_tty
->driver
= *driver
->other
; 915 if(!*o_tp_loc
&& !o_tp
) { 916 o_tp
= (struct termios
*) 917 kmalloc(sizeof(struct termios
), GFP_KERNEL
); 920 *o_tp
= driver
->other
->init_termios
; 923 if(!*o_ltp_loc
&& !o_ltp
) { 924 o_ltp
= (struct termios
*) 925 kmalloc(sizeof(struct termios
), GFP_KERNEL
); 928 memset(o_ltp
,0,sizeof(struct termios
)); 933 /* Now we have allocated all the structures: update all the pointers.. */ 943 tty
->termios
= *tp_loc
; 944 tty
->termios_locked
= *ltp_loc
; 946 (*driver
->refcount
)++; 948 if(tty
->ldisc
.open
) { 949 retval
= (tty
->ldisc
.open
)(tty
); 958 if((*tty_loc
)->flags
& (1<< TTY_CLOSING
)) { 959 printk("Attempt to open closing tty %s.\n", 961 printk("Ack!!!! This should never happen!!\n"); 966 if(driver
->type
== TTY_DRIVER_TYPE_PTY
) { 976 o_tty
->termios
= *o_tp_loc
; 977 o_tty
->termios_locked
= *o_ltp_loc
; 979 (*driver
->other
->refcount
)++; 980 if(o_tty
->ldisc
.open
) { 981 retval
= (o_tty
->ldisc
.open
)(o_tty
); 990 (*tty_loc
)->link
= *o_tty_loc
; 991 (*o_tty_loc
)->link
= *tty_loc
; 992 if(driver
->subtype
== PTY_TYPE_MASTER
) 993 (*o_tty_loc
)->count
++; 995 (*tty_loc
)->driver
= *driver
; 1000 free_page((unsigned long) tty
); 1002 free_page((unsigned long) o_tty
); 1004 kfree_s(tp
,sizeof(struct termios
)); 1006 kfree_s(o_tp
,sizeof(struct termios
)); 1008 kfree_s(ltp
,sizeof(struct termios
)); 1010 kfree_s(o_ltp
,sizeof(struct termios
)); 1015 * Even releasing the tty structures is a tricky business.. We have 1016 * to be very careful that the structures are all released at the 1017 * same time, as interrupts might otherwise get the wrong pointers. 1019 static voidrelease_dev(struct file
* filp
) 1021 struct tty_struct
*tty
, *o_tty
; 1022 struct termios
*tp
, *o_tp
, *ltp
, *o_ltp
; 1023 struct task_struct
**p
; 1026 tty
= (struct tty_struct
*)filp
->private_data
; 1027 if(tty_paranoia_check(tty
, filp
->f_inode
->i_rdev
,"release_dev")) 1030 check_tty_count(tty
,"release_dev"); 1032 tty_fasync(filp
->f_inode
, filp
,0); 1035 ltp
= tty
->termios_locked
; 1037 idx
=MINOR(tty
->device
) - tty
->driver
.minor_start
; 1038 #ifdef TTY_PARANOIA_CHECK 1039 if(idx
<0|| idx
>= tty
->driver
.num
) { 1040 printk("release_dev: bad idx when trying to free (%s)\n", 1041 kdevname(tty
->device
)); 1044 if(tty
!= tty
->driver
.table
[idx
]) { 1045 printk("release_dev: driver.table[%d] not tty for (%s)\n", 1046 idx
,kdevname(tty
->device
)); 1049 if(tp
!= tty
->driver
.termios
[idx
]) { 1050 printk("release_dev: driver.termios[%d] not termios for (" 1052 idx
,kdevname(tty
->device
)); 1055 if(ltp
!= tty
->driver
.termios_locked
[idx
]) { 1056 printk("release_dev: driver.termios_locked[%d] not termios_locked for (" 1058 idx
,kdevname(tty
->device
)); 1063 #ifdef TTY_DEBUG_HANGUP 1064 printk("release_dev of %s (tty count=%d)...",tty_name(tty
), 1069 o_tp
= (o_tty
) ? o_tty
->termios
: NULL
; 1070 o_ltp
= (o_tty
) ? o_tty
->termios_locked
: NULL
; 1072 #ifdef TTY_PARANOIA_CHECK 1073 if(tty
->driver
.other
) { 1074 if(o_tty
!= tty
->driver
.other
->table
[idx
]) { 1075 printk("release_dev: other->table[%d] not o_tty for (" 1077 idx
,kdevname(tty
->device
)); 1080 if(o_tp
!= tty
->driver
.other
->termios
[idx
]) { 1081 printk("release_dev: other->termios[%d] not o_termios for (" 1083 idx
,kdevname(tty
->device
)); 1086 if(o_ltp
!= tty
->driver
.other
->termios_locked
[idx
]) { 1087 printk("release_dev: other->termios_locked[%d] not o_termios_locked for (" 1089 idx
,kdevname(tty
->device
)); 1093 if(o_tty
->link
!= tty
) { 1094 printk("release_dev: bad pty pointers\n"); 1100 if(tty
->driver
.close
) 1101 tty
->driver
.close(tty
, filp
); 1102 if(tty
->driver
.type
== TTY_DRIVER_TYPE_PTY
&& 1103 tty
->driver
.subtype
== PTY_TYPE_MASTER
) { 1104 if(--tty
->link
->count
<0) { 1105 printk("release_dev: bad pty slave count (%d) for %s\n", 1106 tty
->count
,tty_name(tty
)); 1107 tty
->link
->count
=0; 1110 if(--tty
->count
<0) { 1111 printk("release_dev: bad tty->count (%d) for %s\n", 1112 tty
->count
,tty_name(tty
)); 1119 * We're committed; at this point, we must not block! 1124 tty
->driver
.other
->table
[idx
] = NULL
; 1125 tty
->driver
.other
->termios
[idx
] = NULL
; 1126 kfree_s(o_tp
,sizeof(struct termios
)); 1129 #ifdef TTY_DEBUG_HANGUP 1130 printk("freeing tty structure..."); 1132 tty
->flags
|= (1<< TTY_CLOSING
); 1135 * Make sure there aren't any processes that still think this 1136 * tty is their controlling tty. 1138 for(p
= &LAST_TASK
; p
> &FIRST_TASK
; --p
) { 1141 if((*p
)->tty
== tty
) 1143 if(o_tty
&& (*p
)->tty
== o_tty
) 1148 * Shutdown the current line discipline, and reset it to 1151 if(tty
->ldisc
.close
) 1152 (tty
->ldisc
.close
)(tty
); 1153 tty
->ldisc
= ldiscs
[N_TTY
]; 1154 tty
->termios
->c_line
= N_TTY
; 1156 if(o_tty
->ldisc
.close
) 1157 (o_tty
->ldisc
.close
)(o_tty
); 1158 o_tty
->ldisc
= ldiscs
[N_TTY
]; 1161 tty
->driver
.table
[idx
] = NULL
; 1162 if(tty
->driver
.flags
& TTY_DRIVER_RESET_TERMIOS
) { 1163 tty
->driver
.termios
[idx
] = NULL
; 1164 kfree_s(tp
,sizeof(struct termios
)); 1166 if(tty
== redirect
|| o_tty
== redirect
) 1169 * Make sure that the tty's task queue isn't activated. If it 1170 * is, take it out of the linked list. 1173 if(tty
->flip
.tqueue
.sync
) { 1174 struct tq_struct
*tq
, *prev
; 1176 for(tq
=tq_timer
, prev
=0; tq
; prev
=tq
, tq
=tq
->next
) { 1177 if(tq
== &tty
->flip
.tqueue
) { 1179 prev
->next
= tq
->next
; 1181 tq_timer
= tq
->next
; 1188 (*tty
->driver
.refcount
)--; 1189 free_page((unsigned long) tty
); 1190 filp
->private_data
=0; 1193 (*o_tty
->driver
.refcount
)--; 1194 free_page((unsigned long) o_tty
); 1199 * tty_open and tty_release keep up the tty count that contains the 1200 * number of opens done on a tty. We cannot use the inode-count, as 1201 * different inodes might point to the same tty. 1203 * Open-counting is needed for pty masters, as well as for keeping 1204 * track of serial lines: DTR is dropped when the last close happens. 1205 * (This is not done solely through tty->count, now. - Ted 1/27/92) 1207 * The termios state of a pty is reset on first open so that 1208 * settings don't persist across reuse. 1210 static inttty_open(struct inode
* inode
,struct file
* filp
) 1212 struct tty_struct
*tty
; 1218 noctty
= filp
->f_flags
& O_NOCTTY
; 1219 device
= inode
->i_rdev
; 1220 if(device
== TTY_DEV
) { 1223 device
= current
->tty
->device
; 1226 if(device
== CONSOLE_DEV
) { 1227 device
=MKDEV(TTY_MAJOR
, fg_console
+1); 1230 minor
=MINOR(device
); 1232 retval
=init_dev(device
, &tty
); 1235 filp
->private_data
= tty
; 1236 check_tty_count(tty
,"tty_open"); 1237 if(tty
->driver
.type
== TTY_DRIVER_TYPE_PTY
&& 1238 tty
->driver
.subtype
== PTY_TYPE_MASTER
) 1240 #ifdef TTY_DEBUG_HANGUP 1241 printk("opening %s...",tty_name(tty
)); 1243 if(tty
->driver
.open
) 1244 retval
= tty
->driver
.open(tty
, filp
); 1248 if(!retval
&&test_bit(TTY_EXCLUSIVE
, &tty
->flags
) && !suser()) 1252 #ifdef TTY_DEBUG_HANGUP 1253 printk("error %d in opening %s...", retval
,tty_name(tty
)); 1257 if(retval
!= -ERESTARTSYS
) 1259 if(current
->signal
& ~current
->blocked
) 1263 * Need to reset f_op in case a hangup happened. 1265 filp
->f_op
= &tty_fops
; 1273 current
->tty_old_pgrp
=0; 1274 tty
->session
= current
->session
; 1275 tty
->pgrp
= current
->pgrp
; 1281 * Note that releasing a pty master also releases the child, so 1282 * we have to make the redirection checks after that and on both 1285 static voidtty_release(struct inode
* inode
,struct file
* filp
) 1290 static inttty_select(struct inode
* inode
,struct file
* filp
,int sel_type
, select_table
* wait
) 1292 struct tty_struct
* tty
; 1294 tty
= (struct tty_struct
*)filp
->private_data
; 1295 if(tty_paranoia_check(tty
, inode
->i_rdev
,"tty_select")) 1298 if(tty
->ldisc
.select
) 1299 return(tty
->ldisc
.select
)(tty
, inode
, filp
, sel_type
, wait
); 1304 * fasync_helper() is used by some character device drivers (mainly mice) 1305 * to set up the fasync queue. It returns negative on error, 0 if it did 1306 * no changes and positive if it added/deleted the entry. 1308 intfasync_helper(struct inode
* inode
,struct file
* filp
,int on
,struct fasync_struct
**fapp
) 1310 struct fasync_struct
*fa
, **fp
; 1311 unsigned long flags
; 1313 for(fp
= fapp
; (fa
= *fp
) != NULL
; fp
= &fa
->fa_next
) { 1314 if(fa
->fa_file
== filp
) 1321 fa
= (struct fasync_struct
*)kmalloc(sizeof(struct fasync_struct
), GFP_KERNEL
); 1324 fa
->magic
= FASYNC_MAGIC
; 1328 fa
->fa_next
= *fapp
; 1330 restore_flags(flags
); 1338 restore_flags(flags
); 1343 static inttty_fasync(struct inode
* inode
,struct file
* filp
,int on
) 1345 struct tty_struct
* tty
; 1348 tty
= (struct tty_struct
*)filp
->private_data
; 1349 if(tty_paranoia_check(tty
, inode
->i_rdev
,"tty_fasync")) 1352 retval
=fasync_helper(inode
, filp
, on
, &tty
->fasync
); 1357 if(!waitqueue_active(&tty
->read_wait
)) 1358 tty
->minimum_to_wake
=1; 1359 if(filp
->f_owner
==0) { 1361 filp
->f_owner
= -tty
->pgrp
; 1363 filp
->f_owner
= current
->pid
; 1366 if(!tty
->fasync
&& !waitqueue_active(&tty
->read_wait
)) 1367 tty
->minimum_to_wake
= N_TTY_BUF_SIZE
; 1374 * XXX does anyone use this anymore?!? 1376 static intdo_get_ps_info(unsigned long arg
) 1380 int present
[NR_TASKS
]; 1381 struct task_struct tasks
[NR_TASKS
]; 1383 struct tstruct
*ts
= (struct tstruct
*)arg
; 1384 struct task_struct
**p
; 1388 i
=verify_area(VERIFY_WRITE
, (void*)arg
,sizeof(struct tstruct
)); 1391 for(p
= &FIRST_TASK
; p
<= &LAST_TASK
; p
++, n
++) 1395 d
= (char*)(ts
->tasks
+n
); 1396 for(i
=0; i
<sizeof(struct task_struct
) ; i
++) 1397 put_user(*c
++, d
++); 1398 put_user(1, ts
->present
+n
); 1401 put_user(0, ts
->present
+n
); 1406 static inttiocsti(struct tty_struct
*tty
,char* arg
) 1410 if((current
->tty
!= tty
) && !suser()) 1412 if(get_user(ch
, arg
)) 1414 tty
->ldisc
.receive_buf(tty
, &ch
, &mbz
,1); 1418 static inttiocgwinsz(struct tty_struct
*tty
,struct winsize
* arg
) 1420 if(copy_to_user(arg
, &tty
->winsize
,sizeof(*arg
))) 1425 static inttiocswinsz(struct tty_struct
*tty
,struct tty_struct
*real_tty
, 1426 struct winsize
* arg
) 1428 struct winsize tmp_ws
; 1430 if(copy_from_user(&tmp_ws
, arg
,sizeof(*arg
))) 1432 if(!memcmp(&tmp_ws
, &tty
->winsize
,sizeof(*arg
))) 1435 kill_pg(tty
->pgrp
, SIGWINCH
,1); 1436 if((real_tty
->pgrp
!= tty
->pgrp
) && (real_tty
->pgrp
>0)) 1437 kill_pg(real_tty
->pgrp
, SIGWINCH
,1); 1438 tty
->winsize
= tmp_ws
; 1439 real_tty
->winsize
= tmp_ws
; 1443 static inttioccons(struct tty_struct
*tty
,struct tty_struct
*real_tty
) 1445 if(tty
->driver
.type
== TTY_DRIVER_TYPE_CONSOLE
) { 1453 redirect
= real_tty
; 1458 static intfionbio(struct file
*file
,int*arg
) 1462 if(get_user(nonblock
, arg
)) 1466 file
->f_flags
|= O_NONBLOCK
; 1468 file
->f_flags
&= ~O_NONBLOCK
; 1472 static inttiocsctty(struct tty_struct
*tty
,int arg
) 1474 if(current
->leader
&& 1475 (current
->session
== tty
->session
)) 1478 * The process must be a session leader and 1479 * not have a controlling tty already. 1481 if(!current
->leader
|| current
->tty
) 1483 if(tty
->session
>0) { 1485 * This tty is already the controlling 1486 * tty for another session group! 1488 if((arg
==1) &&suser()) { 1492 struct task_struct
*p
; 1501 current
->tty_old_pgrp
=0; 1502 tty
->session
= current
->session
; 1503 tty
->pgrp
= current
->pgrp
; 1507 static inttiocgpgrp(struct tty_struct
*tty
,struct tty_struct
*real_tty
, pid_t
*arg
) 1510 * (tty == real_tty) is a cheap way of 1511 * testing if the tty is NOT a master pty. 1513 if(tty
== real_tty
&& current
->tty
!= real_tty
) 1515 returnput_user(real_tty
->pgrp
, arg
); 1518 static inttiocspgrp(struct tty_struct
*tty
,struct tty_struct
*real_tty
, pid_t
*arg
) 1521 int retval
=tty_check_change(real_tty
); 1528 (current
->tty
!= real_tty
) || 1529 (real_tty
->session
!= current
->session
)) 1531 get_user(pgrp
, (pid_t
*) arg
); 1534 if(session_of_pgrp(pgrp
) != current
->session
) 1536 real_tty
->pgrp
= pgrp
; 1540 static inttioclinux(struct tty_struct
*tty
,unsigned long arg
) 1544 if(tty
->driver
.type
!= TTY_DRIVER_TYPE_CONSOLE
) 1546 if(current
->tty
!= tty
&& !suser()) 1548 if(get_user(type
, (char*)arg
)) 1553 returnset_selection(arg
, tty
,1); 1555 returnpaste_selection(tty
); 1557 do_unblank_screen(); 1560 returnsel_loadlut(arg
); 1564 * Make it possible to react to Shift+Mousebutton. 1565 * Note that 'shift_state' is an undocumented 1566 * kernel-internal variable; programs not closely 1567 * related to the kernel should not use this. 1570 returnput_user(data
, (char*) arg
); 1572 data
=mouse_reporting(); 1573 returnput_user(data
, (char*) arg
); 1575 set_vesa_blanking(arg
); 1577 case11:/* set kmsg redirect */ 1580 if(get_user(data
, (char*)arg
+1)) 1582 kmsg_redirect
= data
; 1584 case12:/* get fg_console */ 1590 static inttiocttygstruct(struct tty_struct
*tty
,struct tty_struct
*arg
) 1592 if(copy_to_user(arg
, tty
,sizeof(*arg
))) 1597 static inttiocsetd(struct tty_struct
*tty
,int*arg
) 1601 retval
=tty_check_change(tty
); 1604 retval
=get_user(ldisc
, arg
); 1607 returntty_set_ldisc(tty
, ldisc
); 1611 * Split this up, as gcc can choke on it otherwise.. 1613 static inttty_ioctl(struct inode
* inode
,struct file
* file
, 1614 unsigned int cmd
,unsigned long arg
) 1616 struct tty_struct
*tty
, *real_tty
; 1618 tty
= (struct tty_struct
*)file
->private_data
; 1619 if(tty_paranoia_check(tty
, inode
->i_rdev
,"tty_ioctl")) 1623 if(tty
->driver
.type
== TTY_DRIVER_TYPE_PTY
&& 1624 tty
->driver
.subtype
== PTY_TYPE_MASTER
) 1625 real_tty
= tty
->link
; 1629 returntiocsti(tty
, (char*)arg
); 1631 returntiocgwinsz(tty
, (struct winsize
*) arg
); 1633 returntiocswinsz(tty
, real_tty
, (struct winsize
*) arg
); 1635 returntioccons(tty
, real_tty
); 1637 returnfionbio(file
, (int*) arg
); 1639 set_bit(TTY_EXCLUSIVE
, &tty
->flags
); 1642 clear_bit(TTY_EXCLUSIVE
, &tty
->flags
); 1645 if(current
->tty
!= tty
) 1648 disassociate_ctty(0); 1649 current
->tty
= NULL
; 1652 returntiocsctty(tty
, arg
); 1654 returntiocgpgrp(tty
, real_tty
, (pid_t
*) arg
); 1656 returntiocspgrp(tty
, real_tty
, (pid_t
*) arg
); 1658 returnput_user(tty
->ldisc
.num
, (int*) arg
); 1660 returntiocsetd(tty
, (int*) arg
); 1662 returntioclinux(tty
, arg
); 1663 case TIOCTTYGSTRUCT
: 1664 returntiocttygstruct(tty
, (struct tty_struct
*) arg
); 1666 if(tty
->driver
.ioctl
) { 1667 int retval
= (tty
->driver
.ioctl
)(tty
, file
, cmd
, arg
); 1668 if(retval
!= -ENOIOCTLCMD
) 1671 if(tty
->ldisc
.ioctl
) { 1672 int retval
= (tty
->ldisc
.ioctl
)(tty
, file
, cmd
, arg
); 1673 if(retval
!= -ENOIOCTLCMD
) 1681 * This implements the "Secure Attention Key" --- the idea is to 1682 * prevent trojan horses by killing all processes associated with this 1683 * tty when the user hits the "Secure Attention Key". Required for 1684 * super-paranoid applications --- see the Orange Book for more details. 1686 * This code could be nicer; ideally it should send a HUP, wait a few 1687 * seconds, then send a INT, and then a KILL signal. But you then 1688 * have to coordinate with the init process, since all processes associated 1689 * with the current tty must be dead before the new getty is allowed 1692 voiddo_SAK(struct tty_struct
*tty
) 1697 struct task_struct
**p
; 1704 session
= tty
->session
; 1705 if(tty
->ldisc
.flush_buffer
) 1706 tty
->ldisc
.flush_buffer(tty
); 1707 if(tty
->driver
.flush_buffer
) 1708 tty
->driver
.flush_buffer(tty
); 1709 for(p
= &LAST_TASK
; p
> &FIRST_TASK
; --p
) { 1712 if(((*p
)->tty
== tty
) || 1713 ((session
>0) && ((*p
)->session
== session
))) 1714 send_sig(SIGKILL
, *p
,1); 1715 else if((*p
)->files
) { 1716 for(i
=0; i
< NR_OPEN
; i
++) { 1717 filp
= (*p
)->files
->fd
[i
]; 1718 if(filp
&& (filp
->f_op
== &tty_fops
) && 1719 (filp
->private_data
== tty
)) { 1720 send_sig(SIGKILL
, *p
,1); 1730 * This routine is called out of the software interrupt to flush data 1731 * from the flip buffer to the line discipline. 1733 static voidflush_to_ldisc(void*private_
) 1735 struct tty_struct
*tty
= (struct tty_struct
*) private_
; 1740 if(tty
->flip
.buf_num
) { 1741 cp
= tty
->flip
.char_buf
+ TTY_FLIPBUF_SIZE
; 1742 fp
= tty
->flip
.flag_buf
+ TTY_FLIPBUF_SIZE
; 1743 tty
->flip
.buf_num
=0; 1746 tty
->flip
.char_buf_ptr
= tty
->flip
.char_buf
; 1747 tty
->flip
.flag_buf_ptr
= tty
->flip
.flag_buf
; 1749 cp
= tty
->flip
.char_buf
; 1750 fp
= tty
->flip
.flag_buf
; 1751 tty
->flip
.buf_num
=1; 1754 tty
->flip
.char_buf_ptr
= tty
->flip
.char_buf
+ TTY_FLIPBUF_SIZE
; 1755 tty
->flip
.flag_buf_ptr
= tty
->flip
.flag_buf
+ TTY_FLIPBUF_SIZE
; 1757 count
= tty
->flip
.count
; 1762 if(count
> tty
->max_flip_cnt
) 1763 tty
->max_flip_cnt
= count
; 1765 tty
->ldisc
.receive_buf(tty
, cp
, fp
, count
); 1769 * This subroutine initializes a tty structure. 1771 static voidinitialize_tty_struct(struct tty_struct
*tty
) 1773 memset(tty
,0,sizeof(struct tty_struct
)); 1774 tty
->magic
= TTY_MAGIC
; 1775 tty
->ldisc
= ldiscs
[N_TTY
]; 1777 tty
->flip
.char_buf_ptr
= tty
->flip
.char_buf
; 1778 tty
->flip
.flag_buf_ptr
= tty
->flip
.flag_buf
; 1779 tty
->flip
.tqueue
.routine
= flush_to_ldisc
; 1780 tty
->flip
.tqueue
.data
= tty
; 1784 * The default put_char routine if the driver did not define one. 1786 voidtty_default_put_char(struct tty_struct
*tty
,unsigned char ch
) 1788 tty
->driver
.write(tty
,0, &ch
,1); 1792 * Called by a tty driver to register itself. 1794 inttty_register_driver(struct tty_driver
*driver
) 1798 if(driver
->flags
& TTY_DRIVER_INSTALLED
) 1801 error
=register_chrdev(driver
->major
, driver
->name
, &tty_fops
); 1804 else if(driver
->major
==0) 1805 driver
->major
= error
; 1807 if(!driver
->put_char
) 1808 driver
->put_char
= tty_default_put_char
; 1811 driver
->next
= tty_drivers
; 1812 if(tty_drivers
) tty_drivers
->prev
= driver
; 1813 tty_drivers
= driver
; 1818 * Called by a tty driver to unregister itself. 1820 inttty_unregister_driver(struct tty_driver
*driver
) 1823 struct tty_driver
*p
; 1825 const char*othername
= NULL
; 1827 if(*driver
->refcount
) 1830 for(p
= tty_drivers
; p
; p
= p
->next
) { 1833 else if(p
->major
== driver
->major
) 1834 othername
= p
->name
; 1840 if(othername
== NULL
) { 1841 retval
=unregister_chrdev(driver
->major
, driver
->name
); 1845 register_chrdev(driver
->major
, othername
, &tty_fops
); 1848 driver
->prev
->next
= driver
->next
; 1850 tty_drivers
= driver
->next
; 1853 driver
->next
->prev
= driver
->prev
; 1860 * Initialize the console device. This is called *early*, so 1861 * we can't necessarily depend on lots of kernel help here. 1862 * Just do some early initializations, and do the complex setup 1865 longconsole_init(long kmem_start
,long kmem_end
) 1867 /* Setup the default TTY line discipline. */ 1868 memset(ldiscs
,0,sizeof(ldiscs
)); 1869 (void)tty_register_ldisc(N_TTY
, &tty_ldisc_N_TTY
); 1872 * Set up the standard termios. Individual tty drivers may 1873 * deviate from this; this is used as a template. 1875 memset(&tty_std_termios
,0,sizeof(struct termios
)); 1876 memcpy(tty_std_termios
.c_cc
, INIT_C_CC
, NCCS
); 1877 tty_std_termios
.c_iflag
= ICRNL
| IXON
; 1878 tty_std_termios
.c_oflag
= OPOST
| ONLCR
; 1879 tty_std_termios
.c_cflag
= B38400
| CS8
| CREAD
| HUPCL
; 1880 tty_std_termios
.c_lflag
= ISIG
| ICANON
| ECHO
| ECHOE
| ECHOK
| 1881 ECHOCTL
| ECHOKE
| IEXTEN
; 1884 * set up the console device so that later boot sequences can 1885 * inform about problems etc.. 1887 returncon_init(kmem_start
); 1890 static struct tty_driver dev_tty_driver
, dev_console_driver
; 1893 * Ok, now we can initialize the rest of the tty devices and can count 1894 * on memory allocations, interrupts etc.. 1898 if(sizeof(struct tty_struct
) > PAGE_SIZE
) 1899 panic("size of tty structure > PAGE_SIZE!"); 1902 * dev_tty_driver and dev_console_driver are actually magic 1903 * devices which get redirected at open time. Nevertheless, 1904 * we register them so that register_chrdev is called 1907 memset(&dev_tty_driver
,0,sizeof(struct tty_driver
)); 1908 dev_tty_driver
.magic
= TTY_DRIVER_MAGIC
; 1909 dev_tty_driver
.name
="tty"; 1910 dev_tty_driver
.name_base
=0; 1911 dev_tty_driver
.major
= TTY_MAJOR
; 1912 dev_tty_driver
.minor_start
=0; 1913 dev_tty_driver
.num
=1; 1915 if(tty_register_driver(&dev_tty_driver
)) 1916 panic("Couldn't register /dev/tty driver\n"); 1918 dev_console_driver
= dev_tty_driver
; 1919 dev_console_driver
.name
="console"; 1920 dev_console_driver
.major
= TTYAUX_MAJOR
; 1922 if(tty_register_driver(&dev_console_driver
)) 1923 panic("Couldn't register /dev/console driver\n"); 1926 #ifdef CONFIG_ESP/* init ESP before rs, so rs doesn't see the port */ 1929 #ifdef CONFIG_SERIAL 1932 #ifdef CONFIG_CYCLADES 1935 #ifdef CONFIG_STALLION 1938 #ifdef CONFIG_ISTALLION 1944 #ifdef CONFIG_RISCOM8