📄 049_fs_namei_c.html
字号:
<span id=fe2k style="FONT-FAMILY:Courier New"> return
0;</span><br id=w9xj style="FONT-FAMILY:Courier New">
<span id=nc70 style="FONT-FAMILY:Courier New">out_dput:</span><br id=re6i style="FONT-FAMILY:Courier New">
<span id=xvm6 style="FONT-FAMILY:Courier New"> dput(dentry);</span><br id=nly3 style="FONT-FAMILY:Courier New">
<span id=erhi style="FONT-FAMILY:Courier New"> break;</span></font><br id=s-_n style="FONT-FAMILY:Courier New">
<span id=jzkc style="FONT-FAMILY:Courier New"> }
//end for</span></font><br id=l1v0 style="FONT-FAMILY:Courier New">
<span id=e4wu style="FONT-FAMILY:Courier New">
path_release(nd);</span><br id=f26c style="FONT-FAMILY:Courier New">
<font color=#ff0000 id=koh6><span id=qlup style="FONT-FAMILY:Courier New">
return_err:</span></font><br id=k4o4 style="FONT-FAMILY:Courier New">
<span id=iyrb style="FONT-FAMILY:Courier New">
return err;</span><br id=ml8e style="FONT-FAMILY:Courier New">
<span id=ouj2 style="FONT-FAMILY:Courier New">}</span></font></font>
</p>
<p align=justify dir=ltr id=wez9>
<br id=f2_r>
</p>
<p align=justify dir=ltr id=r4c7>
</p>
<br id=yqyl>
<p id=y6dn style="FONT-FAMILY:Courier New">
<font color=#0000ff id=yz6i size=4><b id=lbkn>处理 '..'
操作 </b></font>
</p>
<p id=rr0q style="FONT-FAMILY:Courier New">
主要是为什么是一个while循环... 看下面的图就可以明白了.
就是可以将文件系统安装到一个文件系统的根目录,以至于..的时候需要一直顺着dentry和mnt组成的树向上走...<br id=av2h>
</p>
<p id=ei75 style="FONT-FAMILY:Courier New">
static inline void follow_dotdot(struct nameidata *nd)<br id=ibf4>
<img alt="" id=kyct>
</p>
<div id=hafk style="PADDING:1em 0pt; TEXT-ALIGN:left">
<img id=hlm2 src=049__fs_namei_c_images/dcbsxfpf_75fzwkg6cd.bmp style="WIDTH:155px; HEIGHT:305px">
</div>
<br id=r2_9>
<p id=zr5e>
</p>
<p id=e0qr style="FONT-FAMILY:Courier New">
<font color=#0000ff id=tu83 size=4><b id=avbz>flow_down处理mnt</b></font>
</p>
<p id=q1.5 style="FONT-FAMILY:Courier New">
<font color=#073763 id=hhj6>也用一副图来说明,
代码就不贴了.因为一个dentry下可以有多个mnt,所以有__flow_down函数的while循环.然后考虑像dotdot的那种重复,就需要path_walk中的:</font>
</p>
<p id=imfx style="FONT-FAMILY:Courier New">
<font id=b735 size=-0><font id=dm46 size=2><font color=#0b5394 id=z-df><font color=#073763 id=uxxw><span id=b9ze style="FONT-FAMILY:Courier New">while
(<font color=#38761d id=ibq0><b id=rfdu>d_mountpoint</b></font>(dentry)
&&
<font color=#38761d id=zk-s><b id=pil:>__follow_down</b></font>(&nd->mnt,
&dentry))</span><br id=en6r style="FONT-FAMILY:Courier New">
<span id=cic8 style="FONT-FAMILY:Courier New"> ;</span></font></font></font></font>
</p>
<div id=uf9j style="PADDING:1em 0pt; TEXT-ALIGN:left">
<img id=gaxe src=049__fs_namei_c_images/dcbsxfpf_77dxnkxbdp.jpg style="WIDTH:486px; HEIGHT:568px">
</div>
<p id=gk:g style="FONT-FAMILY:Courier New">
<font color=#073763 id=v5wu><br id=lqm4>
</font>
</p>
<p id=v843 style="FONT-FAMILY:Courier New">
<font color=#0000ff id=yel. size=4><b id=l7:c>处理link</b></font>
</p>
<p id=w1e3 style="FONT-FAMILY:Courier New">
static inline int
<font color=#38761d id=m8l1><b id=hr6e>do_follow_link</b></font>(struct
dentry *dentry, struct nameidata *nd)<br id=g-id>
{<br id=v-fg>
int err;<br id=g_t8>
if (current->link_count >= 8)<br id=u8mc>
goto loop;<br id=py.i>
current->link_count++;<br id=wn6t>
UPDATE_ATIME(dentry->d_inode);<br id=iyxh>
err =
dentry->d_inode->i_op-><font color=#38761d id=l01h><b id=p8el>follow_link</b></font>(dentry,
nd);<br id=pgyo>
current->link_count--;<br id=xn1e>
return err;<br id=lw4o>
loop:<br id=ar14>
path_release(nd);<br id=c8ek>
return -ELOOP;<br id=tlzk>
}
</p>
<p id=w4lc style="FONT-FAMILY:Courier New">
注意<font color=#ff0000 id=zrtp><b id=b8sp>ext2_read_inode</b></font>这个函数,这里是ext2文件,inode各种ops的来源,
对于ext2,就选下面的fast symlink看看吧:<br id=akpd>
</p>
<p id=fl2o style="FONT-FAMILY:Courier New">
struct inode_operations ext2_fast_symlink_inode_operations = {<br id=ifpg>
readlink: ext2_readlink,<br id=kxpd>
follow_link: <font color=#38761d id=q8db><b id=xkke>
ext2_follow_link</b></font>,<br id=xsgv>
};<br id=i6of>
</p>
static int ext2_follow_link(struct dentry *dentry, struct nameidata *nd)<br id=up:8>
{<br id=z5zd>
char *s = (char
*)dentry->d_inode->u.ext2_i.i_data;<br id=mqn9>
return
<font color=#38761d id=c43y><b id=ysdl>vfs_follow_link</b></font>(nd,
s);<br id=sjre>
}<br id=kamf>
<p id=t919 style="FONT-FAMILY:Courier New">
很直观的.<br id=smst>
</p>
<p id=zb5c style="FONT-FAMILY:Courier New">
另一方面,vfs提供了另外一种link的方式用于读取比较常的路径名,最长一个page的长度.
</p>
<p id=bb9i style="FONT-FAMILY:Courier New">
struct inode_operations page_symlink_inode_operations = {<br id=dg9y>
readlink:
<font color=#38761d id=i9pu><b id=ov9j>page_readlink</b></font>,<br id=gdba>
follow_link:
<font color=#38761d id=gl4w>page_follow_link</font>,<br id=cwm0>
};
</p>
<p id=xhux style="FONT-FAMILY:Courier New">
方式是直接加载此inode对应文件的头一个page的内容... 不具体分析了.<br id=n0ol>
</p>
<p id=mcq4 style="FONT-FAMILY:Courier New">
<font color=#0000ff id=n1me size=4><b id=n6qo>从磁盘加载还不在这棵树中的内容</b></font>
</p>
<span id=kcq7 style="FONT-FAMILY:Courier New">/*</span><br id=j286 style="FONT-FAMILY:Courier New">
<span id=gqm7 style="FONT-FAMILY:Courier New"> * This is called
when everything else fails, and we actually
have</span><br id=nse0 style="FONT-FAMILY:Courier New">
<span id=u-ub style="FONT-FAMILY:Courier New"> * to go to the
low-level filesystem to find out what we should
do..</span><br id=nemd style="FONT-FAMILY:Courier New">
<span id=xyqv style="FONT-FAMILY:Courier New"> *</span><br id=r353 style="FONT-FAMILY:Courier New">
<span id=j6k7 style="FONT-FAMILY:Courier New"> * We get the
directory semaphore, and after getting that we
also</span><br id=cymd style="FONT-FAMILY:Courier New">
<span id=ypyh style="FONT-FAMILY:Courier New"> * make sure that
nobody added the entry to the dcache in the
meantime..</span><br id=jr63 style="FONT-FAMILY:Courier New">
<span id=rdnt style="FONT-FAMILY:Courier New"> *
SMP-safe</span><br id=rh_1 style="FONT-FAMILY:Courier New">
<span id=o:2r style="FONT-FAMILY:Courier New"> */</span><br id=o_s: style="FONT-FAMILY:Courier New">
<span id=q6jp style="FONT-FAMILY:Courier New">static struct dentry *
<font color=#38761d id=q4-_><b id=bd.u>real_lookup</b></font>(struct
dentry * parent, struct qstr * name, int
flags)</span><br id=e23g style="FONT-FAMILY:Courier New">
<span id=a3-1 style="FONT-FAMILY:Courier New">{</span><br id=x_fn style="FONT-FAMILY:Courier New">
<span id=w7a1 style="FONT-FAMILY:Courier New">
.....</span><br id=trbb style="FONT-FAMILY:Courier New">
<span id=u1r8 style="FONT-FAMILY:Courier New"> if
(!result) {</span><br id=mrfv style="FONT-FAMILY:Courier New">
<span id=bz5k style="FONT-FAMILY:Courier New">
struct dentry * dentry = d_alloc(parent,
name);</span><br id=ioim style="FONT-FAMILY:Courier New">
<span id=ma:i style="FONT-FAMILY:Courier New">
result =
ERR_PTR(-ENOMEM);</span><br id=jbqu style="FONT-FAMILY:Courier New">
<span id=bzjd style="FONT-FAMILY:Courier New">
if (dentry)
{</span><br id=gp1i style="FONT-FAMILY:Courier New">
<span id=qmaq style="FONT-FAMILY:Courier New">
lock_kernel();</spa
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -