【发布时间】:2016-10-19 13:11:53
【问题描述】:
我目前正在研究字符设备模块(驱动程序),我对为什么同时存在使用计数和 *owner(在文件操作结构中)感到困惑。
从以下链接可以看出,文件操作结构为:
struct file_operations {
struct module *owner;
loff_t (*llseek) (struct file *, loff_t, int);
ssize_t (*read) (struct file *, char *, size_t, loff_t *);
ssize_t (*write) (struct file *, const char *, size_t, loff_t *);
int (*readdir) (struct file *, void *, filldir_t);
unsigned int (*poll) (struct file *, struct poll_table_struct *);
int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
int (*mmap) (struct file *, struct vm_area_struct *);
int (*open) (struct inode *, struct file *);
int (*flush) (struct file *);
int (*release) (struct inode *, struct file *);
int (*fsync) (struct file *, struct dentry *, int datasync);
int (*fasync) (int, struct file *, int);
int (*lock) (struct file *, int, struct file_lock *);
ssize_t (*readv) (struct file *, const struct iovec *, unsigned long,
loff_t *);
ssize_t (*writev) (struct file *, const struct iovec *, unsigned long,
loff_t *);
};
http://www.tldp.org/LDP/lkmpg/2.4/html/c577.htm
正如我们在课堂上所教的,*owner 用于确保在有设备仍在使用时模块不会被卸载。 但是,在上面链接中的文章的后面,他们描述了这是通过使用诸如 MOD_INC_USE_COUNT 之类的宏来完成的。
因此,我的问题是:为什么我们需要两者?宏是否使用指针来访问此计数器?
【问题讨论】:
标签: c linux linux-kernel driver kernel-module