Linux Kernel Module - Creating proc file - proc_root undeclared error

前端 未结 2 1861
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-14 11:53

I copy and paste code from this URL for creating and reading/writing a proc file using a kernel module and get the error that proc_root is undeclared. This same example is on a

相关标签:
2条回答
  • 2021-02-14 12:45

    There has been a change in the interface to create an entry in the proc file system. You can have a look at http://pointer-overloading.blogspot.in/2013/09/linux-creating-entry-in-proc-file.html for details

    Here is a 'hello_proc' example with the new interface:

    #include <linux/module.h>
    #include <linux/proc_fs.h>
    #include <linux/seq_file.h>
    
    static int hello_proc_show(struct seq_file *m, void *v) {
      seq_printf(m, "Hello proc!\n");
      return 0;
    }
    
    static int hello_proc_open(struct inode *inode, struct  file *file) {
      return single_open(file, hello_proc_show, NULL);
    }
    
    static const struct file_operations hello_proc_fops = {
      .owner = THIS_MODULE,
      .open = hello_proc_open,
      .read = seq_read,
      .llseek = seq_lseek,
      .release = single_release,
    };
    
    static int __init hello_proc_init(void) {
      proc_create("hello_proc", 0, NULL, &hello_proc_fops);
      return 0;
    }
    
    static void __exit hello_proc_exit(void) {
      remove_proc_entry("hello_proc", NULL);
    }
    
    MODULE_LICENSE("GPL");
    module_init(hello_proc_init);
    module_exit(hello_proc_exit);
    
    0 讨论(0)
  • 2021-02-14 12:46

    That example is out of date. Under the current kernel API, pass NULL for the root of procfs.

    Also, instead of create_proc_entry, you should use proc_create() with a proper const struct file_operations *.

    0 讨论(0)
提交回复
热议问题