16.html
来自「linux 0.11中文版 有注释」· HTML 代码 · 共 49 行
HTML
49 行
<html>
<head>
<title>fs/pipe.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/98.html'>fs</a>/pipe.c</h2>
<i><font color='green'>/* [<][>]<a href='#L18'>[^]</a><a href='#L108'>[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='#L18' title='Defined at 18.'>read_pipe</a>
<li><a href='#L60' title='Defined at 60.'>write_pipe</a>
<li><a href='#L108' title='Defined at 108.'>sys_pipe</a>
</ol>
<hr>
<pre>
<a name='L1'><i><font color='green'>/*</font></i>
<a name='L2'><i><font color='green'>* linux/fs/pipe.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'><font color='darkred'>#include</font> <<a href='39.html'>signal.h</a>> <i><font color='green'>// 信号头文件。定义信号符号常量,信号结构以及信号操作函数原型。</font></i>
<a name='L8'>
<a name='L9'><font color='darkred'>#include</font> <<a href='36.html'>linux/sched.h</a>> <i><font color='green'>// 调度程序头文件,定义了任务结构task_struct、初始任务0 的数据,</font></i>
<a name='L10'><i><font color='green'>// 还有一些有关描述符参数设置和获取的嵌入式汇编函数宏语句。</font></i>
<a name='L11'><font color='darkred'>#include</font> <<a href='35.html'>linux/mm.h</a>> <i><font color='green'>/* for get_free_page */</font></i> <i><font color='green'>/* 使用其中的get_free_page */</font></i>
<a name='L12'><i><font color='green'>// 内存管理头文件。含有页面大小定义和一些页面释放函数原型。</font></i>
<a name='L13'><font color='darkred'>#include</font> <<a href='24.html'>asm/segment.h</a>> <i><font color='green'>// 段操作头文件。定义了有关段寄存器操作的嵌入式汇编函数。</font></i>
<a name='L14'>
<a name='L15'><i><font color='green'>//// 管道读操作函数。</font></i>
<a name='L16'><i><font color='green'>// 参数inode 是管道对应的i 节点,buf 是数据缓冲区指针,count 是读取的字节数。</font></i>
<a name='L17'><b>int</b>
<a name='L18'><a href='../R/564.html' title='Multiple refered from 2 places.'>read_pipe</a> (<b>struct</b> m_inode *inode, <b>char</b> *buf, <b>int</b> count)
<a name='L19'><font color='red'>{</font>
<a name='L20'> <b>int</b> chars, size, read = 0;
<a name='L21'>
<a name='L22'><i><font color='green'>// 若欲读取的字节计数值count 大于0,则循环执行以下操作。</font></i>
<a name='L23'> <b>while</b> (<a href='../D/738.html' title='Multiple defined in 17 places.'>count</a> > 0)
<a name='L24'> <font color='red'>{</font>
<a name='L25'><i><font color='green'>// 若当前管道中没有数据(size=0),则唤醒等待该节点的进程,如果已没有写管道者,则返回已读</font></i>
<a name='L26'><i><font color='green'>// 字节数,退出。否则在该i 节点上睡眠,等待信息。</font></i>
<a name='L27'> <b>while</b> (!(size = <a href='../S/31.html#L79' title='Defined at 79 in include/linux/fs.h.'>PIPE_SIZE</a> (*inode)))
<a name='L28'> <font color='red'>{</font>
<a name='L29'> <a href='../S/74.html#L272' title='Defined at 272 in kernel/sched.c.'>wake_up</a> (&inode->i_wait);
<a name='L30'> 管道缓冲区长度(<a href='../D/324.html' title='Multiple defined in 4 places.'>PAGE_SIZE</a>)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?