函数:dput()
dput()函数的作用是释放一个dentry结构体,并且将该结构体的使用计数d_count的值作减1操作,将该结构体从队列中删除,同时,释放该结构体的资源,如果是父结构体也被释放,则该结构体与父结构体将同时被删除。
文件包含:
#include <linux/dcache.h>
函数定义:
在内核源码中的位置:linux-3.19.3/fs/dcache.c
函数定义格式:
void dput(struct dentry *dentry)
输入参数说明:
返回参数说明:
dput()
函数无返回值。
实例解析:
编写测试文件:dput.c
头文件声明如下:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/fs_struct.h>
#include <linux/path.h>
#include <linux/sched.h>
MODULE_LICENSE("GPL");
模块初始化函数:
int dput_init(void)
{
struct dentry *dentry_pwd = current->fs->pwd.dentry; //获取当前文件的入口目录
/*显示当前目录的引用数目*/
printk("Before \"dput\", the d_count of current dentry is %d\n", dentry_pwd->d_count);
dput(dentry_pwd); //释放dentry_pwd结构体
/*显示函数调用之后,当前目录的引用数目*/
printk("After \"dput\", the d_count of current dentry is %d\n", dentry_pwd->d_count);
return 0;
}
模块退出函数:
void dput_exit(void)
{
printk("Goodbye dput\n");
}
模块初始化及退出函数调用:
module_init(dput_init);
module_exit(dput_exit);
实例运行结果及分析:
首先编译模块,执行命令insmod dput.ko插入模块,然后执行命令dmesg -c,会出现如图所示的结果。
结果分析:
执行函数dput之后,其中的计数器会减去1,而在本例中,一开始的计数器值为247,执行函数过后,释放掉当前dentry结构体,计数器的值变为246。
酷客网相关文章:
评论前必须登录!
注册