?
Solved

Linux Programming

Posted on 2003-03-20
3
Medium Priority
?
306 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

764 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