LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Device Driver Program's file operations error (https://www.linuxquestions.org/questions/programming-9/device-driver-program%27s-file-operations-error-218125/)

thirumalai 08-16-2004 12:38 AM

Device Driver Program's file operations error
 
Hi all,

now i m trying to writea simple device driver program..
in my first sample program, i m getting the following error....



error: variable `fo' has initializer but incomplete type
error: storage size of `fo' isn't known

plz anyone help me to solve this pbm


this is the pgm
===========
#define MODULE
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>


int dopen(struct inode * inode,struct file *file)
{
printk("dopen\n");
return 0;
}
struct file_operations fo={0,0,0,0,0,0,0,dopen,0,0};
int init_module() {
printk("init_module\n");
register_chrdev(251,"cde1",&fo);
return 0;
}
void cleanup_module() {
printk("cleanup_module\n");
unregister_chrdev(251,"cde1");
}


cppkid 08-16-2004 01:23 AM

Quote:

struct file_operations fo={0,0,0,0,0,0,0,dopen,0,0};
In this line of code you have declaired the 'fo' as structure file_operations. I don't know what is that structure file_operations. Is it a predefined structure or you defined it somewhere. But i have got a little experience about this error and it means that the structure file_operations is unkown. Check if you spelled it right or you have included the header file that gives the defination for this structure .... etc..

Wish you all the best.

cppkid 08-16-2004 01:45 AM

sorry i searched for it and found the defination of this structure in linux/fs.h and you have include that file. Now from my point of view there can be one of two problems.

1. You are giving and extra aurgument to the structure, means check for the number of the memebers of the structure and the number of the members you have initialized, are they same. Also try to give some other aurgument instead of 0's, Any dummy augument just to check, Coz while searching it, I read somwhere on search results by google that maybe you have assigned NULL to all the members, this can cause this error too.

2. open the file linux/fs.h and check for that structure and see the member list and order again.

Wish you all the best

thirumalai 08-16-2004 01:48 AM

Thank u for ur inormation...

But that structure is available in the <linux/fs.h>

i checked the spelling also ... no pbm on that.....

infamous41md 08-16-2004 02:36 AM

you need to #define __KERNEL__ before including any headers, or else the many kernel structure and defines won't be included.

thirumalai 08-16-2004 02:56 AM

Thanks a lot....

error is fixed after including the #define __KERNEL__ before including any header files....


All times are GMT -5. The time now is 12:28 AM.