I try to import the struct of file_operations and get this error:
Variable has incomplete type 'struct file_operations'
my imports are
#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"
and the error is here at 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
};
minimal code:
#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
};
If you compare your code to the definition of
file_operations()
in https://docs.huihoo.com/doxygen/linux/kernel/3.7/structfile__operations.html you have not initialized many fields, possibly this is why the incomplete error is thrown.source : https://tldp.org/LDP/lkmpg/2.4/html/c577.htm
Normally your way is valid if you have the C99 extension for gcc