LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 01-03-2006, 12:17 PM   #1
calsoft_pg
LQ Newbie
 
Registered: Aug 2005
Posts: 13

Rep: Reputation: 0
Question 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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
device driver jful99 Programming 6 10-09-2005 12:34 AM
device driver carthyc Linux - Newbie 1 07-07-2005 07:23 AM
Character Device kernel(2.4.18) - module problem shibdas Programming 2 11-11-2004 03:52 AM
How to change character device file name? taphos Linux - General 2 03-28-2004 08:12 AM
device driver yanw Linux - Hardware 1 01-23-2003 09:00 AM


All times are GMT -5. The time now is 03:30 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration