Linux TTY function tracking

Source: Internet
Author: User

1. Introduction

This article describes the function tracking procedures for TTY open, TTY read, and TTY write operations

2. Example

Here is a simple Linux TTY open and read-write process

3. Open

When the device node/dev/ttys0 is opened, the kernel calls Vfs_open and then calls to Tty_open, and Tty_open analyzes the following

Tty_open Tty_alloc_file/*assign Tty_file_private and assign to file::p rivate_data*/Tty_open_current_tty/*If the current device is/dev/tty, try to reopen it, usually returning null*/Tty_open_by_driver/*If the function above returns null by finding the TTY driver to open the TTY device*/Tty_lookup_driver/*find the corresponding TTY driver based on the device number*/Tty_driver_lookup_tty/*Find out if tty_struct exists based on tty_driver::tty_operations::lookup/tty_driver::tty_struct*/Tty_reopen/*if Tty_struct is assigned, open the TTY*/Tty_ldisc_reinit/*wiring procedures for initializing TTY devices*/Tty_ldisc_get/*obtain the corresponding line code for registration according to the category (default is N_tty) and assign the corresponding Tty_ldisc instance*/Tty_set_termios_ldisc/*wiring procedures for setting up the TTY*/Tty_ldisc_open/*call Tty_ldisc::tty_ldisc_ops::open, for N_tty to N_tty_open*/Tty_init_dev/*if Tty_struct is not assigned, it is allocated (!!! The UART is SO!!!) */alloc_tty_struct/*assigning and initializing a tty_struct, including driver, OPS, index, etc.*/Tty_ldisc_init/*wiring procedures for initializing tty_struct*/Tty_ldisc_get/*obtain n_tty corresponding circuit code and assign corresponding Tty_ldisc instance*/tty_struct::tty_operations=tty_driver::tty_operations/*sets the set of function actions for Tty_struct*/Tty_driver_install_tty/*install portals for TTY devices via Tty_driver::tty_operations::install or Tty_standard_install*/Tty_ldisc_setup/*Open Line Procedure*/Tty_ldisc_open/*call Tty_ldisc::tty_ldisc_ops::open, for N_tty to N_tty_open*/Tty_add_file/*associating files to Tty_struce*/Tty_struct::tty_operations::open/*with Tty_driver::tty_operations::open, for the serial port is Uart_open*/
4. Write

Write calls Tty_write, which is parsed as follows:

Tty_write File_tty/*get the corresponding tty_struct by File::tty_file_private::tty_struct*/Do_tty_write/*Call Tty_struct::tty_ldisc::tty_ldisc_ops::write*/N_tty_write/*for line codes of type N_tty, write is N_tty_write*/process_echoes/*handle all pending echoed characters*/__process_echoes/*write the echo character to be processed*/Tty_write_room/*Call Tty_struct::tty_operations::write_room*/echo_buf Tty_put_char/** Call Tty_struct::tty_operations::p Ut_char * or call Tty_struct::tty_operations::write*/Do_output_char/*Call Tty_struct::tty_operations::write*/Tty_struct::tty_operations::flush_chars/*  */process_output_block process_output tty_struct::tty_operations::flush_chars Tty_struct::tty_opera Tions::write
5. Read

Read invokes Tty_read, which is parsed as follows:

tty_read  tty_struct::tty_ldisc::tty_ldisc_ops::read  /**/    N _tty_read      tty_buffer_flush_work        flush_work

Reference:
<>

Linux TTY function tracking

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.