2011-04-08 18:04:27| 分类: linux学习 | 标签:proc_create struct proc_fops const test |举报|字号 订阅
下载LOFTER 我的照片书 | 在看md代码初始化的时候,看到md注册/proc/mdstat用了 proc_create("mdstat", S_IRUGO, NULL, &md_seq_fops); 而我之前写proc下东西的时候经常用create_proc_entry,故看看有什么区别。 1. create_proc_entry比proc_create多了一个赋值默认文件操作的动作 对于规则文件, dp->proc_fops = &proc_file_operations; 而 static const struct file_operations proc_file_operations = { .llseek = proc_file_lseek, .read = proc_file_read, .write = proc_file_write, }; 2. 而proc_create是创建时要提供自己的文件操作函数的。 static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops) { return proc_create_data(name, mode, parent, proc_fops, NULL); } 3. 当然以前我用create_proc_entry时候当创建成功时,其实也没有用默认的文件操作指针 Test = create_proc_entry("TEST", 0666, NULL); if (Test) { Test->proc_fops = &Test_file_ops; } static struct file_operations Test_file_ops = { .owner = THIS_MODULE, .open = Test_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release }; 4. 对于md static const struct file_operations md_seq_fops = { .owner = THIS_MODULE, .open = md_seq_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release_private, .poll = mdstat_poll, }; 只是md还多赋值了一个poll成员。 无本质差异。 特此记录。转载于:https://www.cnblogs.com/Dennis-mi/articles/5239039.html
相关资源:JAVA上百实例源码以及开源项目