c - 为什么变量在导入 fs.h 时具有不完整的类型“struct file_operations”?
问题描述
我尝试导入 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.htmlfile_operations()
中的定义进行比较,您还没有初始化很多字段,这可能就是抛出不完整错误的原因。
某些操作不是由驱动程序实现的。例如,处理视频卡的驱动程序不需要从目录结构中读取。file_operations 结构中的相应条目应设置为 NULL。
来源:https ://tldp.org/LDP/lkmpg/2.4/html/c577.htm
通常,如果您有 gcc 的 C99 扩展,您的方式是有效的
推荐阅读
- complexity-theory - 复杂性,Autometa 谁能解释一下?
- vue.js - 使用 Vuelidate,如果用户输入的内容已经存在于数据库中,如何生成错误?
- c++ - std::unordered_map 类型对象声明期间出现“字段类型不完整”错误
- django - 如何使用 Apache 和 Django(以及 Docker)配置我的 ProxyPass?
- components - 不是 UI 组件的 Blazor 客户端调用代码
- jquery - 在创建时使用创建的 html 元素从左到右填充文本颜色
- android - MPAndroid 图表。如何在单个图表上使用具有不同数据类型的数据集?
- python - Python cv2.imshow() 因中止陷阱而崩溃:6
- jquery-select2 - 多选上的非转义 select2 占位符
- typescript - Typescript 根据接口名称创建对象?