2017-01-05 6 views
0

Ich habe erfolgreich einen Pseudo Hello World Entry mit einem LKM erstellt.Erstelle einen Eintrag in/proc

http://pointer-overloading.blogspot.co.at/2013/09/linux-creating-entry-in-proc-file.html

jedoch in meiner Funktion init, habe ich ein Integer-Wert, die ich in "cat/proc/example" zurückkehren möchten.

Irgendwelche Ideen, wie man das in diesem Code macht?

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

Ihr bereitgestellten Code zeigt keinen ganzzahligen Wert in einer 'init' Funktion? –

+0

In meinem Code habe ich einen ganzzahligen Wert für die CPU-Temperatur. Ich möchte nur diesen Wert anstelle von "Hallo Welt" zurückgeben. Muss ich meiner Struktur weitere Daten hinzufügen oder kann ich sie einfach den bereitgestellten Funktionen geben? –

+2

seq_printf (m, "CPU-Temp:% d \ n", cpu_temp); ? – Mali

Antwort

Verwandte Themen