I'm using Fedora 19 with the kernel of 3.11.6-200.fc19.x86_64

I had some errors when learning proc_fs.h It seems that these codes can be normally compiled on Ubuntu 12.04, I just cannot figure out what's wrong with it on Fedora.

[<a href="/cdn-cgi/l/email-protection" data-cfemail="13617c7c67537561767776617a70783e6370">[email protected]</a> Test]# make make -C /lib/modules/3.11.6-200.fc19.x86_64/build M=/home/frederick/Documents/HW_2nd/Test modules make[1]: Entering directory `/usr/src/kernels/3.11.6-200.fc19.x86_64' CC [M] /home/frederick/Documents/HW_2nd/Test/rw_proc.o /home/frederick/Documents/HW_2nd/Test/rw_proc.c: In function ‘rw_proc_init’: /home/frederick/Documents/HW_2nd/Test/rw_proc.c:43:2: error: implicit declaration of function ‘proc_create_entry’ [-Werror=implicit-function-declaration] p = proc_create_entry(PROCFS_NAME, 0644, NULL); ^ /home/frederick/Documents/HW_2nd/Test/rw_proc.c:43:4: warning: assignment makes pointer from integer without a cast [enabled by default] p = proc_create_entry(PROCFS_NAME, 0644, NULL); ^ /home/frederick/Documents/HW_2nd/Test/rw_proc.c:51:3: error: dereferencing pointer to incomplete type p->read_proc = procfile_read; ^ /home/frederick/Documents/HW_2nd/Test/rw_proc.c:52:3: error: dereferencing pointer to incomplete type p->write_proc = procfile_write; ^ /home/frederick/Documents/HW_2nd/Test/rw_proc.c:54:3: error: dereferencing pointer to incomplete type p->mode = S_IFREG | S_IRUGO; ^ /home/frederick/Documents/HW_2nd/Test/rw_proc.c:55:3: error: dereferencing pointer to incomplete type p->uid = 0; ^ /home/frederick/Documents/HW_2nd/Test/rw_proc.c:56:3: error: dereferencing pointer to incomplete type p->gid = 0; ^ /home/frederick/Documents/HW_2nd/Test/rw_proc.c:57:3: error: dereferencing pointer to incomplete type p->size = 37; ^ cc1: some warnings being treated as errors make[2]: *** [/home/frederick/Documents/HW_2nd/Test/rw_proc.o] Error 1 make[1]: *** [_module_/home/frederick/Documents/HW_2nd/Test] Error 2 make[1]: Leaving directory `/usr/src/kernels/3.11.6-200.fc19.x86_64' make: *** [default] Error 2

here're my codes


#include<linux/module.h> #include<linux/kernel.h> #include<linux/proc_fs.h> #include<asm/uaccess.h> #define PROCFS_MAX_SIZE 1024 #define PROCFS_NAME "my_procfile_1k" MODULE_LICENSE("GPL"); static struct proc_dir_entry *p = NULL; static char procfs_buffer[PROCFS_MAX_SIZE]; static unsigned long procfs_buffer_size = 0; static int procfile_read(char *buffer,char **buffer_location,off_t offset, int buffer_length, int *eof,void *data) { int ret; printk(KERN_INFO "procfile_read (/proc/%s) called\n", PROCFS_NAME); if (offset > 0) { ret = 0; } else { memcpy(buffer, procfs_buffer, procfs_buffer_size); ret = procfs_buffer_size; } return ret; } static int procfile_write(struct file *file, const char *buffer, unsigned long count,void *data) { procfs_buffer_size = count; if (procfs_buffer_size > PROCFS_MAX_SIZE ) { procfs_buffer_size = PROCFS_MAX_SIZE; } if ( copy_from_user(procfs_buffer, buffer, procfs_buffer_size) ) { return EFAULT; } return procfs_buffer_size; } static int rw_proc_init(void) { p = proc_create_entry(PROCFS_NAME, 0644, NULL); if (p == NULL) { remove_proc_entry(PROCFS_NAME, NULL); printk(KERN_ALERT "Error: Could not initialize /proc/%s\n", PROCFS_NAME); return ENOMEM; } p->read_proc = procfile_read; p->write_proc = procfile_write; //p->owner = THIS_MODULE; p->mode = S_IFREG | S_IRUGO; p->uid = 0; p->gid = 0; p->size = 37; printk(KERN_INFO "/proc/%s created\n", PROCFS_NAME); return 0; } static void rw_proc_exit(void) { remove_proc_entry(PROCFS_NAME, NULL); printk(KERN_INFO "/proc/%s removed\n", PROCFS_NAME); } module_init(rw_proc_init); module_exit(rw_proc_exit);

Who can help me? THX

Well finally i resolved the problem myself

it seems that since the version of 3.10.0, the function of proc_create_entry() has been deleted and replaced by proc_create()

so just replace them in the codes if you're compiling with a kernel newer than 3.10.0

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

本文标题:Error &amp; ldquo&amp;semi; Implicit statement &amp; rdquo&amp;semi; Wit ...

技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(11)