All of lore.kernel.org
 help / color / mirror / Atom feed
* Scull Driver - Read
@ 2015-03-15  4:47 sahil aggarwal
  2015-03-20  6:16 ` Pranay Srivastava
  0 siblings, 1 reply; 8+ messages in thread
From: sahil aggarwal @ 2015-03-15  4:47 UTC (permalink / raw)
  To: kernelnewbies

hi all,

Going through scull driver code, i see read function reads only till
end of 1 quantum, so do kernel call read multiple times if count from
q_pos exceeds quantum size limit.?


Ref: ldd3.

if(count > quantum - q_pos)
count = quantum - q_pos;
if(copy_to_user(buf, dptr->data[s_pos] + q_pos,count)){
retval = -EFAULT;
goto out;
}
*f_pos += count;
retval = count;

Thanks
Regards

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Scull Driver - Read
  2015-03-15  4:47 Scull Driver - Read sahil aggarwal
@ 2015-03-20  6:16 ` Pranay Srivastava
  2015-03-20  7:06   ` sahil aggarwal
  0 siblings, 1 reply; 8+ messages in thread
From: Pranay Srivastava @ 2015-03-20  6:16 UTC (permalink / raw)
  To: kernelnewbies

Hi Sahil

On Sun, Mar 15, 2015 at 10:17 AM, sahil aggarwal <sahil.agg15@gmail.com> wrote:
> hi all,
>
> Going through scull driver code, i see read function reads only till
> end of 1 quantum, so do kernel call read multiple times if count from
> q_pos exceeds quantum size limit.?
>
>
> Ref: ldd3.
>
> if(count > quantum - q_pos)
> count = quantum - q_pos;
> if(copy_to_user(buf, dptr->data[s_pos] + q_pos,count)){
> retval = -EFAULT;
> goto out;
> }

If you are not using the default read/write routines, then its up to
you to code that.

Kernel doesn't do multiple read calls. It'll do only what you asked it
for no more but it can do less. For example, a file is say 100 KiB and
you are reading say 4KiB in a loop when do you stop?

Simply put it's the user space application which is doing the looping
and repeatedly doing read calls because it assumes that file isn't
finished.

So again when do you stop reading from the file, without knowing size
of the file.?

> *f_pos += count;
> retval = count;
>
> Thanks
> Regards
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



-- 
        ---P.K.S

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Scull Driver - Read
  2015-03-20  6:16 ` Pranay Srivastava
@ 2015-03-20  7:06   ` sahil aggarwal
  2015-03-20 12:42     ` sahil aggarwal
  0 siblings, 1 reply; 8+ messages in thread
From: sahil aggarwal @ 2015-03-20  7:06 UTC (permalink / raw)
  To: kernelnewbies

Hi Pranay

Well explained.

Thank you.

On 20 March 2015 at 11:46, Pranay Srivastava <pranjas@gmail.com> wrote:
> Hi Sahil
>
> On Sun, Mar 15, 2015 at 10:17 AM, sahil aggarwal <sahil.agg15@gmail.com> wrote:
>> hi all,
>>
>> Going through scull driver code, i see read function reads only till
>> end of 1 quantum, so do kernel call read multiple times if count from
>> q_pos exceeds quantum size limit.?
>>
>>
>> Ref: ldd3.
>>
>> if(count > quantum - q_pos)
>> count = quantum - q_pos;
>> if(copy_to_user(buf, dptr->data[s_pos] + q_pos,count)){
>> retval = -EFAULT;
>> goto out;
>> }
>
> If you are not using the default read/write routines, then its up to
> you to code that.
>
> Kernel doesn't do multiple read calls. It'll do only what you asked it
> for no more but it can do less. For example, a file is say 100 KiB and
> you are reading say 4KiB in a loop when do you stop?
>
> Simply put it's the user space application which is doing the looping
> and repeatedly doing read calls because it assumes that file isn't
> finished.
>
> So again when do you stop reading from the file, without knowing size
> of the file.?
>
>> *f_pos += count;
>> retval = count;
>>
>> Thanks
>> Regards
>>
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies at kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
>
> --
>         ---P.K.S

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Scull Driver - Read
  2015-03-20  7:06   ` sahil aggarwal
@ 2015-03-20 12:42     ` sahil aggarwal
  2015-03-20 12:44       ` sahil aggarwal
  2015-03-21  8:14       ` Pranay Srivastava
  0 siblings, 2 replies; 8+ messages in thread
From: sahil aggarwal @ 2015-03-20 12:42 UTC (permalink / raw)
  To: kernelnewbies

Hi Pranay,

Can you help me with this too.? In case of _IOC_READ why VERIFY_WRITE
and in case of _IOC_WRITE why VERIFY_READ.? . Book says its kernel
oriented so concept of read and write is reversed.

if(_IOC_DIR(cmd) & _IOC_READ)
         err = !access_ok(VERIFY_WRITE, (void __user*)arg, _IOC_SIZE(cmd));
else if(_IOC_DIR(cmd) & _IOC_WRITE)
         err = !access_ok(VERIFY_READ, (void __user*)arg, _IOC_SIZE(cmd));
if(err)
return -EFAULT;

Thanks
Regards






On 20 March 2015 at 12:36, sahil aggarwal <sahil.agg15@gmail.com> wrote:
> Hi Pranay
>
> Well explained.
>
> Thank you.
>
> On 20 March 2015 at 11:46, Pranay Srivastava <pranjas@gmail.com> wrote:
>> Hi Sahil
>>
>> On Sun, Mar 15, 2015 at 10:17 AM, sahil aggarwal <sahil.agg15@gmail.com> wrote:
>>> hi all,
>>>
>>> Going through scull driver code, i see read function reads only till
>>> end of 1 quantum, so do kernel call read multiple times if count from
>>> q_pos exceeds quantum size limit.?
>>>
>>>
>>> Ref: ldd3.
>>>
>>> if(count > quantum - q_pos)
>>> count = quantum - q_pos;
>>> if(copy_to_user(buf, dptr->data[s_pos] + q_pos,count)){
>>> retval = -EFAULT;
>>> goto out;
>>> }
>>
>> If you are not using the default read/write routines, then its up to
>> you to code that.
>>
>> Kernel doesn't do multiple read calls. It'll do only what you asked it
>> for no more but it can do less. For example, a file is say 100 KiB and
>> you are reading say 4KiB in a loop when do you stop?
>>
>> Simply put it's the user space application which is doing the looping
>> and repeatedly doing read calls because it assumes that file isn't
>> finished.
>>
>> So again when do you stop reading from the file, without knowing size
>> of the file.?
>>
>>> *f_pos += count;
>>> retval = count;
>>>
>>> Thanks
>>> Regards
>>>
>>> _______________________________________________
>>> Kernelnewbies mailing list
>>> Kernelnewbies at kernelnewbies.org
>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>>
>>
>> --
>>         ---P.K.S

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Scull Driver - Read
  2015-03-20 12:42     ` sahil aggarwal
@ 2015-03-20 12:44       ` sahil aggarwal
  2015-03-21  8:15         ` Pranay Srivastava
  2015-03-21  8:14       ` Pranay Srivastava
  1 sibling, 1 reply; 8+ messages in thread
From: sahil aggarwal @ 2015-03-20 12:44 UTC (permalink / raw)
  To: kernelnewbies

Does it mean that in kernel space the direction bitfields are reversed.?

On 20 March 2015 at 18:12, sahil aggarwal <sahil.agg15@gmail.com> wrote:
> Hi Pranay,
>
> Can you help me with this too.? In case of _IOC_READ why VERIFY_WRITE
> and in case of _IOC_WRITE why VERIFY_READ.? . Book says its kernel
> oriented so concept of read and write is reversed.
>
> if(_IOC_DIR(cmd) & _IOC_READ)
>          err = !access_ok(VERIFY_WRITE, (void __user*)arg, _IOC_SIZE(cmd));
> else if(_IOC_DIR(cmd) & _IOC_WRITE)
>          err = !access_ok(VERIFY_READ, (void __user*)arg, _IOC_SIZE(cmd));
> if(err)
> return -EFAULT;
>
> Thanks
> Regards
>
>
>
>
>
>
> On 20 March 2015 at 12:36, sahil aggarwal <sahil.agg15@gmail.com> wrote:
>> Hi Pranay
>>
>> Well explained.
>>
>> Thank you.
>>
>> On 20 March 2015 at 11:46, Pranay Srivastava <pranjas@gmail.com> wrote:
>>> Hi Sahil
>>>
>>> On Sun, Mar 15, 2015 at 10:17 AM, sahil aggarwal <sahil.agg15@gmail.com> wrote:
>>>> hi all,
>>>>
>>>> Going through scull driver code, i see read function reads only till
>>>> end of 1 quantum, so do kernel call read multiple times if count from
>>>> q_pos exceeds quantum size limit.?
>>>>
>>>>
>>>> Ref: ldd3.
>>>>
>>>> if(count > quantum - q_pos)
>>>> count = quantum - q_pos;
>>>> if(copy_to_user(buf, dptr->data[s_pos] + q_pos,count)){
>>>> retval = -EFAULT;
>>>> goto out;
>>>> }
>>>
>>> If you are not using the default read/write routines, then its up to
>>> you to code that.
>>>
>>> Kernel doesn't do multiple read calls. It'll do only what you asked it
>>> for no more but it can do less. For example, a file is say 100 KiB and
>>> you are reading say 4KiB in a loop when do you stop?
>>>
>>> Simply put it's the user space application which is doing the looping
>>> and repeatedly doing read calls because it assumes that file isn't
>>> finished.
>>>
>>> So again when do you stop reading from the file, without knowing size
>>> of the file.?
>>>
>>>> *f_pos += count;
>>>> retval = count;
>>>>
>>>> Thanks
>>>> Regards
>>>>
>>>> _______________________________________________
>>>> Kernelnewbies mailing list
>>>> Kernelnewbies at kernelnewbies.org
>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
>>>
>>>
>>> --
>>>         ---P.K.S

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Scull Driver - Read
  2015-03-20 12:42     ` sahil aggarwal
  2015-03-20 12:44       ` sahil aggarwal
@ 2015-03-21  8:14       ` Pranay Srivastava
  1 sibling, 0 replies; 8+ messages in thread
From: Pranay Srivastava @ 2015-03-21  8:14 UTC (permalink / raw)
  To: kernelnewbies

Hi Sahil

On Fri, Mar 20, 2015 at 6:12 PM, sahil aggarwal <sahil.agg15@gmail.com> wrote:
> Hi Pranay,
>
> Can you help me with this too.? In case of _IOC_READ why VERIFY_WRITE
> and in case of _IOC_WRITE why VERIFY_READ.? . Book says its kernel
> oriented so concept of read and write is reversed.
>
> if(_IOC_DIR(cmd) & _IOC_READ)
>          err = !access_ok(VERIFY_WRITE, (void __user*)arg, _IOC_SIZE(cmd));

Here you are asking IOCTL would be returning data from kernel. From a
user space perspective when you do a read then kernel will do a write
to the user land address space. You can ofcourse pass an invalid
pointer (maybe that pointer becomes invalid by the time you are doing
ioctl. So kernel checks this before returning any values to you.

> else if(_IOC_DIR(cmd) & _IOC_WRITE)
>          err = !access_ok(VERIFY_READ, (void __user*)arg, _IOC_SIZE(cmd));

Similarly here, write from user land would mean kernel will read from
that. I hope this clears it.

> if(err)
> return -EFAULT;
>
> Thanks
> Regards
>
>
>
>
>
>
> On 20 March 2015 at 12:36, sahil aggarwal <sahil.agg15@gmail.com> wrote:
>> Hi Pranay
>>
>> Well explained.
>>
>> Thank you.
>>
>> On 20 March 2015 at 11:46, Pranay Srivastava <pranjas@gmail.com> wrote:
>>> Hi Sahil
>>>
>>> On Sun, Mar 15, 2015 at 10:17 AM, sahil aggarwal <sahil.agg15@gmail.com> wrote:
>>>> hi all,
>>>>
>>>> Going through scull driver code, i see read function reads only till
>>>> end of 1 quantum, so do kernel call read multiple times if count from
>>>> q_pos exceeds quantum size limit.?
>>>>
>>>>
>>>> Ref: ldd3.
>>>>
>>>> if(count > quantum - q_pos)
>>>> count = quantum - q_pos;
>>>> if(copy_to_user(buf, dptr->data[s_pos] + q_pos,count)){
>>>> retval = -EFAULT;
>>>> goto out;
>>>> }
>>>
>>> If you are not using the default read/write routines, then its up to
>>> you to code that.
>>>
>>> Kernel doesn't do multiple read calls. It'll do only what you asked it
>>> for no more but it can do less. For example, a file is say 100 KiB and
>>> you are reading say 4KiB in a loop when do you stop?
>>>
>>> Simply put it's the user space application which is doing the looping
>>> and repeatedly doing read calls because it assumes that file isn't
>>> finished.
>>>
>>> So again when do you stop reading from the file, without knowing size
>>> of the file.?
>>>
>>>> *f_pos += count;
>>>> retval = count;
>>>>
>>>> Thanks
>>>> Regards
>>>>
>>>> _______________________________________________
>>>> Kernelnewbies mailing list
>>>> Kernelnewbies at kernelnewbies.org
>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
>>>
>>>
>>> --
>>>         ---P.K.S



-- 
        ---P.K.S

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Scull Driver - Read
  2015-03-20 12:44       ` sahil aggarwal
@ 2015-03-21  8:15         ` Pranay Srivastava
  2015-03-21 15:34           ` sahil aggarwal
  0 siblings, 1 reply; 8+ messages in thread
From: Pranay Srivastava @ 2015-03-21  8:15 UTC (permalink / raw)
  To: kernelnewbies

Hi Sahil

On Fri, Mar 20, 2015 at 6:14 PM, sahil aggarwal <sahil.agg15@gmail.com> wrote:
> Does it mean that in kernel space the direction bitfields are reversed.?

No it doesn't mean that.

>
> On 20 March 2015 at 18:12, sahil aggarwal <sahil.agg15@gmail.com> wrote:
>> Hi Pranay,
>>
>> Can you help me with this too.? In case of _IOC_READ why VERIFY_WRITE
>> and in case of _IOC_WRITE why VERIFY_READ.? . Book says its kernel
>> oriented so concept of read and write is reversed.
>>
>> if(_IOC_DIR(cmd) & _IOC_READ)
>>          err = !access_ok(VERIFY_WRITE, (void __user*)arg, _IOC_SIZE(cmd));
>> else if(_IOC_DIR(cmd) & _IOC_WRITE)
>>          err = !access_ok(VERIFY_READ, (void __user*)arg, _IOC_SIZE(cmd));
>> if(err)
>> return -EFAULT;
>>
>> Thanks
>> Regards
>>
>>
>>
>>
>>
>>
>> On 20 March 2015 at 12:36, sahil aggarwal <sahil.agg15@gmail.com> wrote:
>>> Hi Pranay
>>>
>>> Well explained.
>>>
>>> Thank you.
>>>
>>> On 20 March 2015 at 11:46, Pranay Srivastava <pranjas@gmail.com> wrote:
>>>> Hi Sahil
>>>>
>>>> On Sun, Mar 15, 2015 at 10:17 AM, sahil aggarwal <sahil.agg15@gmail.com> wrote:
>>>>> hi all,
>>>>>
>>>>> Going through scull driver code, i see read function reads only till
>>>>> end of 1 quantum, so do kernel call read multiple times if count from
>>>>> q_pos exceeds quantum size limit.?
>>>>>
>>>>>
>>>>> Ref: ldd3.
>>>>>
>>>>> if(count > quantum - q_pos)
>>>>> count = quantum - q_pos;
>>>>> if(copy_to_user(buf, dptr->data[s_pos] + q_pos,count)){
>>>>> retval = -EFAULT;
>>>>> goto out;
>>>>> }
>>>>
>>>> If you are not using the default read/write routines, then its up to
>>>> you to code that.
>>>>
>>>> Kernel doesn't do multiple read calls. It'll do only what you asked it
>>>> for no more but it can do less. For example, a file is say 100 KiB and
>>>> you are reading say 4KiB in a loop when do you stop?
>>>>
>>>> Simply put it's the user space application which is doing the looping
>>>> and repeatedly doing read calls because it assumes that file isn't
>>>> finished.
>>>>
>>>> So again when do you stop reading from the file, without knowing size
>>>> of the file.?
>>>>
>>>>> *f_pos += count;
>>>>> retval = count;
>>>>>
>>>>> Thanks
>>>>> Regards
>>>>>
>>>>> _______________________________________________
>>>>> Kernelnewbies mailing list
>>>>> Kernelnewbies at kernelnewbies.org
>>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>>
>>>>
>>>>
>>>> --
>>>>         ---P.K.S



-- 
        ---P.K.S

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Scull Driver - Read
  2015-03-21  8:15         ` Pranay Srivastava
@ 2015-03-21 15:34           ` sahil aggarwal
  0 siblings, 0 replies; 8+ messages in thread
From: sahil aggarwal @ 2015-03-21 15:34 UTC (permalink / raw)
  To: kernelnewbies

Hi Pranay

Thanks a lot. That cleared it all.



On 21 March 2015 at 13:45, Pranay Srivastava <pranjas@gmail.com> wrote:
> Hi Sahil
>
> On Fri, Mar 20, 2015 at 6:14 PM, sahil aggarwal <sahil.agg15@gmail.com> wrote:
>> Does it mean that in kernel space the direction bitfields are reversed.?
>
> No it doesn't mean that.
>
>>
>> On 20 March 2015 at 18:12, sahil aggarwal <sahil.agg15@gmail.com> wrote:
>>> Hi Pranay,
>>>
>>> Can you help me with this too.? In case of _IOC_READ why VERIFY_WRITE
>>> and in case of _IOC_WRITE why VERIFY_READ.? . Book says its kernel
>>> oriented so concept of read and write is reversed.
>>>
>>> if(_IOC_DIR(cmd) & _IOC_READ)
>>>          err = !access_ok(VERIFY_WRITE, (void __user*)arg, _IOC_SIZE(cmd));
>>> else if(_IOC_DIR(cmd) & _IOC_WRITE)
>>>          err = !access_ok(VERIFY_READ, (void __user*)arg, _IOC_SIZE(cmd));
>>> if(err)
>>> return -EFAULT;
>>>
>>> Thanks
>>> Regards
>>>
>>>
>>>
>>>
>>>
>>>
>>> On 20 March 2015 at 12:36, sahil aggarwal <sahil.agg15@gmail.com> wrote:
>>>> Hi Pranay
>>>>
>>>> Well explained.
>>>>
>>>> Thank you.
>>>>
>>>> On 20 March 2015 at 11:46, Pranay Srivastava <pranjas@gmail.com> wrote:
>>>>> Hi Sahil
>>>>>
>>>>> On Sun, Mar 15, 2015 at 10:17 AM, sahil aggarwal <sahil.agg15@gmail.com> wrote:
>>>>>> hi all,
>>>>>>
>>>>>> Going through scull driver code, i see read function reads only till
>>>>>> end of 1 quantum, so do kernel call read multiple times if count from
>>>>>> q_pos exceeds quantum size limit.?
>>>>>>
>>>>>>
>>>>>> Ref: ldd3.
>>>>>>
>>>>>> if(count > quantum - q_pos)
>>>>>> count = quantum - q_pos;
>>>>>> if(copy_to_user(buf, dptr->data[s_pos] + q_pos,count)){
>>>>>> retval = -EFAULT;
>>>>>> goto out;
>>>>>> }
>>>>>
>>>>> If you are not using the default read/write routines, then its up to
>>>>> you to code that.
>>>>>
>>>>> Kernel doesn't do multiple read calls. It'll do only what you asked it
>>>>> for no more but it can do less. For example, a file is say 100 KiB and
>>>>> you are reading say 4KiB in a loop when do you stop?
>>>>>
>>>>> Simply put it's the user space application which is doing the looping
>>>>> and repeatedly doing read calls because it assumes that file isn't
>>>>> finished.
>>>>>
>>>>> So again when do you stop reading from the file, without knowing size
>>>>> of the file.?
>>>>>
>>>>>> *f_pos += count;
>>>>>> retval = count;
>>>>>>
>>>>>> Thanks
>>>>>> Regards
>>>>>>
>>>>>> _______________________________________________
>>>>>> Kernelnewbies mailing list
>>>>>> Kernelnewbies at kernelnewbies.org
>>>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>         ---P.K.S
>
>
>
> --
>         ---P.K.S

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-03-21 15:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-15  4:47 Scull Driver - Read sahil aggarwal
2015-03-20  6:16 ` Pranay Srivastava
2015-03-20  7:06   ` sahil aggarwal
2015-03-20 12:42     ` sahil aggarwal
2015-03-20 12:44       ` sahil aggarwal
2015-03-21  8:15         ` Pranay Srivastava
2015-03-21 15:34           ` sahil aggarwal
2015-03-21  8:14       ` Pranay Srivastava

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.