Linux内核模块 - 创建proc文件 - proc_root未声明的错误

Zac*_*ach 9 kernel kernel-module linux-kernel

我复制并粘贴此URL中的代码,用于使用内核模块创建和读取/写入proc文件,并获取proc_root未声明的错误.同样的例子是在几个网站上,所以我认为它的工作原理.有什么想法我会收到这个错误吗?我的makefile需要不同的东西吗?下面是我的makefile:

基本proc文件创建的示例代码(直接复制和粘贴以完成初始测试):http: //tldp.org/LDP/lkmpg/2.6/html/lkmpg.html#AEN769

我正在使用的Makefile:

obj-m    := counter.o

KDIR    := /MY/LINUX/SRC

PWD    := $(shell pwd)

default:
 $(MAKE) ARCH=um -C $(KDIR) SUBDIRS=$(PWD) modules
Run Code Online (Sandbox Code Playgroud)

eph*_*ent 16

那个例子已经过时了.在当前的内核API下,传递NULLprocfs的根目录.

而且,create_proc_entry你应该使用proc_create()适当的const struct file_operations *.


小智 8

在proc文件系统中创建条目的界面发生了变化.您可以查看http://pointer-overloading.blogspot.in/2013/09/linux-creating-entry-in-proc-file.html了解详情

这是一个带有新接口的'hello_proc'示例:

#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);
Run Code Online (Sandbox Code Playgroud)