- 论坛徽章:
- 0
|
292 ssize_t scull_read(struct file *filp, char __user *buf, size_t count,
293 loff_t *f_pos)
294 {
295 struct scull_dev *dev = filp->private_data;
296 struct scull_qset *dptr; /* the first listitem */
297 int quantum = dev->quantum, qset = dev->qset;
298 int itemsize = quantum * qset; /* how many bytes in the listitem */
299 int item, s_pos, q_pos, rest;
300 ssize_t retval = 0;
301
302 if (down_interruptible(&dev->sem))
303 return -ERESTARTSYS;
304 if (*f_pos >= dev->size)
305 goto out;
306 if (*f_pos + count > dev->size)
307 count = dev->size - *f_pos;
308
309 /* find listitem, qset index, and offset in the quantum */
310 item = (long)*f_pos / itemsize;
311 rest = (long)*f_pos % itemsize;
312 s_pos = rest / quantum; q_pos = rest % quantum;
313
314 /* follow the list up to the right position (defined elsewhere) */
315 dptr = scull_follow(dev, item);
316
317 if (dptr == NULL || !dptr->data || ! dptr->data[s_pos])
318 goto out; /* don't fill holes */
319
320 /* read only up to the end of this quantum */
321 if (count > quantum - q_pos)
322 count = quantum - q_pos;
323
324 if (copy_to_user(buf, dptr->data[s_pos] + q_pos, count)) {
325 retval = -EFAULT;
326 goto out;
327 }
328 *f_pos += count;
329 retval = count;
330
331 out:
332 up(&dev->sem);
333 return retval;
334 }
335 |
其中的line:310---line:316的那几个变量是什么意思?看着有点晕,劳驾哪位给讲讲,先谢了 |
|