Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Linux Programming

Posted on 2003-03-20
3
Medium Priority
?
314 Views
Last Modified: 2010-04-21
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
0
Comment
Question by:veeruns
3 Comments
 
LVL 5

Accepted Solution

by:
bryanh earned 375 total points
ID: 8175813
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
 
LVL 1

Author Comment

by:veeruns
ID: 8182126
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
 
LVL 1

Expert Comment

by:dnataraj
ID: 8448890

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question