ouyangyufu2010-10-13 16:52
/*
* Author:Tinnal <Tinnal.Feng@miartech.com>
*
*
* The source code in this file can be freely used, adapted,
* and redistributed in source or binary form, so long as an
* acknowledgment appears in derived source files.No warranty
* is attached;we cannot take responsibility for errors or
* fitness for use.
*
* Modification:
* Tinnal V1.00 2010-10-10 Create the file.
*/
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/kernel.h> /* printk() */
#include <linux/fs.h> /* everything... */
#include <linux/namei.h> /* path_lookup*/
static char *path = NULL;
module_param(path, charp, 0);
static int __init PathLookup_init(void)
{
struct nameidata nd;
void *cookie;
if(path == NULL)
{
printk("PathLookup: Used: insmod PathLookup path=\"<Link file name>\"\n");
return -1;
}
printk("PathLookup: The link file you enter is: %s\n", path);
if (path_lookup(path, 0, &nd)) {
printk("PathLookup: path %s not found!\n", path);
return -1;
}
printk("PathLookup: The real file is %s\n", nd.dentry->d_name.name);
cookie = nd.dentry->d_inode->i_op->follow_link(nd.dentry, &nd);
if (!IS_ERR(cookie)) {
printk("PathLookup: [followlink]:%s\n", nd_get_link(&nd));
if (nd.dentry->d_inode->i_op->put_link)
nd.dentry->d_inode->i_op->put_link(nd.dentry, &nd, cookie);
}
path_release(&nd);
return 0;
}
static void __exit PathLookup_exit(void)
{
}
module_init(PathLookup_init);
module_exit(PathLookup_exit);
MODULE_AUTHOR("Tinnal <tinnal.feng@miartech.com>");
MODULE_LICENSE("Dual BSD/GPL");
MODULE_DESCRIPTION("V1.00");
麻烦一下Tinnal,在测试 得到链接的路径代码,读取/proc进程下的fd下符号链接时,得不到路径,这是为什么,ln 建立却可以