Find the answer to your Linux question:
Results 1 to 4 of 4
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2006
    Posts
    3

    Exclamation 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);
    }
    ---------------------------------------------------------------

  2. #2
    Just Joined!
    Join Date
    Jan 2006
    Location
    India
    Posts
    52
    Hi,

    You can make sure that the kernel function (ext2_get_inode) is exported or not.

    You can check this by seeing "kallsym" or "ksyms" in /proc.
    #cat kallsyms | grep 'ext2_get_inode'

    And read the man pages for 'nm' command to interpret the out put of kallsyms.

  3. #3
    Just Joined!
    Join Date
    Feb 2005
    Location
    Logan, Utah
    Posts
    10
    Hi,

    I am working on a character driver as well. I used hte mknod function to create a device node but am not able to open it in the dev directory using cat /dev/devicename.

    Could you please tell me what I am doing wrong?

  4. #4
    Just Joined!
    Join Date
    Jan 2006
    Location
    India
    Posts
    52
    Hi,

    If you have written the driver for your device file ( /dev/'yourdevice-name' ) Then depending on your implementaion of fileopertaion funtions in device driver you will expect the o/p.

    But if you have not write any drivers to the device file in /dev/ directory and reading that file will result in invalid operations.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •