2011-04-26 11:58:01

by Amit Ben Shahar

[permalink] [raw]
Subject: Why is the 'loff_t *offset' parameter in the file_operations' read function a pointer?

(if i'm off topic or should look elsewhere i apologize - couldn't find
information anywhere)
I am coding a kernel module and implementing a file's operations, the
read operation received an loff_t *offset parameter, why is this a
pointer? is it in userspace?


2011-04-26 12:31:03

by Jiri Slaby

[permalink] [raw]
Subject: Re: Why is the 'loff_t *offset' parameter in the file_operations' read function a pointer?

On 04/26/2011 01:58 PM, Amit Ben Shahar wrote:
> (if i'm off topic or should look elsewhere i apologize - couldn't find
> information anywhere)
> I am coding a kernel module and implementing a file's operations, the
> read operation received an loff_t *offset parameter, why is this a
> pointer?

Because you are responsible for changing it appropriately.

> is it in userspace?

Nope, in kernelspace.

I think this is described in LDD3, isn't it?

regards,
--
js

2011-04-26 12:38:02

by Arnd Bergmann

[permalink] [raw]
Subject: Re: Why is the 'loff_t *offset' parameter in the file_operations' read function a pointer?

On Tuesday 26 April 2011, Amit Ben Shahar wrote:
> (if i'm off topic or should look elsewhere i apologize - couldn't find
> information anywhere)
> I am coding a kernel module and implementing a file's operations, the
> read operation received an loff_t *offset parameter, why is this a
> pointer? is it in userspace?

The read function must update the offset independent of the return value.
See simple_read_from_buffer() as an example.

Arnd

2011-04-26 12:55:12

by Amit Ben Shahar

[permalink] [raw]
Subject: Re: Why is the 'loff_t *offset' parameter in the file_operations' read function a pointer?

> The read function must update the offset independent of the return value.
> See simple_read_from_buffer() as an example.

Thank you - that helped greatly and solved my problem.
Amit.