Problem in Compiling Kernel Module

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

I am a Newbie in Kernel Programming and just now subscribed to this list. Writing my first kernel module and reading Alessandro?s book on Linux Device Driver.

When I compile my simple module with gcc, it throughs al bunch of errors.

As far as I think the errors are because the gcc could not find the defination of few of the structure used, like struct file, struct inode and struct file_operations etc. I have included the linux/fs.h file and have also define the required macros like MODULE and __KERNEL__, but still not able to compile it successfully.

For debugging, I ran the macro option (-E) of gcc to get the output of Macro, so that I could know what exactly is included in file before compilation. In the Macro output I could not find the definations of above mentioned structure, although they are defined in linux/fs.h and I have included that file in my source.

I am pasting the output of gcc below.

Also pasting the source of my module.

Please have a look at it and help me if you can.

In source I have left few of the functions like open, release etc, blank. I have just started writing it and will complete it once I get through this problem.

Details of my system:

Single Processor

Redhat Enterprise 3.1

Kernel: linux-2.4.21-4

Compiler : gcc 3.2.3.20

I have one more this to say, when I cteared the simple "Hello World" module and compiled it, it compiled without any problem, but when I tried to load that module in kernel, insmod command gave me versioning error. It said that you are trying to load the module against different kernel version. Well I know it can happen, but my question on this is, is it possible that the runnning kernel might be different from the kernel in source tree. I did not downloaded the source, It?s the default source which comes with installation.

Anyway, please take a look at the errors and source to help me out.

 

************************************************************************************************

Output of gcc

************************************************************************************************

main.c:27: warning: `struct file' declared inside parameter list

main.c:27: warning: its scope is only this definition or declaration, which is probably not what you want

main.c:27: warning: `struct inode' declared inside parameter list

main.c:28: warning: `struct file' declared inside parameter list

main.c:29: warning: `struct file' declared inside parameter list

main.c:30: warning: `struct file' declared inside parameter list

main.c:31: warning: `struct file' declared inside parameter list

main.c:31: warning: `struct inode' declared inside parameter list

main.c: In function `fifo_init_module':

main.c:71: invalid use of undefined type `struct file_operations'

main.c:72: invalid use of undefined type `struct file_operations'

main.c:73: invalid use of undefined type `struct file_operations'

main.c:73: `write' undeclared (first use in this function)

main.c:73: (Each undeclared identifier is reported only once

main.c:73: for each function it appears in.)

main.c:74: invalid use of undefined type `struct file_operations'

main.c:75: invalid use of undefined type `struct file_operations'

main.c:77: warning: implicit declaration of function `register_chrdev'

main.c:80: warning: implicit declaration of function `printk'

main.c:80: `KERN_EMERG' undeclared (first use in this function)

main.c:80: syntax error before string constant

main.c: In function `fifo_cleanup_module':

main.c:101: warning: implicit declaration of function `unregister_chrdev'

main.c:101: `fifo_f_ops' has an incomplete type

main.c: At top level:

main.c:122: warning: `struct file' declared inside parameter list

main.c:122: warning: `struct inode' declared inside parameter list

main.c:122: conflicting types for `fifo_open'

main.c:27: previous declaration of `fifo_open'

main.c:140: warning: `struct file' declared inside parameter list

main.c:140: conflicting types for `fifo_read'

main.c:28: previous declaration of `fifo_read'

main.c:160: warning: `struct file' declared inside parameter list

main.c:160: conflicting types for `fifo_write'

main.c:29: previous declaration of `fifo_write'

main.c:175: warning: `struct file' declared inside parameter list

main.c:175: conflicting types for `fifo_llseek'

main.c:30: previous declaration of `fifo_llseek'

main.c:194: warning: `struct file' declared inside parameter list

main.c:194: warning: `struct inode' declared inside parameter list

main.c:194: conflicting types for `fifo_release'

main.c:31: previous declaration of `fifo_release'

main.c:203: warning: type defaults to `int' in declaration of `module_init'

main.c:203: warning: parameter names (without types) in function declaration

main.c:203: warning: data definition has no type or storage class

main.c:204: warning: type defaults to `int' in declaration of `module_exit'

main.c:204: warning: parameter names (without types) in function declaration

main.c:204: warning: data definition has no type or storage class

main.c:44: storage size of `fifo_f_ops' isn't known

 

************************************************************************************************

Main.c

************************************************************************************************

/*Simple FIFO Module*/

#define MODULE

#define __KERNEL__

#include<linux/config.h>

#ifdef CONFIG_SMP

#define __SMP__

#endif

#include<linux/fs.h>

#include<linux/kernel.h>

#include<linux/module.h>

#include<linux/wrapper.h>

#include<linux/types.h>

/*#include<linux/init.h>*/

/*#include<linux/kernel.h>*/

#define MAJOR_NUM 0

#define DRIVER_NAME "my_fifo"

/*========================================

Function Declerations

=========================================*/

int fifo_init_module(void);

void fifo_cleanup_module(void);

int fifo_open(struct inode* fifo_inode_p, struct file* fifo_file_p);

int fifo_read(struct file* fifo_file_p, char* fifo_read_buffer, int fifo_num_char, loff_t* fifo_file_position_p);

size_t fifo_write(struct file* fifo_file_p, char* fifo_write_buffer, size_t fifo_num_char, loff_t* fifo_file_position_p);

int fifo_llseek(struct file* fifo_file_p, loff_t fifo_file_position);

int fifo_release(struct inode* fifo_inode_p, struct file* fifo_file_p);

/*========================================

Global Declerations

=========================================*/

/*struct file_operations fifo_f_ops = {

llseek: fifo_lseek,

read: fifo_read,

write: fifo_write,

open: fifo_open

};*/

struct file_operations fifo_f_ops;

/*this flag will be used for tracking and reverting back

in initialization phase, in case some thing goes wrong in initilizing module*/

int fifo_init_flag = 0;

int fifo_major_num = MAJOR_NUM;

MODULE_PARM(fifo_major_num, "i");

/*========================================

Functions Defination

=========================================*/

/*====================================================================

Name: fifo_init_module()

=====================================================================*/

int fifo_init_module(void){

int retval = 0;

fifo_f_ops.llseek = fifo_llseek;

fifo_f_ops.read = fifo_read;

fifo_f_ops.write = write;

fifo_f_ops.open = fifo_open;

fifo_f_ops.release = fifo_release;

retval = register_chrdev(fifo_major_num, DRIVER_NAME, &fifo_f_ops);

if (retval < 0){

printk(KERN_EMERG "fifo driver could not get the free major number.\n");

return retval;

}

fifo_major_num = fifo_major_num?fifo_major_num:retval;

fifo_init_flag = 1;

}

/*====================================================================

Name: fifo_clear_module()

=====================================================================*/

void fifo_cleanup_module(void){

switch(fifo_init_flag){

case 1:

unregister_chrdev(DRIVER_NAME, fifo_f_ops);

break;

};

}

/*====================================================================

Name: fifo_open()

=====================================================================*/

int fifo_open(struct inode* fifo_inode_p, struct file* fifo_file_p){

}

 

/*====================================================================

Name: fifo_read()

=====================================================================*/

int fifo_read(struct file* fifo_file_p, char* fifo_read_buffer, int fifo_num_char, loff_t* fifo_file_position_p){

}

 

 

/*====================================================================

Name: fifo_write()

=====================================================================*/

size_t fifo_write(struct file* fifo_file_p, char* fifo_write_buffer, size_t fifo_num_char, loff_t* fifo_file_position_p){

}

 

/*====================================================================

Name: fifo_lseek()

=====================================================================*/

int fifo_llseek(struct file* fifo_file_p, loff_t fifo_file_position){

}

 

/*====================================================================

Name: fifo_release()

=====================================================================*/

int fifo_release(struct inode* fifo_inode_p, struct file* fifo_file_p){

}

/*====================================================================

Explicitly mentioning the initialization and cleanup function of this

driver module.

=====================================================================*/

module_init(fifo_init_module);

module_exit(fifo_cleanup_module);

 

Regards,

Gaurav


Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux