gpt4 book ai didi

c - 为什么导入 fs.h 后变量的类型不完整 'struct file_operations'?

转载 作者:行者123 更新时间:2023-12-03 10:00:08 24 4
gpt4 key购买 nike

我尝试导入 file_operations 的结构并得到这个错误:

Variable has incomplete type 'struct file_operations'

我的导入是

#include <linux/kernel.h>   /* We're doing kernel work */
#include <linux/module.h> /* Specifically, a module */
#include <linux/fs.h> /* for register_chrdev */
#include "sys/types.h"

错误出现在 fops 处:

 struct file_operations Fops =
{
.owner = THIS_MODULE, // Required for correct count of module usage. This prevents the module from being removed while used.
.read = device_read,
.write = device_write,
.open = device_open,
.release = NULL
};

最少的代码:

#include <linux/kernel.h>   /* We're doing kernel work */
#include <linux/module.h> /* Specifically, a module */
#include <linux/fs.h> /* for register_chrdev */
#include "sys/types.h"

struct file_operations Fops =
{
.owner = THIS_MODULE, // Required for correct count of module usage. This prevents the module from being removed while used.
.read = device_read,
.write = device_write,
.open = device_open,
.release = NULL
};

最佳答案

如果您将代码与 https://docs.huihoo.com/doxygen/linux/kernel/3.7/structfile__operations.html 中的 file_operations() 定义进行比较您没有初始化很多字段,可能这就是抛出不完整错误的原因。

Some operations are not implemented by a driver. For example, a driverthat handles a video card won't need to read from a directorystructure. The corresponding entries in the file_operations structureshould be set to NULL.

来源:https://tldp.org/LDP/lkmpg/2.4/html/c577.htm

如果你有 gcc 的 C99 扩展,通常你的方法是有效的

关于c - 为什么导入 fs.h 后变量的类型不完整 'struct file_operations'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65217029/

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