LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Character device driver (https://www.linuxquestions.org/questions/linux-software-2/character-device-driver-399111/)

calsoft_pg 01-03-2006 12:17 PM

Character device driver
 
I have written a character device driver. In the ioctl function , i want to use a function called ext2_get_inode() which has been defined in the file /usr/src/linux-2.6.11/fs/ext2/inode.c. I am not able to use this function in my device driver.
Following is the code for my 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);
}
------------------------------------------------------------------
It is giving me a lot of warnings of function undefined when i use the make command.
But if i use insmod, it is giving me a lot of errors for the same files.
Can anyone help me as to how to use this function in that particular file???
Thank you.


All times are GMT -5. The time now is 12:32 PM.