Linux Kernel Module - Creating proc file - proc_root undeclared error

10,885

Solution 1

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 *.

Solution 2

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);
Share:
10,885
Zach
Author by

Zach

Updated on June 04, 2022

Comments

  • Zach
    Zach almost 2 years

    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 few sites so I assume it works. Any ideas why I'd get this error? Does my makefile need something different. Below is my makefile as well:

    Example code for a basic proc file creation (direct copy and paste to get initial test done): http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html#AEN769

    Makefile I'm using:

    obj-m    := counter.o
    
    KDIR    := /MY/LINUX/SRC
    
    PWD    := $(shell pwd)
    
    default:
     $(MAKE) ARCH=um -C $(KDIR) SUBDIRS=$(PWD) modules
    
  • Zach
    Zach about 14 years
    Great! Thanks. Now I can get it to compile properly.