- 论坛徽章:
- 0
|
#include <linux/fs.h> /*struct file*/
#include <linux/file.h> /*fget() fput()*/
#include <linux/fdtable.h> /*NR_OPEN_DEFAULT*/
#include <linux/dcache.h> /*d_path()*/
void KernelFd_ShowFd(void)
{
int i_Loop = 0;
char ac_Buf[64];
char * pc_FdName = NULL;
struct file * pst_File = NULL;
printk("\nshow Fd:\n");
//遍历FD
for (i_Loop = 0; i_Loop < NR_OPEN_DEFAULT; i_Loop++)
{
//取出FD对应struct file并检验
pst_File = fget(i_Loop);
if (NULL != pst_File)
{
//取出FD对应文件路径及文件名并检验
pc_FdName = d_path(&(pst_File->f_path), ac_Buf, sizeof(ac_Buf));
if (NULL != pc_FdName)
{
printk("\tfd %02d is %s, addr is 0x%p\n", i_Loop, pc_FdName, pst_File);
}
else
{
printk("\tfd %02d name is NULL, addr is 0x%p\n", i_Loop, pst_File);
}
//fget(),fput()成对
fput(pst_File);
}
}
printk("\n");
} |
|