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

📄 fcntl.c

📁 linux0.11 version(301k)
💻 C
字号:
<!doctype html public "-//W3C//DTD HTML 3.2//EN"><html><head><title>Linux/fs/fcntl.c</title><meta http-equiv=Content-Type content="text/html; charset=gb2312"><base href="http://oldlinux.org/lxr/http/"></head><body bgcolor=white><div align=center>   [<b><i>源代码浏览</i></b>] [<a href="diff/fs/fcntl.c">区别标定</a>] [<a href="ident">标识符搜索</a>] [<a href="search">文本搜索</a>] [<a href="find">文件搜索</a>]</div><h1 align=center>  <a href="http:/">     OldLinux</a>  <a href="http:blurb.html">    交叉引用</a><br>  <a href="source/">Linux</a>/<a href="source/fs/">fs</a>/<a href="source/fs/fcntl.c">fcntl.c</a></h1><div align=center>    <b>版本:</b>   [<a href="source/fs/fcntl.c?v=1.0">1.0</a>] [<a href="source/fs/fcntl.c?v=0.99.11">0.99.11</a>] [<a href="source/fs/fcntl.c?v=0.99">0.99</a>] [<a href="source/fs/fcntl.c?v=0.97">0.97</a>] [<a href="source/fs/fcntl.c?v=0.96a">0.96a</a>] [<a href="source/fs/fcntl.c?v=0.95">0.95</a>] [<a href="source/fs/fcntl.c?v=0.12">0.12</a>] [<b><i>0.11</i></b>] [<a href="source/fs/fcntl.c?v=0.01">0.01</a>]  <br>  <b>体系结构:</b>   [<b><i>i386</i></b>]  <br></div><hr><pre>  <a name=L1 href="source/fs/fcntl.c#L1">1</a> <b><i>/*</i></b>  <a name=L2 href="source/fs/fcntl.c#L2">2</a> <b><i> *  linux/fs/fcntl.c</i></b>  <a name=L3 href="source/fs/fcntl.c#L3">3</a> <b><i> *</i></b>  <a name=L4 href="source/fs/fcntl.c#L4">4</a> <b><i> *  (C) 1991  Linus Torvalds</i></b>  <a name=L5 href="source/fs/fcntl.c#L5">5</a> <b><i> */</i></b>  <a name=L6 href="source/fs/fcntl.c#L6">6</a>   <a name=L7 href="source/fs/fcntl.c#L7">7</a> #include &lt;string.h&gt;  <a name=L8 href="source/fs/fcntl.c#L8">8</a> #include &lt;errno.h&gt;  <a name=L9 href="source/fs/fcntl.c#L9">9</a> #include &lt;linux/sched.h&gt; <a name=L10 href="source/fs/fcntl.c#L10">10</a> #include &lt;linux/kernel.h&gt; <a name=L11 href="source/fs/fcntl.c#L11">11</a> #include &lt;asm/segment.h&gt; <a name=L12 href="source/fs/fcntl.c#L12">12</a>  <a name=L13 href="source/fs/fcntl.c#L13">13</a> #include &lt;fcntl.h&gt; <a name=L14 href="source/fs/fcntl.c#L14">14</a> #include &lt;sys/stat.h&gt; <a name=L15 href="source/fs/fcntl.c#L15">15</a>  <a name=L16 href="source/fs/fcntl.c#L16">16</a> extern int <a href="ident?i=sys_close">sys_close</a>(int fd); <a name=L17 href="source/fs/fcntl.c#L17">17</a>  <a name=L18 href="source/fs/fcntl.c#L18">18</a> static int <a href="ident?i=dupfd">dupfd</a>(unsigned int fd, unsigned int arg) <a name=L19 href="source/fs/fcntl.c#L19">19</a> { <a name=L20 href="source/fs/fcntl.c#L20">20</a>         if (fd &gt;= <a href="ident?i=NR_OPEN">NR_OPEN</a> || !<a href="ident?i=current">current</a>-&gt;filp[fd]) <a name=L21 href="source/fs/fcntl.c#L21">21</a>                 return -<a href="ident?i=EBADF">EBADF</a>; <a name=L22 href="source/fs/fcntl.c#L22">22</a>         if (arg &gt;= <a href="ident?i=NR_OPEN">NR_OPEN</a>) <a name=L23 href="source/fs/fcntl.c#L23">23</a>                 return -<a href="ident?i=EINVAL">EINVAL</a>; <a name=L24 href="source/fs/fcntl.c#L24">24</a>         while (arg &lt; <a href="ident?i=NR_OPEN">NR_OPEN</a>) <a name=L25 href="source/fs/fcntl.c#L25">25</a>                 if (<a href="ident?i=current">current</a>-&gt;filp[arg]) <a name=L26 href="source/fs/fcntl.c#L26">26</a>                         arg++; <a name=L27 href="source/fs/fcntl.c#L27">27</a>                 else <a name=L28 href="source/fs/fcntl.c#L28">28</a>                         break; <a name=L29 href="source/fs/fcntl.c#L29">29</a>         if (arg &gt;= <a href="ident?i=NR_OPEN">NR_OPEN</a>) <a name=L30 href="source/fs/fcntl.c#L30">30</a>                 return -<a href="ident?i=EMFILE">EMFILE</a>; <a name=L31 href="source/fs/fcntl.c#L31">31</a>         <a href="ident?i=current">current</a>-&gt;close_on_exec &amp;= ~(1&lt;&lt;arg); <a name=L32 href="source/fs/fcntl.c#L32">32</a>         (<a href="ident?i=current">current</a>-&gt;filp[arg] = <a href="ident?i=current">current</a>-&gt;filp[fd])-&gt;f_count++; <a name=L33 href="source/fs/fcntl.c#L33">33</a>         return arg; <a name=L34 href="source/fs/fcntl.c#L34">34</a> } <a name=L35 href="source/fs/fcntl.c#L35">35</a>  <a name=L36 href="source/fs/fcntl.c#L36">36</a> int <a href="ident?i=sys_dup2">sys_dup2</a>(unsigned int oldfd, unsigned int newfd) <a name=L37 href="source/fs/fcntl.c#L37">37</a> { <a name=L38 href="source/fs/fcntl.c#L38">38</a>         <a href="ident?i=sys_close">sys_close</a>(newfd); <a name=L39 href="source/fs/fcntl.c#L39">39</a>         return <a href="ident?i=dupfd">dupfd</a>(oldfd,newfd); <a name=L40 href="source/fs/fcntl.c#L40">40</a> } <a name=L41 href="source/fs/fcntl.c#L41">41</a>  <a name=L42 href="source/fs/fcntl.c#L42">42</a> int <a href="ident?i=sys_dup">sys_dup</a>(unsigned int fildes) <a name=L43 href="source/fs/fcntl.c#L43">43</a> { <a name=L44 href="source/fs/fcntl.c#L44">44</a>         return <a href="ident?i=dupfd">dupfd</a>(fildes,0); <a name=L45 href="source/fs/fcntl.c#L45">45</a> } <a name=L46 href="source/fs/fcntl.c#L46">46</a>  <a name=L47 href="source/fs/fcntl.c#L47">47</a> int <a href="ident?i=sys_fcntl">sys_fcntl</a>(unsigned int fd, unsigned int cmd, unsigned long arg) <a name=L48 href="source/fs/fcntl.c#L48">48</a> {        <a name=L49 href="source/fs/fcntl.c#L49">49</a>         struct <a href="ident?i=file">file</a> * filp; <a name=L50 href="source/fs/fcntl.c#L50">50</a>  <a name=L51 href="source/fs/fcntl.c#L51">51</a>         if (fd &gt;= <a href="ident?i=NR_OPEN">NR_OPEN</a> || !(filp = <a href="ident?i=current">current</a>-&gt;filp[fd])) <a name=L52 href="source/fs/fcntl.c#L52">52</a>                 return -<a href="ident?i=EBADF">EBADF</a>; <a name=L53 href="source/fs/fcntl.c#L53">53</a>         switch (cmd) { <a name=L54 href="source/fs/fcntl.c#L54">54</a>                 case <a href="ident?i=F_DUPFD">F_DUPFD</a>: <a name=L55 href="source/fs/fcntl.c#L55">55</a>                         return <a href="ident?i=dupfd">dupfd</a>(fd,arg); <a name=L56 href="source/fs/fcntl.c#L56">56</a>                 case <a href="ident?i=F_GETFD">F_GETFD</a>: <a name=L57 href="source/fs/fcntl.c#L57">57</a>                         return (<a href="ident?i=current">current</a>-&gt;close_on_exec&gt;&gt;fd)&amp;1; <a name=L58 href="source/fs/fcntl.c#L58">58</a>                 case <a href="ident?i=F_SETFD">F_SETFD</a>: <a name=L59 href="source/fs/fcntl.c#L59">59</a>                         if (arg&amp;1) <a name=L60 href="source/fs/fcntl.c#L60">60</a>                                 <a href="ident?i=current">current</a>-&gt;close_on_exec |= (1&lt;&lt;fd); <a name=L61 href="source/fs/fcntl.c#L61">61</a>                         else <a name=L62 href="source/fs/fcntl.c#L62">62</a>                                 <a href="ident?i=current">current</a>-&gt;close_on_exec &amp;= ~(1&lt;&lt;fd); <a name=L63 href="source/fs/fcntl.c#L63">63</a>                         return 0; <a name=L64 href="source/fs/fcntl.c#L64">64</a>                 case <a href="ident?i=F_GETFL">F_GETFL</a>: <a name=L65 href="source/fs/fcntl.c#L65">65</a>                         return filp-&gt;f_flags; <a name=L66 href="source/fs/fcntl.c#L66">66</a>                 case <a href="ident?i=F_SETFL">F_SETFL</a>: <a name=L67 href="source/fs/fcntl.c#L67">67</a>                         filp-&gt;f_flags &amp;= ~(<a href="ident?i=O_APPEND">O_APPEND</a> | <a href="ident?i=O_NONBLOCK">O_NONBLOCK</a>); <a name=L68 href="source/fs/fcntl.c#L68">68</a>                         filp-&gt;f_flags |= arg &amp; (<a href="ident?i=O_APPEND">O_APPEND</a> | <a href="ident?i=O_NONBLOCK">O_NONBLOCK</a>); <a name=L69 href="source/fs/fcntl.c#L69">69</a>                         return 0; <a name=L70 href="source/fs/fcntl.c#L70">70</a>                 case <a href="ident?i=F_GETLK">F_GETLK</a>:   case <a href="ident?i=F_SETLK">F_SETLK</a>:   case <a href="ident?i=F_SETLKW">F_SETLKW</a>: <a name=L71 href="source/fs/fcntl.c#L71">71</a>                         return -1; <a name=L72 href="source/fs/fcntl.c#L72">72</a>                 default: <a name=L73 href="source/fs/fcntl.c#L73">73</a>                         return -1; <a name=L74 href="source/fs/fcntl.c#L74">74</a>         } <a name=L75 href="source/fs/fcntl.c#L75">75</a> } <a name=L76 href="source/fs/fcntl.c#L76">76</a> </pre><hr><div align=center>   [<b><i>源代码浏览</i></b>] [<a href="diff/fs/fcntl.c">区别标定</a>] [<a href="ident">标识符搜索</a>] [<a href="search">文本搜索</a>] [<a href="find">文件搜索</a>] </div><hr>本网页由 <a href="http:blurb.html">LXR引擎</a> 自动生成.<br></html>

⌨️ 快捷键说明

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