Problem in writing a character Device driver ????
Hi friends,
This is swanand. Today i wrote a character device driver. In the ioctl function i wanted to use a function called : "ext2_get_inode", that has been defined in the directory "/usr/src/linux-2.6.11/fs/ext2/inode.c". But i am not able to use that function. CAN ANYONE PLEASE TELL ME THE WAY TO USE THE FUNCTIONS THAT HAVE BEEN DEFINED IN THE FILES WITH .C EXTENSION AND OUTSIDE THE INCLUDE DIRECTORY "include" in the source tree?????
Forwarding the code for my character device driver :
#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/fs.h>
#include<linux/sched.h>
#include<linux/file.h>
#include<linux/dcache.h>
#include<linux/buffer_head.h>
#include<linux/myfile.h>
//#include"/usr/src/linux-2.6.11/fs/ext2/inode.c"
#include<linux/ext2_fs.h>
static int major;
struct task_struct *o;
struct files_struct *o1;
struct file *f;
struct dentry *d;
struct inode *i;
struct ext2_inode *e;
struct buffer_head *bh1;
unsigned long t;
unsigned int fd,t1;
int my_open(struct inode *,struct file *);
int my_release(struct inode *,struct file *);
int my_ioctl(struct inode *,struct file *,unsigned int cmd,unsigned long arg);
struct file_operations my_fops = {
.open = my_open,
.release = my_release,
.ioctl = my_ioctl
};
int main(void);
int init_module(void);
void cleanup_module(void);
int init_module(void)
{
int major=register_chrdev(0,"fchar",&my_fops);
if(major>0)
{
printk(KERN_ALERT "\ndevice registered. The major number is %d. ",major);
}
else
{
printk(KERN_ALERT "device failed to registered");
return -1;
}
return 0;
}
void cleanup_module(void)
{
major=unregister_chrdev(major,"fchar");
if(major<0)
printk(KERN_ALERT "device failed to unregistered");
printk(KERN_ALERT "\ncleaned");
}
int my_open(struct inode *inode,struct file *filep)
{
printk(KERN_ALERT "yahooooooooooooooooooooooo");
return 0;
}
int my_release(struct inode *inode,struct file *filep)
{
printk(KERN_ALERT "byeeeeeeeeeeeeeeeeeeee");
return 0;
}
int my_ioctl(struct inode *inode,struct file *file,unsigned int cmd,unsigned long arg)
{
o=current;
o1=o->files;
fd=arg;
f=o1->fd[fd];
d=f->f_dentry;
i=d->d_inode;
t=i->i_ino;
e=ext2_get_inode(i->i_sb,t,&bh1);
t1=e->osd2.linux2.l_i_reserved2;
printk(KERN_ALERT "\nThe reserved number is %d.",t1);
return(5);
}
---------------------------------------------------------------:oops: