why Variable has incomplete type 'struct file_operations' though importing fs.h?

536 views Asked by At

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
        };
1

There are 1 answers

0
ralf htp On

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.

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

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

Normally your way is valid if you have the C99 extension for gcc