Hi All,

I started learning device drivers and writing and working out few simple drivers with sample application programs.

I learning from LKMP(Linux kernel Module Programming guide)

1) /proc/modules

I read that /proc/modules contains the list of modules which are
currently loaded in the kernel.

In that the third parameter tells that number of process currently
using that driver.

So i tried to check it through sample driver loaded into kernel and
wrote sample application programs to access the device file
simulataneously so that i would see the thrid parameter it will
increase.


sample1.c
--------------------
#include<stdio.h>
int main()
{

int fd;
printf("Pgrogram starts \n");
fd= open("/dev/myown","r");
while(1) {
write(fd,"Manikadan",1,0);
}
fclose(fd);
}

I had the same copy of the program in another file name sample2.c

Driver code
-----------------
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>


static int sample_read(struct file *file,const char* data,int len,loff_t *off);

static int sample_write(struct file *file,const char* data,int len,loff_t *off);

static struct file_operations rwstruct={
open : sample_read,
write : sample_write
};

static int major;

int init_module(void)
{
printk(KERN_ALERT "inside init_module");
major = register_chrdev(0,"myown",&rwstruct);
printk(KERN_ALERT "The major umber assigned is %d",major);
return 0;
}

void cleanup_module(void)
{
int cleanup = unregister_chrdev(major,"file");
printk(KERN_ALERT "The major umber cleaned up is %d",cleanup);

}

static int sample_read(struct file *file,const char* data,int len,loff_t *off)
{
printk(KERN_ALERT "The message is %s",data);
return 0;
}

static int sample_write(struct file *file,const char* data,int len,loff_t *off)
{
char buff[4];
printk(KERN_ALERT "Inside sample_write ");
//copy_from_user(&buff,data,sizeof(buff));
printk(KERN_ALERT "The message is %s %s",data,buff);
return 0;
}

I compiled the above driver code and loaded with insmod then created a
fle under /dev as 'myown' with the major number displayed in
/proc/devices.


Then i compiled both the programs sample1.c & sample2.c and had two
xterms and ran the two ./a.outs simultaneously

#insmod samplerw.ko
# lsmod | grep sample
samplerw 6276 0

I ran the two ./a.out in two different sessions. I could see the
printk statements in sample_write function being pritned in
/var/log/messages file, but the thrid parameter doesnot get increases.

#cat /proc/modules | grep sample
samplerw 6276 0 - Live 0xf8b0a000

If you could throw out some lights on this issue that would be helpful.

- is the way i thought is correct ?
- Will the third parameter is really meant to display the no of
process that the driver is beinng used by ?


I have been stuck up here ...

Anyones help would be appreciable.

Thanks,
Mani