2010-03-28 14 views
5

Tôi sao chép và dán mã từ URL này để tạo và đọc/ghi tệp proc bằng mô-đun hạt nhân và nhận lỗi mà proc_root không khai báo. Ví dụ này là trên một vài trang web vì vậy tôi giả sử nó hoạt động. Bất kỳ ý tưởng tại sao tôi nhận được lỗi này? Không makefile của tôi cần một cái gì đó khác nhau. Dưới đây là makefile của tôi cũng như:Mô-đun hạt nhân Linux - Tạo tệp proc - proc_root lỗi không khai báo

Ví dụ mã cho một sáng tạo tập tin proc cơ bản (bản sao trực tiếp và dán để thử nghiệm ban đầu thực hiện): http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html#AEN769

Makefile Tôi đang sử dụng:

obj-m := counter.o 

KDIR := /MY/LINUX/SRC 

PWD := $(shell pwd) 

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

Trả lời

12

Ví dụ đó đã lỗi thời. Dưới API hạt nhân hiện tại, vượt qua NULL cho thư mục gốc của procfs.

Ngoài ra, thay vì create_proc_entry, bạn nên sử dụng proc_create() với số const struct file_operations * thích hợp.

+0

Tuyệt vời! Cảm ơn. Bây giờ tôi có thể làm cho nó để biên dịch đúng cách. – Zach

6

Đã có thay đổi trong giao diện để tạo mục nhập trong hệ thống tệp proc. Bạn có thể có một cái nhìn tại http://pointer-overloading.blogspot.in/2013/09/linux-creating-entry-in-proc-file.html để biết chi tiết

Đây là một 'hello_proc' dụ với giao diện mới:

#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); 
Các vấn đề liên quan