如何通过fd找到打开文件的路径及名称
在用户程序中打开文件进行编辑,那在内核中如何能通过open后的fd
来找到相应打开文件的路径及其名字呢?
Signature · 3 lines
--------------------------------- Zhenwen Xu - Open and Free Home Page: http://zhwen.org
in fs/open.c
sys_open
| --> do_sys_open
|---> fd_installThen fd is installed into file_fdtable
in fs/file_table.c
fget_light/fget
|----> fcheck_filesThen kernel get files from fd.
2009/11/20 Helight.Xu <[email protected]>:
Quoted 14 lines
在用户程序中打开文件进行编辑,那在内核中如何能通过open后的fd
来找到相应打开文件的路径及其名字呢?--
---------------------------------
Zhenwen Xu - Open and Free
Home Page: http://zhwen.org--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 5 lines · Xiaotian Feng
in
fs/open.c
sys_open| --> do_sys_open |---> fd_install
Quoted 8 lines
Then fd is installed into
file_fdtablein
fs/file_table.cfget_light/fget |----> fcheck_filesThen kernel get files from fd.
struct file is easy to get : current->files->fd_array[fd]
but I didn't find the file name!
Quoted 19 lines
2009/11/20 Helight.Xu <[email protected]>:
Quoted 15 lines
在用户程序中打开文件进行编辑,那在内核中如何能通过open后的fd
来找到相应打开文件的路径及其名字呢?--
---------------------------------
Zhenwen Xu - Open and Free
Home Page: http://zhwen.org--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 3 lines
--------------------------------- Zhenwen Xu - Open and Free Home Page: http://zhwen.org
Quoted 3 lines · Helight.Xu
在用户程序中打开文件进行编辑,那在内核中如何能通过open后的fd
来找到相应打开文件的路径及其名字呢?
问题是你为什么要在内核中做呢?在用户空间完全可以完成:
% readlink /proc/<PID>/fd/X
Signature · 1 line
Live like a child, think like the god.
Quoted 11 lines · Américo Wang
Quoted 4 lines · Helight.Xu
在用户程序中打开文件进行编辑,那在内核中如何能通过open后的fd
来找到相应打开文件的路径及其名字呢?问题是你为什么要在内核中做呢?在用户空间完全可以完成:
% readlink /proc/<PID>/fd/X
我是想在内核中实现一些功能,所以现在内核中找到文件的路径及其名称,现在只 能找到文件名,还在找路径。。。
Quoted 2 lines
Signature · 3 lines
--------------------------------- Zhenwen Xu - Open and Free Home Page: http://zhwen.org
Quoted 8 lines · Helight.Xu
Quoted 7 lines · Américo Wang
Quoted 4 lines · Helight.Xu
在用户程序中打开文件进行编辑,那在内核中如何能通过open后的fd
来找到相应打开文件的路径及其名字呢?
Quoted 5 lines
Quoted 4 lines
问题是你为什么要在内核中做呢?在用户空间完全可以完成:
% readlink /proc/<PID>/fd/X
我是想在内核中实现一些功能,所以现在内核中找到文件的路径及其名称,
能在用户层完成的就不要跑到内核里去做,完全没必要。
而且,你在处理这个问题时还要考虑pipe和socket这些特殊的文件,
它们对应的fd可是没有file的。
Quoted 2 lines
现在只
能找到文件名,还在找路径。。。
你可以看看proc文件中对fd/X的处理,或许能帮上忙。
Signature · 1 line
Live like a child, think like the god.
On Mon, Nov 23, 2009 at 04:05:55PM +0100, Jiri Kosina wrote:
<snip>
Quoted 2 lines
Come on guys, you keep CCing LKML with this :)
Wow, I missed the "lkml" label on this email in my inbox... :-/
I thought it was from [email protected] since $subject is in Chinese.
I guess Helight wanted to send to zh-kernel.org, right?
Signature · 1 line
Live like a child, think like the god.
non-english on list (was Re: ????????????fd????????????????????????????????????)
In reply to Helight.XuQuoted 8 lines · Helight.Xu
Quoted 7 lines · Am??rico Wang
Quoted 4 lines · Helight.Xu
???????????????????????????????????????????????????????????????????????????open??????fd ??????????????????????????????????????????????????????
Quoted 9 lines
Quoted 4 lines
?????????????????????????????????????????????????????????????????????????????????
% readlink /proc/<PID>/fd/X
???????????????????????????????????????????????????????????????????????????????????????????????????????????? ?????????????????????????????????????????????
Quoted 2 lines
Could we keep the list english-only?
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: non-english on list (was Re: ????????????fd????????????????????????????????????)
Quoted 1 line · Pavel Machek
Could we keep the list english-only?
I thought that was the rule, but then concluded that there was probably good reason for using Chinese--perhaps insufficient skill in English--and why shouldn't people be allowed to post in a language they understand? Certainly less people can answer in other languages, but as we've seen, it's more than zero, and I gather a satisfactory result was achieved. If you don't understand the language just skip the thread and move on.
Re: non-english on list
Quoted 10 lines · David Newall
Quoted 1 line · Pavel Machek
Could we keep the list english-only?
I thought that was the rule, but then concluded that there was probably good reason for using Chinese--perhaps insufficient skill in English--and why shouldn't people be allowed to post in a language they understand? Certainly less people can answer in other languages, but as we've seen, it's more than zero, and I gather a satisfactory result was achieved. If you don't understand the language just skip the thread and move on.
Hi, sorry about this.
It was proved to be a mistake, I checked this with Helight, he wanted to send to a Chinese lkml.
Don't worry, none of us has problems to write English emails. ;)
Thanks for your care.
Signature · 1 line
Live like a child, think like the god.