differentiating char and blk devices

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 Hi,

   I am finding difficulty in differentiating between a character and a 
blk device. I am intercepting sys_read and I have my own sys_read which 
has to get executed when the read is request is for a file i.e on hard 
disk. Otherwise it should execute the normal sys_read.


  I am executing this on a vmware which gets the keystrokes and mouse 
input from the ptty device which also has a major number 3. So when I 
install this module for every key stroke or mouse movement I make the if 
statement evaluates to true.

 So this is the code I am executing :



#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/sched.h>
#include <linux/kdev_t.h>
#include <asm/unistd.h>
#include <linux/config.h>
#include <linux/file.h>

extern void* sys_call_table[];


asmlinkage int (*orig_read)(int,char*, int);
asmlinkage int my_read(int fd, char *buffer, int count)
{
  struct file* file;
  struct inode* inode = NULL;
  kdev_t device;
  int major, minor;

  file = fget(fd);
  inode = file->f_dentry->d_inode;
 device = inode->i_dev;

  major = MAJOR(device);
  minor = MINOR(device);


   if(inode && major == 3)
    {
      do my stuff
    }
  else
   {
	  return (orig_read(fd,buffer,count));
	}

}

int init_module()
{


  orig_read = sys_call_table[__NR_read];
  sys_call_table[__NR_read] = my_read;
  return 0;
}



void cleanup_module()
{
  sys_call_table[__NR_read] = orig_read;
  if(sys_call_table[__NR_read] == sys_read)
    printk("Everything is OK . Success\n");
}



  I thought character devices had their inode values to be NULL. What am I 
missing over here. OR is there another way of doing the same thing given a 
fd u can get the device on which the file exists.

  thanks,
raghu

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux