View Single Post
 
Old February 12th, 2007, 12:50 PM
devr.jana devr.jana is offline
Registered User
 
Join Date: Feb 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am new to Linux Kernel Programming. Trying to build a basic char driver (register, open, release, unregister). When I compile the source I get the following errors, (even on kernel - 2.4). I try to compile the char drivers provided with the source and even get errors and warnings with them, here is the error dump,

prcdd.c:6:1: warning: "__KERNEL__" redefined
prcdd.c:1:1: warning: this is the location of the previous definition
prcdd.c:7:1: warning: "MODULE" redefined
prcdd.c:1:1: warning: this is the location of the previous definition
In file included from /usr/include/linux/fs.h:23,
from prcdd.c:11:
/usr/include/linux/string.h:8:2: warning: #warning Using kernel header in userland!
prcdd.c:12:25: asm/uaccess.h: No such file or directory
prcdd.c:17: warning: `struct file' declared inside parameter list
prcdd.c:17: warning: its scope is only this definition or declaration, which is probably not what you want
prcdd.c:17: warning: `struct inode' declared inside parameter list
prcdd.c:18: warning: `struct file' declared inside parameter list
prcdd.c:18: warning: `struct inode' declared inside parameter list
prcdd.c:26: variable `fops' has initializer but incomplete type
prcdd.c:27: unknown field `owner' specified in initializer
prcdd.c:27: warning: excess elements in struct initializer
prcdd.c:27: warning: (near initialization for `fops')
prcdd.c:28: unknown field `open' specified in initializer
prcdd.c:28: warning: excess elements in struct initializer
prcdd.c:28: warning: (near initialization for `fops')
prcdd.c:29: unknown field `release' specified in initializer
prcdd.c:29: warning: excess elements in struct initializer
prcdd.c:29: warning: (near initialization for `fops')
prcdd.c: In function `prcdd_init':
prcdd.c:34: warning: implicit declaration of function `register_chrdev'
prcdd.c:38: warning: implicit declaration of function `printk'
prcdd.c: In function `prcdd_exit':
prcdd.c:48: warning: implicit declaration of function `unregister_chrdev'
prcdd.c: At top level:
prcdd.c:55: warning: `struct file' declared inside parameter list
prcdd.c:55: warning: `struct inode' declared inside parameter list
prcdd.c:56: conflicting types for `prcdd_open'
prcdd.c:17: previous declaration of `prcdd_open'
prcdd.c: In function `prcdd_open':
prcdd.c:59: `EBUSY' undeclared (first use in this function)
prcdd.c:59: (Each undeclared identifier is reported only once
prcdd.c:59: for each function it appears in.)
prcdd.c:63: warning: implicit declaration of function `atomic_inc'
prcdd.c:63: union has no member named `usecount'
prcdd.c: At top level:
prcdd.c:67: warning: `struct file' declared inside parameter list
prcdd.c:67: warning: `struct inode' declared inside parameter list
prcdd.c:68: conflicting types for `prcdd_release'
prcdd.c:18: previous declaration of `prcdd_release'
prcdd.c: In function `prcdd_release':
prcdd.c:71: warning: implicit declaration of function `atomic_dec'
prcdd.c:71: union has no member named `usecount'
prcdd.c: At top level:
prcdd.c:26: storage size of `fops' isn't known

This is the source code,

#if defined(CONFIG_MODVERSIONS) && ! defined(MODVERSIONS)
#include <linux/modversions.h>
#define MODVERSIONS
#endif

#define _KERNEL_
#define MODULE

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <asm/uaccess.h>

//static int module_init(void);
//static void module_exit(void);
static int prcdd_open(struct inode *,struct file *);
static int prcdd_release(struct inode *,struct file *);

#define SUCCESS 0
#define DEVICE_NAME "prcdd"

static int Major;
static int Device_open = 0;

static struct file_operations fops = {
.owner = THIS_MODULE,
.open = prcdd_open,
.release = prcdd_release,
};

static int prcdd_init(void)
{
Major = register_chrdev(0,DEVICE_NAME,&fops);
if (Major < 0)
{
printk("Registering the character device failed with %d \n",Major);
return Major;
}

printk("<1>The assigned major number is %d \n",Major);
return 0;
}

static void prcdd_exit(void)
{
int ret = unregister_chrdev(Major,DEVICE_NAME);
if (ret < 0)
{
printk("Error in unregister_chrdev: %d \n",ret);
}
}

static int prcdd_open(struct inode *inode, struct file *file)
{
if (Device_open)
{
return -EBUSY;
}
Device_open++;

MOD_INC_USE_COUNT;
return SUCCESS;
}

static int prcdd_release(struct inode *inode, struct file *file)
{
Device_open--;

MOD_DEC_USE_COUNT;
return 0;
}

module_init(prcdd_init);
module_exit(prcdd_exit);

Any pointers on how to proceed from here?