LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   file_operations structure (https://www.linuxquestions.org/questions/programming-9/file_operations-structure-287191/)

mp4-10 02-07-2005 04:04 AM

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

itsme86 02-07-2005 09:03 AM

What's the point of the NULLs? That's not valid C syntax.

chrism01 02-07-2005 05:03 PM

You also need to declare the types for each var ...

AngryLlama 02-08-2005 01:32 AM

Since file_operations has so many unused fields I usually choose to use the explicit syntax:

Code:

static struct file_operations fops = {
        .read = vfd_read,
        .write = vfd_write,
        .open = vfd_open,
        .release = vfd_release,
        .ioctl = vfd_ioctl
};

Concidering you use NULL, I assume you are an ex-windows programmer. If you insist on keeping NULL then add a:
Code:

#ifndef NULL
#define NULL (0)
#endif

if you are using plain C then ((void*)0) is a safer define.

bye

deiussum 02-08-2005 08:26 AM

Quote:

Originally posted by AngryLlama

Concidering you use NULL, I assume you are an ex-windows programmer. If you insist on keeping NULL then add a:
Code:

#ifndef NULL
#define NULL (0)
#endif

if you are using plain C then ((void*)0) is a safer define.

bye

From linux/stddef.h on a Slackware 10 box.

Code:

#undef NULL
#if defined(__cplusplus)
#define NULL 0
#else
#define NULL ((void *)0)
#endif

I've found that #including any standard header like iostream, etc. will make it so that NULL is defined for you. Nothing "ex-windows" about it.

AngryLlama 02-08-2005 12:53 PM

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

Aquarius_Girl 10-28-2009 02:50 AM

"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.