Re: Scull Driver - Read

2015-03-21 Thread sahil aggarwal
Hi Pranay

Thanks a lot. That cleared it all.



On 21 March 2015 at 13:45, Pranay Srivastava  wrote:
> Hi Sahil
>
> On Fri, Mar 20, 2015 at 6:14 PM, sahil aggarwal  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  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  wrote:
 Hi Pranay

 Well explained.

 Thank you.

 On 20 March 2015 at 11:46, Pranay Srivastava  wrote:
> Hi Sahil
>
> On Sun, Mar 15, 2015 at 10:17 AM, sahil aggarwal  
> 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@kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
>
> --
> ---P.K.S
>
>
>
> --
> ---P.K.S

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Scull Driver - Read

2015-03-21 Thread Pranay Srivastava
Hi Sahil

On Fri, Mar 20, 2015 at 6:14 PM, sahil aggarwal  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  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  wrote:
>>> Hi Pranay
>>>
>>> Well explained.
>>>
>>> Thank you.
>>>
>>> On 20 March 2015 at 11:46, Pranay Srivastava  wrote:
 Hi Sahil

 On Sun, Mar 15, 2015 at 10:17 AM, sahil aggarwal  
 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@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



 --
 ---P.K.S



-- 
---P.K.S

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Scull Driver - Read

2015-03-21 Thread Pranay Srivastava
Hi Sahil

On Fri, Mar 20, 2015 at 6:12 PM, sahil aggarwal  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  wrote:
>> Hi Pranay
>>
>> Well explained.
>>
>> Thank you.
>>
>> On 20 March 2015 at 11:46, Pranay Srivastava  wrote:
>>> Hi Sahil
>>>
>>> On Sun, Mar 15, 2015 at 10:17 AM, sahil aggarwal  
>>> 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@kernelnewbies.org
 http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
>>>
>>>
>>> --
>>> ---P.K.S



-- 
---P.K.S

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Scull Driver - Read

2015-03-20 Thread sahil aggarwal
Does it mean that in kernel space the direction bitfields are reversed.?

On 20 March 2015 at 18:12, sahil aggarwal  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  wrote:
>> Hi Pranay
>>
>> Well explained.
>>
>> Thank you.
>>
>> On 20 March 2015 at 11:46, Pranay Srivastava  wrote:
>>> Hi Sahil
>>>
>>> On Sun, Mar 15, 2015 at 10:17 AM, sahil aggarwal  
>>> 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@kernelnewbies.org
 http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
>>>
>>>
>>> --
>>> ---P.K.S

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Scull Driver - Read

2015-03-20 Thread sahil aggarwal
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  wrote:
> Hi Pranay
>
> Well explained.
>
> Thank you.
>
> On 20 March 2015 at 11:46, Pranay Srivastava  wrote:
>> Hi Sahil
>>
>> On Sun, Mar 15, 2015 at 10:17 AM, sahil aggarwal  
>> 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@kernelnewbies.org
>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>>
>>
>> --
>> ---P.K.S

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Scull Driver - Read

2015-03-20 Thread sahil aggarwal
Hi Pranay

Well explained.

Thank you.

On 20 March 2015 at 11:46, Pranay Srivastava  wrote:
> Hi Sahil
>
> On Sun, Mar 15, 2015 at 10:17 AM, sahil aggarwal  
> 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@kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
>
> --
> ---P.K.S

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Scull Driver - Read

2015-03-19 Thread Pranay Srivastava
Hi Sahil

On Sun, Mar 15, 2015 at 10:17 AM, sahil aggarwal  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@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



-- 
---P.K.S

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Scull Driver - Read

2015-03-14 Thread sahil aggarwal
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

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies