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

标签 linux-kernel kernel kernel-module

我从这个 URL 复制并粘贴代码,用于使用内核模块创建和读取/写入 proc 文件,并得到 proc_root 未声明的错误。这个相同的例子在几个网站上,所以我认为它有效。任何想法为什么我会收到此错误?我的makefile是否需要不同的东西。下面也是我的makefile:

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

生成文件 我正在使用:

obj-m    := counter.o

KDIR    := /MY/LINUX/SRC

PWD    := $(shell pwd)

default:
 $(MAKE) ARCH=um -C $(KDIR) SUBDIRS=$(PWD) modules

最佳答案

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

这是一个带有新接口(interface)的“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);

关于linux-kernel - Linux 内核模块 - 创建 proc 文件 - proc_root 未声明的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2531730/

相关文章:

linux - 在 linux sk_buff 中,skb->data 是物理地址还是虚拟地址?

c - ISRS 没有接到电话

c - linux内核模块权限

linux - 在引导时提供无效参数后如何加载内核模块?

networking - 待传输数据包skb分配的空间量到底是如何确定和分配的?

linux - 在 Linux 内核中调用给定函数的上下文

linux - 不使用 printk 写入 Linux 控制台

linux-kernel - 在内核模块中监听 netlink 广播

c - 读取时工作队列和计时器模块崩溃

docker - Kubernetes pods 重启问题异常