2010-03-28 14 views
5

Ich kopiere und füge Code von dieser URL zum Erstellen und Lesen/Schreiben einer proc-Datei mit einem Kernel-Modul und den Fehler, dass proc_root nicht deklariert ist. Das gleiche Beispiel ist auf einigen Seiten, also nehme ich an, es funktioniert. Irgendwelche Ideen, warum ich diesen Fehler bekommen würde? Benötigt mein Makefile etwas anderes? Unten ist meine Make-Datei auch:Linux-Kernel-Modul - Proc-Datei erstellen - proc_root undeclared Fehler

Beispielcode für eine grundlegende proc-Dateierstellung (direkte Kopieren und Einfügen Erstprüfung zu erledigen): http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html#AEN769

Makefile Ich verwende:

obj-m := counter.o 

KDIR := /MY/LINUX/SRC 

PWD := $(shell pwd) 

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

Antwort

12

Dieses Beispiel ist veraltet. Übergeben Sie unter der aktuellen Kernel-API NULL für das Stammverzeichnis von procfs.

Auch anstelle von create_proc_entry sollten Sie proc_create() mit einem richtigen const struct file_operations * verwenden.

+0

Great! Vielen Dank. Jetzt kann ich es richtig kompilieren. – Zach

6

Die Schnittstelle wurde geändert, um einen Eintrag im proc-Dateisystem zu erstellen. Sie können an http://pointer-overloading.blogspot.in/2013/09/linux-creating-entry-in-proc-file.html für Details

hier einen Blick ist ein 'hello_proc' Beispiel mit der neuen Schnittstelle:

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