proc_create() example for kernel module

前端 未结 2 1922
北恋
北恋 2020-12-13 04:45

Can someone give me proc_create() example?

Earlier they used create_proc_entry() in the kernel but now they are using proc_create()<

2条回答
  •  轮回少年
    2020-12-13 05:31

    Here is a 'hello_proc' code, which makes use of the newer 'proc_create()' interface.

    #include 
    #include 
    #include 
    
    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);
    

    This code has been taken from http://pointer-overloading.blogspot.com/2013/09/linux-creating-entry-in-proc-file.html

提交回复
热议问题