file_operations structure
HI,
I am writing chardev driver and get int troubles while compiling module with gcc -c modulename.c. Error reported from compiler is: error: chardev.c 255:variable `fops' has initializer but incomplete type chardev.c:257: warning: excess elements in struct initializer chardev.c:257: warning: (near initialization for `fops') chardev.c:258: warning: excess elements in struct initializer chardev.c:258: warning: (near initialization for `fops') chardev.c:259: warning: excess elements in struct initializer chardev.c:259: warning: (near initialization for `fops') chardev.c:260: warning: excess elements in struct initializer chardev.c:260: warning: (near initialization for `fops') chardev.c:261: warning: excess elements in struct initializer chardev.c:261: warning: (near initialization for `fops') chardev.c:262: warning: excess elements in struct initializer chardev.c:262: warning: (near initialization for `fops') chardev.c:263: warning: excess elements in struct initializer chardev.c:263: warning: (near initialization for `fops') chardev.c:264: warning: excess elements in struct initializer chardev.c:264: warning: (near initialization for `fops') chardev.c:265: warning: excess elements in struct initializer chardev.c:265: warning: (near initialization for `fops') chardev.c:266: warning: excess elements in struct initializer chardev.c:266: warning: (near initialization for `fops') chardev.c:267: warning: excess elements in struct initializer chardev.c:267: warning: (near initialization for `fops') chardev.c:268: warning: excess elements in struct initializer chardev.c:268: warning: (near initialization for `fops') chardev.c:269: warning: excess elements in struct initializer chardev.c:269: warning: (near initialization for `fops') chardev.c:270: warning: excess elements in struct initializer chardev.c:270: warning: (near initialization for `fops') chardev.c:271: warning: excess elements in struct initializer chardev.c:271: warning: (near initialization for `fops') chardev.c:273: warning: excess elements in struct initializer chardev.c:273: warning: (near initialization for `fops') chardev.c:255: error: storage size of `fops' isn't known source code: static struct file_operations fops={ NULL, NULL, device_read, device_write, NULL, NULL, device_ioctl, NULL, device_open, NULL, device_release }; Bye |
What's the point of the NULLs? That's not valid C syntax.
|
You also need to declare the types for each var ...
|
Since file_operations has so many unused fields I usually choose to use the explicit syntax:
Code:
static struct file_operations fops = { Code:
#ifndef NULL bye |
Quote:
Code:
#undef NULL |
oh, well I didn't think NULL was a part of the C specification. However, it does not surprise me it is defined by default. And by ex-windows I figured he is a seasoned Windows programmer because of how much Windows uses NULL in it's api
|
"chardev.c 255:variable `fops' has initializer but incomplete type"
This error points out that you have not included "linux/fs.h" ! "gcc -c modulename.c" You cant compile a kernel module with gcc you need to write a makefile for it ! |
All times are GMT -5. The time now is 01:54 PM. |