error: variable ‘fops’ has initializer but incomplete type
Dear All,
the source code and the error file attached here. please remove the error. Note: the important error is line no 69. as shown in the error file. so how to solve that error. Source code: #define MODULE #include<linux/kernel.h> #include<linux/module.h> #include<linux/fs.h> #define SUCCESS 0 #define DEVICE_NAME "chardev" /* Dev name as it appears in /proc/devices */ #define BUF_LEN 80 /* Max length of the message from the device */ /* * Global variables are declared as static, so are global within the file. */ static int Major; /* Major number assigned to our device driver */ static int Device_Open = 0; /* Is device open? * Used to prevent multiple access to device */ static char msg[BUF_LEN]; /* The msg the device will give when asked */ static char *msg_Ptr; /* struct file_operations fops = { read: device_read, write: device_write, open: device_open, release: device_release }; */ /* * Called when a process tries to open the device file, like * "cat /dev/mycharfile" */ static int device_open(struct inode *inode, struct file *file) { /* static int counter = 0; if (Device_Open) return -EBUSY; Device_Open++; sprintf(msg, "I already told you %d times Hello world!\n", counter++); msg_Ptr = msg; try_module_get(THIS_MODULE); return SUCCESS;*/ printk("In device open function \n"); } /* * Called when a process closes the device file. */ static int device_release(struct inode *inode, struct file *file) { // Device_Open--; /* We're now ready for our next caller */ /* * Decrement the usage count, or else once you opened the file, you'll * never get get rid of the module. */ // module_put(THIS_MODULE); // return 0; printk("IN device release function \n"); } static struct file_operations fops = { .open = device_open, .release = device_release }; int init_module(void) { Major = register_chrdev(0, DEVICE_NAME, &fops); if (Major < 0) { printk("Registering char device failed with %d\n", Major); return Major; } printk("I was assigned major number %d. To talk to\n", Major); return SUCCESS; } /* * This function is called when the module is unloaded */ void cleanup_module(void) { int ret = unregister_chrdev(Major, DEVICE_NAME); if (ret < 0) printk("Error in unregister_chrdev: %d\n", ret); } The error file. [root@localhost check]# gcc -c -O2 char.c char.c:35: warning: ‘struct file’ declared inside parameter list char.c:35: warning: its scope is only this definition or declaration, which is probably not what you want char.c:35: warning: ‘struct inode’ declared inside parameter list char.c:54: warning: ‘struct file’ declared inside parameter list char.c:54: warning: ‘struct inode’ declared inside parameter list char.c:69: error: variable ‘fops’ has initializer but incomplete type char.c:70: error: unknown field ‘open’ specified in initializer char.c:70: warning: excess elements in struct initializer char.c:70: warning: (near initialization for ‘fops’) char.c:71: error: unknown field ‘release’ specified in initializer char.c:72: warning: excess elements in struct initializer char.c:72: warning: (near initialization for ‘fops’) [root@localhost check]# please reply me how to solve the error. Thank & Regards, Rajkumar Halle |
I'd say your compiler doesn't like that initialization style, try this instead (don't forget to remove the /* */ you have surrounding it):
Code:
struct file_operations fops = { |
All times are GMT -5. The time now is 12:52 AM. |