LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-22-2008, 02:04 AM   #1
rajkumar_halle
LQ Newbie
 
Registered: Aug 2008
Posts: 2

Rep: Reputation: 0
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
 
Old 08-24-2008, 08:57 AM   #2
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,114
Blog Entries: 2

Rep: Reputation: 112Reputation: 112
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 = {
  .read = device_read,
  .write = device_write,
  .open = device_open,
  .release = device_release
};
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error: variable ‘scull_fops’ has initializer but incomplete type rajkumar_halle Programming 1 08-19-2008 12:51 AM
error: array type has incomplete element type duduarbel Programming 8 05-27-2008 12:25 PM
error :variable fops has initializer but incomplete type in compile device driver saffari62 Programming 1 04-06-2008 01:53 PM


All times are GMT -5. The time now is 08:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration