📄 042_fs_file_c.html
字号:
<html lang="zh-CN" xmlns:gdoc=""> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <style type="text/css">/* default css */table { font-size: 1em; line-height: inherit;}div, address, ol, ul, li, option, select { margin-top: 0px; margin-bottom: 0px;}p { margin: 0px;}body { margin: 0px; padding: 0px; font-family: Verdana, sans-serif; font-size: 10pt; background-color: #ffffff;}h6 { font-size: 10pt }h5 { font-size: 11pt }h4 { font-size: 12pt }h3 { font-size: 13pt }h2 { font-size: 14pt }h1 { font-size: 16pt }blockquote {padding: 10px; border: 1px #DDD dashed }a img {border: 0}div.google_header, div.google_footer { position: relative; margin-top: 1em; margin-bottom: 1em;}/* end default css */ /* default print css */ @media print { body { padding: 0; margin: 0; } div.google_header, div.google_footer { display: block; min-height: 0; border: none; } div.google_header { flow: static(header); } /* used to insert page numbers */ div.google_header::before, div.google_footer::before { position: absolute; top: 0; } div.google_footer { flow: static(footer); } /* always consider this element at the start of the doc */ div#google_footer { flow: static(footer, start); } span.google_pagenumber { content: counter(page); } span.google_pagecount { content: counter(pages); } } @page { @top { content: flow(header); } @bottom { content: flow(footer); } } /* end default print css */ /* custom css *//* end custom css */ /* ui edited css */ body { font-family: Verdana; font-size: 10.0pt; line-height: normal; background-color: #ffffff; } .documentBG { background-color: #ffffff; } /* end ui edited css */</style> </head> <body revision="dcbsxfpf_30c5x2fsgb:30"> <table align=center cellpadding=0 cellspacing=0 height=5716 width=802>
<tbody>
<tr>
<td height=5716 valign=top width=802>
<pre>2007-12-19 <br><br>这是一个比较简单的模块,从open.c中copy出来的.先看看task_struct 里有关文件的几个控制结构吧.<br>struct <font color=#000099><b>task_struct</b></font> {<br> ........ <br>/* task state */<br> struct linux_binfmt *binfmt; <font color=#3333ff>/*elf aout ....*/</font><br> .....<br> int dumpable:1;<font color=#3333ff> /*是否可以core dump*/</font><br>/* limits */<br> char comm[16]; <font color=#3333ff> /*core dump的名称(可执行文件名)*/</font><br>/* file system info */<br> ...<br> unsigned int locks; <font color=#3333ff>/* How many file locks are being held */</font><br>/* filesystem information */<br> struct fs_struct *<font color=#000099><b>fs</b></font>;<br>/* open file information */<br> struct <font color=#006600><b>files_struct</b></font> *<font color=#000099><b>files</b></font>;<br> .....<br>};<br>struct <font color=#009900><b>files_struct</b></font> {<br> atomic_t count;<br> rwlock_t file_lock;<br> int max_fds;<br> int max_fdset;<br> int next_fd;<br> <font color=#006600>struct file ** <b>fd</b></font>; /* current fd array,init is fd_arrary */<br> fd_set *<b>close_on_exec</b>;<br> fd_set *<b>open_fds</b>; /*bitmap for open fd_array*/<br> fd_set <font color=#000099><b>close_on_exec_init</b></font>;<br> fd_set open_fds_init;<br> struct file * <font color=#006600><b>fd_array</b></font>[NR_OPEN_DEFAULT]; /*inline的fd array*/<br>};<br><br>这里只关心files_struct. file_struct含有两个fd_set一个fd array(黑体和绿体字). 已开始fd指向fd_array,见<br>static int <font color=#000099><b>copy_files</b></font>(unsigned long clone_flags, struct task_struct * tsk)<br>{<br> .....<br> newf->close_on_exec = &newf->close_on_exec_init;<br> newf->open_fds = &newf->open_fds_init;<br> newf->fd = &newf->fd_array[0];<br> ...<br>}<br><br>之后需要扩展的时候.... 就是这个模块的事情了.<br>struct file ** <font color=#000099><b>alloc_fd_array</b></font>(int num)<br>void <font color=#000099><b>free_fd_array</b></font>(struct file **array, int num)<br>int <font color=#000099><b>expand_fd_array</b></font>(struct files_struct *files, int nr)<br>fd_set * <font color=#000099><b>alloc_fdset</b></font>(int num)<br>void <font color=#000099><b>free_fdset</b></font>(fd_set *array, int num)<br>int <font color=#000099><b>expand_fdset</b></font>(struct files_struct *files, int nr)<br><br>自己觉得没有必要每个函数分析了,就这四个函数....<br></pre>
</td>
</tr>
</tbody>
</table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -