file_operations:从不兼容的指针类型.read初始化

时间:2019-01-23 14:24:52

标签: c module char kernel

我一直在尝试测试proc_create()函数,因此我试图了解file_operations结构,但是不幸的是,我一直遇到指针错误,在这一点上,我似乎无法弄清楚是什么原因的。 这是代码:

static size_t read_proc(struct file *filp,char *buf,size_t count, loff_t *offp) 
{

    if(count>temp)
    {
        count=temp;
    }
    temp=temp-count;
    copy_to_user(buf,msg, count);
    if(count==0)
    temp=len;

    return count;
}

struct file_operations proc_fops = {
    .read = read_proc
};

这是makefile重新存储:

make -C /lib/modules/4.15.0-29-generic/build M=/home/ubuntu/Desktop/XX3 modules
make[1]: Entering directory '/usr/src/linux-headers-4.15.0-29-generic'
Makefile:976: "Cannot use CONFIG_STACK_VALIDATION=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel"
  CC [M]  /home/ubuntu/Desktop/XX3/proc.o
/home/ubuntu/Desktop/XX3/proc.c:27:9: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
 .read = read_proc
         ^~~~~~~~~
/home/ubuntu/Desktop/XX3/proc.c:27:9: note: (near initialization for ‘proc_fops.read’)
cc1: some warnings being treated as errors
scripts/Makefile.build:339: recipe for target '/home/ubuntu/Desktop/XX3/proc.o' failed
make[2]: *** [/home/ubuntu/Desktop/XX3/proc.o] Error 1
Makefile:1552: recipe for target '_module_/home/ubuntu/Desktop/XX3' failed
make[1]: *** [_module_/home/ubuntu/Desktop/XX3] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-29-generic'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2
root@ubuntu:/home/ubuntu/

很明显,这是一个在Ubuntu上运行的4.20内核,其他内核模块也可以正常运行,因此我认为这是我造成的。 为帮助喝彩

编辑:是的,我现在看到了。 size_t上的双“ s”很糟糕

0 个答案:

没有答案