Linux terminal device-line procedure

Source: Internet
Author: User

Line discipline (ldisc) is a software driver layer for Linux and Unix-like system terminal subsystems. The terminal subsystem can be divided into three layers from top to bottom:

  • The top layer tty core driver layer provides the character device interface (because all terminal devices are character devices );
  • The underlying layer is the TTY driver layer used to communicate with the hardware, so that tty_operations can be called by the TTY core and ldisc layers;
  • The middle layer line discipline implements the input/output data processing policy of the terminal.

Line discipline binds tty core and tty driver. Policy separation eliminates the need for tty core and tty driver to focus on data syntax processing. tty driver can be reused by the same hardware, you only need to change the line discipline.

The default line for Linux terminal devices is n_tty. It receives data from tty driver and applications and processes the data according to the terminal settings. For input data, it processes special interrupt characters (such as control-C), delete characters (backspace, delete), and so on; for output data, it replaces lf characters with Cr/LF sequences. The n_tty line procedure is used when the UART port is used as a common serial port.

When the UART port device uses an Internet dialing connection for the serial modem, the PPP line procedure is used to process data. The PPP ldisc assembles the serial port data from the UART core into the PPP input packet, then it is distributed to the network protocol stack. PPP ldisc sends data packages sent from the network protocol stack to the UART port.

When I first read the Linux tty terminal system code, I was very confused about ldisc. Unless I want to understand the details of line discipline syntax processing, I can skip most of the ldisc code.

Ldisc works between tty core and tty driver. ldisc must provide the following interface functions for both:

Tty core interface:

Open ()

Close ()

Hangup ()

Write ()

Flush_buffer ()

Chars_in_buffer ()

Set_termios ()

Read ()

Poll ()

IOCTL ()

Compat_ioctl ()

Tty driver interface:

Receive_buf ()

Write_wakeup ()

Dcd_change ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.