Linux Programming

have anyone written a character device driver?
when i compile its giving me an error saying the structure for file_opertions is not intialized..
the exact error is given below
can anyone suggest a solution...thanx


chardev2.c:47: warning: `struct file' declared inside parameter list
chardev2.c:47: warning: its scope is only this definition or declaration, which is probably not what you want
chardev2.c:47: warning: `struct inode' declared inside parameter list
chardev2.c: In function `device_open':
chardev2.c:57: dereferencing pointer to incomplete type
chardev2.c:57: dereferencing pointer to incomplete type
chardev2.c: At top level:
chardev2.c:108: warning: `struct file' declared inside parameter list
chardev2.c:108: warning: `struct inode' declared inside parameter list
chardev2.c:128: warning: `struct file' declared inside parameter list
chardev2.c:128: warning: `struct inode' declared inside parameter list
chardev2.c:170: warning: `struct file' declared inside parameter list
chardev2.c:170: warning: `struct inode' declared inside parameter list
chardev2.c:192: variable `Fops' has initializer but incomplete type
chardev2.c:193: warning: excess elements in struct initializer
chardev2.c:193: warning: (near initialization for `Fops')
chardev2.c:194: warning: excess elements in struct initializer
chardev2.c:194: warning: (near initialization for `Fops')
chardev2.c:195: warning: excess elements in struct initializer
chardev2.c:195: warning: (near initialization for `Fops')
chardev2.c:196: warning: excess elements in struct initializer
chardev2.c:196: warning: (near initialization for `Fops')
chardev2.c:197: warning: excess elements in struct initializer
chardev2.c:197: warning: (near initialization for `Fops')
chardev2.c:198: warning: excess elements in struct initializer
chardev2.c:198: warning: (near initialization for `Fops')
chardev2.c:199: warning: excess elements in struct initializer
chardev2.c:199: warning: (near initialization for `Fops')
chardev2.c:200: warning: excess elements in struct initializer
chardev2.c:200: warning: (near initialization for `Fops')
chardev2.c:202: warning: excess elements in struct initializer
chardev2.c:202: warning: (near initialization for `Fops')
chardev2.c:192: storage size of `Fops' isn't known
LVL 1
veerunsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bryanhCommented:
This is actually not a device driver question -- it's a C question.

You did not intend for Line 47 to declare the data type "struct file", so the warning that Line 47 did just that tells you you have a problem.  What is supposed to declare "struct file" is a statement in a .h file that you include prior to Line 47.  In particular, Linux's 'fs.h' interface header file declares it.  It also declares all those other data structures that have the same problem in your program.

#include <linux/fs.h>, assuming a proper compilation environment, should solve this problem.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
veerunsAuthor Commented:
thanx a lot
i figured that out..it was a problem in my Makefile..now i have different problem,i wrote a character dvice driver,
it compiles,i did a mknod,everythig works fine,the module is initialized,but when i try to open the device sat cat /dev/< name of device> it says invalid argument,and the open routine is not initiazed at all..i am stuck now
thanx a lot anyways
0
dnatarajCommented:

Hey,
 PLZ check below to make the thing works for your program to get fixed.
Have nice time

eg: A simple module

#define MODULE
#include <linux/module.h>

int init_module (void) /* Loads a module in the kernel */
{
printk("Hello kernel n");
return 0;
}

void cleanup_module(void) /* Removes module from kernel */
{
printk("GoodBye Kerneln");
}

Compiling the module

# gcc -c hello.c
# insmod hello.o

The output is

Hello kernel

# rmmod hello.o

GoodBye Kernel


How init_module works?


init_module loads the relocated module image into kernel space and runs
the module's init function.
The module image begins with a module structure and is followed by code
and data as appropriate.

The module structure is defined as follows:

struct module
{
unsigned long size_of_struct;
struct module *next;
const char *name;
unsigned long size;
long usecount;
unsigned long flags;
unsigned int nsyms;
unsigned int ndeps;
struct module_symbol *syms;
struct module_ref *deps;
struct module_ref *refs;
int (*init)(void);
void (*cleanup)(void);
const struct exception_table_entry *ex_table_start;
const struct exception_table_entry *ex_table_end;
#ifdef __alpha__
unsigned long gp;
#endif
};


All of the pointer fields, with the exception of next and refs, are
expected to point within the module body and be initialized as appropriate
for kernel space, i.e. relocated with the rest of the module.

Return Values

On success, zero is returned. On error, -1 is returned
and errno is set appropriately.

Errors

EPERM The user is not the superuser.

ENOENT No module by that name exists.

EINVAL Some image slot filled in incorrectly, image->name
does not correspond to the original module name,
some image->deps entry does not correspond to a
loaded module, or some other similar inconsistency.

EBUSY The module's initialization routine failed.

EFAULT name or image is outside the program's accessible
address space.


How cleanup_module works?


cleanup_module attempts to remove an unused loadable module entry. If
name is NULL, all unused modules marked auto clean will be removed.
Return Values

On success, zero is returned. On error, -1 is returned and errno is
set appropriately.

Errors

EPERM The user is not the superuser.

ENOENT No module by that name exists.

EINVAL name was the empty string.

EBUSY The module is in use.

EFAULT name is outside the program's accessible address
space.

This simple module is called skull, short for Simple Kernel Utility For
Loading Localities.

General flags used for compiling any driver are

-D__KERNEL__ _DMODULE -O -Wall -I$(INCLUDEDIR)

Note: The INCLUDEDIR should contain the header files of the kernel source.

Module code has to be recompiled for each version of the kernel that it
will be linked to. Each module defines a symbol called kernel_version
which is defined in <linux/module.h>. In case of a version mismatch, use
the insmod -f (force) option to load the module.


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.