⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 65.html

📁 linux 0.11中文版 有注释
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<html>
<head>
<title>kernel/chr_drv/tty_io.c</title>
<meta name='robots' content='noindex,nofollow'>
<meta name='generator' content='GLOBAL-5.4.1'>
</head>
<body text='#191970' bgcolor='#f5f5dc' vlink='gray'>
<a name='TOP'><h2><a href='../mains.html'>root</a>/<a href='../files/104.html'>kernel</a>/<a href='../files/106.html'>chr_drv</a>/tty_io.c</h2>
<i><font color='green'>/* [&lt;][&gt;]<a href='#L126'>[^]</a><a href='#L534'>[v]</a>[top]<a href='#BOTTOM'>[bottom]</a><a href='../mains.html'>[index]</a><a href='../help.html'>[help]</a> */</font></i>
<hr>
<h2>DEFINITIONS</h2>
This source file includes following definitions.
<ol>
<li><a href='#L126' title='Defined at 126.'>tty_init</a>
<li><a href='#L135' title='Defined at 135.'>tty_intr</a>
<li><a href='#L153' title='Defined at 153.'>sleep_if_empty</a>
<li><a href='#L167' title='Defined at 167.'>sleep_if_full</a>
<li><a href='#L183' title='Defined at 183.'>wait_for_keypress</a>
<li><a href='#L192' title='Defined at 192.'>copy_to_cooked</a>
<li><a href='#L331' title='Defined at 331.'>tty_read</a>
<li><a href='#L437' title='Defined at 437.'>tty_write</a>
<li><a href='#L527' title='Defined at 527.'>do_tty_interrupt</a>
<li><a href='#L534' title='Defined at 534.'>chr_dev_init</a>
</ol>
<hr>
<pre>
<a name='L1'><i><font color='green'>/*</font></i>
<a name='L2'><i><font color='green'>* linux/kernel/tty_io.c</font></i>
<a name='L3'><i><font color='green'>*</font></i>
<a name='L4'><i><font color='green'>* (C) 1991 Linus Torvalds</font></i>
<a name='L5'><i><font color='green'>*/</font></i>
<a name='L6'>
<a name='L7'><i><font color='green'>/*</font></i>
<a name='L8'><i><font color='green'>* 'tty_io.c' gives an orthogonal feeling to tty's, be they consoles</font></i>
<a name='L9'><i><font color='green'>* or rs-channels. It also implements echoing, cooked mode etc.</font></i>
<a name='L10'><i><font color='green'>*</font></i>
<a name='L11'><i><font color='green'>* Kill-line thanks to John T Kohl.</font></i>
<a name='L12'><i><font color='green'>*/</font></i>
<a name='L13'><i><font color='green'>/*</font></i>
<a name='L14'><i><font color='green'>* 'tty_io.c'给tty 一种非相关的感觉,是控制台还是串行通道。该程序同样</font></i>
<a name='L15'><i><font color='green'>* 实现了回显、规范(熟)模式等。</font></i>
<a name='L16'><i><font color='green'>*</font></i>
<a name='L17'><i><font color='green'>* Kill-line,谢谢John T Kahl。</font></i>
<a name='L18'><i><font color='green'>*/</font></i>
<a name='L19'><font color='darkred'>#include</font> &lt;<a href='27.html'>ctype.h</a>&gt;              <i><font color='green'>// 字符类型头文件。定义了一些有关字符类型判断和转换的宏。</font></i>
<a name='L20'><font color='darkred'>#include</font> &lt;<a href='28.html'>errno.h</a>&gt;              <i><font color='green'>// 错误号头文件。包含系统中各种出错号。(Linus 从minix 中引进的)。</font></i>
<a name='L21'><font color='darkred'>#include</font> &lt;<a href='39.html'>signal.h</a>&gt;             <i><font color='green'>// 信号头文件。定义信号符号常量,信号结构以及信号操作函数原型。</font></i>
<a name='L22'>
<a name='L23'><i><font color='green'>// 下面给出相应信号在信号位图中的对应比特位。</font></i>
<a name='L24'><font color='darkred'>#define</font> <a href='../R/2.html' title='Multiple refered from 2 places.'>ALRMMASK</a> (1&lt;&lt;(<a href='../S/39.html#L27' title='Defined at 27 in include/signal.h.'>SIGALRM</a>-1))       <i><font color='green'>// 警告(alarm)信号屏蔽位。</font></i>
<a name='L25'><font color='darkred'>#define</font> KILLMASK (1&lt;&lt;(<a href='../S/39.html#L22' title='Defined at 22 in include/signal.h.'>SIGKILL</a>-1))       <i><font color='green'>// 终止(kill)信号屏蔽位。</font></i>
<a name='L26'><font color='darkred'>#define</font> <a href='../S/65.html#L284' title='Refered from 284 in kernel/chr_drv/tty_io.c.'>INTMASK</a> (1&lt;&lt;(<a href='../S/39.html#L14' title='Defined at 14 in include/signal.h.'>SIGINT</a>-1)) <i><font color='green'>// 键盘中断(int)信号屏蔽位。</font></i>
<a name='L27'><font color='darkred'>#define</font> <a href='../S/65.html#L290' title='Refered from 290 in kernel/chr_drv/tty_io.c.'>QUITMASK</a> (1&lt;&lt;(<a href='../S/39.html#L15' title='Defined at 15 in include/signal.h.'>SIGQUIT</a>-1))       <i><font color='green'>// 键盘退出(quit)信号屏蔽位。</font></i>
<a name='L28'><font color='darkred'>#define</font> TSTPMASK (1&lt;&lt;(<a href='../S/39.html#L33' title='Defined at 33 in include/signal.h.'>SIGTSTP</a>-1))       <i><font color='green'>// tty 发出的停止进程(tty stop)信号屏蔽位。</font></i>
<a name='L29'>
<a name='L30'><font color='darkred'>#include</font> &lt;<a href='36.html'>linux/sched.h</a>&gt;        <i><font color='green'>// 调度程序头文件,定义了任务结构task_struct、初始任务0 的数据,</font></i>
<a name='L31'><i><font color='green'>// 还有一些有关描述符参数设置和获取的嵌入式汇编函数宏语句。</font></i>
<a name='L32'><font color='darkred'>#include</font> &lt;<a href='38.html'>linux/tty.h</a>&gt;          <i><font color='green'>// tty 头文件,定义了有关tty_io,串行通信方面的参数、常数。</font></i>
<a name='L33'><font color='darkred'>#include</font> &lt;<a href='24.html'>asm/segment.h</a>&gt;        <i><font color='green'>// 段操作头文件。定义了有关段寄存器操作的嵌入式汇编函数。</font></i>
<a name='L34'><font color='darkred'>#include</font> &lt;<a href='25.html'>asm/system.h</a>&gt;         <i><font color='green'>// 系统头文件。定义了设置或修改描述符/中断门等的嵌入式汇编宏。</font></i>
<a name='L35'>
<a name='L36'><font color='darkred'>#define</font> <a href='../R/334.html' title='Multiple refered from 7 places.'>_L_FLAG</a>(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>,f) ((tty)-&gt;termios.c_lflag &amp; f)     <i><font color='green'>// 取termios 结构中的本地模式标志。</font></i>
<a name='L37'><font color='darkred'>#define</font> <a href='../R/331.html' title='Multiple refered from 4 places.'>_I_FLAG</a>(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>,f) ((tty)-&gt;termios.c_iflag &amp; f)     <i><font color='green'>// 取termios 结构中的输入模式标志。</font></i>
<a name='L38'><font color='darkred'>#define</font> <a href='../R/340.html' title='Multiple refered from 5 places.'>_O_FLAG</a>(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>,f) ((tty)-&gt;termios.c_oflag &amp; f)     <i><font color='green'>// 取termios 结构中的输出模式标志。</font></i>
<a name='L39'>
<a name='L40'><i><font color='green'>// 取termios 结构中本地模式标志集中的一个标志位。</font></i>
<a name='L41'><font color='darkred'>#define</font> <a href='../R/116.html' title='Multiple refered from 5 places.'>L_CANON</a>(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>) <a href='../S/65.html#L36' title='Defined at 36 in kernel/chr_drv/tty_io.c.'>_L_FLAG</a>((tty),<a href='../S/48.html#L223' title='Defined at 223 in include/termios.h.'>ICANON</a>)      <i><font color='green'>// 取本地模式标志集中规范(熟)模式标志位。</font></i>
<a name='L42'><font color='darkred'>#define</font> <a href='../S/65.html#L279' title='Refered from 279 in kernel/chr_drv/tty_io.c.'>L_ISIG</a>(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>) <a href='../S/65.html#L36' title='Defined at 36 in kernel/chr_drv/tty_io.c.'>_L_FLAG</a>((tty),<a href='../S/48.html#L222' title='Defined at 222 in include/termios.h.'>ISIG</a>) <i><font color='green'>// 取信号标志位。</font></i>
<a name='L43'><font color='darkred'>#define</font> <a href='../R/117.html' title='Multiple refered from 3 places.'>L_ECHO</a>(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>) <a href='../S/65.html#L36' title='Defined at 36 in kernel/chr_drv/tty_io.c.'>_L_FLAG</a>((tty),<a href='../S/48.html#L225' title='Defined at 225 in include/termios.h.'>ECHO</a>) <i><font color='green'>// 取回显字符标志位。</font></i>
<a name='L44'><font color='darkred'>#define</font> L_ECHOE(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>) <a href='../S/65.html#L36' title='Defined at 36 in kernel/chr_drv/tty_io.c.'>_L_FLAG</a>((tty),<a href='../S/48.html#L226' title='Defined at 226 in include/termios.h.'>ECHOE</a>)       <i><font color='green'>// 规范模式时,取回显擦出标志位。</font></i>
<a name='L45'><font color='darkred'>#define</font> L_ECHOK(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>) <a href='../S/65.html#L36' title='Defined at 36 in kernel/chr_drv/tty_io.c.'>_L_FLAG</a>((tty),<a href='../S/48.html#L227' title='Defined at 227 in include/termios.h.'>ECHOK</a>)       <i><font color='green'>// 规范模式时,取KILL 擦除当前行标志位。</font></i>
<a name='L46'><font color='darkred'>#define</font> <a href='../S/65.html#L310' title='Refered from 310 in kernel/chr_drv/tty_io.c.'>L_ECHOCTL</a>(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>) <a href='../S/65.html#L36' title='Defined at 36 in kernel/chr_drv/tty_io.c.'>_L_FLAG</a>((tty),<a href='../S/48.html#L233' title='Defined at 233 in include/termios.h.'>ECHOCTL</a>)   <i><font color='green'>// 取回显控制字符标志位。</font></i>
<a name='L47'><font color='darkred'>#define</font> L_ECHOKE(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>) <a href='../S/65.html#L36' title='Defined at 36 in kernel/chr_drv/tty_io.c.'>_L_FLAG</a>((tty),<a href='../S/48.html#L236' title='Defined at 236 in include/termios.h.'>ECHOKE</a>)     <i><font color='green'>// 规范模式时,取KILL 擦除行并回显标志位。</font></i>
<a name='L48'>
<a name='L49'><i><font color='green'>// 取termios 结构中输入模式标志中的一个标志位。</font></i>
<a name='L50'><font color='darkred'>#define</font> <a href='../S/65.html#L214' title='Refered from 214 in kernel/chr_drv/tty_io.c.'>I_UCLC</a>(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>) <a href='../S/65.html#L37' title='Defined at 37 in kernel/chr_drv/tty_io.c.'>_I_FLAG</a>((tty),<a href='../S/48.html#L142' title='Defined at 142 in include/termios.h.'>IUCLC</a>)        <i><font color='green'>// 取输入模式标志集中大写到小写转换标志位。</font></i>
<a name='L51'><font color='darkred'>#define</font> <a href='../S/65.html#L211' title='Refered from 211 in kernel/chr_drv/tty_io.c.'>I_NLCR</a>(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>) <a href='../S/65.html#L37' title='Defined at 37 in kernel/chr_drv/tty_io.c.'>_I_FLAG</a>((tty),<a href='../S/48.html#L139' title='Defined at 139 in include/termios.h.'>INLCR</a>)        <i><font color='green'>// 取换行符NL 转回车符CR 标志位。</font></i>
<a name='L52'><font color='darkred'>#define</font> <a href='../S/65.html#L205' title='Refered from 205 in kernel/chr_drv/tty_io.c.'>I_CRNL</a>(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>) <a href='../S/65.html#L37' title='Defined at 37 in kernel/chr_drv/tty_io.c.'>_I_FLAG</a>((tty),<a href='../S/48.html#L141' title='Defined at 141 in include/termios.h.'>ICRNL</a>)        <i><font color='green'>// 取回车符CR 转换行符NL 标志位。</font></i>
<a name='L53'><font color='darkred'>#define</font> <a href='../S/65.html#L207' title='Refered from 207 in kernel/chr_drv/tty_io.c.'>I_NOCR</a>(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>) <a href='../S/65.html#L37' title='Defined at 37 in kernel/chr_drv/tty_io.c.'>_I_FLAG</a>((tty),<a href='../S/48.html#L140' title='Defined at 140 in include/termios.h.'>IGNCR</a>)        <i><font color='green'>// 取忽略回车符CR 标志位。</font></i>
<a name='L54'>
<a name='L55'><i><font color='green'>// 取termios 结构中输出模式标志中的一个标志位。</font></i>
<a name='L56'><font color='darkred'>#define</font> <a href='../S/65.html#L463' title='Refered from 463 in kernel/chr_drv/tty_io.c.'>O_POST</a>(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>) <a href='../S/65.html#L38' title='Defined at 38 in kernel/chr_drv/tty_io.c.'>_O_FLAG</a>((tty),<a href='../S/48.html#L150' title='Defined at 150 in include/termios.h.'>OPOST</a>)        <i><font color='green'>// 取输出模式标志集中执行输出处理标志。</font></i>
<a name='L57'><font color='darkred'>#define</font> <a href='../S/65.html#L474' title='Refered from 474 in kernel/chr_drv/tty_io.c.'>O_NLCR</a>(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>) <a href='../S/65.html#L38' title='Defined at 38 in kernel/chr_drv/tty_io.c.'>_O_FLAG</a>((tty),<a href='../S/48.html#L152' title='Defined at 152 in include/termios.h.'>ONLCR</a>)        <i><font color='green'>// 取换行符NL 转回车换行符CR-NL 标志。</font></i>
<a name='L58'><font color='darkred'>#define</font> <a href='../S/65.html#L468' title='Refered from 468 in kernel/chr_drv/tty_io.c.'>O_CRNL</a>(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>) <a href='../S/65.html#L38' title='Defined at 38 in kernel/chr_drv/tty_io.c.'>_O_FLAG</a>((tty),<a href='../S/48.html#L153' title='Defined at 153 in include/termios.h.'>OCRNL</a>)        <i><font color='green'>// 取回车符CR 转换行符NL 标志。</font></i>
<a name='L59'><font color='darkred'>#define</font> <a href='../S/65.html#L470' title='Refered from 470 in kernel/chr_drv/tty_io.c.'>O_NLRET</a>(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>) <a href='../S/65.html#L38' title='Defined at 38 in kernel/chr_drv/tty_io.c.'>_O_FLAG</a>((tty),<a href='../S/48.html#L155' title='Defined at 155 in include/termios.h.'>ONLRET</a>)      <i><font color='green'>// 取换行符NL 执行回车功能的标志。</font></i>
<a name='L60'><font color='darkred'>#define</font> <a href='../S/65.html#L481' title='Refered from 481 in kernel/chr_drv/tty_io.c.'>O_LCUC</a>(<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>) <a href='../S/65.html#L38' title='Defined at 38 in kernel/chr_drv/tty_io.c.'>_O_FLAG</a>((tty),<a href='../S/48.html#L151' title='Defined at 151 in include/termios.h.'>OLCUC</a>)        <i><font color='green'>// 取小写转大写字符标志。</font></i>
<a name='L61'>
<a name='L62'><i><font color='green'>// tty 数据结构的tty_table 数组。其中包含三个初始化项数据,分别对应控制台、串口终端1 和</font></i>
<a name='L63'><i><font color='green'>// 串口终端2 的初始化数据。</font></i>
<a name='L64'><b>struct</b> tty_struct tty_table[] = <font color='red'>{</font>
<a name='L65'>  <font color='red'>{</font>
<a name='L66'>   <font color='red'>{</font><a href='../S/48.html#L141' title='Defined at 141 in include/termios.h.'>ICRNL</a>,                      <i><font color='green'>/* change incoming CR to NL */</font></i><i><font color='green'>/* 将输入的CR 转换为NL */</font></i>
<a name='L67'>    <a href='../S/48.html#L150' title='Defined at 150 in include/termios.h.'>OPOST</a> | <a href='../S/48.html#L152' title='Defined at 152 in include/termios.h.'>ONLCR</a>,              <i><font color='green'>/* change outgoing NL to CRNL */</font></i><i><font color='green'>/* 将输出的NL 转CRNL */</font></i>
<a name='L68'>    0,                          <i><font color='green'>// 控制模式标志初始化为0。</font></i>
<a name='L69'>    <a href='../S/48.html#L222' title='Defined at 222 in include/termios.h.'>ISIG</a> | <a href='../S/48.html#L223' title='Defined at 223 in include/termios.h.'>ICANON</a> | <a href='../S/48.html#L225' title='Defined at 225 in include/termios.h.'>ECHO</a> | <a href='../S/48.html#L233' title='Defined at 233 in include/termios.h.'>ECHOCTL</a> | <a href='../S/48.html#L236' title='Defined at 236 in include/termios.h.'>ECHOKE</a>,    <i><font color='green'>// 本地模式标志。</font></i>
<a name='L70'>    0,                          <i><font color='green'>/* console termio */</font></i><i><font color='green'>// 控制台termio。</font></i>
<a name='L71'>    <a href='../S/38.html#L92' title='Defined at 92 in include/linux/tty.h.'>INIT_C_CC</a><font color='red'>}</font>,                 <i><font color='green'>// 控制字符数组。</font></i>
<a name='L72'>   0,                           <i><font color='green'>/* initial pgrp */</font></i><i><font color='green'>// 所属初始进程组。</font></i>
<a name='L73'>   0,                           <i><font color='green'>/* initial stopped */</font></i><i><font color='green'>// 初始停止标志。</font></i>
<a name='L74'>   <a href='../S/60.html#L605' title='Defined at 605 in kernel/chr_drv/console.c.'>con_write</a>,                   <i><font color='green'>// tty 写函数指针。</font></i>
<a name='L75'>   <font color='red'>{</font>0, 0, 0, 0, ""<font color='red'>}</font>,            <i><font color='green'>/* console read-queue */</font></i><i><font color='green'>// tty 控制台读队列。</font></i>
<a name='L76'>   <font color='red'>{</font>0, 0, 0, 0, ""<font color='red'>}</font>,            <i><font color='green'>/* console write-queue */</font></i><i><font color='green'>// tty 控制台写队列。</font></i>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -