linux 文件删除过程浅析

来源:互联网 发布:复旦博士后待遇 知乎 编辑:程序博客网 时间:2024/06/08 19:37

1.Linux文件删除原理

Linux是通过link的数量控制文件删除的,只有当文件不存在任何链接时,该文件才会被删除,一般每个文件有两个link计数器: i_count 和 i_nlink,从VFS inode结构体中可以找到:

<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="kwd" style="color: rgb(30, 52, 123); margin-top: 0px;">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> inode </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="kwd" style="color: rgb(30, 52, 123); margin-top: 0px;">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> hlist_node   i_hash</span><span class="pun" style="color: rgb(147, 161, 161);">;</span><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="com" style="color: rgb(147, 161, 161);">/* hash链表的指针 */</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="kwd" style="color: rgb(30, 52, 123); margin-top: 0px;">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> list_head    i_list</span><span class="pun" style="color: rgb(147, 161, 161);">;</span><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="com" style="color: rgb(147, 161, 161);">/* backing dev IO list */</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="kwd" style="color: rgb(30, 52, 123); margin-top: 0px;">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> list_head    i_sb_list</span><span class="pun" style="color: rgb(147, 161, 161);">;</span><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="com" style="color: rgb(147, 161, 161);">/* 超级块的inode链表 */</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="kwd" style="color: rgb(30, 52, 123); margin-top: 0px;">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> list_head    i_dentry</span><span class="pun" style="color: rgb(147, 161, 161);">;</span><span class="pln" style="color: rgb(72, 72, 76);">   </span><span class="com" style="color: rgb(147, 161, 161);">/* 引用inode的目录项对象链表头 */</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="kwd" style="color: rgb(30, 52, 123); margin-top: 0px;">unsigned</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">long</span><span class="pln" style="color: rgb(72, 72, 76);">    i_ino</span><span class="pun" style="color: rgb(147, 161, 161);">;</span><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="com" style="color: rgb(147, 161, 161);">/* 索引节点号 */</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="typ" style="color: teal; margin-top: 0px;">atomic_t</span><span class="pln" style="color: rgb(72, 72, 76);">     i_count</span><span class="pun" style="color: rgb(147, 161, 161);">;</span><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="com" style="color: rgb(147, 161, 161);">/* 引用计数器 */</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="kwd" style="color: rgb(30, 52, 123); margin-top: 0px;">unsigned</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">int</span><span class="pln" style="color: rgb(72, 72, 76);">     i_nlink</span><span class="pun" style="color: rgb(147, 161, 161);">;</span><span class="pln" style="color: rgb(72, 72, 76);">   </span><span class="com" style="color: rgb(147, 161, 161);">/* 硬链接数目 */</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">...</span></code></div></div>

i_count: 引用计数器,文件被一进程引用,i_count数增加 ,可以认为是当前文件使用者的数量; 
i_nlink: 硬链接数目(可以理解为磁盘的引用计数器),创建硬链接对应的 i_nlink 就会增加

对于rm命令来说,实际就是减少磁盘的引用计数 i_nlink 。如果当文件被另外一个进程调用时,用户执行rm命令删除文件,再去cat文件内容时就会找不到文件,但是调用该删除文件的那个进程却仍然可以对文件进行正常的操作。这就是因为 i_nlink 为 0 ,但 i_count 并不为 0 。只有当 i_nlink 和 i_count 均为 0 时,文件才会被删除(这里的删除是指将文件名到 inode 的链接删除了,但文件在磁盘上的block数据块并未被删除)。

首先使用strace追踪rm命令,看看rm具体使用了哪些系统调用:

<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">[</span><span class="pln" style="color: rgb(72, 72, 76);">root@ty </span><span class="pun" style="color: rgb(147, 161, 161);">~]#</span><span class="pln" style="color: rgb(72, 72, 76);"> strace rm test </span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">execve</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="str" style="color: rgb(221, 17, 68);">"/bin/rm"</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">[</span><span class="str" style="color: rgb(221, 17, 68);">"rm"</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="str" style="color: rgb(221, 17, 68);">"test"</span><span class="pun" style="color: rgb(147, 161, 161);">],</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">[</span><span class="com" style="color: rgb(147, 161, 161);">/* 19 vars */</span><span class="pun" style="color: rgb(147, 161, 161);">])</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">brk</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);">                                  </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0x175c000</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">mmap</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">NULL</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">4096</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> PROT_READ</span><span class="pun" style="color: rgb(147, 161, 161);">|</span><span class="pln" style="color: rgb(72, 72, 76);">PROT_WRITE</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> MAP_PRIVATE</span><span class="pun" style="color: rgb(147, 161, 161);">|</span><span class="pln" style="color: rgb(72, 72, 76);">MAP_ANONYMOUS</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">-</span><span class="lit" style="color: rgb(25, 95, 145);">1</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0x7f1365a2f000</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">access</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="str" style="color: rgb(221, 17, 68);">"/etc/ld.so.preload"</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> R_OK</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);">      </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">-</span><span class="lit" style="color: rgb(25, 95, 145);">1</span><span class="pln" style="color: rgb(72, 72, 76);"> ENOENT </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">No</span><span class="pln" style="color: rgb(72, 72, 76);"> such file </span><span class="kwd" style="color: rgb(30, 52, 123);">or</span><span class="pln" style="color: rgb(72, 72, 76);"> directory</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">open</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="str" style="color: rgb(221, 17, 68);">"/etc/ld.so.cache"</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> O_RDONLY</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);">      </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">3</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">fstat</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="lit" style="color: rgb(25, 95, 145);">3</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span><span class="pln" style="color: rgb(72, 72, 76);">st_mode</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);">S_IFREG</span><span class="pun" style="color: rgb(147, 161, 161);">|</span><span class="lit" style="color: rgb(25, 95, 145);">0644</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> st_size</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="lit" style="color: rgb(25, 95, 145);">62329</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">...})</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">mmap</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">NULL</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">62329</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> PROT_READ</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> MAP_PRIVATE</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">3</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0x7f1365a1f000</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">close</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="lit" style="color: rgb(25, 95, 145);">3</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);">                                </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">open</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="str" style="color: rgb(221, 17, 68);">"/lib64/libc.so.6"</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> O_RDONLY</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);">      </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">3</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">read</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="lit" style="color: rgb(25, 95, 145);">3</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="str" style="color: rgb(221, 17, 68);">"\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360\355\201\2160\0\0\0"</span><span class="pun" style="color: rgb(147, 161, 161);">...,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">832</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">832</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">fstat</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="lit" style="color: rgb(25, 95, 145);">3</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span><span class="pln" style="color: rgb(72, 72, 76);">st_mode</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);">S_IFREG</span><span class="pun" style="color: rgb(147, 161, 161);">|</span><span class="lit" style="color: rgb(25, 95, 145);">0755</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> st_size</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="lit" style="color: rgb(25, 95, 145);">1922152</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">...})</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">...</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">...</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">brk</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);">                                  </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0x175c000</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">brk</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="lit" style="color: rgb(25, 95, 145);">0x177d000</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);">                          </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0x177d000</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">open</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="str" style="color: rgb(221, 17, 68);">"/usr/lib/locale/locale-archive"</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> O_RDONLY</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">3</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">fstat</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="lit" style="color: rgb(25, 95, 145);">3</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span><span class="pln" style="color: rgb(72, 72, 76);">st_mode</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);">S_IFREG</span><span class="pun" style="color: rgb(147, 161, 161);">|</span><span class="lit" style="color: rgb(25, 95, 145);">0644</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> st_size</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="lit" style="color: rgb(25, 95, 145);">99158576</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">...})</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">mmap</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">NULL</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">99158576</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> PROT_READ</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> MAP_PRIVATE</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">3</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0x7f135fb8b000</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">close</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="lit" style="color: rgb(25, 95, 145);">3</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);">                                </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">ioctl</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> SNDCTL_TMR_TIMEBASE </span><span class="kwd" style="color: rgb(30, 52, 123);">or</span><span class="pln" style="color: rgb(72, 72, 76);"> TCGETS</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span><span class="pln" style="color: rgb(72, 72, 76);">B38400 opost isig icanon echo </span><span class="pun" style="color: rgb(147, 161, 161);">...})</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">newfstatat</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">AT_FDCWD</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="str" style="color: rgb(221, 17, 68);">"test"</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span><span class="pln" style="color: rgb(72, 72, 76);">st_mode</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);">S_IFREG</span><span class="pun" style="color: rgb(147, 161, 161);">|</span><span class="lit" style="color: rgb(25, 95, 145);">0644</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> st_size</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">...},</span><span class="pln" style="color: rgb(72, 72, 76);"> AT_SYMLINK_NOFOLLOW</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">geteuid</span><span class="pun" style="color: rgb(147, 161, 161);">()</span><span class="pln" style="color: rgb(72, 72, 76);">                               </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">unlinkat</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">AT_FDCWD</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="str" style="color: rgb(221, 17, 68);">"test"</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);">           </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">close</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);">                                </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">close</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="lit" style="color: rgb(25, 95, 145);">1</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);">                                </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">close</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="lit" style="color: rgb(25, 95, 145);">2</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);">                                </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">exit_group</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);">                           </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">?</span></code></div></div>

由上发现最终调用unlinkat系统调用删除文件。 

2.系统调用unlinkat

unistd.h、unistd_64.h、unistd_32.h中定义系统调用号

<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;">#define</span><span class="pln" style="color: rgb(72, 72, 76);"> __NR_link         </span><span class="lit" style="color: rgb(25, 95, 145);">9</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;">#define</span><span class="pln" style="color: rgb(72, 72, 76);"> __NR_unlink      </span><span class="lit" style="color: rgb(25, 95, 145);">10</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">...</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;">#define</span><span class="pln" style="color: rgb(72, 72, 76);"> __NR_unlinkat           </span><span class="lit" style="color: rgb(25, 95, 145);">456</span></code></div></div>

两个函数定义在 Namei.c 文件中,如下:

<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">SYSCALL_DEFINE3</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">unlinkat</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">int</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> dfd</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">const</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">char</span><span class="pln" style="color: rgb(72, 72, 76);"> __user </span><span class="pun" style="color: rgb(147, 161, 161);">*,</span><span class="pln" style="color: rgb(72, 72, 76);"> pathname</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">int</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> flag</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">((</span><span class="pln" style="color: rgb(72, 72, 76);">flag </span><span class="pun" style="color: rgb(147, 161, 161);">&</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">~</span><span class="pln" style="color: rgb(72, 72, 76);">AT_REMOVEDIR</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">!=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">-</span><span class="pln" style="color: rgb(72, 72, 76);">EINVAL</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">flag </span><span class="pun" style="color: rgb(147, 161, 161);">&</span><span class="pln" style="color: rgb(72, 72, 76);"> AT_REMOVEDIR</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> do_rmdir</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dfd</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> pathname</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> do_unlinkat</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dfd</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> pathname</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">}</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">SYSCALL_DEFINE1</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">unlink</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">const</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">char</span><span class="pln" style="color: rgb(72, 72, 76);"> __user </span><span class="pun" style="color: rgb(147, 161, 161);">*,</span><span class="pln" style="color: rgb(72, 72, 76);"> pathname</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">{</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> do_unlinkat</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">AT_FDCWD</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> pathname</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">}</span></code></div></div>

在unlinkat函数定义中会判断flag标志,如果有设置AT_REMOVEDIR标志,说明删除的是目录则调用do_rmdir函数,否则调用do_unlinkat函数删除一个文件。

3.do_unlinkat函数

<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;">/*</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;"> * 确保文件的实际截断发生在其目录的i_mutex之外,如果有很多写操作发生截断需要很长时间</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;"> * 在等待I/O发生时,我们不想阻止目录的访问</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;"> */</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="kwd" style="color: rgb(30, 52, 123); margin-top: 0px;">static</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">long</span><span class="pln" style="color: rgb(72, 72, 76);"> do_unlinkat</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">int</span><span class="pln" style="color: rgb(72, 72, 76);"> dfd</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">const</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">char</span><span class="pln" style="color: rgb(72, 72, 76);"> __user </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);">pathname</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">{</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">int</span><span class="pln" style="color: rgb(72, 72, 76);"> error</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">char</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);">name</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> dentry </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> nameidata nd</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> inode </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);">inode </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> NULL</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    error </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> user_path_parent</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dfd</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> pathname</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">&</span><span class="pln" style="color: rgb(72, 72, 76);">nd</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">&</span><span class="pln" style="color: rgb(72, 72, 76);">name</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="com" style="color: rgb(147, 161, 161);">/* 获取父目录信息,成功保存在nd结构体中,并返回0*/</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">error</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> error</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    error </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">-</span><span class="pln" style="color: rgb(72, 72, 76);">EISDIR</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">nd</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">last_type </span><span class="pun" style="color: rgb(147, 161, 161);">!=</span><span class="pln" style="color: rgb(72, 72, 76);"> LAST_NORM</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="com" style="color: rgb(147, 161, 161);">/*路径名中最后一个分量类型不是一个普通文件名*/</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">goto</span><span class="pln" style="color: rgb(72, 72, 76);"> exit1</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    nd</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">flags </span><span class="pun" style="color: rgb(147, 161, 161);">&=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">~</span><span class="pln" style="color: rgb(72, 72, 76);">LOOKUP_PARENT</span><span class="pun" style="color: rgb(147, 161, 161);">;</span><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="com" style="color: rgb(147, 161, 161);">/*清除LOOKUP_PARENT标志*/</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    mutex_lock_nested</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">nd</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">path</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_inode</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_mutex</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> I_MUTEX_PARENT</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    dentry </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> lookup_hash</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">nd</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">   </span><span class="com" style="color: rgb(147, 161, 161);">/*返回要删除文件的dentry结构*/</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    error </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> PTR_ERR</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(!</span><span class="pln" style="color: rgb(72, 72, 76);">IS_ERR</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">))</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="com" style="color: rgb(147, 161, 161);">/* Why not before? Because we want correct error value */</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">nd</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="kwd" style="color: rgb(30, 52, 123);">last</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">name</span><span class="pun" style="color: rgb(147, 161, 161);">[</span><span class="pln" style="color: rgb(72, 72, 76);">nd</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="kwd" style="color: rgb(30, 52, 123);">last</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">len</span><span class="pun" style="color: rgb(147, 161, 161);">])</span><span class="pln" style="color: rgb(72, 72, 76);">   </span><span class="com" style="color: rgb(147, 161, 161);">/*last域代表路径名中的最后一个分量,在LOOKUP_PARENT标志设置时使用,因为上边已经做了清除标志操作,此处这样做可以判断是否清除成功,否的话,返回正确的错误码*/</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">            </span><span class="kwd" style="color: rgb(30, 52, 123);">goto</span><span class="pln" style="color: rgb(72, 72, 76);"> slashes</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        inode </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_inode</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">            atomic_inc</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_count</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">   </span><span class="com" style="color: rgb(147, 161, 161);">/*i_count引用计数器(文件当前使用者的数量)原子的加1*/</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        error </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> mnt_want_write</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">nd</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">path</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">mnt</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="com" style="color: rgb(147, 161, 161);">/*判断mnt对象是否有可写权限,是返回0*/</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">error</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">            </span><span class="kwd" style="color: rgb(30, 52, 123);">goto</span><span class="pln" style="color: rgb(72, 72, 76);"> exit2</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        error </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> security_path_unlink</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">nd</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">path</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> dentry</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="com" style="color: rgb(147, 161, 161);">/*检查权限允许删除一个到文件的硬链接,调用path_unlink是一个函数指针(如果有定义)*/</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">error</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">            </span><span class="kwd" style="color: rgb(30, 52, 123);">goto</span><span class="pln" style="color: rgb(72, 72, 76);"> exit3</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        error </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> vfs_unlink</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">nd</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">path</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_inode</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> dentry</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">exit3</span><span class="pun" style="color: rgb(147, 161, 161);">:</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        mnt_drop_write</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">nd</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">path</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">mnt</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    exit2</span><span class="pun" style="color: rgb(147, 161, 161);">:</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        dput</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">   </span><span class="com" style="color: rgb(147, 161, 161);">/*释放dentry结构体,并释放资源*/</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    mutex_unlock</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">nd</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">path</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_inode</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_mutex</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        iput</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="com" style="color: rgb(147, 161, 161);">/* truncate the inode here */</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">exit1</span><span class="pun" style="color: rgb(147, 161, 161);">:</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    path_put</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">nd</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">path</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="com" style="color: rgb(147, 161, 161);">/*释放引用的一个path结构体*/</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    putname</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">name</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">      </span><span class="com" style="color: rgb(147, 161, 161);">/*释放name*/</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> error</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">slashes</span><span class="pun" style="color: rgb(147, 161, 161);">:</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    error </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">!</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_inode </span><span class="pun" style="color: rgb(147, 161, 161);">?</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">-</span><span class="pln" style="color: rgb(72, 72, 76);">ENOENT </span><span class="pun" style="color: rgb(147, 161, 161);">:</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        S_ISDIR</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_inode</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_mode</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">?</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">-</span><span class="pln" style="color: rgb(72, 72, 76);">EISDIR </span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">-</span><span class="pln" style="color: rgb(72, 72, 76);">ENOTDIR</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">goto</span><span class="pln" style="color: rgb(72, 72, 76);"> exit2</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">}</span></code></div><div><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;"></span></code></div></div>

主要分为以下几个步骤:

<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">(</span><span class="lit" style="color: rgb(25, 95, 145);">1</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> error </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> user_path_parent</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dfd</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> pathname</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">&</span><span class="pln" style="color: rgb(72, 72, 76);">nd</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">&</span><span class="pln" style="color: rgb(72, 72, 76);">name</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">(</span><span class="lit" style="color: rgb(25, 95, 145);">2</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> dentry </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> lookup_hash</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">nd</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">(</span><span class="lit" style="color: rgb(25, 95, 145);">3</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> atomic_inc</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_count</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">(</span><span class="lit" style="color: rgb(25, 95, 145);">4</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> vfs_unlink</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">nd</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_inode</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> dentry</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">(</span><span class="lit" style="color: rgb(25, 95, 145);">5</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> dput</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">(</span><span class="lit" style="color: rgb(25, 95, 145);">6</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> iput</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="com" style="color: rgb(147, 161, 161);">/* truncate the inode here */</span></code></div></div>

该函数中首先使用user_path_parent()函数获取要删除文件的父目录信息,成功会返回0,并且将父目录信息保存在nameidata类型的结构体nd中,然后通过lookup_hash函数在当前目录中找寻要删除文件的目录项信息,if语句判断获取的dentry是否有错误,有错误就使用path_put()和putname()释放前几步获取到的数据,然后返回,结束;若没有错误,得到该文件的inode,增加其i_count进程引用计数,判断当前挂载点是否有可写权限,有可写权限就调用vfs_unlink函数执行文件dentry的删除,释放dentry结构体,并释放资源,最后调用iput函数截断inode。

3.1 vfs_unlink函数

<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="kwd" style="color: rgb(30, 52, 123); margin-top: 0px;">int</span><span class="pln" style="color: rgb(72, 72, 76);"> vfs_unlink</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> inode </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);">dir</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> dentry </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="com" style="color: rgb(147, 161, 161);">/*删除dentry,即就是硬链接*/</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">int</span><span class="pln" style="color: rgb(72, 72, 76);"> error </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> may_delete</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dir</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> dentry</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="com" style="color: rgb(147, 161, 161);">/*权限检查,是否有删除权限*/</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">error</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> error</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(!</span><span class="pln" style="color: rgb(72, 72, 76);">dir</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_op</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">unlink</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">-</span><span class="pln" style="color: rgb(72, 72, 76);">EPERM</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    vfs_dq_init</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dir</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    mutex_lock</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_inode</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_mutex</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">d_mountpoint</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">))</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        error </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">-</span><span class="pln" style="color: rgb(72, 72, 76);">EBUSY</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">else</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        error </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> security_inode_unlink</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dir</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> dentry</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(!</span><span class="pln" style="color: rgb(72, 72, 76);">error</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">            error </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> dir</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_op</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">unlink</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dir</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> dentry</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="com" style="color: rgb(147, 161, 161);">/*调用具体文件系统的unlink函数,如ext3_unlink()*/</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    mutex_unlock</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_inode</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_mutex</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="com" style="color: rgb(147, 161, 161);">/* We don't d_delete() NFS sillyrenamed files--they still exist. */</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(!</span><span class="pln" style="color: rgb(72, 72, 76);">error </span><span class="pun" style="color: rgb(147, 161, 161);">&&</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">!(</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_flags </span><span class="pun" style="color: rgb(147, 161, 161);">&</span><span class="pln" style="color: rgb(72, 72, 76);"> DCACHE_NFSFS_RENAMED</span><span class="pun" style="color: rgb(147, 161, 161);">))</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        fsnotify_link_count</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_inode</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        d_delete</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="com" style="color: rgb(147, 161, 161);">/* 若dentry的使用计数为 1,说明没有其他进程引用该dentry,就尝试把该dentry的inode删除 */</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> error</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">}</span></code></div></div>

在vfs_unlink()函数中会调用具体文件系统的删除函数。首先检查要删除文件所在目录的权限,判断是否有删除权限,有删除权限,然后判断具体文件系统是否还有定义自己的unlink函数,没有就退出vfs_unlink函数,否则调用具体文件系统unlink函数(如ext3_unlink()函数)。

3.2 ext3_unlink函数

<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="kwd" style="color: rgb(30, 52, 123); margin-top: 0px;">static</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">int</span><span class="pln" style="color: rgb(72, 72, 76);"> ext3_unlink</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> inode </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);"> dir</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> dentry </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">int</span><span class="pln" style="color: rgb(72, 72, 76);"> retval</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> inode </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);"> inode</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> buffer_head </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);"> bh</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> ext3_dir_entry_2 </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);"> de</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="typ" style="color: teal;">handle_t</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);">handle</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="pun" style="color: rgb(147, 161, 161);">......</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    bh </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> ext3_find_entry</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dir</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">&</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_name</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">&</span><span class="pln" style="color: rgb(72, 72, 76);">de</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="com" style="color: rgb(147, 161, 161);">/*返回该inode对应的buffer_head,并填充其ext3_dir_entry_2结构体*/</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(!</span><span class="pln" style="color: rgb(72, 72, 76);">bh</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">goto</span><span class="pln" style="color: rgb(72, 72, 76);"> end_unlink</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    inode </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_inode</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    retval </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">-</span><span class="pln" style="color: rgb(72, 72, 76);">EIO</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">le32_to_cpu</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">de</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">!=</span><span class="pln" style="color: rgb(72, 72, 76);"> inode</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_ino</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">goto</span><span class="pln" style="color: rgb(72, 72, 76);"> end_unlink</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="pun" style="color: rgb(147, 161, 161);">......</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    retval </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> ext3_delete_entry</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">handle</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> dir</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> de</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> bh</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="com" style="color: rgb(147, 161, 161);">/*从该文件父目录中删除该文件目录项*/</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">retval</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">goto</span><span class="pln" style="color: rgb(72, 72, 76);"> end_unlink</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    dir</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_ctime </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> dir</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_mtime </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> CURRENT_TIME_SEC</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    ext3_update_dx_flag</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dir</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    ext3_mark_inode_dirty</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">handle</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> dir</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="com" style="color: rgb(147, 161, 161);">/*drop_nlink()将i_nlink数减1 */</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    drop_nlink</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">    </span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="com" style="color: rgb(147, 161, 161);">/*</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;">     * 如果i_nlink为0,说明该inode再也没有任何dentry引用它了(即就是硬链接数位0)</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;">     * 则认为当前节点为孤儿节点(准备删除的inode),加入到orphan inode链表中*/</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">     </span><span class="pun" style="color: rgb(147, 161, 161);">*/</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(!</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_nlink</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        ext3_orphan_add</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">handle</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> inode</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">    </span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    inode</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_ctime </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> dir</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_ctime</span><span class="pun" style="color: rgb(147, 161, 161);">;</span><span class="pln" style="color: rgb(72, 72, 76);">      </span><span class="com" style="color: rgb(147, 161, 161);">/*更新修改索引节点的时间*/</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    ext3_mark_inode_dirty</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">handle</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> inode</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    retval </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">end_unlink</span><span class="pun" style="color: rgb(147, 161, 161);">:</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    ext3_journal_stop</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">handle</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    brelse </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">bh</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> retval</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">}</span></code></div></div>

该函数中最主要的操作是ext3_delete_entry函数,从该文件父目录中删除文件目录项,然后修改父目录的i_ctime(上次修改文件)和i_mtime(上次写文件)字段。然后将该文件inode 的硬链接计数减一后若为0,就将其添加到orphan inode(孤儿链表,后边介绍)链表中,更新该inode的修改时间。

3.3 dput函数(release a dentry)

<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="kwd" style="color: rgb(30, 52, 123); margin-top: 0px;">void</span><span class="pln" style="color: rgb(72, 72, 76);"> dput</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> dentry </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(!</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">repeat</span><span class="pun" style="color: rgb(147, 161, 161);">:</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">atomic_read</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_count</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">==</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">1</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        might_sleep</span><span class="pun" style="color: rgb(147, 161, 161);">();</span><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="com" style="color: rgb(147, 161, 161);">/*提醒用户调用该函数的函数可能会sleep*/</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="com" style="color: rgb(147, 161, 161);">/*</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;">     * 将d_count原子的减1,并同时对dcache_lock进行加锁,若d_count减1后仍非0,则直接返回return</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;">     * 这块就是判断d_count个数,如果此时d_count大于1,存在多个引用就不能释放该dentry,直接返回;</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;">     * 若为1,则可以删除dentry,继续后边的释放语句</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;">     **/</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(!</span><span class="pln" style="color: rgb(72, 72, 76);">atomic_dec_and_lock</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_count</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">&</span><span class="pln" style="color: rgb(72, 72, 76);">dcache_lock</span><span class="pun" style="color: rgb(147, 161, 161);">))</span><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    spin_lock</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_lock</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="com" style="color: rgb(147, 161, 161);">/*上一步对dentry->d_count递减,此处加锁,防止其他进程进行操作*/</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">atomic_read</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_count</span><span class="pun" style="color: rgb(147, 161, 161);">))</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span><span class="pln" style="color: rgb(72, 72, 76);">   </span><span class="com" style="color: rgb(147, 161, 161);">/**/</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        spin_unlock</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_lock</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        spin_unlock</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">dcache_lock</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="com" style="color: rgb(147, 161, 161);">/*</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;">     * AV: ->d_delete() is _NOT_ allowed to block now.</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;">     * </span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;">     */</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="com" style="color: rgb(147, 161, 161);">/*</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;">     * 判断具体文件系统是否定义了d_op->d_delete接口函数,</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;">     * ext2、ext3没定义,NFS有定义该接口函数,但没什么实质内容,基本是直接返回;</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;">     * 若定义该接口函数则调用__d_drop()函数,把dentry从哈希链上移除,再调用dentry_iput函数尝试删除inode</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="com" style="color: rgb(147, 161, 161); margin-top: 0px;">     */</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_op </span><span class="pun" style="color: rgb(147, 161, 161);">&&</span><span class="pln" style="color: rgb(72, 72, 76);"> dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_op</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_delete</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span><span class="pln" style="color: rgb(72, 72, 76);">  </span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_op</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_delete</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">))</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">            </span><span class="kwd" style="color: rgb(30, 52, 123);">goto</span><span class="pln" style="color: rgb(72, 72, 76);"> unhash_it</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="com" style="color: rgb(147, 161, 161);">/* Unreachable? Get rid of it */</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">d_unhashed</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">))</span><span class="pln" style="color: rgb(72, 72, 76);">   </span><span class="com" style="color: rgb(147, 161, 161);">/*dentry从dcache hash链上移除了,表示该元数据对应的对象已经被删除,此时可以释放该元数据*/</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">goto</span><span class="pln" style="color: rgb(72, 72, 76);"> kill_it</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">list_empty</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_lru</span><span class="pun" style="color: rgb(147, 161, 161);">))</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span><span class="pln" style="color: rgb(72, 72, 76);">     </span><span class="com" style="color: rgb(147, 161, 161);">/*没有从dcache哈希链移除,表示该元数据对应的对象没有被删除,这时把dentry挂到LRU队列dentry_unused上*/</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_flags </span><span class="pun" style="color: rgb(147, 161, 161);">|=</span><span class="pln" style="color: rgb(72, 72, 76);"> DCACHE_REFERENCED</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        dentry_lru_add</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    spin_unlock</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">d_lock</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    spin_unlock</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">dcache_lock</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">unhash_it</span><span class="pun" style="color: rgb(147, 161, 161);">:</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    __d_drop</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">kill_it</span><span class="pun" style="color: rgb(147, 161, 161);">:</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="com" style="color: rgb(147, 161, 161);">/* if dentry was on the d_lru list delete it from there */</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    dentry_lru_del</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    dentry </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> d_kill</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="com" style="color: rgb(147, 161, 161);">/*删除该dentry,返回父目录项*/</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">dentry</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">goto</span><span class="pln" style="color: rgb(72, 72, 76);"> repeat</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">}</span></code></div></div>

dput函数的主要功能是释放一个dentry结构体,并且将该结构体的使用计数d_count的值减1操作,将该结构体从队列中删除,同时,释放该结构体的资源,无返回值。 
函数中出现repeat字段,每次释放一个dentry,都要获取其父目录项,然后又跳转到dput()开头,继续对父目录dentry进行释放操作;是因为:每次创建一个dentry结构,除了增加自身的使用计数外,还会增加其父目录dentry的使用计数,所以当释放了一个dentry后也需要递减其父目录dentry的使用计数。才能保证父目录为空时能够被释放。

4.iput函数(truncate the inode here)

<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="kwd" style="color: rgb(30, 52, 123); margin-top: 0px;">void</span><span class="pln" style="color: rgb(72, 72, 76);"> iput</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> inode </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        BUG_ON</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_state </span><span class="pun" style="color: rgb(147, 161, 161);">==</span><span class="pln" style="color: rgb(72, 72, 76);"> I_CLEAR</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">atomic_dec_and_lock</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_count</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">&</span><span class="pln" style="color: rgb(72, 72, 76);">inode_lock</span><span class="pun" style="color: rgb(147, 161, 161);">))</span><span class="pln" style="color: rgb(72, 72, 76);"> </span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">            iput_final</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">}</span></code></div></div>

atomic_dec_and_lock宏先对i_count(进程使用计数)加锁后原子的减一,结果为0时,返回true,再进行调用iput_final函数进行删除操作,否则不进行任何操作。

4.1 iput_final函数

<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="kwd" style="color: rgb(30, 52, 123); margin-top: 0px;">static</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">inline</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> iput_final</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> inode </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">const</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> super_operations </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);">op </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> inode</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_sb</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">s_op</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(*</span><span class="pln" style="color: rgb(72, 72, 76);">drop</span><span class="pun" style="color: rgb(147, 161, 161);">)(</span><span class="kwd" style="color: rgb(30, 52, 123);">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> inode </span><span class="pun" style="color: rgb(147, 161, 161);">*)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> generic_drop_inode</span><span class="pun" style="color: rgb(147, 161, 161);">;</span><span class="pln" style="color: rgb(72, 72, 76);"> </span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">op </span><span class="pun" style="color: rgb(147, 161, 161);">&&</span><span class="pln" style="color: rgb(72, 72, 76);"> op</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">drop_inode</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        drop </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> op</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">drop_inode</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    drop</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">}</span></code></div></div>

该函数主要是调用generic_drop_inode()函数,其会判断inode->i_nlink的值,若为0,则该inode可以被删除,调用generic_delete_inode()实现。

<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="kwd" style="color: rgb(30, 52, 123); margin-top: 0px;">void</span><span class="pln" style="color: rgb(72, 72, 76);"> generic_drop_inode</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> inode </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(!</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_nlink</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="com" style="color: rgb(147, 161, 161);">/*i_nlink硬链接数为 0,删除 */</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        generic_delete_inode</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">else</span><span class="pln" style="color: rgb(72, 72, 76);">                    </span><span class="com" style="color: rgb(147, 161, 161);">/* 不为 0 ,不能删除*/</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        generic_forget_inode</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">}</span></code></div></div>

在generic_delete_inode()函数中会判断是否定义具体文件系统的超级块操作函数delete_inode,若定义的就调用具体的inode删除函数(如ext3_delete_inode ),否则调用truncate_inode_pages和clear_inode函数(在具体文件系统的delete_inode函数中也必须调用这两个函数)。

4.2 ext3_delete_inode 函数

<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="kwd" style="color: rgb(30, 52, 123); margin-top: 0px;">void</span><span class="pln" style="color: rgb(72, 72, 76);"> ext3_delete_inode </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">struct</span><span class="pln" style="color: rgb(72, 72, 76);"> inode </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);"> inode</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="typ" style="color: teal;">handle_t</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">*</span><span class="pln" style="color: rgb(72, 72, 76);">handle</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    truncate_inode_pages</span><span class="pun" style="color: rgb(147, 161, 161);">(&</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_data</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">is_bad_inode</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">))</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">goto</span><span class="pln" style="color: rgb(72, 72, 76);"> no_delete</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    handle </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> start_transaction</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">IS_ERR</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">handle</span><span class="pun" style="color: rgb(147, 161, 161);">))</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">         </span><span class="com" style="color: rgb(147, 161, 161);">/* 如果我们要跳过正常清理,我们仍然需要确保内核孤儿链表进行适当的清理。*/</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        ext3_orphan_del</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">NULL</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> inode</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="kwd" style="color: rgb(30, 52, 123);">goto</span><span class="pln" style="color: rgb(72, 72, 76);"> no_delete</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">IS_SYNC</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">))</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        handle</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">h_sync </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">1</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    inode</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_size </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pun" style="color: rgb(147, 161, 161);">;</span><span class="pln" style="color: rgb(72, 72, 76);">      </span><span class="com" style="color: rgb(147, 161, 161);">/*将索引节点中记录的文件大小设置为0*/</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">-></span><span class="pln" style="color: rgb(72, 72, 76);">i_blocks</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        ext3_truncate</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);">   </span><span class="com" style="color: rgb(147, 161, 161);">/*将索引节点中的文件占用块数清除*/</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    ext3_orphan_del</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">handle</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> inode</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    EXT3_I</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">)-></span><span class="pln" style="color: rgb(72, 72, 76);">i_dtime  </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> get_seconds</span><span class="pun" style="color: rgb(147, 161, 161);">();</span><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="com" style="color: rgb(147, 161, 161);">/*修改该文件索引节点中的删除时间*/</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"> </code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">ext3_mark_inode_dirty</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">handle</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> inode</span><span class="pun" style="color: rgb(147, 161, 161);">))</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        </span><span class="com" style="color: rgb(147, 161, 161);">/* If that failed, just do the required in-core inode clear. */</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        clear_inode</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">else</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">        ext3_free_inode</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">handle</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> inode</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    ext3_journal_stop</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">handle</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">no_delete</span><span class="pun" style="color: rgb(147, 161, 161);">:</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pln" style="color: rgb(72, 72, 76); margin-top: 0px;">    clear_inode</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">inode</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="com" style="color: rgb(147, 161, 161);">/* We must guarantee clearing of inode... */</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code style="margin: 0px; padding: 0px; border: none; word-wrap: break-word; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; max-width: 100%; background-color: transparent;"><span class="pun" style="color: rgb(147, 161, 161); margin-top: 0px;">}</span></code></div></div>

该函数会删除指定的inode,其中主要会调用如下函数(还没看完):

  • ext3_truncate 截断磁盘上的索引信息
  • ext3_orphan_del

  • ext3_free_inode 从内存中和磁盘上分别删除该inode
文章转载自:http://blog.csdn.net/ty_laurel/article/details/51407107

0 0
原创粉丝点击