1 /*IN THIS READ OPERATON...WE HAVE TO READ CHARACTERS FROM THE DEVICE & WRITE INTO APPL ICATION*/
2 #include"header.h"
3 #include"dec.h"
4 ssize_t scullread(struct file* filep,char* buff,size_t size,loff_t *loff)//THERE ARE 4 PARAEMTERS FOR THIS FUNCTION//1st is struct file pointer//2nd is buff from which data is to taken & written into device memory//3rd one is size of data which is written fr om application//loff_t type parameter will contains the no. of characters succesfully written..//
5 {
6 struct Scullqset *lscullqset=NULL;
7 struct Sculldev *lsculldev=NULL;
8 int quantum_size=8,ret=0,noctr=size,nocsr=0,i=0;
9 printk(KERN_INFO"BEGIN %s func",__func__);
10 lsculldev=filep->private_data;//take address of device from private_data..//
11 printk(KERN_INFO"LSCULlDEV=%p\n",lsculldev);
12 lscullqset=lsculldev->scullqset;//take address of scullqset//
13 if(!lscullqset)
14 printk(KERN_INFO"SCULQSET IN READ IN NOT FOUND\n");
15 printk(KERN_INFO"LSCULLQSET=%p\n",lscullqset);
16 while(noctr)
17 {
18 if(noctr>quantum_size)//untill numbeer of characters to read is more than size of quan tum i.e. 8.....then read 8 characters into lsculldev+data[i]....//which is the memory of device...//
19 //
20 noctr=quantum_size;//every time untill when no. of characters are more than 8 then put value 8 characters from lscullqset->data[i]....means read 8 characters everytime ..// when no. of characters to read are less then than 8....then read...those number of cha racters from device & put into application//
21 ret=copy_to_user(buff+nocsr,lscullqset->data[i],noctr);//COPY_TO_USER FUNCTION IS USED TO READ CHARACTERS FROM DEVICE & WRITE INTO APPLICATION//
22 printk(KERN_INFO"LSCULLQSET->DATA[%d]=%s\n",i,(char*)lscullqset->data[i]);//TO PRINT T HE CHJARACTERS ....(char*)type typecasting is used..//
23 i++;//i is representing the quantum number..//
24 nocsr=nocsr+noctr-ret;//number of characters succesfully read are 0 already ...so add number of characters read just now...means (noctr)...//ret representing the number of characters which could not be read from the register due to some region//
25 noctr=size-nocsr;//after reading some of the characters /...now number of characters t o read is some less characters ,leaving those characters which are read just now//
26 if(i==8 && lscullqset->next != NULL)
27 {
28 lscullqset=lscullqset->next;//move scullqset to next & next///untill whole the data is not read//
29 i=0;//after reading 8 quantums from 0 to 7 ..//again read from 0th quantum of next scu llqset//...& then bagain read from next scullqset again//