gpt4 book ai didi

c - 来自 proc_fs.h 的 proc_create_entry 错误 "implicit declaration"

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:01:08 24 4
gpt4 key购买 nike

我正在使用内核为 3.11.6-200.fc19.x86_64 的 Fedora 19

我在学习proc_fs.h的时候出现了一些错误貌似这些代码在Ubuntu 12.04上可以正常编译,就是在Fedora上搞不懂是怎么回事。

[root@frederick-pc 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

这是我的代码

rw_proc.c

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

谁能帮帮我?谢谢

最佳答案

最后我自己解决了这个问题

好像是从3.10.0版本开始,proc_create_entry()这个函数被删除了,取而代之的是proc_create()

因此,如果您使用高于 3.10.0 的内核进行编译,只需在代码中替换它们

关于c - 来自 proc_fs.h 的 proc_create_entry 错误 "implicit declaration",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19977581/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com