Scull Driver - Read
Pranay Srivastava
pranjas at gmail.com
Sat Mar 21 04:14:55 EDT 2015
Hi Sahil
On Fri, Mar 20, 2015 at 6:12 PM, sahil aggarwal <sahil.agg15 at 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 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
--
---P.K.S
More information about the Kernelnewbies
mailing list