2010-03-28 69 views
5

我複製並粘貼此URL中的代碼,用於使用內核模塊創建和讀取/寫入proc文件,並獲取proc_root未聲明的錯誤。同樣的例子是在幾個網站上,所以我認爲它的工作原理。任何想法,爲什麼我會得到這個錯誤?我的生成文件是否需要不同的東西?下面是我的makefile還有:Linux內核模塊 - 創建proc文件 - proc_root未聲明的錯誤

一個基本的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 

回答

12

該示例已過時。在當前的內核API下,通過NULL作爲procfs的根目錄。

此外,而不是create_proc_entry,您應該使用proc_create()與適當的const struct file_operations *

+0

太好了!謝謝。現在我可以正確地編譯它。 – Zach 2010-03-28 03:47:26

6

在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);