Scull Driver - Read

sahil aggarwal sahil.agg15 at gmail.com
Fri Mar 20 08:42:35 EDT 2015


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 at gmail.com> wrote:
> Hi Pranay
>
> Well explained.
>
> Thank you.
>
> On 20 March 2015 at 11:46, Pranay Srivastava <pranjas at gmail.com> wrote:
>> Hi Sahil
>>
>> On Sun, Mar 15, 2015 at 10:17 AM, sahil aggarwal <sahil.agg15 at 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



More information about the Kernelnewbies mailing list