EmbLogic's Blog

problem in scull_read()

int scull_read(struct file *filp, char *buff, size_t count, loff_t *fpos)
{
scull_dev *dev;

printk(“%s \n”,__func__);

dev=(scull_dev *)filp->private_data;

struct scull_qset *dptr;         // Pointer to the beginning of the data
int quantum = dev->quantum;      // Size of a quantum
int qset = dev->qset;            // Number of quantums
int itemsize = quantum * qset;   // number of bytes in the listitem
int item, s_pos, q_pos, rest;
ssize_t retval = 0;

char read_buff[100];
int pos=0;
int temp=count/quantum;

if(*fpos >= dev->size){
goto out;
}

if(*fpos+count > dev->size){
count = dev->size – *fpos;
}

item = (long) *fpos / itemsize;
rest = (long) *fpos % itemsize;
s_pos = rest / quantum;
q_pos = rest % quantum;
dptr = scull_follow(dev,item);

if(dptr == NULL || !dptr->data || !dptr->data[s_pos]){
goto out;
}

while(temp!=0)
{
read_buff[pos]=*dptr->data[s_pos]+q_pos;
printk(“the address of quantums is %x\n”,dptr->data[s_pos]);
if(q_pos <= quantum)
{
pos++;
q_pos++;
}

if(q_pos > quantum)
{
s_pos++;
q_pos=0;
pos–;
temp–;
}
}

if(count > quantum – q_pos)
{
count = quantum – q_pos;
}

if(copy_to_user(buff, read_buff, count))
{
retval = -EFAULT;
goto out;
}
printk(“the data in the buff is %s\n”,read_buff);
*fpos += count;
retval = count;
out:
return retval;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>